crocus: fixup index buffer dirtying.
authorDave Airlie <airlied@redhat.com>
Mon, 5 Jul 2021 02:45:13 +0000 (12:45 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 5 Jul 2021 02:45:13 +0000 (12:45 +1000)
This fixes a possible problem if a non-indexed draw comes in first
in a new batch, then the batch might not emit the index buffer.

I'm unsure if we see this, I just spotted it trying to fix alacritty

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11705>

src/gallium/drivers/crocus/crocus_state.c

index df858c8..f415be4 100644 (file)
@@ -7723,13 +7723,10 @@ crocus_upload_render_state(struct crocus_context *ice,
 #if GFX_VER >= 7
    bool use_predicate = ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT;
 #endif
-   bool emit_index = false;
+
    batch->no_wrap = true;
+   batch->contains_draw = true;
 
-   if (!batch->contains_draw) {
-      emit_index = true;
-      batch->contains_draw = true;
-   }
    crocus_update_surface_base_address(batch);
 
    crocus_upload_dirty_render_state(ice, batch, draw);
@@ -7738,6 +7735,7 @@ crocus_upload_render_state(struct crocus_context *ice,
    if (draw->index_size > 0) {
       unsigned offset;
       unsigned size;
+      bool emit_index = false;
 
       if (draw->has_user_indices) {
          unsigned start_offset = draw->index_size * sc->start;
@@ -7750,9 +7748,9 @@ crocus_upload_render_state(struct crocus_context *ice,
          emit_index = true;
       } else {
          struct crocus_resource *res = (void *) draw->index.resource;
-         res->bind_history |= PIPE_BIND_INDEX_BUFFER;
 
          if (ice->state.index_buffer.res != draw->index.resource) {
+            res->bind_history |= PIPE_BIND_INDEX_BUFFER;
             pipe_resource_reference(&ice->state.index_buffer.res,
                                     draw->index.resource);
             emit_index = true;
@@ -8990,6 +8988,9 @@ crocus_state_finish_batch(struct crocus_batch *batch)
 static void
 crocus_batch_reset_dirty(struct crocus_batch *batch)
 {
+   /* unreference any index buffer so it get reemitted. */
+   pipe_resource_reference(&batch->ice->state.index_buffer.res, NULL);
+
    /* for GEN4/5 need to reemit anything that ends up in the state batch that points to anything in the state batch
     * as the old state batch won't still be available.
     */