From 99416624e52526a0d1ef579c1a40d02b7aef3d9c Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Mon, 27 Feb 2023 17:15:45 +0100 Subject: [PATCH] ntt: add option to lower SSBO bindings to buffer index 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 Part-of: --- src/gallium/auxiliary/nir/nir_to_tgsi.c | 27 +++++++++++++++++++-------- src/gallium/auxiliary/nir/nir_to_tgsi.h | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c index 9336289..5b25c21 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi.c +++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c @@ -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; diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.h b/src/gallium/auxiliary/nir/nir_to_tgsi.h index d3366cb..cfdabc5 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi.h +++ b/src/gallium/auxiliary/nir/nir_to_tgsi.h @@ -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; }; -- 2.7.4