[Mesa-dev] [PATCH 3/4] nir: Validate that tex_instr src components are the right size.

Eric Anholt eric at anholt.net
Mon Apr 13 13:36:48 PDT 2015


---
 src/glsl/nir/nir_validate.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/glsl/nir/nir_validate.c b/src/glsl/nir/nir_validate.c
index a7aa798..d7ba374 100644
--- a/src/glsl/nir/nir_validate.c
+++ b/src/glsl/nir/nir_validate.c
@@ -97,6 +97,16 @@ typedef struct {
 static void validate_src(nir_src *src, validate_state *state);
 
 static void
+validate_src_components(nir_src *src, int num_components)
+{
+   if (src->is_ssa) {
+      assert(num_components <= src->ssa->num_components);
+   } else if (!src->reg.reg->is_packed) {
+      assert(num_components <= src->reg.reg->num_components);
+   }
+}
+
+static void
 validate_reg_src(nir_reg_src *src, validate_state *state)
 {
    assert(src->reg != NULL);
@@ -361,13 +371,8 @@ validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state)
 
       assert(components_read > 0);
 
-      if (instr->src[i].is_ssa) {
-         assert(components_read <= instr->src[i].ssa->num_components);
-      } else if (!instr->src[i].reg.reg->is_packed) {
-         assert(components_read <= instr->src[i].reg.reg->num_components);
-      }
-
       validate_src(&instr->src[i], state);
+      validate_src_components(&instr->src[i], components_read);
    }
 
    if (nir_intrinsic_infos[instr->intrinsic].has_dest) {
@@ -423,6 +428,8 @@ validate_tex_instr(nir_tex_instr *instr, validate_state *state)
       assert(!src_type_seen[instr->src[i].src_type]);
       src_type_seen[instr->src[i].src_type] = true;
       validate_src(&instr->src[i].src, state);
+      validate_src_components(&instr->src[i].src,
+                              nir_tex_instr_src_size(instr, i));
    }
 
    if (instr->sampler != NULL)
-- 
2.1.4



More information about the mesa-dev mailing list