blob: 80702b75986d44727cd457c06a46979c163ae239 [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 int8_t i8;
20 i8vec2 i8v2;
21 i8vec3 i8v3;
22 i8vec4 i8v4;
23 uint8_t u8;
24 u8vec2 u8v2;
25 u8vec3 u8v3;
26 u8vec4 u8v4;
27} block;
28
29void main()
30{
31}
32
33void literal()
34{
35 const int8_t i8Const[3] =
36 {
37 int8_t(-0x11), // Hex
38 int8_t(-1), // Dec
39 int8_t(0400), // Oct
40 };
41
42 int8_t i8 = i8Const[index];
43
44 const uint8_t u8Const[] =
45 {
46 uint8_t(0xFF), // Hex
47 uint8_t(255), // Dec
48 uint8_t(0177), // Oct
49 };
50
51 uint8_t u8 = u8Const[index];
52}
53
54void typeCast8()
55{
56 i8vec2 i8v;
57 u8vec2 u8v;
58 i16vec2 i16v;
59 u16vec2 u16v;
60 i32vec2 i32v;
61 u32vec2 u32v;
62 i64vec2 i64v;
63 u64vec2 u64v;
64 f16vec2 f16v;
65 f32vec2 f32v;
66 f64vec2 f64v;
67 bvec2 bv;
68
69 u8v = i8v; // int8_t -> uint8_t
70 i16v = i8v; // int8_t -> int16_t
71 i16v = u8v; // uint8_t -> int16_t
72 i32v = i8v; // int8_t -> int32_t
73 i32v = u8v; // uint8_t -> int32_t
74 u32v = i8v; // int8_t -> uint32_t
75 i64v = i8v; // int8_t -> int64_t
76 u64v = i8v; // int8_t -> uint64_t
77 u32v = u8v; // uint8_t -> uint32_t
78 i64v = u8v; // uint8_t -> int64_t
79 u64v = u8v; // uint8_t -> uint64_t
80 f16v = i8v; // int8_t -> float16_t
81 f32v = i8v; // int8_t -> float32_t
82 f64v = i8v; // int8_t -> float64_t
83 f16v = u8v; // uint8_t -> float16_t
84 f32v = u8v; // uint8_t -> float32_t
85 f64v = u8v; // uint8_t -> float64_t
86
87 i8v = i8vec2(u8v); // uint8_t -> int8_t
88 i16v = i16vec2(i8v); // int8_t -> int16_t
89 i16v = i16vec2(u8v); // uint8_t -> int16_t
90 i32v = i32vec2(i8v); // int8_t -> int32_t
91 i32v = i32vec2(u8v); // uint8_t -> int32_t
92 i64v = i64vec2(i8v); // int8_t -> int64_t
93 u64v = i64vec2(i8v); // int8_t -> uint64_t
94 u16v = u16vec2(i8v); // int8_t -> uint16_t
95 u16v = u16vec2(u8v); // uint8_t -> uint16_t
96 u32v = u32vec2(u8v); // uint8_t -> uint32_t
97 i64v = i64vec2(u8v); // uint8_t -> int64_t
98 u64v = i64vec2(u8v); // uint8_t -> uint64_t
99 f16v = f16vec2(i8v); // int8_t -> float16_t
100 f32v = f32vec2(i8v); // int8_t -> float32_t
101 f64v = f64vec2(i8v); // int8_t -> float64_t
102 f16v = f16vec2(u8v); // uint8_t -> float16_t
103 f32v = f32vec2(u8v); // uint8_t -> float32_t
104 f64v = f64vec2(u8v); // uint8_t -> float64_t
105
106 i8v = i8vec2(bv); // bool -> int8
107 u8v = u8vec2(bv); // bool -> uint8
108 bv = bvec2(i8v); // int8 -> bool
109 bv = bvec2(u8v); // uint8 -> bool
110}
111
112void operators()
113{
114 u8vec3 u8v;
115 int8_t i8;
116 uvec3 uv;
117 int32_t i;
118 int16_t i16;
119 bool b;
120
121 // Unary
122 u8v++;
123 i8--;
124 ++i8;
125 --u8v;
126
127 u8v = ~u8v;
128
129 i8 = +i8;
130 u8v = -u8v;
131
132 // Arithmetic
133 i8 += i8;
134 u8v -= u8v;
135 i *= i8;
136 uv /= u8v;
137 uv %= i8;
138
139 uv = u8v + uv;
140 i16 = i8 - i16;
141 uv = u8v * uv;
142 i16 = i8 * i16;
143 i = i8 % i;
144
145 // Shift
146 u8v <<= i8;
147 i8 >>= u8v.y;
148
149 i8 = i8 << u8v.z;
150 u8v = u8v << i8;
151
152 // Relational
153 b = (u8v.x != i8);
154 b = (i8 == u8v.x);
155 b = (u8v.x > uv.y);
156 b = (i8 < i);
157 b = (u8v.y >= uv.x);
158 b = (i8 <= i);
159
160 // Bitwise
161 uv |= i8;
162 i = i8 | i;
163 i16 &= i8;
164 uv = u8v & uv;
165 uv ^= i8;
166 u8v = u8v ^ i8;
167}
168
169void builtinFuncs()
170{
171 i8vec2 i8v;
172 i8vec4 i8v4;
173 u8vec3 u8v;
174 u8vec2 u8v2;
175 u8vec4 u8v4;
176 bvec3 bv;
177 int16_t i16;
178 int32_t i32;
179 uint16_t u16;
180 uint32_t u32;
181
182 int8_t i8;
183 uint8_t u8;
184
185 // abs()
186 i8v = abs(i8v);
187
188 // sign()
189 i8 = sign(i8);
190
191 // min()
192 i8v = min(i8v, i8);
193 i8v = min(i8v, i8vec2(-1));
194 u8v = min(u8v, u8);
195 u8v = min(u8v, u8vec3(0));
196
197 // max()
198 i8v = max(i8v, i8);
199 i8v = max(i8v, i8vec2(-1));
200 u8v = max(u8v, u8);
201 u8v = max(u8v, u8vec3(0));
202
203 // clamp()
204 i8v = clamp(i8v, -i8, i8);
205 i8v = clamp(i8v, -i8v, i8v);
206 u8v = clamp(u8v, -u8, u8);
207 u8v = clamp(u8v, -u8v, u8v);
208
209 // mix()
210 i8 = mix(i8v.x, i8v.y, true);
211 i8v = mix(i8vec2(i8), i8vec2(-i8), bvec2(false));
212 u8 = mix(u8v.x, u8v.y, true);
213 u8v = mix(u8vec3(u8), u8vec3(-u8), bvec3(false));
214
215 //pack
216 i16 = pack16(i8v);
217 i32 = pack32(i8v4);
218 u16 = pack16(u8v2);
219 u32 = pack32(u8v4);
220
221 i8v = unpack8(i16);
222 i8v4 = unpack8(i32);
223 u8v2 = unpack8(u16);
224 u8v4 = unpack8(u32);
225
226 // lessThan()
227 bv = lessThan(u8v, u8vec3(u8));
228 bv.xy = lessThan(i8v, i8vec2(i8));
229
230 // lessThanEqual()
231 bv = lessThanEqual(u8v, u8vec3(u8));
232 bv.xy = lessThanEqual(i8v, i8vec2(i8));
233
234 // greaterThan()
235 bv = greaterThan(u8v, u8vec3(u8));
236 bv.xy = greaterThan(i8v, i8vec2(i8));
237
238 // greaterThanEqual()
239 bv = greaterThanEqual(u8v, u8vec3(u8));
240 bv.xy = greaterThanEqual(i8v, i8vec2(i8));
241
242 // equal()
243 bv = equal(u8v, u8vec3(u8));
244 bv.xy = equal(i8v, i8vec2(i8));
245
246 // notEqual()
247 bv = notEqual(u8v, u8vec3(u8));
248 bv.xy = notEqual(i8v, i8vec2(i8));
249}
250
251// Type conversion for specialization constant
252layout(constant_id = 100) const int8_t si8 = int8_t(-10);
253layout(constant_id = 101) const uint8_t su8 = uint8_t(20);