nir/lower_system_values: Assert/assume direct var derefs
authorJason Ekstrand <jason.ekstrand@intel.com>
Sat, 7 Apr 2018 05:34:57 +0000 (22:34 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 23 Jun 2018 04:23:06 +0000 (21:23 -0700)
System values are never arrays or structs so we can assume a direct var
deref.  This simplifies things a bit and prevents us from accidentally
throwing away an array index.

Suggested-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Acked-by: Rob Clark <robdclark@gmail.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Acked-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir_lower_system_values.c

index a5f44e657a5f8508c49e52a2f0dc4b45ccb61fda..f315b7ae96fdc3dda3ccba4695af5b79807f9047 100644 (file)
@@ -41,12 +41,21 @@ convert_block(nir_block *block, nir_builder *b)
       if (load_deref->intrinsic != nir_intrinsic_load_deref)
          continue;
 
-      nir_variable *var =
-         nir_deref_instr_get_variable(nir_src_as_deref(load_deref->src[0]));
-
-      if (var->data.mode != nir_var_system_value)
+      nir_deref_instr *deref = nir_src_as_deref(load_deref->src[0]);
+      if (deref->mode != nir_var_system_value)
          continue;
 
+      if (deref->deref_type != nir_deref_type_var) {
+         /* The only one system value that is an array and that is
+          * gl_SampleMask which is always an array of one element.
+          */
+         assert(deref->deref_type == nir_deref_type_array);
+         deref = nir_deref_instr_parent(deref);
+         assert(deref->deref_type == nir_deref_type_var);
+         assert(deref->var->data.location == SYSTEM_VALUE_SAMPLE_MASK_IN);
+      }
+      nir_variable *var = deref->var;
+
       b->cursor = nir_after_instr(&load_deref->instr);
 
       nir_ssa_def *sysval = NULL;