John Kessenich | 66011cb | 2018-03-06 16:12:04 -0700 | [diff] [blame] | 1 | #version 450 |
| 2 | |
Alexander Galazin | 32def9f | 2018-12-03 13:16:59 +0100 | [diff] [blame] | 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 |
John Kessenich | 66011cb | 2018-03-06 16:12:04 -0700 | [diff] [blame] | 11 | |
| 12 | void main() |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | // Single float literals |
| 17 | void 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 |
| 28 | struct S |
| 29 | { |
| 30 | float64_t x; |
| 31 | f64vec2 y; |
| 32 | f64vec3 z; |
| 33 | }; |
| 34 | |
| 35 | layout(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 |
| 48 | layout(constant_id = 100) const float16_t sf16 = 0.125hf; |
| 49 | layout(constant_id = 101) const float32_t sf = 0.25; |
| 50 | layout(constant_id = 102) const float64_t sd = 0.5lf; |
| 51 | |
| 52 | const float f16_to_f = float(sf16); |
| 53 | const double f16_to_d = float(sf16); |
| 54 | |
| 55 | const float16_t f_to_f16 = float16_t(sf); |
| 56 | const float16_t d_to_f16 = float16_t(sd); |
| 57 | |
| 58 | void 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 | |
| 98 | void 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 | void builtinAngleTrigFuncs() |
| 131 | { |
| 132 | f64vec4 f64v1, f64v2; |
| 133 | |
| 134 | f64v2 = radians(f64v1); |
| 135 | f64v2 = degrees(f64v1); |
| 136 | f64v2 = sin(f64v1); |
| 137 | f64v2 = cos(f64v1); |
| 138 | f64v2 = tan(f64v1); |
| 139 | f64v2 = asin(f64v1); |
| 140 | f64v2 = acos(f64v1); |
| 141 | f64v2 = atan(f64v1, f64v2); |
| 142 | f64v2 = atan(f64v1); |
| 143 | f64v2 = sinh(f64v1); |
| 144 | f64v2 = cosh(f64v1); |
| 145 | f64v2 = tanh(f64v1); |
| 146 | f64v2 = asinh(f64v1); |
| 147 | f64v2 = acosh(f64v1); |
| 148 | f64v2 = atanh(f64v1); |
| 149 | } |
| 150 | |
| 151 | void builtinExpFuncs() |
| 152 | { |
| 153 | f64vec2 f64v1, f64v2; |
| 154 | |
| 155 | f64v2 = pow(f64v1, f64v2); |
| 156 | f64v2 = exp(f64v1); |
| 157 | f64v2 = log(f64v1); |
| 158 | f64v2 = exp2(f64v1); |
| 159 | f64v2 = log2(f64v1); |
| 160 | f64v2 = sqrt(f64v1); |
| 161 | f64v2 = inversesqrt(f64v1); |
| 162 | } |
| 163 | |
| 164 | void builtinCommonFuncs() |
| 165 | { |
| 166 | f64vec3 f64v1, f64v2, f64v3; |
| 167 | float64_t f64; |
| 168 | bool b; |
| 169 | bvec3 bv; |
| 170 | ivec3 iv; |
| 171 | |
| 172 | f64v2 = abs(f64v1); |
| 173 | f64v2 = sign(f64v1); |
| 174 | f64v2 = floor(f64v1); |
| 175 | f64v2 = trunc(f64v1); |
| 176 | f64v2 = round(f64v1); |
| 177 | f64v2 = roundEven(f64v1); |
| 178 | f64v2 = ceil(f64v1); |
| 179 | f64v2 = fract(f64v1); |
| 180 | f64v2 = mod(f64v1, f64v2); |
| 181 | f64v2 = mod(f64v1, f64); |
| 182 | f64v3 = modf(f64v1, f64v2); |
| 183 | f64v3 = min(f64v1, f64v2); |
| 184 | f64v3 = min(f64v1, f64); |
| 185 | f64v3 = max(f64v1, f64v2); |
| 186 | f64v3 = max(f64v1, f64); |
| 187 | f64v3 = clamp(f64v1, f64, f64v2.x); |
| 188 | f64v3 = clamp(f64v1, f64v2, f64vec3(f64)); |
| 189 | f64v3 = mix(f64v1, f64v2, f64); |
| 190 | f64v3 = mix(f64v1, f64v2, f64v3); |
| 191 | f64v3 = mix(f64v1, f64v2, bv); |
| 192 | f64v3 = step(f64v1, f64v2); |
| 193 | f64v3 = step(f64, f64v3); |
| 194 | f64v3 = smoothstep(f64v1, f64v2, f64v3); |
| 195 | f64v3 = smoothstep(f64, f64v1.x, f64v2); |
| 196 | b = isnan(f64); |
| 197 | bv = isinf(f64v1); |
| 198 | f64v3 = fma(f64v1, f64v2, f64v3); |
| 199 | f64v2 = frexp(f64v1, iv); |
| 200 | f64v2 = ldexp(f64v1, iv); |
| 201 | } |
| 202 | |
| 203 | void builtinGeometryFuncs() |
| 204 | { |
| 205 | float64_t f64; |
| 206 | f64vec3 f64v1, f64v2, f64v3; |
John Kessenich | 2a805d9 | 2018-06-19 09:43:09 -0600 | [diff] [blame] | 207 | |
John Kessenich | 66011cb | 2018-03-06 16:12:04 -0700 | [diff] [blame] | 208 | f64 = length(f64v1); |
| 209 | f64 = distance(f64v1, f64v2); |
| 210 | f64 = dot(f64v1, f64v2); |
| 211 | f64v3 = cross(f64v1, f64v2); |
| 212 | f64v2 = normalize(f64v1); |
| 213 | f64v3 = faceforward(f64v1, f64v2, f64v3); |
| 214 | f64v3 = reflect(f64v1, f64v2); |
John Kessenich | 2a805d9 | 2018-06-19 09:43:09 -0600 | [diff] [blame] | 215 | f64v3 = refract(f64v1, f64v2, f64); |
John Kessenich | 66011cb | 2018-03-06 16:12:04 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void builtinMatrixFuncs() |
| 219 | { |
| 220 | f64mat2x3 f64m1, f64m2, f64m3; |
| 221 | f64mat3x2 f64m4; |
| 222 | f64mat3 f64m5; |
| 223 | f64mat4 f64m6, f64m7; |
| 224 | |
| 225 | f64vec3 f64v1; |
| 226 | f64vec2 f64v2; |
| 227 | |
| 228 | float64_t f64; |
| 229 | |
| 230 | f64m3 = matrixCompMult(f64m1, f64m2); |
| 231 | f64m1 = outerProduct(f64v1, f64v2); |
| 232 | f64m4 = transpose(f64m1); |
| 233 | f64 = determinant(f64m5); |
| 234 | f64m6 = inverse(f64m7); |
| 235 | } |
| 236 | |
| 237 | void builtinVecRelFuncs() |
| 238 | { |
| 239 | f64vec3 f64v1, f64v2; |
| 240 | bvec3 bv; |
| 241 | |
| 242 | bv = lessThan(f64v1, f64v2); |
| 243 | bv = lessThanEqual(f64v1, f64v2); |
| 244 | bv = greaterThan(f64v1, f64v2); |
| 245 | bv = greaterThanEqual(f64v1, f64v2); |
| 246 | bv = equal(f64v1, f64v2); |
| 247 | bv = notEqual(f64v1, f64v2); |
| 248 | } |
| 249 | |
| 250 | in flat f64vec3 if64v; |
| 251 | |
| 252 | void builtinFragProcFuncs() |
| 253 | { |
| 254 | f64vec3 f64v; |
| 255 | |
| 256 | // Derivative |
| 257 | f64v.x = dFdx(if64v.x); |
| 258 | f64v.y = dFdy(if64v.y); |
| 259 | f64v.xy = dFdxFine(if64v.xy); |
| 260 | f64v.xy = dFdyFine(if64v.xy); |
| 261 | f64v = dFdxCoarse(if64v); |
| 262 | f64v = dFdxCoarse(if64v); |
| 263 | |
| 264 | f64v.x = fwidth(if64v.x); |
| 265 | f64v.xy = fwidthFine(if64v.xy); |
| 266 | f64v = fwidthCoarse(if64v); |
| 267 | |
| 268 | // Interpolation |
| 269 | f64v.x = interpolateAtCentroid(if64v.x); |
| 270 | f64v.xy = interpolateAtSample(if64v.xy, 1); |
| 271 | f64v = interpolateAtOffset(if64v, f64vec2(0.5f)); |
| 272 | } |