diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 9748f9e1d14..8b8aeaf9666 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -423,6 +423,22 @@ nir_find_state_variable(nir_shader *s, return NULL; } +nir_variable *nir_find_sampler_variable_with_tex_index(nir_shader *shader, + unsigned texture_index) +{ + nir_foreach_variable_with_modes(var, shader, nir_var_uniform) { + unsigned size = + glsl_type_is_array(var->type) ? glsl_array_size(var->type) : 1; + if ((glsl_type_is_texture(glsl_without_array(var->type)) || + glsl_type_is_sampler(glsl_without_array(var->type))) && + (var->data.binding == texture_index || + (var->data.binding < texture_index && + var->data.binding + size > texture_index))) + return var; + } + return NULL; +} + /* Annoyingly, qsort_r is not in the C standard library and, in particular, we * can't count on it on MSV and Android. So we stuff the CMP function into * each array element. It's a bit messy and burns more memory but the list of diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index d9ec891a131..7d919a81de2 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4060,6 +4060,9 @@ nir_variable *nir_find_variable_with_driver_location(nir_shader *shader, nir_variable *nir_find_state_variable(nir_shader *s, gl_state_index16 tokens[STATE_LENGTH]); +nir_variable *nir_find_sampler_variable_with_tex_index(nir_shader *shader, + unsigned texture_index); + void nir_sort_variables_with_modes(nir_shader *shader, int (*compar)(const nir_variable *, const nir_variable *), diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 5b220ff59aa..d714dd72f19 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -4827,18 +4827,6 @@ type_image(nir_shader *nir, nir_variable *var) var->data.mode = nir_var_shader_temp; } -static nir_variable * -find_sampler_var(nir_shader *nir, unsigned texture_index) -{ - nir_foreach_variable_with_modes(var, nir, nir_var_uniform) { - unsigned size = glsl_type_is_array(var->type) ? glsl_array_size(var->type) : 1; - if ((glsl_type_is_texture(glsl_without_array(var->type)) || glsl_type_is_sampler(glsl_without_array(var->type))) && - (var->data.binding == texture_index || (var->data.binding < texture_index && var->data.binding + size > texture_index))) - return var; - } - return NULL; -} - static bool type_sampler_vars(nir_shader *nir, unsigned *sampler_mask) { @@ -4860,7 +4848,7 @@ type_sampler_vars(nir_shader *nir, unsigned *sampler_mask) break; } *sampler_mask |= BITFIELD_BIT(tex->sampler_index); - nir_variable *var = find_sampler_var(nir, tex->texture_index); + nir_variable *var = nir_find_sampler_variable_with_tex_index(nir, tex->texture_index); assert(var); if (glsl_get_sampler_result_type(glsl_without_array(var->type)) != GLSL_TYPE_VOID) continue; @@ -4890,7 +4878,7 @@ type_sampler_vars(nir_shader *nir, unsigned *sampler_mask) continue; } *sampler_mask |= BITFIELD_BIT(tex->sampler_index); - nir_variable *var = find_sampler_var(nir, tex->texture_index); + nir_variable *var = nir_find_sampler_variable_with_tex_index(nir, tex->texture_index); assert(var); if (glsl_get_sampler_result_type(glsl_without_array(var->type)) != GLSL_TYPE_VOID) continue;