iris: Use state_refs for draw parameters.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 19 Sep 2019 03:12:33 +0000 (20:12 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 19 Sep 2019 05:50:52 +0000 (22:50 -0700)
iris_state_ref is a <resource, offset> tuple, which is exactly what we
need here.

src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_draw.c
src/gallium/drivers/iris/iris_state.c

index f711398f33b82aa64bdacef1321e9e8e3e0f5f9a..ed814ee6824954f6c3deac3b1d04655739416192 100644 (file)
@@ -555,8 +555,7 @@ struct iris_context {
        * buffer or to the buffer that stures the previous values for non
        * indirect draws.
        */
-      struct pipe_resource *draw_params_res;
-      uint32_t draw_params_offset;
+      struct iris_state_ref draw_params;
 
       struct {
          /**
@@ -577,8 +576,7 @@ struct iris_context {
        * contains parameters that are not present in the indirect buffer as
        * drawid and is_indexed_draw. They will go in their own vertex element.
        */
-      struct pipe_resource *derived_draw_params_res;
-      uint32_t derived_draw_params_offset;
+      struct iris_state_ref derived_draw_params;
 
       bool is_indirect;
    } draw;
index fc2c14eab7f7f4fc9c67bb6c56958ff8ac4f4466..005da3f7a6d7143d5bf4ff460450fcd001872f00 100644 (file)
@@ -114,9 +114,9 @@ iris_update_draw_parameters(struct iris_context *ice,
                             const struct pipe_draw_info *info)
 {
    if (info->indirect) {
-      pipe_resource_reference(&ice->draw.draw_params_res,
+      pipe_resource_reference(&ice->draw.draw_params.res,
                               info->indirect->buffer);
-      ice->draw.draw_params_offset = info->indirect->offset +
+      ice->draw.draw_params.offset = info->indirect->offset +
                                      (info->index_size ? 12 : 8);
       ice->draw.params.firstvertex = 0;
       ice->draw.params.baseinstance = 0;
@@ -127,8 +127,8 @@ iris_update_draw_parameters(struct iris_context *ice,
               ice->draw.params.firstvertex !=
               (info->index_size ? info->index_bias : info->start) ||
               (ice->draw.params.baseinstance != info->start_instance)) {
-      pipe_resource_reference(&ice->draw.draw_params_res, NULL);
-      ice->draw.draw_params_offset = 0;
+      pipe_resource_reference(&ice->draw.draw_params.res, NULL);
+      ice->draw.draw_params.offset = 0;
       ice->draw.params.firstvertex =
          info->index_size ? info->index_bias : info->start;
       ice->draw.params.baseinstance = info->start_instance;
index ce68e998c1358dff8face873f24f8a23a99648f7..609115bce60a46c4c974c5a36c4ceebeb64d2082 100644 (file)
@@ -5293,26 +5293,26 @@ iris_upload_dirty_render_state(struct iris_context *ice,
       int dynamic_bound = ice->state.bound_vertex_buffers;
 
       if (ice->state.vs_uses_draw_params) {
-         if (ice->draw.draw_params_offset == 0) {
+         if (ice->draw.draw_params.offset == 0) {
             u_upload_data(ice->ctx.stream_uploader, 0, sizeof(ice->draw.params),
-                          4, &ice->draw.params, &ice->draw.draw_params_offset,
-                          &ice->draw.draw_params_res);
+                          4, &ice->draw.params, &ice->draw.draw_params.offset,
+                          &ice->draw.draw_params.res);
          }
-         assert(ice->draw.draw_params_res);
+         assert(ice->draw.draw_params.res);
 
          struct iris_vertex_buffer_state *state =
             &(ice->state.genx->vertex_buffers[count]);
-         pipe_resource_reference(&state->resource, ice->draw.draw_params_res);
+         pipe_resource_reference(&state->resource, ice->draw.draw_params.res);
          struct iris_resource *res = (void *) state->resource;
 
          iris_pack_state(GENX(VERTEX_BUFFER_STATE), state->state, vb) {
             vb.VertexBufferIndex = count;
             vb.AddressModifyEnable = true;
             vb.BufferPitch = 0;
-            vb.BufferSize = res->bo->size - ice->draw.draw_params_offset;
+            vb.BufferSize = res->bo->size - ice->draw.draw_params.offset;
             vb.BufferStartingAddress =
                ro_bo(NULL, res->bo->gtt_offset +
-                           (int) ice->draw.draw_params_offset);
+                           (int) ice->draw.draw_params.offset);
             vb.MOCS = mocs(res->bo);
          }
          dynamic_bound |= 1ull << count;
@@ -5323,24 +5323,24 @@ iris_upload_dirty_render_state(struct iris_context *ice,
          u_upload_data(ice->ctx.stream_uploader, 0,
                        sizeof(ice->draw.derived_params), 4,
                        &ice->draw.derived_params,
-                       &ice->draw.derived_draw_params_offset,
-                       &ice->draw.derived_draw_params_res);
+                       &ice->draw.derived_draw_params.offset,
+                       &ice->draw.derived_draw_params.res);
 
          struct iris_vertex_buffer_state *state =
             &(ice->state.genx->vertex_buffers[count]);
          pipe_resource_reference(&state->resource,
-                                 ice->draw.derived_draw_params_res);
-         struct iris_resource *res = (void *) ice->draw.derived_draw_params_res;
+                                 ice->draw.derived_draw_params.res);
+         struct iris_resource *res = (void *) ice->draw.derived_draw_params.res;
 
          iris_pack_state(GENX(VERTEX_BUFFER_STATE), state->state, vb) {
              vb.VertexBufferIndex = count;
             vb.AddressModifyEnable = true;
             vb.BufferPitch = 0;
             vb.BufferSize =
-               res->bo->size - ice->draw.derived_draw_params_offset;
+               res->bo->size - ice->draw.derived_draw_params.offset;
             vb.BufferStartingAddress =
                ro_bo(NULL, res->bo->gtt_offset +
-                           (int) ice->draw.derived_draw_params_offset);
+                           (int) ice->draw.derived_draw_params.offset);
             vb.MOCS = mocs(res->bo);
          }
          dynamic_bound |= 1ull << count;
@@ -5930,8 +5930,8 @@ iris_destroy_state(struct iris_context *ice)
 {
    struct iris_genx_state *genx = ice->state.genx;
 
-   pipe_resource_reference(&ice->draw.draw_params_res, NULL);
-   pipe_resource_reference(&ice->draw.derived_draw_params_res, NULL);
+   pipe_resource_reference(&ice->draw.draw_params.res, NULL);
+   pipe_resource_reference(&ice->draw.derived_draw_params.res, NULL);
 
    uint64_t bound_vbs = ice->state.bound_vertex_buffers;
    while (bound_vbs) {