[Mesa-dev] [PATCH 04/11] i965: Store per-stage push constant BO pointers.

Kenneth Graunke kenneth at whitecape.org
Fri Jul 7 00:22:13 UTC 2017


Right now, we always upload new push constant data, and immediately
emit 3DSTATE_CONSTANT_* packets.  We call intel_upload_space and store
the resulting BO pointer in brw->curbe.curbe_bo.  We read that when
emitting the packets.  This works today, but is fragile - it depends on
upload and packet emission being interleaved.

If we instead were to upload all the data, then emit all the packets,
then upload BO wrapping will get us into trouble.  For example, the VS
constants may land in one upload BO, but the FS constants may not fit
and land in a second upload BO.  Uploading FS constants would overwrite
the brw->curbe.curbe_bo pointer, so when we emitted 3DSTATE_CONSTANT_VS,
we'd get the wrong BO.

I intend to separate out this code in a future commit, so I need to fix
this.  To fix it, we simply store a per-stage BO pointer.
---
 src/mesa/drivers/dri/i965/brw_context.h         | 3 ++-
 src/mesa/drivers/dri/i965/gen6_constant_state.c | 3 ++-
 src/mesa/drivers/dri/i965/genX_state_upload.c   | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 817396dddf6..9587c74304d 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -552,7 +552,8 @@ struct brw_stage_state
    /** Offset in the batchbuffer to Gen4-5 pipelined state (VS/WM/GS_STATE). */
    uint32_t state_offset;
 
-   uint32_t push_const_offset; /* Offset in the batchbuffer */
+   struct brw_bo *push_const_bo; /* NULL if using the batchbuffer */
+   uint32_t push_const_offset; /* Offset in the push constant BO or batch */
    int push_const_size; /* in 256-bit register increments */
 
    /* Binding table: pointers to SURFACE_STATE entries. */
diff --git a/src/mesa/drivers/dri/i965/gen6_constant_state.c b/src/mesa/drivers/dri/i965/gen6_constant_state.c
index f3927c5dba2..920f502ca37 100644
--- a/src/mesa/drivers/dri/i965/gen6_constant_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_constant_state.c
@@ -65,7 +65,8 @@ gen6_upload_push_constants(struct brw_context *brw,
       const int size = prog_data->nr_params * sizeof(gl_constant_value);
       gl_constant_value *param;
       if (brw->gen >= 8 || brw->is_haswell) {
-         param = intel_upload_space(brw, size, 32, &brw->curbe.curbe_bo,
+         param = intel_upload_space(brw, size, 32,
+                                    &stage_state->push_const_bo,
                                     &stage_state->push_const_offset);
       } else {
          param = brw_state_batch(brw, size, 32,
diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
index 06b9cd50728..bc47e5a16fe 100644
--- a/src/mesa/drivers/dri/i965/genX_state_upload.c
+++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
@@ -2754,7 +2754,8 @@ upload_constant_state(struct brw_context *brw,
 #if GEN_GEN >= 8 || GEN_IS_HASWELL
          pkt.ConstantBody.ReadLength[2] = stage_state->push_const_size;
          pkt.ConstantBody.Buffer[2] =
-            render_ro_bo(brw->curbe.curbe_bo, stage_state->push_const_offset);
+            render_ro_bo(stage_state->push_const_bo,
+                         stage_state->push_const_offset);
 #else
          pkt.ConstantBody.ReadLength[0] = stage_state->push_const_size;
          pkt.ConstantBody.Buffer[0].offset =
-- 
2.13.2



More information about the mesa-dev mailing list