1#version 450
2
3#extension GL_KHX_shader_explicit_arithmetic_types: enable
4#extension GL_KHX_shader_explicit_arithmetic_types_int8: require
5#extension GL_KHX_shader_explicit_arithmetic_types_int16: require
6#extension GL_KHX_shader_explicit_arithmetic_types_int32: require
7#extension GL_KHX_shader_explicit_arithmetic_types_int64: require
8#extension GL_KHX_shader_explicit_arithmetic_types_float16: require
9#extension GL_KHX_shader_explicit_arithmetic_types_float32: require
10#extension GL_KHX_shader_explicit_arithmetic_types_float64: require
11
12void main()
13{
14}
15
16// Single float literals
17void literal()
18{
19    const float32_t f32c  = 0.000001f;
20    const f32vec2   f32cv = f32vec2(-0.25F, 0.03f);
21
22    f32vec2 f32v;
23    f32v.x  = f32c;
24    f32v   += f32cv;
25}
26
27// Block memory layout
28struct S
29{
30    float32_t  x;
31    f32vec2    y;
32    f32vec3    z;
33};
34
35layout(column_major, std140) uniform B1
36{
37    float32_t  a;
38    f32vec2    b;
39    f32vec3    c;
40    float32_t  d[2];
41    f32mat2x3  e;
42    f32mat2x3  f[2];
43    S          g;
44    S          h[2];
45};
46
47// Specialization constant
48layout(constant_id = 100) const float16_t sf16 = 0.125hf;
49layout(constant_id = 101) const float32_t sf   = 0.25;
50layout(constant_id = 102) const float64_t sd   = 0.5lf;
51
52const float  f16_to_f = float(sf16);
53const double f16_to_d = float(sf16);
54
55const float16_t f_to_f16 = float16_t(sf);
56const float16_t d_to_f16 = float16_t(sd);
57
58void operators()
59{
60    float32_t f32;
61    f32vec2   f32v;
62    f32mat2x2 f32m;
63    bool      b;
64
65    // Arithmetic
66    f32v += f32v;
67    f32v -= f32v;
68    f32v *= f32v;
69    f32v /= f32v;
70    f32v++;
71    f32v--;
72    ++f32m;
73    --f32m;
74    f32v = -f32v;
75    f32m = -f32m;
76
77    f32 = f32v.x + f32v.y;
78    f32 = f32v.x - f32v.y;
79    f32 = f32v.x * f32v.y;
80    f32 = f32v.x / f32v.y;
81
82    // Relational
83    b = (f32v.x != f32);
84    b = (f32v.y == f32);
85    b = (f32v.x >  f32);
86    b = (f32v.y <  f32);
87    b = (f32v.x >= f32);
88    b = (f32v.y <= f32);
89
90    // Vector/matrix operations
91    f32v = f32v * f32;
92    f32m = f32m * f32;
93    f32v = f32m * f32v;
94    f32v = f32v * f32m;
95    f32m = f32m * f32m;
96}
97
98void typeCast()
99{
100    bvec3   bv;
101    f32vec3   f32v;
102    f64vec3   f64v;
103    i8vec3    i8v;
104    u8vec3    u8v;
105    i16vec3   i16v;
106    u16vec3   u16v;
107    i32vec3   i32v;
108    u32vec3   u32v;
109    i64vec3   i64v;
110    u64vec3   u64v;
111    f16vec3   f16v;
112
113    f64v = f32v;            // float32_t -> float64_t
114
115    f32v = f32vec3(bv);     // bool -> float32
116    bv   = bvec3(f32v);     // float32 -> bool
117
118    f32v = f32vec3(f64v);   // double -> float32
119    f64v = f64vec3(f32v);   // float32 -> double
120
121    f32v = f32vec3(f16v);   // float16 -> float32
122    f16v = f16vec3(f32v);   // float32 -> float16
123
124    i8v  = i8vec3(f32v);    //  float32 -> int8
125    i16v = i16vec3(f32v);    // float32 -> int16
126    i32v = i32vec3(f32v);    // float32 -> int32
127    i64v = i64vec3(f32v);    // float32 -> int64
128
129    u8v  = u8vec3(f32v);    //  float32 -> uint8
130    u16v = u16vec3(f32v);    // float32 -> uint16
131    u32v = u32vec3(f32v);    // float32 -> uint32
132    u64v = u64vec3(f32v);    // float32 -> uint64
133}
134
135void builtinAngleTrigFuncs()
136{
137    f32vec4 f32v1, f32v2;
138
139    f32v2 = radians(f32v1);
140    f32v2 = degrees(f32v1);
141    f32v2 = sin(f32v1);
142    f32v2 = cos(f32v1);
143    f32v2 = tan(f32v1);
144    f32v2 = asin(f32v1);
145    f32v2 = acos(f32v1);
146    f32v2 = atan(f32v1, f32v2);
147    f32v2 = atan(f32v1);
148    f32v2 = sinh(f32v1);
149    f32v2 = cosh(f32v1);
150    f32v2 = tanh(f32v1);
151    f32v2 = asinh(f32v1);
152    f32v2 = acosh(f32v1);
153    f32v2 = atanh(f32v1);
154}
155
156void builtinExpFuncs()
157{
158    f32vec2 f32v1, f32v2;
159
160    f32v2 = pow(f32v1, f32v2);
161    f32v2 = exp(f32v1);
162    f32v2 = log(f32v1);
163    f32v2 = exp2(f32v1);
164    f32v2 = log2(f32v1);
165    f32v2 = sqrt(f32v1);
166    f32v2 = inversesqrt(f32v1);
167}
168
169void builtinCommonFuncs()
170{
171    f32vec3   f32v1, f32v2, f32v3;
172    float32_t f32;
173    bool  b;
174    bvec3 bv;
175    ivec3 iv;
176
177    f32v2 = abs(f32v1);
178    f32v2 = sign(f32v1);
179    f32v2 = floor(f32v1);
180    f32v2 = trunc(f32v1);
181    f32v2 = round(f32v1);
182    f32v2 = roundEven(f32v1);
183    f32v2 = ceil(f32v1);
184    f32v2 = fract(f32v1);
185    f32v2 = mod(f32v1, f32v2);
186    f32v2 = mod(f32v1, f32);
187    f32v3 = modf(f32v1, f32v2);
188    f32v3 = min(f32v1, f32v2);
189    f32v3 = min(f32v1, f32);
190    f32v3 = max(f32v1, f32v2);
191    f32v3 = max(f32v1, f32);
192    f32v3 = clamp(f32v1, f32, f32v2.x);
193    f32v3 = clamp(f32v1, f32v2, f32vec3(f32));
194    f32v3 = mix(f32v1, f32v2, f32);
195    f32v3 = mix(f32v1, f32v2, f32v3);
196    f32v3 = mix(f32v1, f32v2, bv);
197    f32v3 = step(f32v1, f32v2);
198    f32v3 = step(f32, f32v3);
199    f32v3 = smoothstep(f32v1, f32v2, f32v3);
200    f32v3 = smoothstep(f32, f32v1.x, f32v2);
201    b     = isnan(f32);
202    bv    = isinf(f32v1);
203    f32v3 = fma(f32v1, f32v2, f32v3);
204    f32v2 = frexp(f32v1, iv);
205    f32v2 = ldexp(f32v1, iv);
206}
207
208void builtinGeometryFuncs()
209{
210    float32_t f32;
211    f32vec3   f32v1, f32v2, f32v3;
212
213    f32   = length(f32v1);
214    f32   = distance(f32v1, f32v2);
215    f32   = dot(f32v1, f32v2);
216    f32v3 = cross(f32v1, f32v2);
217    f32v2 = normalize(f32v1);
218    f32v3 = faceforward(f32v1, f32v2, f32v3);
219    f32v3 = reflect(f32v1, f32v2);
220    f32v3 = refract(f32v1, f32v2, f32);
221}
222
223void builtinMatrixFuncs()
224{
225    f32mat2x3 f32m1, f32m2, f32m3;
226    f32mat3x2 f32m4;
227    f32mat3   f32m5;
228    f32mat4   f32m6, f32m7;
229
230    f32vec3 f32v1;
231    f32vec2 f32v2;
232
233    float32_t f32;
234
235    f32m3 = matrixCompMult(f32m1, f32m2);
236    f32m1 = outerProduct(f32v1, f32v2);
237    f32m4 = transpose(f32m1);
238    f32   = determinant(f32m5);
239    f32m6 = inverse(f32m7);
240}
241
242void builtinVecRelFuncs()
243{
244    f32vec3 f32v1, f32v2;
245    bvec3   bv;
246
247    bv = lessThan(f32v1, f32v2);
248    bv = lessThanEqual(f32v1, f32v2);
249    bv = greaterThan(f32v1, f32v2);
250    bv = greaterThanEqual(f32v1, f32v2);
251    bv = equal(f32v1, f32v2);
252    bv = notEqual(f32v1, f32v2);
253}
254
255in f32vec3 if32v;
256
257void builtinFragProcFuncs()
258{
259    f32vec3 f32v;
260
261    // Derivative
262    f32v.x  = dFdx(if32v.x);
263    f32v.y  = dFdy(if32v.y);
264    f32v.xy = dFdxFine(if32v.xy);
265    f32v.xy = dFdyFine(if32v.xy);
266    f32v    = dFdxCoarse(if32v);
267    f32v    = dFdxCoarse(if32v);
268
269    f32v.x  = fwidth(if32v.x);
270    f32v.xy = fwidthFine(if32v.xy);
271    f32v    = fwidthCoarse(if32v);
272
273    // Interpolation
274    f32v.x  = interpolateAtCentroid(if32v.x);
275    f32v.xy = interpolateAtSample(if32v.xy, 1);
276    f32v    = interpolateAtOffset(if32v, f32vec2(0.5f));
277}
278