xref: /aosp_15_r20/external/skia/resources/sksl/shared/ConstantCompositeAccessViaConstantIndex.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform half4 colorRed;
2uniform half2x2 testMatrix2x2;
3uniform half testArray[5];
4
5const int zero = 0;
6
7const half[5] globalArray = half[5](1, 1, 1, 1, 1);
8const half2 globalVector = half2(1, 1);
9const half2x2 globalMatrix = half2x2(1, 1, 1, 1);
10
11half4 main(float2) {
12    const half[5] localArray = half[5](0, 1, 2, 3, 4);
13    const half2 localVector = half2(1, 1);
14    const half2x2 localMatrix = half2x2(0, 1, 2, 3);
15
16    // The comparisons against uniforms prevent the constant folding from eliminating the constant
17    // composite variables entirely. We expect all of the variables to propagate to the codegen
18    // backends, though the backend itself is allowed to eliminate variables.
19    if (globalArray == testArray ||
20        globalVector == colorRed.xy ||
21        globalMatrix == testMatrix2x2 ||
22        localArray == testArray ||
23        localVector == colorRed.xy ||
24        localMatrix == testMatrix2x2) {
25        return colorRed;
26    }
27
28    return half4(globalArray[zero] * localArray[zero],
29                 globalVector[zero] * localVector[zero],
30                 globalMatrix[zero] * localMatrix[zero]);
31}
32