mesa: Add a new function for getting the nonconst sampler array index
authorChris Forbes <chrisf@ijw.co.nz>
Sun, 3 Aug 2014 07:55:55 +0000 (19:55 +1200)
committerChris Forbes <chrisf@ijw.co.nz>
Tue, 12 Aug 2014 07:18:55 +0000 (19:18 +1200)
If the array index is not a constant expression, the existing support
will assume a zero offset (giving us the sampler index of the base of
the array).

For dynamically uniform indexing of sampler arrays, we need both that
and the indexing expression.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/mesa/program/sampler.cpp
src/mesa/program/sampler.h

index e6532be84d3e7726aedc852b83ff563de89d1c40..29a5408717a8c42b3aceb1672a499244d8b5b4bd 100644 (file)
@@ -134,3 +134,14 @@ _mesa_get_sampler_uniform_value(class ir_dereference *sampler,
    return shader_program->UniformStorage[location].sampler[shader].index +
           getname.offset;
 }
+
+
+extern "C" class ir_rvalue *
+_mesa_get_sampler_array_nonconst_index(class ir_dereference *sampler)
+{
+   ir_dereference_array *deref_arr = sampler->as_dereference_array();
+   if (!deref_arr || deref_arr->array_index->as_constant())
+      return NULL;
+
+   return deref_arr->array_index;
+}
index 22467e99020a3fd01da3bb454c145cac38241cdc..8b7c3b63ed5ad537b34821451a7d188477c8b4cd 100644 (file)
@@ -27,3 +27,6 @@ int
 _mesa_get_sampler_uniform_value(class ir_dereference *sampler,
                                struct gl_shader_program *shader_program,
                                const struct gl_program *prog);
+
+class ir_rvalue *
+_mesa_get_sampler_array_nonconst_index(class ir_dereference *sampler);