skia2/tests/sksl/shared/UnaryPositiveNegative.glsl
Arman Uguray 5f16ed4c58 [sksl] Special-case unary negation on matrix types in MSL/SPIR-V
MSL does not support the unary "-" operator on matrix types. Similarly
the SPIR-V OpFNegate/OpSNegate operations only work on scalar and vector
type.

* An expression such as "-<mat>" is now transformed to "-1.0 * <mat>" when
generating MSL.
* The same expression now generates a component-wise negation in SPIR-V,
matching what glslang outputs for GLSL.
* A unary "+" is now treated as NOP for MSL, matching the SPIR-V backend.
An expression such as "+<expr>" is now evaluated as "<expr>".
* The shared/Negation.sksl has been moved to folding/ as much of its
contents exercise constant-folding of comparison expressions.
* The shared/UnaryPositiveNegative.sksl test has been extended to
exercise scalar and matrix types.

NOTE: The SPIR-V backend changes have caused a minor re-ordering of SSA
IDs generated when writing out a prefix-expression. The affected gold
files have been updated.

Bug: skia:12627, skia:12992
Change-Id: Iec5cdafc591aed7e49b3b52bda42a02661380bab
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/513976
Auto-Submit: Arman Uguray <armansito@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Arman Uguray <armansito@google.com>
2022-03-01 20:14:46 +00:00

47 lines
1.2 KiB
GLSL

out vec4 sk_FragColor;
uniform vec4 colorWhite;
uniform vec4 colorGreen;
uniform vec4 colorRed;
uniform mat2 testMatrix2x2;
uniform mat3 testMatrix3x3;
uniform mat4 testMatrix4x4;
bool test_iscalar_b() {
int x = int(colorWhite.x);
x = -x;
return x == -1;
}
bool test_fvec_b() {
vec2 x = colorWhite.xy;
x = -x;
return x == vec2(-1.0);
}
bool test_ivec_b() {
ivec2 x = ivec2(int(colorWhite.x));
x = -x;
return x == ivec2(-1);
}
bool test_mat2_b() {
const mat2 negated = mat2(-1.0, -2.0, -3.0, -4.0);
mat2 x = testMatrix2x2;
x = -x;
return x == negated;
}
bool test_mat3_b() {
const mat3 negated = mat3(-1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0);
mat3 x = testMatrix3x3;
x = -x;
return x == negated;
}
bool test_mat4_b() {
const mat4 negated = mat4(-1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0, -13.0, -14.0, -15.0, -16.0);
mat4 x = testMatrix4x4;
x = -x;
return x == negated;
}
vec4 main() {
float _0_x = colorWhite.x;
_0_x = -_0_x;
return (((((_0_x == -1.0 && test_iscalar_b()) && test_fvec_b()) && test_ivec_b()) && test_mat2_b()) && test_mat3_b()) && test_mat4_b() ? colorGreen : colorRed;
}