Mesa (master): glsl: fix sampler index calculation in nir linker

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Feb 29 00:30:28 UTC 2020


Module: Mesa
Branch: master
Commit: 61dc9354c0c9b5dae3f6763c5141ff38e3e72816
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=61dc9354c0c9b5dae3f6763c5141ff38e3e72816

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Fri Feb 28 12:13:55 2020 +1100

glsl: fix sampler index calculation in nir linker

Here we reset the counter to 0 for each shader stage not each program.
We also make add a flag to stop iterating over indices that have
already been processed.

Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3992>

---

 src/compiler/glsl/gl_nir_link_uniforms.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c
index 8c55b9a2dc1..fc2de8753b1 100644
--- a/src/compiler/glsl/gl_nir_link_uniforms.c
+++ b/src/compiler/glsl/gl_nir_link_uniforms.c
@@ -244,10 +244,10 @@ struct nir_link_uniforms_state {
    unsigned num_hidden_uniforms;
    unsigned num_values;
    unsigned max_uniform_location;
-   unsigned next_sampler_index;
 
    /* per-shader stage */
    unsigned next_image_index;
+   unsigned next_sampler_index;
    unsigned num_shader_samplers;
    unsigned num_shader_images;
    unsigned num_shader_uniform_components;
@@ -318,7 +318,7 @@ free_type_tree(struct type_tree_entry *entry)
 static unsigned
 get_next_index(struct nir_link_uniforms_state *state,
                const struct gl_uniform_storage *uniform,
-               unsigned *next_index)
+               unsigned *next_index, bool *initialised)
 {
    /* If we’ve already calculated an index for this member then we can just
     * offset from there.
@@ -338,7 +338,9 @@ get_next_index(struct nir_link_uniforms_state *state,
 
       state->current_type->next_index = *next_index;
       *next_index += array_size;
-   }
+      *initialised = true;
+   } else
+      *initialised = false;
 
    unsigned index = state->current_type->next_index;
 
@@ -608,8 +610,10 @@ nir_link_uniform(struct gl_context *ctx,
       unsigned values = glsl_get_component_slots(type);
 
       if (glsl_type_is_sampler(type_no_array)) {
+         bool init_idx;
          int sampler_index =
-            get_next_index(state, uniform, &state->next_sampler_index);
+            get_next_index(state, uniform, &state->next_sampler_index,
+                           &init_idx);
 
          /* Samplers (bound or bindless) are counted as two components as
           * specified by ARB_bindless_texture.
@@ -619,15 +623,16 @@ nir_link_uniform(struct gl_context *ctx,
          uniform->opaque[stage].active = true;
          uniform->opaque[stage].index = sampler_index;
 
-         const unsigned shadow = glsl_sampler_type_is_shadow(type_no_array);
-
-         for (unsigned i = sampler_index;
-              i < MIN2(state->next_sampler_index, MAX_SAMPLERS);
-              i++) {
-            stage_program->sh.SamplerTargets[i] =
-               glsl_get_sampler_target(type_no_array);
-            state->shader_samplers_used |= 1U << i;
-            state->shader_shadow_samplers |= shadow << i;
+         if (init_idx) {
+            const unsigned shadow = glsl_sampler_type_is_shadow(type_no_array);
+            for (unsigned i = sampler_index;
+                 i < MIN2(state->next_sampler_index, MAX_SAMPLERS);
+                 i++) {
+               stage_program->sh.SamplerTargets[i] =
+                  glsl_get_sampler_target(type_no_array);
+               state->shader_samplers_used |= 1U << i;
+               state->shader_shadow_samplers |= shadow << i;
+            }
          }
 
          state->num_values += values;
@@ -707,6 +712,7 @@ gl_nir_link_uniforms(struct gl_context *ctx,
       assert(nir);
 
       state.next_image_index = 0;
+      state.next_sampler_index = 0;
       state.num_shader_samplers = 0;
       state.num_shader_images = 0;
       state.num_shader_uniform_components = 0;



More information about the mesa-commit mailing list