blob: 818e6d83d315631a65ebd4b71812f1a1be1cd45e [file] [log] [blame]
John Kessenich66011cb2018-03-06 16:12:04 -07001#version 450 core
2
3#extension GL_ARB_gpu_shader_int64: enable
4#extension GL_AMD_gpu_shader_half_float: enable
5#extension GL_AMD_gpu_shader_int16: enable
6
7layout(binding = 0) uniform Uniforms
8{
9 uint i;
10};
11
12// int16/uint16 in block
13layout(std140, binding = 1) uniform Block
14{
15 i16vec3 i16v;
16 uint16_t u16;
17} block;
18
19// int16/uint16 for input
20layout(location = 0) in flat u16vec3 iu16v;
21layout(location = 1) in flat int16_t ii16;
22
23void literal()
24{
25 const int16_t i16c[3] =
26 {
27 0x111S, // Hex
28 -2s, // Dec
29 0400s, // Oct
30 };
31
32 const uint16_t u16c[] =
33 {
34 0xFFFFus, // Hex
35 65535US, // Dec
36 0177777us, // Oct
37 };
38
39 uint16_t u16 = i16c[i] + u16c[i];
40}
41
42void operators()
43{
44 u16vec3 u16v;
45 int16_t i16;
46 uint16_t u16;
47 int i;
48 uint u;
49 bool b;
50
51 // Unary
52 u16v++;
53 i16--;
54 ++i16;
55 --u16v;
56
57 u16v = ~u16v;
58
59 i16 = +i16;
60 u16v = -u16v;
61
62 // Arithmetic
63 u16 += i16;
64 u16v -= u16v;
65 i16 *= i16;
66 u16v /= u16v;
67 u16v %= i16;
68
69 u16v = u16v + u16v;
70 u16 = i16 - u16;
71 u16v = u16v * i16;
72 i16 = i16 * i16;
73 i16 = i16 % i16;
74
75 // Shift
76 u16v <<= i16;
77 i16 >>= u16v.y;
78
79 i16 = i16 << u16v.z;
80 u16v = u16v << i16;
81
82 // Relational
83 b = (u16v.x != i16);
84 b = (i16 == u16v.x);
85 b = (u16v.x > u16v.y);
86 b = (i16 < u);
87 b = (u16v.y >= u16v.x);
88 b = (i16 <= i);
89
90 // Bitwise
91 u16v |= i16;
92 u16 = i16 | u16;
93 i16 &= i16;
94 u16v = u16v & u16v;
95 u16v ^= i16;
96 u16v = u16v ^ i16;
97}
98
99void typeCast()
100{
101 bvec2 bv;
102 ivec2 iv;
103 uvec2 uv;
104 vec2 fv;
105 dvec2 dv;
106
107 f16vec2 f16v;
108 i64vec2 i64v;
109 u64vec2 u64v;
110 i16vec2 i16v;
111 u16vec2 u16v;
112
113 i16v = i16vec2(bv); // bool -> int16
114 u16v = u16vec2(bv); // bool -> uint16
115 bv = bvec2(i16v); // int16 -> bool
116 bv = bvec2(u16v); // uint16 -> bool
117
118 i16v = i16vec2(iv); // int -> int16
119 u16v = u16vec2(iv); // int -> uint16
120 iv = i16v; // int16 -> int
121 iv = ivec2(u16v); // uint16 -> int
122
123 i16v = i16vec2(uv); // uint -> int16
124 u16v = u16vec2(uv); // uint -> uint16
125 uv = i16v; // int16 -> uint
126 uv = u16v; // uint16 -> uint
127
128 i16v = i16vec2(fv); // float -> int16
129 u16v = u16vec2(fv); // float -> uint16
130 fv = i16v; // int16 -> float
131 fv = u16v; // uint16 -> float
132
133 i16v = i16vec2(dv); // double -> int16
134 u16v = u16vec2(dv); // double -> uint16
135 dv = i16v; // int16 -> double
136 dv = u16v; // uint16 -> double
137
138 i16v = i16vec2(f16v); // float16 -> int16
139 u16v = u16vec2(f16v); // float16 -> uint16
140 f16v = i16v; // int16 -> float16
141 f16v = u16v; // uint16 -> float16
142
143 i16v = i16vec2(i64v); // int64 -> int16
144 u16v = u16vec2(i64v); // int64 -> uint16
145 i64v = i16v; // int16 -> int64
146 i64v = i64vec2(u16v); // uint16 -> int64
147
148 i16v = i16vec2(u64v); // uint64 -> int16
149 u16v = u16vec2(u64v); // uint64 -> uint16
150 u64v = i16v; // int16 -> uint64
151 u64v = u16v; // uint16 -> uint64
152
153 i16v = i16vec2(u16v); // uint16 -> int16
154 u16v = i16v; // int16 -> uint16
155}
156
157void builtinFuncs()
158{
159 i16vec2 i16v;
160 u16vec3 u16v;
161 f16vec3 f16v;
162 bvec3 bv;
163
164 int16_t i16;
165 uint16_t u16;
166
167 // abs()
168 i16v = abs(i16v);
169
170 // sign()
171 i16v = sign(i16v);
172
173 // min()
174 i16v = min(i16v, i16);
175 i16v = min(i16v, i16vec2(-1s));
176 u16v = min(u16v, u16);
177 u16v = min(u16v, u16vec3(0us));
178
179 // max()
180 i16v = max(i16v, i16);
181 i16v = max(i16v, i16vec2(-1s));
182 u16v = max(u16v, u16);
183 u16v = max(u16v, u16vec3(0us));
184
185 // clamp()
186 i16v = clamp(i16v, -i16, i16);
187 i16v = clamp(i16v, -i16v, i16v);
188 u16v = clamp(u16v, -u16, u16);
189 u16v = clamp(u16v, -u16v, u16v);
190
191 // mix()
192 i16 = mix(i16v.x, i16v.y, true);
193 i16v = mix(i16vec2(i16), i16vec2(-i16), bvec2(false));
194 u16 = mix(u16v.x, u16v.y, true);
195 u16v = mix(u16vec3(u16), u16vec3(-u16), bvec3(false));
196
197 // frexp()
198 i16vec3 exp;
199 f16v = frexp(f16v, exp);
200
201 // ldexp()
202 f16v = ldexp(f16v, exp);
203
204 // float16BitsToInt16()
205 i16v = float16BitsToInt16(f16v.xy);
206
207 // float16BitsToUint16()
208 u16v.x = float16BitsToUint16(f16v.z);
209
210 // int16BitsToFloat16()
211 f16v.xy = int16BitsToFloat16(i16v);
212
213 // uint16BitsToFloat16()
214 f16v = uint16BitsToFloat16(u16v);
215
216 // packInt2x16()
217 int packi = packInt2x16(i16v);
218
219 // unpackInt2x16()
220 i16v = unpackInt2x16(packi);
221
222 // packUint2x16()
223 uint packu = packUint2x16(u16v.xy);
224
225 // unpackUint2x16()
226 u16v.xy = unpackUint2x16(packu);
227
228 // packInt4x16()
229 int64_t packi64 = packInt4x16(i16vec4(i16));
230
231 // unpackInt4x16()
232 i16v = unpackInt4x16(packi64).xy;
233
234 // packUint4x16()
235 uint64_t packu64 = packUint4x16(u16vec4(u16));
236
237 // unpackUint4x16()
238 u16v = unpackUint4x16(packu64).xyz;
239
240 // lessThan()
241 bv = lessThan(u16v, u16vec3(u16));
242 bv.xy = lessThan(i16v, i16vec2(i16));
243
244 // lessThanEqual()
245 bv = lessThanEqual(u16v, u16vec3(u16));
246 bv.xy = lessThanEqual(i16v, i16vec2(i16));
247
248 // greaterThan()
249 bv = greaterThan(u16v, u16vec3(u16));
250 bv.xy = greaterThan(i16v, i16vec2(i16));
251
252 // greaterThanEqual()
253 bv = greaterThanEqual(u16v, u16vec3(u16));
254 bv.xy = greaterThanEqual(i16v, i16vec2(i16));
255
256 // equal()
257 bv = equal(u16v, u16vec3(u16));
258 bv.xy = equal(i16v, i16vec2(i16));
259
260 // notEqual()
261 bv = notEqual(u16v, u16vec3(u16));
262 bv.xy = notEqual(i16v, i16vec2(i16));
263}
264
265// Type conversion for specialization constant
266layout(constant_id = 100) const int64_t si64 = -10L;
267layout(constant_id = 101) const uint64_t su64 = 20UL;
268layout(constant_id = 102) const int si = -5;
269layout(constant_id = 103) const uint su = 4;
270layout(constant_id = 104) const bool sb = true;
271layout(constant_id = 105) const int16_t si16 = -5S;
272layout(constant_id = 106) const uint16_t su16 = 4US;
273
274// bool <-> int16/uint16
275const bool i16_to_b = bool(si16);
276const bool u16_to_b = bool(su16);
277const int16_t b_to_i16 = int16_t(sb);
278const uint16_t b_to_u16 = uint16_t(sb);
279
280// int <-> int16/uint16
281const int i16_to_i = int(si16);
282const int u16_to_i = int(su16);
283const int16_t i_to_i16 = int16_t(si);
284const uint16_t i_to_u16 = uint16_t(si);
285
286// uint <-> int16/uint16
287const uint i16_to_u = uint(si16);
288const uint u16_to_u = uint(su16);
289const int16_t u_to_i16 = int16_t(su);
290const uint16_t u_to_u16 = uint16_t(su);
291
292// int64 <-> int16/uint16
293const int64_t i16_to_i64 = int64_t(si16);
294const int64_t u16_to_i64 = int64_t(su16);
295const int16_t i64_to_i16 = int16_t(si64);
296const uint16_t i64_to_u16 = uint16_t(si64);
297
298// uint64 <-> int16/uint16
299const uint64_t i16_to_u64 = uint64_t(si16);
300const uint64_t u16_to_u64 = uint64_t(su16);
301const int16_t u64_to_i16 = int16_t(su64);
302const uint16_t u64_to_u16 = uint16_t(su64);
303
304// int16 <-> uint16
305const uint16_t i16_to_u16 = uint16_t(si16);
306const int16_t u16_to_i16 = int16_t(su16);
307
308void main()
309{
310 literal();
311 operators();
312 typeCast();
313 builtinFuncs();
314}