summaryrefslogtreecommitdiffstats
path: root/src/glsl/ast_to_hir.cpp
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2011-01-04 16:09:00 -0800
committerIan Romanick <[email protected]>2011-01-06 10:06:59 -0800
commite942f328365309a1d8240cfe8eb5d88391015f37 (patch)
tree106383f28234c79ba990dd05d7cb9c3e3c0c549a /src/glsl/ast_to_hir.cpp
parentc60f1d8b007625f62a53010bb75e70462eb970ae (diff)
glsl: Allow less restrictive uses of sampler array indexing in GLSL <= 1.20
GLSL 1.10 and 1.20 allow any sort of sampler array indexing. Restrictions were added in GLSL 1.30. Commit f0f2ec4d added support for the 1.30 restrictions, but it broke some valid 1.10/1.20 shaders. This changes the error to a warning in GLSL 1.10, GLSL 1.20, and GLSL ES 1.00. There are some spurious whitespace changes in this commit. I changed the layout (and wording) of the error message so that all three cases would be similar. The 1.10/1.20 and 1.30 text is the same. The only difference is that one is an error, and the other is a warning. The GLSL ES 1.00 wording is similar but not quite the same. Fixes piglit test spec/glsl-1.10/compiler/constant-expressions/sampler-array-index-02.frag and bugzilla #32374.
Diffstat (limited to 'src/glsl/ast_to_hir.cpp')
-rw-r--r--src/glsl/ast_to_hir.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 67202dfc3c9..80c4ef4314c 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1564,18 +1564,38 @@ ast_expression::hir(exec_list *instructions,
}
}
- /* From section 4.1.7 of the GLSL 1.30 spec:
+ /* From page 23 (29 of the PDF) of the GLSL 1.30 spec:
+ *
* "Samplers aggregated into arrays within a shader (using square
* brackets [ ]) can only be indexed with integral constant
* expressions [...]."
+ *
+ * This restriction was added in GLSL 1.30. Shaders using earlier version
+ * of the language should not be rejected by the compiler front-end for
+ * using this construct. This allows useful things such as using a loop
+ * counter as the index to an array of samplers. If the loop in unrolled,
+ * the code should compile correctly. Instead, emit a warning.
*/
if (array->type->is_array() &&
array->type->element_type()->is_sampler() &&
const_index == NULL) {
- _mesa_glsl_error(&loc, state, "sampler arrays can only be indexed "
- "with constant expressions");
- error_emitted = true;
+ if (state->language_version == 100) {
+ _mesa_glsl_warning(&loc, state,
+ "sampler arrays indexed with non-constant "
+ "expressions is optional in GLSL ES 1.00");
+ } else if (state->language_version < 130) {
+ _mesa_glsl_warning(&loc, state,
+ "sampler arrays indexed with non-constant "
+ "expressions is forbidden in GLSL 1.30 and "
+ "later");
+ } else {
+ _mesa_glsl_error(&loc, state,
+ "sampler arrays indexed with non-constant "
+ "expressions is forbidden in GLSL 1.30 and "
+ "later");
+ error_emitted = true;
+ }
}
if (error_emitted)