6ee5d9e3c9
Yesterday's implementation was close but I realized later that it wasn't quite ideal. - Array index-folding was gated on `isCompileTimeConstant`, which is too strict. The real limitation is `hasSideEffects`. If an array contains a side-effecting expression, we should leave it alone. Otherwise it is safe to pluck out an element from the array and toss the rest. - Matrix index-folding was gated on `getConstantSubexpression` for the extracted elements, but did not check the other elements at all. This was too lenient; we now only proceed to the folding step if `hasSideEffects` returns false. I added some tests to verify the final behavior and also discovered a small related issue. Diagonal matrices were not substituting literals in for constant-values, which inhibited folding as well and would break constant-expression evaluation. This is now fixed. Change-Id: Idda32fd8643c1f32ba21475251cd4d4dd7cea94c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/470396 Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: John Stiles <johnstiles@google.com>
20 lines
606 B
GLSL
20 lines
606 B
GLSL
|
|
out vec4 sk_FragColor;
|
|
uniform vec4 colorRed;
|
|
uniform vec4 colorGreen;
|
|
int globalValue = 0;
|
|
int side_effecting_ii(int value) {
|
|
globalValue++;
|
|
return value;
|
|
}
|
|
vec4 main() {
|
|
int _7_two = 2;
|
|
int _8_flatten0 = 1;
|
|
int _9_flatten1 = _7_two;
|
|
int _10_flatten2 = 3;
|
|
int _11_noFlatten0 = int[3](--_7_two, side_effecting_ii(2), 3)[0];
|
|
int _12_noFlatten1 = int[3](side_effecting_ii(1), 2, 3)[1];
|
|
int _13_noFlatten2 = int[3](1, ++_7_two, 3)[2];
|
|
return (_8_flatten0 == _11_noFlatten0 && _9_flatten1 == _12_noFlatten1) && _10_flatten2 == _13_noFlatten2 ? colorGreen : colorRed;
|
|
}
|