Debian Codegraph @

third_party/spirv-cross/shaders-msl/frag/lut-promotion.frag

raw
1 #version 310 es
2 precision mediump float;
3 layout(location = 0) out float FragColor;
4 layout(location = 0) flat in int index;
5
6 const float LUT[16] = float[](
7 1.0, 2.0, 3.0, 4.0,
8 1.0, 2.0, 3.0, 4.0,
9 1.0, 2.0, 3.0, 4.0,
10 1.0, 2.0, 3.0, 4.0);
11
12 void main()
13 {
14 // Try reading LUTs, both in branches and not branch.
15 FragColor = LUT[index];
16 if (index < 10)
17 FragColor += LUT[index ^ 1];
18 else
19 FragColor += LUT[index & 1];
20
21 // Not declared as a LUT, but can be promoted to one.
22 vec4 foo[4] = vec4[](vec4(0.0), vec4(1.0), vec4(8.0), vec4(5.0));
23 if (index > 30)
24 {
25 FragColor += foo[index & 3].y;
26 }
27 else
28 {
29 FragColor += foo[index & 1].x;
30 }
31
32 // Not declared as a LUT, but this cannot be promoted, because we have a partial write.
33 vec4 foobar[4] = vec4[](vec4(0.0), vec4(1.0), vec4(8.0), vec4(5.0));
34 if (index > 30)
35 {
36 foobar[1].z = 20.0;
37 }
38 FragColor += foobar[index & 3].z;
39
40 // Not declared as a LUT, but this cannot be promoted, because we have two complete writes.
41 vec4 baz[4] = vec4[](vec4(0.0), vec4(1.0), vec4(8.0), vec4(5.0));
42 baz = vec4[](vec4(20.0), vec4(30.0), vec4(50.0), vec4(60.0));
43 FragColor += baz[index & 3].z;
44 }