mesa: skip extra state updates for clear calls
authorIllia Polishchuk <illia.a.polishchuk@globallogic.com>
Mon, 12 Sep 2022 07:36:17 +0000 (10:36 +0300)
committerMarge Bot <emma+marge@anholt.net>
Mon, 12 Sep 2022 15:22:51 +0000 (15:22 +0000)
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 <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18459>

src/mesa/main/clear.c
src/mesa/main/state.c
src/mesa/main/state.h

index 447170f..611b406 100644 (file)
@@ -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) {
index 43440bc..d6133a2 100644 (file)
@@ -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
index d23a348..411cbcc 100644 (file)
@@ -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);