7b361499c9
This adds Analysis::IsConstantExpression, to determine if an expression is a constant-expression. It now expands to cover 'const' local and global variables, because we also enforce that the initializer on those variables is - in turn - a constant expression. This fixes 10837 - previously you could initialize a const variable with a non-constant expression, and we'd emit GLSL that contained that same pattern, which would fail to compile at the driver level. That should not be possible any longer. Bug: skia:10679 Bug: skia:10837 Change-Id: I517820ef4da57fff45768c0b04c55aebc18d3272 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375856 Reviewed-by: John Stiles <johnstiles@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
23 lines
988 B
Plaintext
23 lines
988 B
Plaintext
uniform float u;
|
|
|
|
const float c = 1;
|
|
float f = 1;
|
|
|
|
struct S { float f; } s;
|
|
|
|
// Valid constant-expression initializers. Should not produce errors:
|
|
void from_literal() { const float x = 0; }
|
|
void from_const_global() { const float x = c; }
|
|
void from_const_local() { const float x = 0; const float y = x; }
|
|
void from_const_constructor() { const int i = int(c); }
|
|
void from_expression() { const float x = 2 * c; }
|
|
|
|
// Invalid constant-expression initializers. Should all produce errors:
|
|
void from_uniform() { const float x = u; }
|
|
void from_parameter(float p) { const float x = p; }
|
|
void from_const_parameter(const float p) { const float x = p; }
|
|
void from_non_const_local() { float x = u; const float y = x; }
|
|
void from_non_const_expression() { const float x = u + u; }
|
|
void from_mixed_expression() { const float x = c + u; }
|
|
void from_non_const_struct_field() { const float x = s.f; }
|