Module: Mesa
Branch: main
Commit: c37c6ac613b17ae34978065871f90fe16d154da4
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c37c6ac613b17ae34978065871f90fe16d154da4

Author: Mike Blumenkrantz <[email protected]>
Date:   Wed Aug  3 10:58:03 2022 -0400

nir/validate: add some (light) validation for sampler type matching

this adds minimal validation for tex ops with derefs to check that the
dest type integer-ness matches the sampled type's integer-ness

the aim is to provide the most basic validation that nir is being modified
and created consistently, not to perform exact verification that
the types are identical

fix #6985

Reviewed-by: Jason Ekstrand <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17874>

---

 src/compiler/nir/nir_validate.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index eca05e0eab3..94fb9a366a5 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -899,6 +899,31 @@ validate_tex_instr(nir_tex_instr *instr, validate_state 
*state)
          validate_assert(state, glsl_type_is_image(deref->type) ||
                                 glsl_type_is_texture(deref->type) ||
                                 glsl_type_is_sampler(deref->type));
+         switch (instr->op) {
+         case nir_texop_descriptor_amd:
+            break;
+         case nir_texop_lod:
+            validate_assert(state, 
nir_alu_type_get_base_type(instr->dest_type) == nir_type_float);
+            break;
+         case nir_texop_samples_identical:
+            validate_assert(state, 
nir_alu_type_get_base_type(instr->dest_type) == nir_type_bool);
+            break;
+         case nir_texop_txs:
+         case nir_texop_texture_samples:
+         case nir_texop_query_levels:
+         case nir_texop_fragment_mask_fetch_amd:
+         case nir_texop_txf_ms_mcs_intel:
+            validate_assert(state, 
nir_alu_type_get_base_type(instr->dest_type) == nir_type_int ||
+                                   
nir_alu_type_get_base_type(instr->dest_type) == nir_type_uint);
+
+            break;
+         default:
+            validate_assert(state,
+                            glsl_get_sampler_result_type(deref->type) == 
GLSL_TYPE_VOID ||
+                            
glsl_base_type_is_integer(glsl_get_sampler_result_type(deref->type)) ==
+                            (nir_alu_type_get_base_type(instr->dest_type) == 
nir_type_int ||
+                             nir_alu_type_get_base_type(instr->dest_type) == 
nir_type_uint));
+         }
          break;
       }
 

Reply via email to