nir: Validate image variable modes

We can also significantly simplify the foreach_image_variable helper.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4743>
This commit is contained in:
Jason Ekstrand 2021-09-15 11:39:12 -05:00 committed by Marge Bot
parent 97a7c0ab1b
commit 4c5a88d735
2 changed files with 10 additions and 17 deletions

View file

@ -715,26 +715,11 @@ _nir_shader_variable_has_mode(nir_variable *var, unsigned modes)
#define nir_foreach_uniform_variable_safe(var, shader) \
nir_foreach_variable_with_modes_safe(var, shader, nir_var_uniform)
static inline bool
_nir_variable_is_image(const nir_variable *var)
{
if (!glsl_type_contains_image(var->type))
return false;
/* GL, Vulkan, and OpenCL only allows arrays of arrays of images */
assert(glsl_type_is_image(glsl_without_array(var->type)));
return true;
}
#define nir_foreach_image_variable(var, shader) \
nir_foreach_variable_with_modes(var, shader, nir_var_uniform | \
nir_var_mem_image) \
if (_nir_variable_is_image(var))
nir_foreach_variable_with_modes(var, shader, nir_var_mem_image)
#define nir_foreach_image_variable_safe(var, shader) \
nir_foreach_variable_with_modes_safe(var, shader, nir_var_uniform | \
nir_var_mem_image) \
if (_nir_variable_is_image(var))
nir_foreach_variable_with_modes_safe(var, shader, nir_var_mem_image)
static inline bool
nir_variable_is_global(const nir_variable *var)

View file

@ -1518,6 +1518,14 @@ validate_var_decl(nir_variable *var, nir_variable_mode valid_modes,
if (var->constant_initializer)
validate_constant(var->constant_initializer, var->type, state);
if (glsl_type_contains_image(var->type) && !var->data.bindless)
validate_assert(state, var->data.mode == nir_var_mem_image);
if (var->data.mode == nir_var_mem_image) {
validate_assert(state, !var->data.bindless);
validate_assert(state, glsl_type_is_image(glsl_without_array(var->type)));
}
/*
* TODO validate some things ir_validate.cpp does (requires more GLSL type
* support)