From 1d15dc04b5dcbe13c0acd182d805946f0856b7b1 Mon Sep 17 00:00:00 2001 From: Illia Polishchuk Date: Mon, 12 Sep 2022 10:36:17 +0300 Subject: [PATCH] mesa: skip extra state updates for clear calls MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The glClear call updates draw state in the same way as other draw calls with _mesa_update_state func If currently used shader uses textures, _mesa_update_state will try to update the shader texture state But if the texture not set yet, before glClear call, it will detect incompleted texture and will create dummy texture with default values (see the update_single_program_texture func). And this will be complete waste of time for glClear Closes: #7128 Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/clear.c | 12 ++++++------ src/mesa/main/state.c | 17 +++++++++++++++++ src/mesa/main/state.h | 6 ++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/mesa/main/clear.c b/src/mesa/main/clear.c index 447170f..611b406 100644 --- a/src/mesa/main/clear.c +++ b/src/mesa/main/clear.c @@ -140,7 +140,7 @@ color_buffer_writes_enabled(const struct gl_context *ctx, unsigned idx) * \param mask bit-mask indicating the buffers to be cleared. * * Flushes the vertices and verifies the parameter. - * If __struct gl_contextRec::NewState is set then calls _mesa_update_state() + * If __struct gl_contextRec::NewState is set then calls _mesa_update_clear_state() * to update gl_frame_buffer::_Xmin, etc. If the rasterization mode is set to * GL_RENDER then requests the driver to clear the buffers, via the * dd_function_table::Clear callback. @@ -170,7 +170,7 @@ clear(struct gl_context *ctx, GLbitfield mask, bool no_error) } if (ctx->NewState) { - _mesa_update_state( ctx ); /* update _Xmin, etc */ + _mesa_update_clear_state( ctx ); /* update _Xmin, etc */ } if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -349,7 +349,7 @@ clear_bufferiv(struct gl_context *ctx, GLenum buffer, GLint drawbuffer, FLUSH_VERTICES(ctx, 0, 0); if (ctx->NewState) { - _mesa_update_state( ctx ); + _mesa_update_clear_state( ctx ); } if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -468,7 +468,7 @@ clear_bufferuiv(struct gl_context *ctx, GLenum buffer, GLint drawbuffer, FLUSH_VERTICES(ctx, 0, 0); if (ctx->NewState) { - _mesa_update_state( ctx ); + _mesa_update_clear_state( ctx ); } if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE) { @@ -562,7 +562,7 @@ clear_bufferfv(struct gl_context *ctx, GLenum buffer, GLint drawbuffer, FLUSH_VERTICES(ctx, 0, 0); if (ctx->NewState) { - _mesa_update_state( ctx ); + _mesa_update_clear_state( ctx ); } if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE) { @@ -722,7 +722,7 @@ clear_bufferfi(struct gl_context *ctx, GLenum buffer, GLint drawbuffer, return; if (ctx->NewState) { - _mesa_update_state( ctx ); + _mesa_update_clear_state( ctx ); } if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 43440bc..d6133a2 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -503,6 +503,23 @@ _mesa_update_state( struct gl_context *ctx ) _mesa_unlock_context_textures(ctx); } +/* This is the usual entrypoint for state updates in glClear calls: + */ +void +_mesa_update_clear_state( struct gl_context *ctx ) +{ + GLbitfield new_state = ctx->NewState; + + if (MESA_VERBOSE & VERBOSE_STATE) + _mesa_print_state("_mesa_update_clear_state", new_state); + + if (new_state & _NEW_BUFFERS) { + _mesa_update_framebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer); + + st_invalidate_buffers(st_context(ctx)); + ctx->NewState &= ~_NEW_BUFFERS; + } +} /** * Used by drivers to tell core Mesa that the driver is going to diff --git a/src/mesa/main/state.h b/src/mesa/main/state.h index d23a348..411cbcc 100644 --- a/src/mesa/main/state.h +++ b/src/mesa/main/state.h @@ -40,6 +40,12 @@ _mesa_update_state(struct gl_context *ctx); extern void _mesa_update_state_locked(struct gl_context *ctx); +/* + * Update state for glClear calls +*/ +extern void +_mesa_update_clear_state(struct gl_context *ctx); + extern void _mesa_set_vp_override(struct gl_context *ctx, GLboolean flag); -- 2.7.4