zink: move find_sampler_var from zink to nir core

Avoid code duplication because it need to be used in following commits

Fixes: 1a8dd84ec6 ("nir: Propagate the type sampler type change to the used variable.")

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Signed-off-by: Illia Polishchuk <illia.a.polishchuk@globallogic.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25145>
This commit is contained in:
Illia Polishchuk
2023-09-11 16:08:31 +03:00
committed by Marge Bot
parent 010147cd64
commit 5a7044d0bc
3 changed files with 21 additions and 14 deletions

View File

@@ -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

View File

@@ -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 *),

View File

@@ -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;