xref: /aosp_15_r20/external/skia/resources/sksl/shared/Assignment.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform half4 colorGreen;
2
3struct S {
4    float f;
5    float af[5];
6    half4 h4;
7    half4 ah4[5];
8};
9
10half4 globalVar;
11S globalStruct;
12
13noinline void keepAlive(inout half h) {}
14noinline void keepAlive(inout float f) {}
15noinline void keepAlive(inout int i) {}
16
17void assignToFunctionParameter(int x, inout float y) {
18    x = 1;
19    y = 1;
20}
21
22half4 main(float2 coords) {
23    /* assign to scalar */               int i; i = 0;
24    /* assign to vector */               int4 i4; i4 = int4(1,2,3,4);
25    /* assign to matrix */               float3x3 f3x3; f3x3 = float3x3(1,2,3,4,5,6,7,8,9);
26    /* assign to swizzle */              half4 x; x.w = 0; x.yx = half2(0);
27    /* assign to array of scalar */      int ai[1]; ai[0] = 0;
28    /* assign to array of vector */      int4 ai4[1]; ai4[0] = int4(1,2,3,4);
29    /* assign to array of matrix */      half3x3 ah3x3[1]; ah3x3[0] = half3x3(1,2,3,4,5,6,7,8,9);
30    /* assign to array swizzle */        float4 af4[1]; af4[0].x = 0; af4[0].ywxz = float4(1);
31
32    /* assign to struct variable */      S s; s.f = 0;
33    /* assign to struct array */         s.af[1] = 0;
34    /* assign to struct swizzle */       s.h4.zxy = half3(9);
35    /* assign to struct array swizzle */ s.ah4[2].yw = half2(5);
36
37    /* assign to global var */           globalVar = half4(0);
38    /* assign to global struct */        globalStruct.f = 0;
39
40    /* assign to function parameter */   assignToFunctionParameter(0, f3x3[0][0]);
41
42// Not allowed in ES2
43//  /* assign to array idx by lookup */  ai[0] = 0; ai[ai[0]] = 0;
44
45// Not allowed natively in GLSL, but SkSL will turn these into valid GLSL expressions.
46    /* assign to folded ternary */       half l, r; (true ? l : r) = 0;
47    /* assign to unary plus */           +ai[0] += +ai4[0][0];
48    /* assign to struct unary plus */    +s.f = 1; +s.af[0] = 2;
49                                         +s.h4 = half4(1); +s.ah4[0] = half4(2);
50
51    /* repeat assignment */              float repeat; repeat = repeat = 1.0;
52
53    keepAlive(af4[0][0]);
54    keepAlive(ah3x3[0][0][0]);
55    keepAlive(i);
56    keepAlive(i4.y);
57    keepAlive(ai[0]);
58    keepAlive(ai4[0][0]);
59    keepAlive(x.y);
60    keepAlive(s.f);
61    keepAlive(l);
62    keepAlive(f3x3[0][0]);
63    keepAlive(repeat);
64
65    return colorGreen;
66}
67