From 8c1472bc84dd6c7b55039aae3fe67248e051eb21 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 9 Dec 2021 13:57:08 +1000 Subject: [PATCH] mesa/bufferobj: move invalidate buffer to optional feature MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák Part-of: --- 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 89b158b..512d222 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 7d361ce..e658535 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 6ef02b1..f522dc3 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); -- 2.7.4