• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1uniform half4 colorRed, colorGreen;
2uniform half  unknownInput;
3
4bool test_half() {
5    bool ok = true;
6
7    // Vector op scalar
8    half4 x = half4(half2(1), half2(2, 3)) + 5;
9    ok = ok && (x == half4(6, 6, 7, 8));
10    x = half4(8, half3(10)) - 1;
11    ok = ok && (x == half4(7, 9, 9, 9));
12    x = half4(half2(8), half2(9)) + 1;
13    ok = ok && (x == half4(9, 9, 10, 10));
14    x.xyz = half3(2) * 3;
15    ok = ok && (x == half4(6, 6, 6, 10));
16    x.xy = half2(12) / 4;
17    ok = ok && (x == half4(3, 3, 6, 10));
18
19    // (Vector op scalar).swizzle
20    x = (half4(12) / 2).yxwz;
21    ok = ok && (x == half4(6));
22
23    // Scalar op vector
24    x = 5 + half4(half2(1), half2(2, 3));
25    ok = ok && (x == half4(6, 6, 7, 8));
26    x = 1 - half4(8, half3(10));
27    ok = ok && (x == half4(-7, -9, -9, -9));
28    x = 1 + half4(half2(8), half2(9));
29    ok = ok && (x == half4(9, 9, 10, 10));
30    x.xyz = 3 * half3(2);
31    ok = ok && (x == half4(6, 6, 6, 10));
32    x.xy = 4 / half2(0.5);
33    ok = ok && (x == half4(8, 8, 6, 10));
34    x = 20 / half4(10, 20, 40, 80);
35    ok = ok && (x == half4(2, 1, 0.5, 0.25));
36
37    // (Scalar op vector).swizzle
38    x = (12 / half4(2)).yxwz;
39    ok = ok && (x == half4(6));
40
41    // Vector op unknown scalar
42    half  unknown = unknownInput;
43    x = half4(0) + unknown;
44    ok = ok && (x == half4(unknown));
45    x = half4(0) * unknown;
46    ok = ok && (x == half4(0));
47    x = half4(0) / unknown;
48    ok = ok && (x == half4(0));
49    x = half4(1) * unknown;
50    ok = ok && (x == half4(unknown));
51
52    // Unknown scalar op vector
53    x = unknown * half4(1);
54    ok = ok && (x == half4(unknown));
55    x = unknown + half4(0);
56    ok = ok && (x == half4(unknown));
57    x = unknown - half4(0);
58    ok = ok && (x == half4(unknown));
59    x = unknown / half4(1);
60    ok = ok && (x == half4(unknown));
61
62    // Scalar op unknown vector
63    x = 0 + half4(unknown);
64    ok = ok && (x == half4(unknown));
65    x = 0 * half4(unknown);
66    ok = ok && (x == half4(0));
67    x = 0 / half4(unknown);  // this should NOT optimize away
68    ok = ok && (x == half4(0));
69    x = 1 * half4(unknown);
70    ok = ok && (x == half4(unknown));
71
72    // X = Unknown op scalar
73    x = half4(unknown) + 0;
74    ok = ok && (x == half4(unknown));
75    x = half4(unknown) * 0;
76    ok = ok && (x == half4(0));
77    x = half4(unknown) * 1;
78    ok = ok && (x == half4(unknown));
79    x = half4(unknown) - 0;
80    ok = ok && (x == half4(unknown));
81
82    // X op= scalar.
83    x = half4(unknown);
84    x += 1;
85    x += 0;
86    x -= 1;
87    x -= 0;
88    x *= 1;
89    x /= 1;
90    ok = ok && (x == half4(unknown));
91
92    // X = X op scalar.
93    x = half4(unknown);
94    x = x + 1;
95    x = x + 0;
96    x = x - 1;
97    x = x - 0;
98    x = x * 1;
99    x = x / 1;
100    ok = ok && (x == half4(unknown));
101
102    return ok;
103}
104
105bool test_int() {
106    bool ok = true;
107
108    // Vector op scalar
109    int4 x = int4(int2(1), int2(2, 3)) + 5;
110    ok = ok && (x == int4(6, 6, 7, 8));
111    x = int4(8, int3(10)) - 1;
112    ok = ok && (x == int4(7, 9, 9, 9));
113    x = int4(int2(8), int2(9)) + 1;
114    ok = ok && (x == int4(9, 9, 10, 10));
115    x.xyz = int3(2) * 3;
116    ok = ok && (x == int4(6, 6, 6, 10));
117    x.xy = int2(12) / 4;
118    ok = ok && (x == int4(3, 3, 6, 10));
119
120    // (Vector op scalar).swizzle
121    x = (int4(12) / 2).yxwz;
122    ok = ok && (x == int4(6));
123
124    // Scalar op vector
125    x = 5 + int4(int2(1), int2(2, 3));
126    ok = ok && (x == int4(6, 6, 7, 8));
127    x = 1 - int4(8, int3(10));
128    ok = ok && (x == int4(-7, -9, -9, -9));
129    x = 1 + int4(int2(8), int2(9));
130    ok = ok && (x == int4(9, 9, 10, 10));
131    x.xyz = 3 * int3(2);
132    ok = ok && (x == int4(6, 6, 6, 10));
133    x.xy = 16 / int2(2);
134    ok = ok && (x == int4(8, 8, 6, 10));
135    x = 2000 / int4(10, 20, 40, 80);
136    ok = ok && (x == int4(200, 100, 50, 25));
137
138    // (Scalar op vector).swizzle
139    x = (12 / int4(2)).yxwz;
140    ok = ok && (x == int4(6));
141
142    // Vector op unknown scalar
143    int  unknown = int(unknownInput);
144    x = int4(0) + unknown;
145    ok = ok && (x == int4(unknown));
146    x = int4(0) * unknown;
147    ok = ok && (x == int4(0));
148    x = int4(0) / unknown;
149    ok = ok && (x == int4(0));
150    x = int4(1) * unknown;
151    ok = ok && (x == int4(unknown));
152
153    // Unknown scalar op vector
154    x = unknown * int4(1);
155    ok = ok && (x == int4(unknown));
156    x = unknown + int4(0);
157    ok = ok && (x == int4(unknown));
158    x = unknown - int4(0);
159    ok = ok && (x == int4(unknown));
160    x = unknown / int4(1);
161    ok = ok && (x == int4(unknown));
162
163    // Scalar op unknown vector
164    x = 0 + int4(unknown);
165    ok = ok && (x == int4(unknown));
166    x = 0 * int4(unknown);
167    ok = ok && (x == int4(0));
168    x = 0 / int4(unknown);
169    ok = ok && (x == int4(0));
170    x = 1 * int4(unknown);
171    ok = ok && (x == int4(unknown));
172
173    // Unknown vector op scalar
174    x = int4(unknown) + 0;
175    ok = ok && (x == int4(unknown));
176    x = int4(unknown) * 0;
177    ok = ok && (x == int4(0));
178    x = int4(unknown) * 1;
179    ok = ok && (x == int4(unknown));
180    x = int4(unknown) - 0;
181    ok = ok && (x == int4(unknown));
182
183    // X op= scalar.
184    x = int4(unknown);
185    x += 1;
186    x += 0;
187    x -= 1;
188    x -= 0;
189    x *= 1;
190    x /= 1;
191    ok = ok && (x == int4(unknown));
192
193    // X = X op scalar.
194    x = int4(unknown);
195    x = x + 1;
196    x = x + 0;
197    x = x - 1;
198    x = x - 0;
199    x = x * 1;
200    x = x / 1;
201    ok = ok && (x == int4(unknown));
202
203    return ok;
204}
205
206half4 main(float2 coords) {
207    return test_half() && test_int() ? colorGreen : colorRed;
208}
209