ntt: add option to lower SSBO bindings to buffer index
authorGert Wollny <gert.wollny@collabora.com>
Mon, 27 Feb 2023 16:15:45 +0000 (17:15 +0100)
committerMarge Bot <emma+marge@anholt.net>
Thu, 16 Mar 2023 09:30:00 +0000 (09:30 +0000)
When a shader uses SSBOs in various shader stages, then we have to track
the binding locations in order to be able to properly bind these SSBOs.

Therefore add a flag that enables adding the start index of the bindings to
the SSBO index.

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21586>

src/gallium/auxiliary/nir/nir_to_tgsi.c
src/gallium/auxiliary/nir/nir_to_tgsi.h

index 9336289..5b25c21 100644 (file)
@@ -109,6 +109,7 @@ struct ntt_compile {
    uint64_t centroid_inputs;
 
    uint32_t first_ubo;
+   uint32_t first_ssbo;
 
    struct ureg_src images[PIPE_MAX_SHADER_IMAGES];
 };
@@ -1049,13 +1050,22 @@ ntt_setup_uniforms(struct ntt_compile *c)
          ureg_DECL_constant2D(c->ureg, 0, DIV_ROUND_UP(ubo_sizes[i], 16) - 1, i);
    }
 
-   for (int i = 0; i < c->s->info.num_ssbos; i++) {
-      /* XXX: nv50 uses the atomic flag to set caching for (lowered) atomic
-       * counters
-       */
-      bool atomic = false;
-      ureg_DECL_buffer(c->ureg, i, atomic);
-   }
+   if (c->options->lower_ssbo_bindings) {
+      c->first_ssbo = 255;
+      nir_foreach_variable_with_modes(var, c->s, nir_var_mem_ssbo) {
+         if (c->first_ssbo > var->data.binding)
+            c->first_ssbo = var->data.binding;
+      }
+   } else
+      c->first_ssbo = 0;
+
+   /* XXX: nv50 uses the atomic flag to set caching for (lowered) atomic
+    * counters
+    */
+   bool atomic = false;
+   for (int i = 0; i < c->s->info.num_ssbos; ++i)
+      ureg_DECL_buffer(c->ureg, c->first_ssbo + i, atomic);
+
 }
 
 static void
@@ -1886,7 +1896,8 @@ ntt_emit_mem(struct ntt_compile *c, nir_intrinsic_instr *instr,
    struct ureg_src memory;
    switch (mode) {
    case nir_var_mem_ssbo:
-      memory = ntt_ureg_src_indirect(c, ureg_src_register(TGSI_FILE_BUFFER, 0),
+      memory = ntt_ureg_src_indirect(c, ureg_src_register(TGSI_FILE_BUFFER,
+                                                          c->first_ssbo),
                                      instr->src[is_store ? 1 : 0], 2);
       next_src = 1;
       break;
index d3366cb..cfdabc5 100644 (file)
@@ -36,6 +36,7 @@ struct nir_to_tgsi_options {
    /* Emit MAX(a,-a) instead of abs src modifier) */
    bool lower_fabs;
    bool unoptimized_ra;
+   bool lower_ssbo_bindings;
    uint32_t ubo_vec4_max;
 };