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

Author: Chia-I Wu <[email protected]>
Date:   Wed Jul 27 16:48:36 2022 -0700

turnip: shared_consts and push_consts are mutually exclusive

Skip gather_push_constants when shared consts are enabled.  This makes
sure push_consts is only zero-initialized, and reserved_user_consts is
0.  This saves some space in the const file.

This change also adds a few asserts and a comment to
lower_load_push_constant.  Because shared consts share the same range
for all stages, we should not apply per-stage offsets in
lower_load_push_constant.  It worked because nir_lower_explicit_io
always sets base to 0 for nir_var_mem_push_const and
shader->push_consts.lo was always 0 for all stages.

Fixes: 0c787d57e66 ("tu: increase maxPushConstantsSize to 256.")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17777>

---

 src/freedreno/vulkan/tu_cmd_buffer.c |  6 ++++++
 src/freedreno/vulkan/tu_shader.c     | 17 +++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c 
b/src/freedreno/vulkan/tu_cmd_buffer.c
index 285d2c9872b..e0a0efb9841 100644
--- a/src/freedreno/vulkan/tu_cmd_buffer.c
+++ b/src/freedreno/vulkan/tu_cmd_buffer.c
@@ -4213,6 +4213,12 @@ tu6_emit_consts(struct tu_cmd_buffer *cmd,
 
    if (pipeline->shared_consts.dwords > 0) {
       tu6_emit_shared_consts(&cs, pipeline, cmd->push_constants, compute);
+
+      for (uint32_t i = 0; i < ARRAY_SIZE(pipeline->program.link); i++) {
+         const struct tu_program_descriptor_linkage *link =
+            &pipeline->program.link[i];
+         assert(!link->push_consts.dwords);
+      }
    } else {
       if (compute) {
          tu6_emit_user_consts(&cs, pipeline, MESA_SHADER_COMPUTE, 
cmd->push_constants);
diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c
index 24a43f0fddd..b0519960714 100644
--- a/src/freedreno/vulkan/tu_shader.c
+++ b/src/freedreno/vulkan/tu_shader.c
@@ -146,11 +146,17 @@ lower_load_push_constant(struct tu_device *dev,
 {
    uint32_t base = nir_intrinsic_base(instr);
    assert(base % 4 == 0);
-   assert(base >= shader->push_consts.lo * 4);
-   base -= shader->push_consts.lo * 4;
 
-   if (tu6_shared_constants_enable(layout, dev->compiler))
+   if (tu6_shared_constants_enable(layout, dev->compiler)) {
+      /* All stages share the same range.  We could potentially add
+       * push_constant_offset to layout and apply it, but this is good for
+       * now.
+       */
       base += dev->compiler->shared_consts_base_offset * 4;
+   } else {
+      assert(base >= shader->push_consts.lo * 4);
+      base -= shader->push_consts.lo * 4;
+   }
 
    nir_ssa_def *load =
       nir_load_uniform(b, instr->num_components,
@@ -641,7 +647,8 @@ tu_lower_io(nir_shader *shader, struct tu_device *dev,
             struct tu_shader *tu_shader,
             const struct tu_pipeline_layout *layout)
 {
-   gather_push_constants(shader, tu_shader);
+   if (!tu6_shared_constants_enable(layout, dev->compiler))
+      gather_push_constants(shader, tu_shader);
 
    struct lower_instr_params params = {
       .dev = dev,
@@ -835,6 +842,8 @@ tu_shader_create(struct tu_device *dev,
 
    uint32_t reserved_consts_vec4 = align(shader->push_consts.dwords, 16) / 4;
    bool shared_consts_enable = tu6_shared_constants_enable(layout, 
dev->compiler);
+   if (shared_consts_enable)
+      assert(!shader->push_consts.dwords);
 
    shader->ir3_shader =
       ir3_shader_from_nir(dev->compiler, nir, &(struct ir3_shader_options) {

Reply via email to