blob: 0a39ecd4544b08fe0338e97a71c201a593d12a49 [file] [log] [blame]
John Kessenich66011cb2018-03-06 16:12:04 -07001#version 450
2
Alexander Galazin32def9f2018-12-03 13:16:59 +01003#extension GL_EXT_shader_explicit_arithmetic_types: enable
4#extension GL_EXT_shader_explicit_arithmetic_types_int8: require
5#extension GL_EXT_shader_explicit_arithmetic_types_int16: require
6#extension GL_EXT_shader_explicit_arithmetic_types_int32: require
7#extension GL_EXT_shader_explicit_arithmetic_types_int64: require
8#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
9#extension GL_EXT_shader_explicit_arithmetic_types_float32: require
10#extension GL_EXT_shader_explicit_arithmetic_types_float64: require
John Kessenich66011cb2018-03-06 16:12:04 -070011
12layout(binding = 0) uniform Uniforms
13{
14 uint index;
15};
16
17layout(std140, binding = 1) uniform Block
18{
19 int32_t i32;
20 i32vec2 i32v2;
21 i32vec3 i32v3;
22 i32vec4 i32v4;
23 uint32_t u32;
24 u32vec2 u32v2;
25 u32vec3 u32v3;
26 u32vec4 u32v4;
27} block;
28
29void main()
30{
31}
32
33void literal()
34{
35
36 const int32_t i32Const[3] =
37 {
38 -0x11111111, // Hex
39 -1, // Dec
40 04000000000, // Oct
41 };
42
43 int32_t i32 = i32Const[index];
44
45 const uint32_t u32Const[] =
46 {
47 0xFFFFFFFF, // Hex
48 4294967295, // Dec
49 017777777777, // Oct
50 };
51
52 uint32_t u32 = u32Const[index];
53}
54
55void typeCast32()
56{
57 i8vec2 i8v;
58 u8vec2 u8v;
59 i16vec2 i16v;
60 u16vec2 u16v;
61 i32vec2 i32v;
62 u32vec2 u32v;
63 i64vec2 i64v;
64 u64vec2 u64v;
65 f16vec2 f16v;
66 f32vec2 f32v;
67 f64vec2 f64v;
68 bvec2 bv;
69
70 u32v = i32v; // int32_t -> uint32_t
71 i64v = i32v; // int32_t -> int64_t
72 u64v = i32v; // int32_t -> uint64_t
73 i64v = u32v; // uint32_t -> int64_t
74 u64v = u32v; // uint32_t -> uint64_t
75 f32v = i32v; // int32_t -> float32_t
76 f64v = i32v; // int32_t -> float64_t
77 f32v = u32v; // uint32_t -> float32_t
78 f64v = u32v; // uint32_t -> float64_t
79
80 i8v = i8vec2(i32v); // int32_t -> int8_t
81 i8v = i8vec2(u32v); // uint32_t -> int8_t
82 i16v = i16vec2(i32v); // int32_t -> int16_t
83 i16v = i16vec2(u32v); // uint32_t -> int16_t
84 i32v = i32vec2(i32v); // int32_t -> int32_t
85 i32v = i32vec2(u32v); // uint32_t -> int32_t
86 i64v = i64vec2(i32v); // int32_t -> int64_t
87 i64v = i64vec2(u32v); // uint32_t -> int64_t
88 u8v = u8vec2(i32v); // int32_t -> uint8_t
89 u8v = u8vec2(u32v); // uint32_t -> uint8_t
90 u16v = u16vec2(i32v); // int32_t -> uint16_t
91 u16v = u16vec2(u32v); // uint32_t -> uint16_t
92 u32v = u32vec2(i32v); // int32_t -> uint32_t
93 u32v = u32vec2(u32v); // uint32_t -> uint32_t
94 u64v = u64vec2(i32v); // int32_t -> uint64_t
95 u64v = u64vec2(u32v); // uint32_t -> uint64_t
96
97 f16v = f16vec2(i32v); // int32_t -> float16_t
98 f32v = f32vec2(i32v); // int32_t -> float32_t
99 f64v = f64vec2(i32v); // int32_t -> float64_t
100 f16v = f16vec2(u32v); // uint32_t -> float16_t
101 f32v = f32vec2(u32v); // uint32_t -> float32_t
102 f64v = f64vec2(u32v); // uint32_t -> float64_t
103
104 i32v = i32vec2(bv); // bool -> int32
105 u32v = u32vec2(bv); // bool -> uint32
106 bv = bvec2(i32v); // int32 -> bool
107 bv = bvec2(u32v); // uint32 -> bool
108}
109
110void operators()
111{
112 u32vec3 u32v;
113 int32_t i32;
114 uvec3 uv;
115 int32_t i;
116 int64_t i64;
117 bool b;
118
119 // Unary
120 u32v++;
121 i32--;
122 ++i32;
123 --u32v;
124
125 u32v = ~u32v;
126
127 i32 = +i32;
128 u32v = -u32v;
129
130 // Arithmetic
131 i32 += i32;
132 u32v -= u32v;
133 i *= i32;
134 uv /= u32v;
135 uv %= i32;
136
137 uv = u32v + uv;
138 i64 = i32 - i64;
139 uv = u32v * uv;
140 i64 = i32 * i64;
141 i = i32 % i;
142
143 // Shift
144 u32v <<= i32;
145 i32 >>= u32v.y;
146
147 i64 = i64 << u32v.z;
148 uv = u32v << i;
149
150 // Relational
151 b = (u32v.x != i32);
152 b = (i32 == u32v.x);
153 b = (u32v.x > uv.y);
154 b = (i32 < i);
155 b = (u32v.y >= uv.x);
156 b = (i32 <= i);
157
158 // Bitwise
159 uv |= i32;
160 i = i32 | i;
161 i64 &= i32;
162 uv = u32v & uv;
163 uv ^= i32;
164 u32v = u32v ^ i32;
165}
166
167void builtinFuncs()
168{
169 i32vec2 i32v;
170 i32vec4 i32v4;
171 u32vec3 u32v;
172 u32vec2 u32v2;
173 u32vec4 u32v4;
174 bvec3 bv;
175 int32_t i32;
176 uint32_t u32;
177 int64_t i64;
178 uint64_t u64;
179 i8vec4 i8v4;
180 u8vec4 u8v4;
181 i16vec2 i16v2;
182 u16vec2 u16v2;
183
184 // abs()
185 i32v = abs(i32v);
186
187 // sign()
188 i32 = sign(i32);
189
190 // min()
191 i32v = min(i32v, i32);
192 i32v = min(i32v, i32vec2(-1));
193 u32v = min(u32v, u32);
194 u32v = min(u32v, u32vec3(0));
195
196 // max()
197 i32v = max(i32v, i32);
198 i32v = max(i32v, i32vec2(-1));
199 u32v = max(u32v, u32);
200 u32v = max(u32v, u32vec3(0));
201
202 // clamp()
203 i32v = clamp(i32v, -i32, i32);
204 i32v = clamp(i32v, -i32v, i32v);
205 u32v = clamp(u32v, -u32, u32);
206 u32v = clamp(u32v, -u32v, u32v);
207
208 // mix()
209 i32 = mix(i32v.x, i32v.y, true);
210 i32v = mix(i32vec2(i32), i32vec2(-i32), bvec2(false));
211 u32 = mix(u32v.x, u32v.y, true);
212 u32v = mix(u32vec3(u32), u32vec3(-u32), bvec3(false));
213
214 //pack
215 i32 = pack32(i8v4);
216 i32 = pack32(i16v2);
217 u32 = pack32(u8v4);
218 u32 = pack32(u16v2);
219
220 i32v = unpack32(i64);
221 u32v2 = unpack32(u64);
222
223 // lessThan()
224 bv = lessThan(u32v, u32vec3(u32));
225 bv.xy = lessThan(i32v, i32vec2(i32));
226
227 // lessThanEqual()
228 bv = lessThanEqual(u32v, u32vec3(u32));
229 bv.xy = lessThanEqual(i32v, i32vec2(i32));
230
231 // greaterThan()
232 bv = greaterThan(u32v, u32vec3(u32));
233 bv.xy = greaterThan(i32v, i32vec2(i32));
234
235 // greaterThanEqual()
236 bv = greaterThanEqual(u32v, u32vec3(u32));
237 bv.xy = greaterThanEqual(i32v, i32vec2(i32));
238
239 // equal()
240 bv = equal(u32v, u32vec3(u32));
241 bv.xy = equal(i32v, i32vec2(i32));
242
243 // notEqual()
244 bv = notEqual(u32v, u32vec3(u32));
245 bv.xy = notEqual(i32v, i32vec2(i32));
246}
247
248// Type conversion for specialization constant
249layout(constant_id = 100) const int32_t si32 = -10;
250layout(constant_id = 101) const uint32_t su32 = 20U;
251layout(constant_id = 102) const int si = -5;
252layout(constant_id = 103) const uint su = 4;
253layout(constant_id = 104) const bool sb = true;
254
255#define UINT32_MAX 4294967295u
256uint32_t u32Max = UINT32_MAX;