Mesa (master): glsl: Treat ir_dereference_array of non-var as a constant for lowering

Ian Romanick idr at kemper.freedesktop.org
Sat Jul 23 08:25:09 UTC 2011


Module: Mesa
Branch: master
Commit: 156f85336f80d542569f0b0182bd27c7f3218e70
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=156f85336f80d542569f0b0182bd27c7f3218e70

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Jul 18 16:25:33 2011 -0700

glsl: Treat ir_dereference_array of non-var as a constant for lowering

Previously the code would just look at deref->array->type to see if it
was a constant.  This isn't good enough because deref->array might be
another ir_dereference_array... of a constant.  As a result,
deref->array->type wouldn't be a constant, but
deref->variable_referenced() would return NULL.  The unchecked NULL
pointer would shortly lead to a segfault.

Instead just look at the return of deref->variable_referenced().  If
it's NULL, assume that either a constant or some other form of
anonymous temporary storage is being dereferenced.

This is a bit hinkey because most drivers treat constant arrays as
uniforms, but the lowering pass treats them as temporaries.  This
keeps the behavior of the old code, so this change isn't making things
worse.

Fixes i965 piglit:

    vs-temp-array-mat[234]-index-col-rd
    vs-temp-array-mat[234]-index-col-row-rd
    vs-uniform-array-mat[234]-index-col-rd
    vs-uniform-array-mat[234]-index-col-row-rd

Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/glsl/lower_variable_index_to_cond_assign.cpp |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/glsl/lower_variable_index_to_cond_assign.cpp b/src/glsl/lower_variable_index_to_cond_assign.cpp
index e08ec13..79fa58e 100644
--- a/src/glsl/lower_variable_index_to_cond_assign.cpp
+++ b/src/glsl/lower_variable_index_to_cond_assign.cpp
@@ -321,10 +321,16 @@ public:
 
    bool storage_type_needs_lowering(ir_dereference_array *deref) const
    {
-      if (deref->array->ir_type == ir_type_constant)
+      /* If a variable isn't eventually the target of this dereference, then
+       * it must be a constant or some sort of anonymous temporary storage.
+       *
+       * FINISHME: Is this correct?  Most drivers treat arrays of constants as
+       * FINISHME: uniforms.  It seems like this should do the same.
+       */
+      const ir_variable *const var = deref->array->variable_referenced();
+      if (var == NULL)
 	 return this->lower_temps;
 
-      const ir_variable *const var = deref->array->variable_referenced();
       switch (var->mode) {
       case ir_var_auto:
       case ir_var_temporary:




More information about the mesa-commit mailing list