xref: /aosp_15_r20/external/skia/resources/sksl/intrinsics/Inverse.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform half4 colorGreen, colorRed;
2
3half4 main(float2 xy) {
4    const float2x2 matrix2x2 = float2x2(1, 2, 3, 4);
5    float2x2 inv2x2 = float2x2(-2, 1, 1.5, -0.5);
6    float3x3 inv3x3 = float3x3(-24, 18, 5, 20, -15, -4, -5, 4, 1);
7    float4x4 inv4x4 = float4x4(-2, -0.5, 1, 0.5, 1, 0.5, 0, -0.5, -8, -1, 2, 2, 3, 0.5, -1, -0.5);
8    float Zero = colorGreen.b;
9
10    // This test would require some slack to pass on real GPUs, since `inverse` on GPU hardware
11    // introduces a bit of floating-point error.
12    return (inverse(matrix2x2) == inv2x2 &&
13            inverse(float3x3(1, 2, 3, 0, 1, 4, 5, 6, 0)) == inv3x3 &&
14            inverse(float4x4(1, 0, 0, 1, 0, 2, 1, 2, 2, 1, 0, 1, 2, 0, 1, 4)) == inv4x4 &&
15            inverse(float3x3(1, 2, 3, 4, 5, 6, 7, 8, 9)) != inv3x3 &&
16            inverse(matrix2x2 + Zero) == inv2x2 &&
17            inverse(float3x3(1, 2, 3, 0, 1, 4, 5, 6, 0) + Zero) == inv3x3 &&
18            inverse(float4x4(1, 0, 0, 1, 0, 2, 1, 2, 2, 1, 0, 1, 2, 0, 1, 4) + Zero) == inv4x4)
19                ? colorGreen : colorRed;
20}
21