Module: Mesa
Branch: main
Commit: 7a1d3d3abc5366ea75e2b159cd2e46c4b7ea815c
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7a1d3d3abc5366ea75e2b159cd2e46c4b7ea815c

Author: Pierre-Eric Pelloux-Prayer <[email protected]>
Date:   Thu Dec 16 17:44:20 2021 +0100

vbo/dlist: fix loopback crash

The original code incorrectly adjusted only when Loopback
was false, while primitives' start value is actually
modified unconditionnally.

Fixes: 32535942680 ("vbo/dlist: rework buffer sizes")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5754
Acked-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14243>

---

 src/mesa/vbo/vbo_save_api.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index ec5c98d8a4b..bae9fd6ad0c 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -834,12 +834,14 @@ compile_vertex_list(struct gl_context *ctx)
       free(temp_vertices_buffer);
    }
 
-   /* Since we're append the indices to an existing buffer, we need to adjust 
the start value of each
+   /* Since we append the indices to an existing buffer, we need to adjust the 
start value of each
     * primitive (not the indices themselves). */
-   save->current_bo_bytes_used += align(save->current_bo_bytes_used, 4) - 
save->current_bo_bytes_used;
-   int indices_offset = save->current_bo_bytes_used / 4;
-   for (int i = 0; i < merged_prim_count; i++) {
-      merged_prims[i].start += indices_offset;
+   if (!ctx->ListState.Current.UseLoopback) {
+      save->current_bo_bytes_used += align(save->current_bo_bytes_used, 4) - 
save->current_bo_bytes_used;
+      int indices_offset = save->current_bo_bytes_used / 4;
+      for (int i = 0; i < merged_prim_count; i++) {
+         merged_prims[i].start += indices_offset;
+      }
    }
 
    /* Then upload the indices. */
@@ -956,20 +958,16 @@ end:
       _glapi_set_dispatch(ctx->Exec);
 
       /* _vbo_loopback_vertex_list doesn't use the index buffer, so we have to
-       * use buffer_in_ram instead of current_bo which contains all vertices 
instead
-       * of the deduplicated vertices only in the !UseLoopback case.
+       * use buffer_in_ram (which contains all vertices) instead of current_bo
+       * (which contains deduplicated vertices *when* UseLoopback is false).
        *
        * The problem is that the VAO offset is based on current_bo's layout,
        * so we have to use a temp value.
        */
       struct gl_vertex_array_object *vao = node->cold->VAO[VP_MODE_SHADER];
       GLintptr original = vao->BufferBinding[0].Offset;
-      if (!ctx->ListState.Current.UseLoopback) {
-         GLintptr new_offset = 0;
-         /* 'start_offset' has been added to all primitives 'start', so undo 
it here. */
-         new_offset -= start_offset * stride;
-         vao->BufferBinding[0].Offset = new_offset;
-      }
+      /* 'start_offset' has been added to all primitives 'start', so undo it 
here. */
+      vao->BufferBinding[0].Offset = -(GLintptr)(start_offset * stride);
       _vbo_loopback_vertex_list(ctx, node, save->vertex_store->buffer_in_ram);
       vao->BufferBinding[0].Offset = original;
 

Reply via email to