path: root/src/glsl/lower_const_arrays_to_uniforms.cpp
diff options
authorKenneth Graunke <>2014-11-22 14:14:05 -0800
committerKenneth Graunke <>2014-11-24 15:30:09 -0800
commit60f011af1a370004333cbc3fee7fec137ebd9d6a (patch)
tree032a6828ab5fbbd569aeea14a6f336415b3ea1f0 /src/glsl/lower_const_arrays_to_uniforms.cpp
parentf0c91f32c0b09f27f67cac34cba070bdc5274a15 (diff)
glsl: Make lower_constant_arrays_to_uniforms require dereferences.
Ilia noticed that my lowering pass was converting the constant array used by textureGatherOffsets' offsets parameter to a uniform. This broke textureGather for Nouveau, and is generally a horrible plan, since it violates the GLSL constraint that offsets must be an immediate constant. When I wrote this pass, I neglected to consider whole array assignment. I figured opt_array_splitting would handle constant indexing, so this pass was really about fixing variable indexing. textureGatherOffsets is an example of whole array access that we really don't want to touch. Whole array copies don't appear to benefit from this either - they're most likely initializers for temporary arrays which are going to be mutated anyway. Since you're copying, you may as well copy from immediates, not uniforms. This patch makes the pass look for ir_dereference_arrays of ir_constants, rather than looking for any ir_constant directly. This way, it ignores whole array assignment. No shader-db changes or Piglit regressions on Haswell. Some Piglit tests generate different code (fixing textureGatherOffsets on Nouveau). Signed-off-by: Kenneth Graunke <> Tested-by: Ilia Mirkin <> Reviewed-by: Matt Turner <> Cc: "10.4" <>
Diffstat (limited to 'src/glsl/lower_const_arrays_to_uniforms.cpp')
1 files changed, 7 insertions, 2 deletions
diff --git a/src/glsl/lower_const_arrays_to_uniforms.cpp b/src/glsl/lower_const_arrays_to_uniforms.cpp
index 700e9039f74..2243f479a11 100644
--- a/src/glsl/lower_const_arrays_to_uniforms.cpp
+++ b/src/glsl/lower_const_arrays_to_uniforms.cpp
@@ -72,7 +72,11 @@ lower_const_array_visitor::handle_rvalue(ir_rvalue **rvalue)
if (!*rvalue)
- ir_constant *con = (*rvalue)->as_constant();
+ ir_dereference_array *dra = (*rvalue)->as_dereference_array();
+ if (!dra)
+ return;
+ ir_constant *con = dra->array->as_constant();
if (!con || !con->type->is_array())
@@ -91,7 +95,8 @@ lower_const_array_visitor::handle_rvalue(ir_rvalue **rvalue)
uni->data.max_array_access = uni->type->length - 1;
- *rvalue = new(mem_ctx) ir_dereference_variable(uni);
+ ir_dereference_variable *varref = new(mem_ctx) ir_dereference_variable(uni);
+ *rvalue = new(mem_ctx) ir_dereference_array(varref, dra->array_index);
progress = true;