Commit e942f328 authored by Ian Romanick's avatar Ian Romanick
Browse files

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
and bugzilla #32374.
parent c60f1d8b
......@@ -1564,19 +1564,39 @@ 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");
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 "
} else {
_mesa_glsl_error(&loc, state,
"sampler arrays indexed with non-constant "
"expressions is forbidden in GLSL 1.30 and "
error_emitted = true;
if (error_emitted)
result->type = glsl_type::error_type;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment