glsl: Collect all of the non-constant index error checks together

This puts all of the checks togeher for easier reading.  It also means
that all the checks are blocked on array->type->is_array.  Shortly this
will allow elimination of some is_error check work-arounds in this
function.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Ian Romanick
2013-03-15 15:10:35 -07:00
parent f9d8ca2817
commit a70d2f05dc

View File

@@ -118,19 +118,18 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
check_builtin_array_max_size(v->name, idx+1, loc, state); check_builtin_array_max_size(v->name, idx+1, loc, state);
} }
} }
} else if (array->type->array_size() == 0) { } else if (array->type->is_array()) {
_mesa_glsl_error(&loc, state, "unsized array index must be constant"); if (array->type->array_size() == 0) {
} else if (array->type->is_array() _mesa_glsl_error(&loc, state, "unsized array index must be constant");
&& array->type->fields.array->is_interface()) { } else if (array->type->fields.array->is_interface()) {
/* Page 46 in section 4.3.7 of the OpenGL ES 3.00 spec says: /* Page 46 in section 4.3.7 of the OpenGL ES 3.00 spec says:
* *
* "All indexes used to index a uniform block array must be * "All indexes used to index a uniform block array must be
* constant integral expressions." * constant integral expressions."
*/ */
_mesa_glsl_error(&loc, state, _mesa_glsl_error(&loc, state,
"uniform block array index must be constant"); "uniform block array index must be constant");
} else { } else {
if (array->type->is_array()) {
/* whole_variable_referenced can return NULL if the array is a /* whole_variable_referenced can return NULL if the array is a
* member of a structure. In this case it is safe to not update * member of a structure. In this case it is safe to not update
* the max_array_access field because it is never used for fields * the max_array_access field because it is never used for fields
@@ -140,41 +139,39 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
if (v != NULL) if (v != NULL)
v->max_array_access = array->type->array_size() - 1; v->max_array_access = array->type->array_size() - 1;
} }
}
/* From page 23 (29 of the PDF) 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 * "Samplers aggregated into arrays within a shader (using square
* brackets [ ]) can only be indexed with integral constant * brackets [ ]) can only be indexed with integral constant
* expressions [...]." * expressions [...]."
* *
* This restriction was added in GLSL 1.30. Shaders using earlier version * This restriction was added in GLSL 1.30. Shaders using earlier
* of the language should not be rejected by the compiler front-end for * version of the language should not be rejected by the compiler
* using this construct. This allows useful things such as using a loop * front-end for using this construct. This allows useful things such
* counter as the index to an array of samplers. If the loop in unrolled, * as using a loop counter as the index to an array of samplers. If the
* the code should compile correctly. Instead, emit a warning. * loop in unrolled, the code should compile correctly. Instead, emit a
*/ * warning.
if (array->type->is_array() && */
array->type->element_type()->is_sampler() && if (array->type->element_type()->is_sampler()) {
const_index == NULL) { if (!state->is_version(130, 100)) {
if (state->es_shader) {
if (!state->is_version(130, 100)) { _mesa_glsl_warning(&loc, state,
if (state->es_shader) { "sampler arrays indexed with non-constant "
_mesa_glsl_warning(&loc, state, "expressions is optional in %s",
"sampler arrays indexed with non-constant " state->get_version_string());
"expressions is optional in %s", } else {
state->get_version_string()); _mesa_glsl_warning(&loc, state,
"sampler arrays indexed with non-constant "
"expressions will be forbidden in GLSL 1.30 "
"and later");
}
} else { } else {
_mesa_glsl_warning(&loc, state, _mesa_glsl_error(&loc, state,
"sampler arrays indexed with non-constant " "sampler arrays indexed with non-constant "
"expressions will be forbidden in GLSL 1.30 and " "expressions is forbidden in GLSL 1.30 and "
"later"); "later");
} }
} else {
_mesa_glsl_error(&loc, state,
"sampler arrays indexed with non-constant "
"expressions is forbidden in GLSL 1.30 and "
"later");
} }
} }