Merge pull request #2891 from dneto0/hlsl-namespace
[platform/upstream/glslang.git] / Test / spv.int16.frag
1 #version 450
2
3 #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
11
12 layout(binding = 0) uniform Uniforms
13 {
14     uint index;
15 };
16
17 layout(std140, binding = 1) uniform Block
18 {
19     int16_t   i16;
20     i16vec2   i16v2;
21     i16vec3   i16v3;
22     i16vec4   i16v4;
23     uint16_t  u16;
24     u16vec2   u16v2;
25     u16vec3   u16v3;
26     u16vec4   u16v4;
27 } block;
28
29 void main()
30 {
31 }
32
33 void literal()
34 {
35     const int16_t i16Const[3] =
36     {
37         int16_t(-0x1111),           // Hex
38         int16_t(-1),                // Dec
39         int16_t(040000),            // Oct
40     };
41
42     int16_t i16 = i16Const[index];
43
44     const uint16_t u16Const[] =
45     {
46         uint16_t(0xFFFF),             // Hex
47         uint16_t(65535),              // Dec
48         uint16_t(077777),             // Oct
49     };
50
51     uint16_t u16 = u16Const[index];
52 }
53
54 void typeCast16()
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     i32v = i16v;     // int16_t  ->   int32_t
70     i32v = u16v;     // uint16_t ->   int32_t
71     u16v = i16v;     // int16_t  ->  uint16_t
72     u32v = i16v;     // int16_t  ->  uint32_t
73     i64v = i16v;     // int16_t  ->   int64_t
74     u64v = i16v;     // int16_t  ->  uint64_t
75     u32v = u16v;     // uint16_t ->  uint32_t
76     i64v = u16v;     // uint16_t ->   int64_t
77     u64v = u16v;     // uint16_t ->  uint64_t
78     f16v = i16v;     // int16_t  ->  float16_t
79     f32v = i16v;     // int16_t  ->  float32_t
80     f64v = i16v;     // int16_t  ->  float64_t
81     f16v = u16v;     // uint16_t ->  float16_t
82     f32v = u16v;     // uint16_t ->  float32_t
83     f64v = u16v;     // uint16_t ->  float64_t
84
85     i32v = i32vec2(i16v);     // int16_t  ->   int32_t
86     i32v = i32vec2(u16v);     // uint16_t ->   int32_t
87     u16v = u16vec2(i16v);     // int16_t  ->  uint16_t
88     u32v = u32vec2(i16v);     // int16_t  ->  uint32_t
89     i64v = i64vec2(i16v);     // int16_t  ->   int64_t
90     u64v = i64vec2(i16v);     // int16_t  ->  uint64_t
91     u32v = u32vec2(u16v);     // uint16_t ->  uint32_t
92     i64v = i64vec2(u16v);     // uint16_t ->   int64_t
93     u64v = i64vec2(u16v);     // uint16_t ->  uint64_t
94     f16v = f16vec2(i16v);     // int16_t  ->  float16_t
95     f32v = f32vec2(i16v);     // int16_t  ->  float32_t
96     f64v = f64vec2(i16v);     // int16_t  ->  float64_t
97     f16v = f16vec2(u16v);     // uint16_t ->  float16_t
98     f32v = f32vec2(u16v);     // uint16_t ->  float32_t
99     f64v = f64vec2(u16v);     // uint16_t ->  float64_t
100
101     i8v  = i8vec2(i16v);      // int16_t  ->   int8_t
102     i8v  = i8vec2(u16v);      // uint16_t ->   int8_t
103     u8v  = u8vec2(i16v);      // int16_t  ->  uint8_t
104     u8v  = u8vec2(u16v);      // uint16_t ->  uint8_t
105     i16v = u8vec2(u16v);      // uint16_t ->   int16_t
106     i16v = i16vec2(bv);       // bool     ->   int16
107     u16v = u16vec2(bv);       // bool     ->   uint16
108     bv   = bvec2(i16v);       // int16    ->   bool
109     bv   = bvec2(u16v);       // uint16   ->   bool
110 }
111 void operators()
112 {
113     u16vec3 u16v;
114     int16_t i16;
115     uvec3   uv;
116     int32_t i;
117     int64_t i64;
118     bool    b;
119     float   f;
120     float   arr[4] = {1.0, 2.0, 3.0, 4.0};
121
122     // Unary
123     u16v++;
124     i16--;
125     ++i16;
126     --u16v;
127
128     u16v = ~u16v;
129
130     i16 = +i16;
131     u16v = -u16v;
132
133     // Arithmetic
134     i16  += i16;
135     u16v -= u16v;
136     i  *= i16;
137     uv /= u16v;
138     uv %= i16;
139
140     uv = u16v + uv;
141     i64  = i16 - i64;
142     uv = u16v * uv;
143     i64  = i16 * i64;
144     i  = i16 % i;
145
146     // Shift
147     u16v <<= i16;
148     i16  >>= u16v.y;
149
150     i16  = i16 << u16v.z;
151     uv = u16v << i;
152
153     // Relational
154     b = (u16v.x != i16);
155     b = (i16 == u16v.x);
156     b = (u16v.x > uv.y);
157     b = (i16 < i);
158     b = (u16v.y >= uv.x);
159     b = (i16 <= i);
160
161     // Bitwise
162     uv |= i16;
163     i  = i16 | i;
164     i64  &= i16;
165     uv = u16v & uv;
166     uv ^= i16;
167     u16v = u16v ^ i16;
168
169     // Index
170     f = arr[i16];
171 }
172
173 void builtinFuncs()
174 {
175     i16vec2  i16v;
176     i16vec4  i16v4;
177     u16vec3  u16v;
178     u16vec2  u16v2;
179     u16vec4  u16v4;
180     bvec3   bv;
181     int16_t i16;
182     uint16_t u16;
183     int32_t i32;
184     uint32_t u32;
185     int64_t i64;
186     uint64_t u64;
187
188     // abs()
189     i16v = abs(i16v);
190
191     // sign()
192     i16  = sign(i16);
193
194     // min()
195     i16v = min(i16v, i16);
196     i16v = min(i16v, i16vec2(-1));
197     u16v = min(u16v, u16);
198     u16v = min(u16v, u16vec3(0));
199
200     // max()
201     i16v = max(i16v, i16);
202     i16v = max(i16v, i16vec2(-1));
203     u16v = max(u16v, u16);
204     u16v = max(u16v, u16vec3(0));
205
206     // clamp()
207     i16v = clamp(i16v, -i16, i16);
208     i16v = clamp(i16v, -i16v, i16v);
209     u16v = clamp(u16v, -u16, u16);
210     u16v = clamp(u16v, -u16v, u16v);
211
212     // mix()
213     i16  = mix(i16v.x, i16v.y, true);
214     i16v = mix(i16vec2(i16), i16vec2(-i16), bvec2(false));
215     u16  = mix(u16v.x, u16v.y, true);
216     u16v = mix(u16vec3(u16), u16vec3(-u16), bvec3(false));
217
218     //pack
219     i32 = pack32(i16v);
220     i64 = pack64(i16v4);
221     u32 = pack32(u16v2);
222     u64 = pack64(u16v4);
223
224     i16v  = unpack16(i32);
225     i16v4 = unpack16(i64);
226     u16v2 = unpack16(u32);
227     u16v4 = unpack16(u64);
228
229     // lessThan()
230     bv    = lessThan(u16v, u16vec3(u16));
231     bv.xy = lessThan(i16v, i16vec2(i16));
232
233     // lessThanEqual()
234     bv    = lessThanEqual(u16v, u16vec3(u16));
235     bv.xy = lessThanEqual(i16v, i16vec2(i16));
236
237     // greaterThan()
238     bv    = greaterThan(u16v, u16vec3(u16));
239     bv.xy = greaterThan(i16v, i16vec2(i16));
240
241     // greaterThanEqual()
242     bv    = greaterThanEqual(u16v, u16vec3(u16));
243     bv.xy = greaterThanEqual(i16v, i16vec2(i16));
244
245     // equal()
246     bv    = equal(u16v, u16vec3(u16));
247     bv.xy = equal(i16v, i16vec2(i16));
248
249     // notEqual()
250     bv    = notEqual(u16v, u16vec3(u16));
251     bv.xy = notEqual(i16v, i16vec2(i16));
252 }
253
254 // Type conversion for specialization constant
255 layout(constant_id = 100) const int16_t  si16 = int16_t(-10);
256 layout(constant_id = 101) const uint16_t su16 = uint16_t(20);