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 12layout(binding = 0) uniform Uniforms 13{ 14 uint index; 15}; 16 17layout(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 29void main() 30{ 31} 32 33void 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 54void 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} 111void operators() 112{ 113 u16vec3 u16v; 114 int16_t i16; 115 uvec3 uv; 116 int32_t i; 117 int64_t i64; 118 bool b; 119 120 // Unary 121 u16v++; 122 i16--; 123 ++i16; 124 --u16v; 125 126 u16v = ~u16v; 127 128 i16 = +i16; 129 u16v = -u16v; 130 131 // Arithmetic 132 i16 += i16; 133 u16v -= u16v; 134 i *= i16; 135 uv /= u16v; 136 uv %= i16; 137 138 uv = u16v + uv; 139 i64 = i16 - i64; 140 uv = u16v * uv; 141 i64 = i16 * i64; 142 i = i16 % i; 143 144 // Shift 145 u16v <<= i16; 146 i16 >>= u16v.y; 147 148 i16 = i16 << u16v.z; 149 uv = u16v << i; 150 151 // Relational 152 b = (u16v.x != i16); 153 b = (i16 == u16v.x); 154 b = (u16v.x > uv.y); 155 b = (i16 < i); 156 b = (u16v.y >= uv.x); 157 b = (i16 <= i); 158 159 // Bitwise 160 uv |= i16; 161 i = i16 | i; 162 i64 &= i16; 163 uv = u16v & uv; 164 uv ^= i16; 165 u16v = u16v ^ i16; 166} 167 168void builtinFuncs() 169{ 170 i16vec2 i16v; 171 i16vec4 i16v4; 172 u16vec3 u16v; 173 u16vec2 u16v2; 174 u16vec4 u16v4; 175 bvec3 bv; 176 int16_t i16; 177 uint16_t u16; 178 int32_t i32; 179 uint32_t u32; 180 int64_t i64; 181 uint64_t u64; 182 183 // abs() 184 i16v = abs(i16v); 185 186 // sign() 187 i16 = sign(i16); 188 189 // min() 190 i16v = min(i16v, i16); 191 i16v = min(i16v, i16vec2(-1)); 192 u16v = min(u16v, u16); 193 u16v = min(u16v, u16vec3(0)); 194 195 // max() 196 i16v = max(i16v, i16); 197 i16v = max(i16v, i16vec2(-1)); 198 u16v = max(u16v, u16); 199 u16v = max(u16v, u16vec3(0)); 200 201 // clamp() 202 i16v = clamp(i16v, -i16, i16); 203 i16v = clamp(i16v, -i16v, i16v); 204 u16v = clamp(u16v, -u16, u16); 205 u16v = clamp(u16v, -u16v, u16v); 206 207 // mix() 208 i16 = mix(i16v.x, i16v.y, true); 209 i16v = mix(i16vec2(i16), i16vec2(-i16), bvec2(false)); 210 u16 = mix(u16v.x, u16v.y, true); 211 u16v = mix(u16vec3(u16), u16vec3(-u16), bvec3(false)); 212 213 //pack 214 i32 = pack32(i16v); 215 i64 = pack64(i16v4); 216 u32 = pack32(u16v2); 217 u64 = pack64(u16v4); 218 219 i16v = unpack16(i32); 220 i16v4 = unpack16(i64); 221 u16v2 = unpack16(u32); 222 u16v4 = unpack16(u64); 223 224 // lessThan() 225 bv = lessThan(u16v, u16vec3(u16)); 226 bv.xy = lessThan(i16v, i16vec2(i16)); 227 228 // lessThanEqual() 229 bv = lessThanEqual(u16v, u16vec3(u16)); 230 bv.xy = lessThanEqual(i16v, i16vec2(i16)); 231 232 // greaterThan() 233 bv = greaterThan(u16v, u16vec3(u16)); 234 bv.xy = greaterThan(i16v, i16vec2(i16)); 235 236 // greaterThanEqual() 237 bv = greaterThanEqual(u16v, u16vec3(u16)); 238 bv.xy = greaterThanEqual(i16v, i16vec2(i16)); 239 240 // equal() 241 bv = equal(u16v, u16vec3(u16)); 242 bv.xy = equal(i16v, i16vec2(i16)); 243 244 // notEqual() 245 bv = notEqual(u16v, u16vec3(u16)); 246 bv.xy = notEqual(i16v, i16vec2(i16)); 247} 248 249// Type conversion for specialization constant 250layout(constant_id = 100) const int16_t si16 = int16_t(-10); 251layout(constant_id = 101) const uint16_t su16 = uint16_t(20); 252