1#version 450 2 3#extension GL_ARB_gpu_shader_int64: enable 4#extension GL_EXT_shader_explicit_arithmetic_types_int64: require 5 6layout(binding = 0) uniform Uniforms 7{ 8 uint index; 9}; 10 11layout(std140, binding = 1) uniform Block 12{ 13 i64vec3 i64v; 14 uint64_t u64; 15} block; 16 17void main() 18{ 19} 20 21void literal() 22{ 23 const int64_t i64Const[3] = 24 { 25 -0x1111111111111111l, // Hex 26 -1l, // Dec 27 040000000000l, // Oct 28 }; 29 30 int64_t i64 = i64Const[index]; 31 32 const uint64_t u64Const[] = 33 { 34 0xFFFFFFFFFFFFFFFFul, // Hex 35 4294967296UL, // Dec 36 077777777777ul, // Oct 37 }; 38 39 uint64_t u64 = u64Const[index]; 40} 41 42void typeCast() 43{ 44 bvec2 bv; 45 ivec2 iv; 46 uvec2 uv; 47 vec2 fv; 48 dvec2 dv; 49 50 i64vec2 i64v; 51 u64vec2 u64v; 52 53 i64v = i64vec2(bv); // bool -> int64 54 u64v = u64vec2(bv); // bool -> uint64 55 56 i64v = iv; // int -> int64 57 iv = ivec2(i64v); // int64 -> int 58 59 u64v = uv; // uint -> uint64 60 uv = uvec2(u64v); // uint64 -> uint 61 62 fv = vec2(i64v); // int64 -> float 63 dv = i64v; // int64 -> double 64 65 fv = vec2(u64v); // uint64 -> float 66 dv = u64v; // uint64 -> double 67 68 i64v = i64vec2(fv); // float -> int64 69 i64v = i64vec2(dv); // double -> int64 70 71 u64v = u64vec2(fv); // float -> uint64 72 u64v = u64vec2(dv); // double -> uint64 73 74 bv = bvec2(i64v); // int64 -> bool 75 bv = bvec2(u64v); // uint64 -> bool 76 77 u64v = i64v; // int64 -> uint64 78 i64v = i64vec2(u64v); // uint64 -> int64 79 80 uv = uvec2(i64v); // int64 -> uint 81 i64v = i64vec2(uv); // uint -> int64 82 iv = ivec2(u64v); // uint64 -> int 83 u64v = iv; // int -> uint64 84} 85 86void operators() 87{ 88 u64vec3 u64v; 89 int64_t i64; 90 uvec3 uv; 91 int i; 92 bool b; 93 94 // Unary 95 u64v++; 96 i64--; 97 ++i64; 98 --u64v; 99 100 u64v = ~u64v; 101 102 i64 = +i64; 103 u64v = -u64v; 104 105 // Arithmetic 106 i64 += i64; 107 u64v -= u64v; 108 i64 *= i; 109 u64v /= uv; 110 u64v %= i; 111 112 u64v = u64v + uv; 113 i64 = i64 - i; 114 u64v = u64v * uv; 115 i64 = i64 * i; 116 i64 = i64 % i; 117 118 // Shift 119 u64v = u64v << i; 120 i64 = i64 >> uv.y; 121 u64v <<= i; 122 i64 >>= uv.y; 123 124 i64 = i64 << u64v.z; 125 u64v = u64v << i64; 126 127 // Relational 128 b = (u64v.x != i64); 129 b = (i64 == u64v.x); 130 b = (u64v.x > uv.y); 131 b = (i64 < i); 132 b = (u64v.y >= uv.x); 133 b = (i64 <= i); 134 135 // Bitwise 136 u64v |= i; 137 i64 = i64 | i; 138 i64 &= i; 139 u64v = u64v & uv; 140 u64v ^= i64; 141 u64v = u64v ^ i64; 142} 143 144void builtinFuncs() 145{ 146 i64vec2 i64v; 147 u64vec3 u64v; 148 dvec3 dv; 149 bvec3 bv; 150 151 int64_t i64; 152 uint64_t u64; 153 154 // abs() 155 i64v = abs(i64v); 156 157 // sign() 158 i64 = sign(i64); 159 160 // min() 161 i64v = min(i64v, i64); 162 i64v = min(i64v, i64vec2(-1)); 163 u64v = min(u64v, u64); 164 u64v = min(u64v, u64vec3(0)); 165 166 // max() 167 i64v = max(i64v, i64); 168 i64v = max(i64v, i64vec2(-1)); 169 u64v = max(u64v, u64); 170 u64v = max(u64v, u64vec3(0)); 171 172 // clamp() 173 i64v = clamp(i64v, -i64, i64); 174 i64v = clamp(i64v, -i64v, i64v); 175 u64v = clamp(u64v, -u64, u64); 176 u64v = clamp(u64v, -u64v, u64v); 177 178 // mix() 179 i64 = mix(i64v.x, i64v.y, true); 180 i64v = mix(i64vec2(i64), i64vec2(-i64), bvec2(false)); 181 u64 = mix(u64v.x, u64v.y, true); 182 u64v = mix(u64vec3(u64), u64vec3(-u64), bvec3(false)); 183 184 // doubleBitsToInt64() 185 i64v = doubleBitsToInt64(dv.xy); 186 187 // doubleBitsToUint64() 188 u64v.x = doubleBitsToUint64(dv.z); 189 190 // int64BitsToDouble() 191 dv.xy = int64BitsToDouble(i64v); 192 193 // uint64BitsToDouble() 194 dv = uint64BitsToDouble(u64v); 195 196 // packInt2x32() 197 i64 = packInt2x32(ivec2(1, 2)); 198 199 // unpackInt2x32() 200 ivec2 iv = unpackInt2x32(i64); 201 202 // packUint2x32() 203 u64 = packUint2x32(uvec2(2, 3)); 204 205 // unpackUint2x32() 206 uvec2 uv = unpackUint2x32(u64); 207 208 // lessThan() 209 bv = lessThan(u64v, u64vec3(u64)); 210 bv.xy = lessThan(i64v, i64vec2(i64)); 211 212 // lessThanEqual() 213 bv = lessThanEqual(u64v, u64vec3(u64)); 214 bv.xy = lessThanEqual(i64v, i64vec2(i64)); 215 216 // greaterThan() 217 bv = greaterThan(u64v, u64vec3(u64)); 218 bv.xy = greaterThan(i64v, i64vec2(i64)); 219 220 // greaterThanEqual() 221 bv = greaterThanEqual(u64v, u64vec3(u64)); 222 bv.xy = greaterThanEqual(i64v, i64vec2(i64)); 223 224 // equal() 225 bv = equal(u64v, u64vec3(u64)); 226 bv.xy = equal(i64v, i64vec2(i64)); 227 228 // notEqual() 229 bv = notEqual(u64v, u64vec3(u64)); 230 bv.xy = notEqual(i64v, i64vec2(i64)); 231} 232 233// Type conversion for specialization constant 234layout(constant_id = 100) const int64_t si64 = -10L; 235layout(constant_id = 101) const uint64_t su64 = 20UL; 236layout(constant_id = 102) const int si = -5; 237layout(constant_id = 103) const uint su = 4; 238layout(constant_id = 104) const bool sb = true; 239layout(constant_id = 105) const uint64_t su64inc = su64 + 1UL; 240 241// bool <-> int64/uint64 242const bool i64_to_b = bool(si64); 243const bool u64_to_b = bool(su64); 244const int64_t b_to_i64 = int64_t(sb); 245const uint64_t b_to_u64 = uint64_t(sb); 246 247// int <-> int64 248const int i64_to_i = int(si64); 249const int64_t i_to_i64 = int64_t(si); 250 251// uint <-> uint64 252const uint u64_to_u = uint(su64); 253const uint64_t u_to_u64 = uint64_t(su); 254 255// int64 <-> uint64 256const int64_t u64_to_i64 = int64_t(su64); 257const uint64_t i64_to_u64 = uint64_t(si64); 258 259// int <-> uint64 260const int u64_to_i = int(su64); 261const uint64_t i_to_u64 = uint64_t(si); 262 263// uint <-> int64 264const uint i64_to_u = uint(si64); 265const int64_t u_to_i64 = int64_t(su); 266 267#define UINT64_MAX 18446744073709551615ul 268uint64_t u64Max = UINT64_MAX; 269