From 5a7044d0bc9376aa67d74b735aab425790d8a935 Mon Sep 17 00:00:00 2001 From: Illia Polishchuk Date: Mon, 11 Sep 2023 16:08:31 +0300 Subject: [PATCH] zink: move find_sampler_var from zink to nir core Avoid code duplication because it need to be used in following commits Fixes: 1a8dd84ec61 ("nir: Propagate the type sampler type change to the used variable.") Reviewed-By: Mike Blumenkrantz Signed-off-by: Illia Polishchuk Part-of: --- src/compiler/nir/nir.c | 16 ++++++++++++++++ src/compiler/nir/nir.h | 3 +++ src/gallium/drivers/zink/zink_compiler.c | 16 ++-------------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 9748f9e..8b8aeaf 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 d9ec891..7d919a8 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 5b220ff..d714dd7 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; -- 2.7.4