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 <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>
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
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 *),
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)
{
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;
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;