skia2/resources/sksl/intrinsics/MatrixCompMultES3.sksl
John Stiles eb68973c2f 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>
2021-09-16 22:14:49 +00:00

22 lines
1.2 KiB
Plaintext

uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const float2x3 f23 = matrixCompMult(float2x3(4), float2x3(5));
const half3x2 h32 = matrixCompMult(half3x2(5), half3x2(3));
half2x4 h24 = matrixCompMult(half2x4(9, 9, 9, 9, 9, 9, 9, 9),
half2x4(colorRed, colorGreen));
half4x2 h42 = matrixCompMult(half4x2(1, 2, 3, 4, 5, 6, 7, 8),
half4x2(colorRed.xy, colorRed.zw, colorGreen.xy, colorGreen.zw));
const float3x4 f34 = matrixCompMult(float3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
float3x4(12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
float4x3 f43 = matrixCompMult(float4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
float4x3(12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
return (f23 == float2x3(20) &&
h32 == half3x2(15) &&
h24 == half2x4(9, 0, 0, 9, 0, 9, 0, 9) &&
h42 == half4x2(1, 0, 0, 4, 0, 6, 0, 8) &&
f34 == float3x4(12, 22, 30, 36, 40, 42, 42, 40, 36, 30, 22, 12) &&
f43 == float4x3(12, 22, 30, 36, 40, 42, 42, 40, 36, 30, 22, 12)) ? colorGreen
: colorRed;
}