skia2/resources/sksl/shared/Matrices.sksl
John Stiles 21fe518fbb Revert "Disallow matrix ctors which overflow a column."
This reverts commit eb68973c2f.

Reason for revert: ES2 conformance test checks this

Original change's description:
> Disallow matrix ctors which overflow a column.
>
> 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>

Bug: skia:12443
Change-Id: I5a32744c88b9b830ad657488824c8c7dd0b0a652
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/458056
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
2021-10-14 01:30:08 +00:00

95 lines
2.5 KiB
Plaintext

uniform half4 colorGreen, colorRed;
bool test_float() {
bool ok = true;
float2x2 m1 = float2x2(float4(1, 2, 3, 4));
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, float3(6, 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));
return ok;
}
bool test_half() {
bool ok = true;
half2x2 m1 = half2x2(half4(1, 2, 3, 4));
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, half3(6, 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));
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;
}