Mesa (main): mesa/bufferobj: move invalidate buffer to optional feature
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Dec 15 14:02:49 UTC 2021
Module: Mesa
Branch: main
Commit: 8c1472bc84dd6c7b55039aae3fe67248e051eb21
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8c1472bc84dd6c7b55039aae3fe67248e051eb21
Author: Dave Airlie <airlied at redhat.com>
Date: Thu Dec 9 13:57:08 2021 +1000
mesa/bufferobj: move invalidate buffer to optional feature
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14133>
---
src/mesa/main/bufferobj.c | 26 ++++++++++++++++++++++++--
src/mesa/main/mtypes.h | 1 +
src/mesa/state_tracker/st_context.c | 3 +++
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 89b158bfb51..512d2227738 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -5179,13 +5179,35 @@ _mesa_BindBuffersBase(GLenum target, GLuint first, GLsizei count,
}
}
+/**
+ * Called via glInvalidateBuffer(Sub)Data.
+ */
+static void
+bufferobj_invalidate(struct gl_context *ctx,
+ struct gl_buffer_object *obj,
+ GLintptr offset,
+ GLsizeiptr size)
+{
+ struct pipe_context *pipe = ctx->pipe;
+
+ /* We ignore partial invalidates. */
+ if (offset != 0 || size != obj->Size)
+ return;
+
+ /* If the buffer is mapped, we can't invalidate it. */
+ if (!obj->buffer || _mesa_bufferobj_mapped(obj, MAP_USER))
+ return;
+
+ pipe->invalidate_resource(pipe, obj->buffer);
+}
+
static ALWAYS_INLINE void
invalidate_buffer_subdata(struct gl_context *ctx,
struct gl_buffer_object *bufObj, GLintptr offset,
GLsizeiptr length)
{
- if (ctx->Driver.InvalidateBufferSubData)
- ctx->Driver.InvalidateBufferSubData(ctx, bufObj, offset, length);
+ if (ctx->has_invalidate_buffer)
+ bufferobj_invalidate(ctx, bufObj, offset, length);
}
void GLAPIENTRY
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 7d361ce305e..e658535321f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -5577,6 +5577,7 @@ struct gl_context
struct pipe_context *pipe;
struct st_config_options *st_opts;
struct cso_context *cso_context;
+ bool has_invalidate_buffer;
/*@}*/
/**
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 6ef02b1aa8e..f522dc3268f 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -995,6 +995,9 @@ st_create_context(gl_api api, struct pipe_context *pipe,
if (debug_get_option_mesa_mvp_dp4())
ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = GL_TRUE;
+ if (pipe->screen->get_param(pipe->screen, PIPE_CAP_INVALIDATE_BUFFER))
+ ctx->has_invalidate_buffer = true;
+
st = st_create_context_priv(ctx, pipe, options, no_error);
if (!st) {
_mesa_free_context_data(ctx, true);
More information about the mesa-commit
mailing list