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 12void main() 13{ 14} 15 16// Single float literals 17void literal() 18{ 19 const float64_t f64c = 0.000001LF; 20 const f64vec2 f64cv = f64vec2(-0.25lF, 0.03Lf); 21 22 f64vec2 f64v; 23 f64v.x = f64c; 24 f64v += f64cv; 25} 26 27// Block memory layout 28struct S 29{ 30 float64_t x; 31 f64vec2 y; 32 f64vec3 z; 33}; 34 35layout(column_major, std140) uniform B1 36{ 37 float64_t a; 38 f64vec2 b; 39 f64vec3 c; 40 float64_t d[2]; 41 f64mat2x3 e; 42 f64mat2x3 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 float64_t f64; 61 f64vec2 f64v; 62 f64mat2x2 f64m; 63 bool b; 64 65 // Arithmetic 66 f64v += f64v; 67 f64v -= f64v; 68 f64v *= f64v; 69 f64v /= f64v; 70 f64v++; 71 f64v--; 72 ++f64m; 73 --f64m; 74 f64v = -f64v; 75 f64m = -f64m; 76 77 f64 = f64v.x + f64v.y; 78 f64 = f64v.x - f64v.y; 79 f64 = f64v.x * f64v.y; 80 f64 = f64v.x / f64v.y; 81 82 // Relational 83 b = (f64v.x != f64); 84 b = (f64v.y == f64); 85 b = (f64v.x > f64); 86 b = (f64v.y < f64); 87 b = (f64v.x >= f64); 88 b = (f64v.y <= f64); 89 90 // Vector/matrix operations 91 f64v = f64v * f64; 92 f64m = f64m * f64; 93 f64v = f64m * f64v; 94 f64v = f64v * f64m; 95 f64m = f64m * f64m; 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 = f64vec3(bv); // bool -> float64 114 bv = bvec3(f64v); // float64 -> bool 115 116 f64v = f64vec3(f16v); // float16 -> float64 117 f16v = f16vec3(f64v); // float64 -> float16 118 119 i8v = i8vec3(f64v); // float64 -> int8 120 i16v = i16vec3(f64v); // float64 -> int16 121 i32v = i32vec3(f64v); // float64 -> int32 122 i64v = i64vec3(f64v); // float64 -> int64 123 124 u8v = u8vec3(f64v); // float64 -> uint8 125 u16v = u16vec3(f64v); // float64 -> uint16 126 u32v = u32vec3(f64v); // float64 -> uint32 127 u64v = u64vec3(f64v); // float64 -> uint64 128} 129 130// Trig, pow, exp and log are not supported for f64 131 132void builtinTranscendentalFuncs() 133{ 134 f64vec2 f64v1, f64v2; 135 136 f64v2 = sqrt(f64v1); 137 f64v2 = inversesqrt(f64v1); 138} 139 140void builtinCommonFuncs() 141{ 142 f64vec3 f64v1, f64v2, f64v3; 143 float64_t f64; 144 bool b; 145 bvec3 bv; 146 ivec3 iv; 147 148 f64v2 = abs(f64v1); 149 f64v2 = sign(f64v1); 150 f64v2 = floor(f64v1); 151 f64v2 = trunc(f64v1); 152 f64v2 = round(f64v1); 153 f64v2 = roundEven(f64v1); 154 f64v2 = ceil(f64v1); 155 f64v2 = fract(f64v1); 156 f64v2 = mod(f64v1, f64v2); 157 f64v2 = mod(f64v1, f64); 158 f64v3 = modf(f64v1, f64v2); 159 f64v3 = min(f64v1, f64v2); 160 f64v3 = min(f64v1, f64); 161 f64v3 = max(f64v1, f64v2); 162 f64v3 = max(f64v1, f64); 163 f64v3 = clamp(f64v1, f64, f64v2.x); 164 f64v3 = clamp(f64v1, f64v2, f64vec3(f64)); 165 f64v3 = mix(f64v1, f64v2, f64); 166 f64v3 = mix(f64v1, f64v2, f64v3); 167 f64v3 = mix(f64v1, f64v2, bv); 168 f64v3 = step(f64v1, f64v2); 169 f64v3 = step(f64, f64v3); 170 f64v3 = smoothstep(f64v1, f64v2, f64v3); 171 f64v3 = smoothstep(f64, f64v1.x, f64v2); 172 b = isnan(f64); 173 bv = isinf(f64v1); 174 f64v3 = fma(f64v1, f64v2, f64v3); 175 f64v2 = frexp(f64v1, iv); 176 f64v2 = ldexp(f64v1, iv); 177} 178 179void builtinGeometryFuncs() 180{ 181 float64_t f64; 182 f64vec3 f64v1, f64v2, f64v3; 183 184 f64 = length(f64v1); 185 f64 = distance(f64v1, f64v2); 186 f64 = dot(f64v1, f64v2); 187 f64v3 = cross(f64v1, f64v2); 188 f64v2 = normalize(f64v1); 189 f64v3 = faceforward(f64v1, f64v2, f64v3); 190 f64v3 = reflect(f64v1, f64v2); 191 f64v3 = refract(f64v1, f64v2, f64); 192} 193 194void builtinMatrixFuncs() 195{ 196 f64mat2x3 f64m1, f64m2, f64m3; 197 f64mat3x2 f64m4; 198 f64mat3 f64m5; 199 f64mat4 f64m6, f64m7; 200 201 f64vec3 f64v1; 202 f64vec2 f64v2; 203 204 float64_t f64; 205 206 f64m3 = matrixCompMult(f64m1, f64m2); 207 f64m1 = outerProduct(f64v1, f64v2); 208 f64m4 = transpose(f64m1); 209 f64 = determinant(f64m5); 210 f64m6 = inverse(f64m7); 211} 212 213void builtinVecRelFuncs() 214{ 215 f64vec3 f64v1, f64v2; 216 bvec3 bv; 217 218 bv = lessThan(f64v1, f64v2); 219 bv = lessThanEqual(f64v1, f64v2); 220 bv = greaterThan(f64v1, f64v2); 221 bv = greaterThanEqual(f64v1, f64v2); 222 bv = equal(f64v1, f64v2); 223 bv = notEqual(f64v1, f64v2); 224} 225 226in flat f64vec3 if64v; 227 228void builtinFragProcFuncs() 229{ 230 f64vec3 f64v; 231 232 // Derivative 233 f64v.x = dFdx(if64v.x); 234 f64v.y = dFdy(if64v.y); 235 f64v.xy = dFdxFine(if64v.xy); 236 f64v.xy = dFdyFine(if64v.xy); 237 f64v = dFdxCoarse(if64v); 238 f64v = dFdxCoarse(if64v); 239 240 f64v.x = fwidth(if64v.x); 241 f64v.xy = fwidthFine(if64v.xy); 242 f64v = fwidthCoarse(if64v); 243 244 // Interpolation 245 f64v.x = interpolateAtCentroid(if64v.x); 246 f64v.xy = interpolateAtSample(if64v.xy, 1); 247 f64v = interpolateAtOffset(if64v, f64vec2(0.5f)); 248} 249