mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 04:48:08 +02:00
glsl: Track variable usage, use that to enforce semantics
In particular, variables cannot be redeclared invariant after being
used.
Fixes piglit test invariant-05.vert and bugzilla #29164.
NOTE: This is a candidate for the 7.9 and 7.10 branches.
(cherry picked from commit bd33055ef4)
This commit is contained in:
parent
d81615ee19
commit
aff4170849
3 changed files with 26 additions and 2 deletions
|
|
@ -1626,6 +1626,7 @@ ast_expression::hir(exec_list *instructions,
|
|||
result = new(ctx) ir_dereference_variable(var);
|
||||
|
||||
if (var != NULL) {
|
||||
var->used = true;
|
||||
type = result->type;
|
||||
} else {
|
||||
_mesa_glsl_error(& loc, state, "`%s' undeclared",
|
||||
|
|
@ -1800,8 +1801,16 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
|
|||
struct _mesa_glsl_parse_state *state,
|
||||
YYLTYPE *loc)
|
||||
{
|
||||
if (qual->flags.q.invariant)
|
||||
var->invariant = 1;
|
||||
if (qual->flags.q.invariant) {
|
||||
if (var->used) {
|
||||
_mesa_glsl_error(loc, state,
|
||||
"variable `%s' may not be redeclared "
|
||||
"`invariant' after being used",
|
||||
var->name);
|
||||
} else {
|
||||
var->invariant = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* FINISHME: Mark 'in' variables at global scope as read-only. */
|
||||
if (qual->flags.q.constant || qual->flags.q.attribute
|
||||
|
|
@ -2008,6 +2017,11 @@ ast_declarator_list::hir(exec_list *instructions,
|
|||
_mesa_glsl_error(& loc, state,
|
||||
"`%s' cannot be marked invariant, fragment shader "
|
||||
"inputs only\n", decl->identifier);
|
||||
} else if (earlier->used) {
|
||||
_mesa_glsl_error(& loc, state,
|
||||
"variable `%s' may not be redeclared "
|
||||
"`invariant' after being used",
|
||||
earlier->name);
|
||||
} else {
|
||||
earlier->invariant = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1277,6 +1277,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
|
|||
this->constant_value = NULL;
|
||||
this->origin_upper_left = false;
|
||||
this->pixel_center_integer = false;
|
||||
this->used = false;
|
||||
|
||||
if (type && type->base_type == GLSL_TYPE_SAMPLER)
|
||||
this->read_only = true;
|
||||
|
|
|
|||
|
|
@ -294,6 +294,15 @@ public:
|
|||
unsigned centroid:1;
|
||||
unsigned invariant:1;
|
||||
|
||||
/**
|
||||
* Has this variable been used for reading or writing?
|
||||
*
|
||||
* Several GLSL semantic checks require knowledge of whether or not a
|
||||
* variable has been used. For example, it is an error to redeclare a
|
||||
* variable as invariant after it has been used.
|
||||
*/
|
||||
unsigned used:1;
|
||||
|
||||
/**
|
||||
* Storage class of the variable.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue