From 1aa7218a1f779ba70eeaec9c6d8997975f3abd0f Mon Sep 17 00:00:00 2001 From: Sviatoslav Peleshko Date: Tue, 10 Sep 2024 01:01:08 +0300 Subject: [PATCH] mesa: Reset vbo attributes after flushing them to Current in glPopAttrib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: 2fe771f4 ("vbo: use FlushVertices flags properly and clear NeedFlush correctly") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11498 Signed-off-by: Sviatoslav Peleshko Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/attrib.c | 8 ++++++-- src/mesa/vbo/vbo.h | 3 +++ src/mesa/vbo/vbo_exec_api.c | 16 +++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index 3d960f962d4..1a045a36b78 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -682,10 +682,14 @@ _mesa_PopAttrib(void) unsigned mask = attr->Mask; /* Flush current attribs. This must be done before PopAttribState is - * applied. + * applied. Also reset the attributes stored in vbo, as after this we'll + * change Current directly, and these changed values would've been then + * overridden by another flush in the future. */ - if (mask & GL_CURRENT_BIT) + if ((mask & GL_CURRENT_BIT) && ctx->Driver.NeedFlush) { FLUSH_CURRENT(ctx, 0); + vbo_reset_all_attr(ctx); + } /* Only restore states that have been changed since glPushAttrib. */ mask &= ctx->PopAttribState; diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h index f11824cdaa4..ecc326840d9 100644 --- a/src/mesa/vbo/vbo.h +++ b/src/mesa/vbo/vbo.h @@ -202,6 +202,9 @@ vbo_install_save_vtxfmt_noop(struct gl_context *ctx); void vbo_exec_update_eval_maps(struct gl_context *ctx); +void +vbo_reset_all_attr(struct gl_context *ctx); + void vbo_exec_FlushVertices(struct gl_context *ctx, GLuint flags); diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c index be79ce9ef61..5c7da0483fc 100644 --- a/src/mesa/vbo/vbo_exec_api.c +++ b/src/mesa/vbo/vbo_exec_api.c @@ -51,10 +51,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #define IMM_BUFFER_NAME 0xaabbccdd -static void -vbo_reset_all_attr(struct vbo_exec_context *exec); - - /** * Close off the last primitive, execute the buffer, restart the * primitive. This is called when we fill a vertex buffer before @@ -294,7 +290,7 @@ vbo_exec_wrap_upgrade_vertex(struct vbo_exec_context *exec, if (!_mesa_inside_begin_end(ctx) && !oldSize && lastcount > 8 && exec->vtx.vertex_size) { vbo_exec_copy_to_current(exec); - vbo_reset_all_attr(exec); + vbo_reset_all_attr(ctx); } /* Fix up sizes: @@ -695,7 +691,7 @@ vbo_exec_FlushVertices_internal(struct vbo_exec_context *exec, unsigned flags) if (exec->vtx.vertex_size) { vbo_exec_copy_to_current(exec); - vbo_reset_all_attr(exec); + vbo_reset_all_attr(ctx); } /* All done. */ @@ -1105,9 +1101,11 @@ vbo_init_dispatch_begin_end(struct gl_context *ctx) } -static void -vbo_reset_all_attr(struct vbo_exec_context *exec) +void +vbo_reset_all_attr(struct gl_context *ctx) { + struct vbo_exec_context *exec = &vbo_context(ctx)->exec; + while (exec->vtx.enabled) { const int i = u_bit_scan64(&exec->vtx.enabled); @@ -1130,7 +1128,7 @@ vbo_exec_vtx_init(struct vbo_exec_context *exec) exec->vtx.bufferobj = _mesa_bufferobj_alloc(ctx, IMM_BUFFER_NAME); exec->vtx.enabled = u_bit_consecutive64(0, VBO_ATTRIB_MAX); /* reset all */ - vbo_reset_all_attr(exec); + vbo_reset_all_attr(ctx); exec->vtx.info.instance_count = 1; exec->vtx.info.max_index = ~0;