aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/nir/nir_lower_samplers.cpp
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-11-25 21:36:25 -0800
committerJason Ekstrand <[email protected]>2015-01-15 07:19:02 -0800
commit829aa98320fcd529407d16991b476b71af017479 (patch)
tree5ff603507c7cded684a6ee460126b64c1e02f112 /src/glsl/nir/nir_lower_samplers.cpp
parent4f8230e247a222314ab124e348482628adb5af32 (diff)
nir: Use an integer index for specifying structure fields
Previously, we used a string name. It was nice for translating out of GLSL IR (which also does that) but cumbersome the rest of the time. Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/glsl/nir/nir_lower_samplers.cpp')
-rw-r--r--src/glsl/nir/nir_lower_samplers.cpp65
1 files changed, 34 insertions, 31 deletions
diff --git a/src/glsl/nir/nir_lower_samplers.cpp b/src/glsl/nir/nir_lower_samplers.cpp
index be6a75525b7..4fa764ca378 100644
--- a/src/glsl/nir/nir_lower_samplers.cpp
+++ b/src/glsl/nir/nir_lower_samplers.cpp
@@ -47,38 +47,41 @@ get_deref_name_offset(nir_deref_var *deref_var,
*name = ralloc_strdup(mem_ctx, deref_var->var->name);
while (deref->child != NULL) {
- deref = deref->child;
- switch (deref->deref_type) {
- case nir_deref_type_array:
- deref_array = nir_deref_as_array(deref);
- if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
- /* GLSL 1.10 and 1.20 allowed variable sampler array indices,
- * while GLSL 1.30 requires that the array indices be
- * constant integer expressions. We don't expect any driver
- * to actually work with a really variable array index, so
- * all that would work would be an unrolled loop counter that
- * ends up being constant.
- */
- ralloc_strcat(&shader_program->InfoLog,
- "warning: Variable sampler array index unsupported.\n"
- "This feature of the language was removed in GLSL 1.20 "
- "and is unlikely to be supported for 1.10 in Mesa.\n");
- }
- if (deref->child == NULL) {
- return deref_array->base_offset;
- }
- ralloc_asprintf_append(name, "[%u]", deref_array->base_offset);
- break;
-
- case nir_deref_type_struct:
- deref_struct = nir_deref_as_struct(deref);
- ralloc_asprintf_append(name, ".%s", deref_struct->elem);
- break;
-
- default:
- assert(0);
- break;
+ switch (deref->child->deref_type) {
+ case nir_deref_type_array:
+ deref_array = nir_deref_as_array(deref->child);
+ if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
+ /* GLSL 1.10 and 1.20 allowed variable sampler array indices,
+ * while GLSL 1.30 requires that the array indices be
+ * constant integer expressions. We don't expect any driver
+ * to actually work with a really variable array index, so
+ * all that would work would be an unrolled loop counter that
+ * ends up being constant.
+ */
+ ralloc_strcat(&shader_program->InfoLog,
+ "warning: Variable sampler array index unsupported.\n"
+ "This feature of the language was removed in GLSL 1.20 "
+ "and is unlikely to be supported for 1.10 in Mesa.\n");
+ }
+ if (deref_array->deref.child == NULL) {
+ return deref_array->base_offset;
+ }
+ ralloc_asprintf_append(name, "[%u]", deref_array->base_offset);
+ break;
+
+ case nir_deref_type_struct: {
+ deref_struct = nir_deref_as_struct(deref->child);
+ const char *field = glsl_get_struct_elem_name(deref->type,
+ deref_struct->index);
+ ralloc_asprintf_append(name, ".%s", field);
+ break;
}
+
+ default:
+ assert(0);
+ break;
+ }
+ deref = deref->child;
}
return 0;