iris: inherit the index buffer properly
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 21 Sep 2018 00:27:47 +0000 (17:27 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 21 Feb 2019 18:26:08 +0000 (10:26 -0800)
src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_state.c

index 31433a534d8c584055fe083db6762713072f3e4b..9f847136937a407d8f82a286e33611c12d2d7986 100644 (file)
@@ -407,6 +407,7 @@ struct iris_context {
          struct pipe_resource *color_calc;
          struct pipe_resource *scissor;
          struct pipe_resource *blend;
+         struct pipe_resource *index_buffer;
       } last_res;
    } state;
 };
index 09360545ea3524900f3c4553b3b025ebec19bf8e..0abd0fd2f02aff05fd5ac055ad84e5bd2d6ca9c7 100644 (file)
@@ -3344,8 +3344,12 @@ iris_restore_context_saved_bos(struct iris_context *ice,
       }
    }
 
-   if (draw->index_size > 0) {
-      // XXX: index buffer
+   if (draw->index_size == 0 && ice->state.last_res.index_buffer) {
+      /* This draw didn't emit a new index buffer, so we are inheriting the
+       * older index buffer.  This draw didn't need it, but future ones may.
+       */
+      struct iris_bo *bo = iris_resource_bo(ice->state.last_res.index_buffer);
+      iris_use_pinned_bo(batch, bo, false);
    }
 
    if (clean & IRIS_DIRTY_VERTEX_BUFFERS) {
@@ -3845,23 +3849,25 @@ iris_upload_render_state(struct iris_context *ice,
    iris_upload_dirty_render_state(ice, batch, draw);
 
    if (draw->index_size > 0) {
-      struct iris_resource *res = NULL;
       unsigned offset;
 
       if (draw->has_user_indices) {
          u_upload_data(ice->ctx.stream_uploader, 0,
                        draw->count * draw->index_size, 4, draw->index.user,
-                       &offset, (struct pipe_resource **) &res);
+                       &offset, &ice->state.last_res.index_buffer);
       } else {
-         res = (struct iris_resource *) draw->index.resource;
+         pipe_resource_reference(&ice->state.last_res.index_buffer,
+                                 draw->index.resource);
          offset = 0;
       }
 
+      struct iris_bo *bo = iris_resource_bo(ice->state.last_res.index_buffer);
+
       iris_emit_cmd(batch, GENX(3DSTATE_INDEX_BUFFER), ib) {
          ib.IndexFormat = draw->index_size >> 1;
          ib.MOCS = MOCS_WB;
-         ib.BufferSize = res->bo->size;
-         ib.BufferStartingAddress = ro_bo(res->bo, offset);
+         ib.BufferSize = bo->size;
+         ib.BufferStartingAddress = ro_bo(bo, offset);
       }
    }
 
@@ -3963,6 +3969,7 @@ iris_destroy_state(struct iris_context *ice)
    pipe_resource_reference(&ice->state.last_res.color_calc, NULL);
    pipe_resource_reference(&ice->state.last_res.scissor, NULL);
    pipe_resource_reference(&ice->state.last_res.blend, NULL);
+   pipe_resource_reference(&ice->state.last_res.index_buffer, NULL);
 }
 
 /* ------------------------------------------------------------------- */