eb68973c2f
The GLSL spec allows matrix constructors containing vectors that would split between multiple columns of the matrix. However, in practice, this does not actually work well on a lot of GPUs! - "cast not allowed", "internal error": Tegra 3 Quadro P400 GTX 660 GTX 960 - Compiles, but generates wrong result: RadeonR9M470X RadeonHD7770 Since this isn't a pattern we expect to see in user code, we now report it as an error at compile time. mat2(vec4) is treated as an exceptional case and still allowed. Change-Id: Id6925984a2d1ec948aec4defcc790a197a96cf86 Bug: skia:12443 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/449518 Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
110 lines
3.3 KiB
Plaintext
110 lines
3.3 KiB
Plaintext
uniform half4 colorGreen, colorRed;
|
|
uniform float2x2 testMatrix2x2;
|
|
|
|
bool test_float() {
|
|
bool ok = true;
|
|
|
|
float2x2 m1 = testMatrix2x2;
|
|
ok = ok && (m1 == float2x2(1, 2, 3, 4));
|
|
|
|
// This generates {5, 0, 0, 5} on some Radeon GPUs.
|
|
// float2x2 m2 = float2x2(float4(5));
|
|
// ok = ok && (m2 == float2x2(5, 5, 5, 5));
|
|
|
|
float2x2 m3 = float2x2(m1);
|
|
ok = ok && (m3 == float2x2(1, 2, 3, 4));
|
|
|
|
float2x2 m4 = float2x2(6);
|
|
ok = ok && (m4 == float2x2(6, 0, 0, 6));
|
|
|
|
m3 *= m4;
|
|
ok = ok && (m3 == float2x2(6, 12, 18, 24));
|
|
|
|
float2x2 m5 = float2x2(m1[1][1]);
|
|
ok = ok && (m5 == float2x2(4, 0, 0, 4));
|
|
|
|
m1 += m5;
|
|
ok = ok && (m1 == float2x2(5, 2, 3, 8));
|
|
|
|
float2x2 m7 = float2x2(5, 6, float2(7, 8));
|
|
ok = ok && (m7 == float2x2(5, 6, 7, 8));
|
|
|
|
float3x3 m9 = float3x3(9);
|
|
ok = ok && (m9 == float3x3(9, 0, 0, 0, 9, 0, 0, 0, 9));
|
|
|
|
float4x4 m10 = float4x4(11);
|
|
ok = ok && (m10 == float4x4(11, 0, 0, 0, 0, 11, 0, 0, 0, 0, 11, 0, 0, 0, 0, 11));
|
|
|
|
float4x4 m11 = float4x4(20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20);
|
|
m11 -= m10;
|
|
ok = ok && (m11 == float4x4(9, 20, 20, 20, 20, 9, 20, 20, 20, 20, 9, 20, 20, 20, 20, 9));
|
|
|
|
float4 f4 = float4(testMatrix2x2);
|
|
ok = ok && float2x2(f4.xy, f4.z, 4) ==
|
|
float2x2(1, 2, 3, 4);
|
|
ok = ok && float3x3(f4.xy, f4.z, f4.w, f4.xy, f4.zw, f4.x) ==
|
|
float3x3(1, 2, 3, 4, 1, 2, 3, 4, 1);
|
|
ok = ok && float4x4(f4.xy, f4.zw, f4.xyz, f4.w, f4.xyzw, 1, f4.yzw) ==
|
|
float4x4(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4);
|
|
return ok;
|
|
}
|
|
|
|
bool test_half() {
|
|
bool ok = true;
|
|
|
|
half2x2 m1 = half2x2(testMatrix2x2);
|
|
ok = ok && (m1 == half2x2(1, 2, 3, 4));
|
|
|
|
// This generates {5, 0, 0, 5} on some Radeon GPUs.
|
|
// half2x2 m2 = half2x2(half4(5));
|
|
// ok = ok && (m2 == half2x2(5, 5, 5, 5));
|
|
|
|
half2x2 m3 = half2x2(m1);
|
|
ok = ok && (m3 == half2x2(1, 2, 3, 4));
|
|
|
|
half2x2 m4 = half2x2(6);
|
|
ok = ok && (m4 == half2x2(6, 0, 0, 6));
|
|
|
|
m3 *= m4;
|
|
ok = ok && (m3 == half2x2(6, 12, 18, 24));
|
|
|
|
half2x2 m5 = half2x2(m1[1][1]);
|
|
ok = ok && (m5 == half2x2(4, 0, 0, 4));
|
|
|
|
m1 += m5;
|
|
ok = ok && (m1 == half2x2(5, 2, 3, 8));
|
|
|
|
half2x2 m7 = half2x2(5, 6, half2(7, 8));
|
|
ok = ok && (m7 == half2x2(5, 6, 7, 8));
|
|
|
|
half3x3 m9 = half3x3(9);
|
|
ok = ok && (m9 == half3x3(9, 0, 0, 0, 9, 0, 0, 0, 9));
|
|
|
|
half4x4 m10 = half4x4(11);
|
|
ok = ok && (m10 == half4x4(11, 0, 0, 0, 0, 11, 0, 0, 0, 0, 11, 0, 0, 0, 0, 11));
|
|
|
|
half4x4 m11 = half4x4(20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20);
|
|
m11 -= m10;
|
|
ok = ok && (m11 == half4x4(9, 20, 20, 20, 20, 9, 20, 20, 20, 20, 9, 20, 20, 20, 20, 9));
|
|
|
|
half4 h4 = half4(testMatrix2x2);
|
|
ok = ok && half2x2(h4.xy, h4.z, 4) ==
|
|
half2x2(1, 2, 3, 4);
|
|
ok = ok && half3x3(h4.xy, h4.z, h4.w, h4.xy, h4.zw, h4.x) ==
|
|
half3x3(1, 2, 3, 4, 1, 2, 3, 4, 1);
|
|
ok = ok && half4x4(h4.xy, h4.zw, h4.xyz, h4.w, h4.xyzw, 1, h4.yzw) ==
|
|
half4x4(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4);
|
|
return ok;
|
|
}
|
|
|
|
bool test_comma() {
|
|
float2x2 x, y;
|
|
return (x = float2x2(1, 2, 3, 4),
|
|
y = 0.5 * float2x2(2, 4, 6, 8),
|
|
x == y);
|
|
}
|
|
|
|
half4 main(float2 coords) {
|
|
return test_float() && test_half() && test_comma() ? colorGreen : colorRed;
|
|
}
|