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

Author: Jason Ekstrand <[email protected]>
Date:   Fri Apr 15 16:16:03 2022 -0500

nir: Gather samplers_used separately from textures

Reviewed-by: Marek Olšák <[email protected]>
Reviewed-by: Karol Herbst <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15988>

---

 src/compiler/glsl/gl_nir_lower_samplers_as_deref.c | 16 ++++++++++++++++
 src/compiler/shader_info.h                         |  3 +++
 src/mesa/state_tracker/st_glsl_to_nir.cpp          |  1 +
 3 files changed, 20 insertions(+)

diff --git a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c 
b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
index 887b9b5ccc6..a6f72d77f6c 100644
--- a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
+++ b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
@@ -255,6 +255,21 @@ record_textures_used(struct shader_info *info,
    }
 }
 
+static void
+record_samplers_used(struct shader_info *info,
+                     nir_deref_instr *deref,
+                     nir_texop op)
+{
+   nir_variable *var = nir_deref_instr_get_variable(deref);
+
+   /* Structs have been lowered already, so get_aoa_size is sufficient. */
+   const unsigned size =
+      glsl_type_is_array(var->type) ? glsl_get_aoa_size(var->type) : 1;
+
+   BITSET_SET_RANGE(info->samplers_used, var->data.binding,
+                    var->data.binding + (MAX2(size, 1) - 1));
+}
+
 static bool
 lower_sampler(nir_tex_instr *instr, struct lower_samplers_as_deref_state 
*state,
               nir_builder *b)
@@ -287,6 +302,7 @@ lower_sampler(nir_tex_instr *instr, struct 
lower_samplers_as_deref_state *state,
       if (sampler_deref) {
          nir_instr_rewrite_src(&instr->instr, &instr->src[sampler_idx].src,
                                nir_src_for_ssa(&sampler_deref->dest.ssa));
+         record_samplers_used(&b->shader->info, sampler_deref, instr->op);
       }
    }
 
diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
index aa525761860..05eae55c08a 100644
--- a/src/compiler/shader_info.h
+++ b/src/compiler/shader_info.h
@@ -202,6 +202,9 @@ typedef struct shader_info {
    /** Bitfield of which textures are used by texelFetch() */
    BITSET_DECLARE(textures_used_by_txf, 32);
 
+   /** Bitfield of which samplers are used */
+   BITSET_DECLARE(samplers_used, 32);
+
    /** Bitfield of which images are used */
    BITSET_DECLARE(images_used, 32);
    /** Bitfield of which images are buffers. */
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp 
b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index bc4d5dcf68c..0c87103ed70 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -990,6 +990,7 @@ st_nir_lower_samplers(struct pipe_screen *screen, 
nir_shader *nir,
    if (prog) {
       BITSET_COPY(prog->info.textures_used, nir->info.textures_used);
       BITSET_COPY(prog->info.textures_used_by_txf, 
nir->info.textures_used_by_txf);
+      BITSET_COPY(prog->info.samplers_used, nir->info.samplers_used);
       BITSET_COPY(prog->info.images_used, nir->info.images_used);
       BITSET_COPY(prog->info.image_buffers, nir->info.image_buffers);
       BITSET_COPY(prog->info.msaa_images, nir->info.msaa_images);

Reply via email to