diff --git a/include/slang.h b/include/slang.h index 632bcbcbc5..3024aa8844 100644 --- a/include/slang.h +++ b/include/slang.h @@ -637,6 +637,7 @@ extern "C" SLANG_PASS_THROUGH_LLVM, ///< LLVM 'compiler' - includes LLVM and Clang SLANG_PASS_THROUGH_SPIRV_OPT, ///< SPIRV-opt SLANG_PASS_THROUGH_METAL, ///< Metal compiler + SLANG_PASS_THROUGH_WGSL, ///< WGSL compiler SLANG_PASS_THROUGH_COUNT_OF, }; diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index a8241bf736..7c68a641c1 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -5445,7 +5445,7 @@ void abort(); __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T abs(T x) { __target_switch @@ -5458,6 +5458,7 @@ T abs(T x) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 SAbs $x }; + case wgsl: __intrinsic_asm "abs"; //default: // Note: this simple definition may not be appropriate for floating-point inputs // return x < 0 ? -x : x; @@ -5466,7 +5467,7 @@ T abs(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector abs(vector x) { __target_switch @@ -5477,6 +5478,7 @@ vector abs(vector x) case spirv: return spirv_asm { result:$$vector = OpExtInst glsl450 SAbs $x; }; + case wgsl: __intrinsic_asm "abs"; default: VECTOR_MAP_UNARY(T, N, abs, x); } @@ -5484,7 +5486,7 @@ vector abs(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix abs(matrix x) { __target_switch @@ -5497,7 +5499,7 @@ matrix abs(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T abs(T x) { __target_switch @@ -5510,12 +5512,13 @@ T abs(T x) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 FAbs $x; }; + case wgsl: __intrinsic_asm "abs"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector abs(vector x) { __target_switch @@ -5526,6 +5529,7 @@ vector abs(vector x) case spirv: return spirv_asm { result:$$vector = OpExtInst glsl450 FAbs $x; }; + case wgsl: __intrinsic_asm "abs"; default: VECTOR_MAP_UNARY(T, N, abs, x); } @@ -5533,7 +5537,7 @@ vector abs(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix abs(matrix x) { __target_switch @@ -5547,7 +5551,7 @@ matrix abs(matrix x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T fabs(T x) { __target_switch @@ -5561,7 +5565,7 @@ T fabs(T x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector fabs(vector x) { __target_switch @@ -5577,7 +5581,7 @@ vector fabs(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T acos(T x) { __target_switch @@ -5590,12 +5594,13 @@ T acos(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Acos $x }; + case wgsl: __intrinsic_asm "acos"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector acos(vector x) { __target_switch @@ -5606,6 +5611,7 @@ vector acos(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Acos $x }; + case wgsl: __intrinsic_asm "acos"; default: VECTOR_MAP_UNARY(T, N, acos, x); } @@ -5613,7 +5619,7 @@ vector acos(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix acos(matrix x) { __target_switch @@ -5629,7 +5635,7 @@ matrix acos(matrix x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T acosh(T x) { __target_switch @@ -5641,6 +5647,7 @@ T acosh(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Acosh $x }; + case wgsl: __intrinsic_asm "acosh"; default: return log(x + sqrt( x * x - T(1))); } @@ -5649,7 +5656,7 @@ T acosh(T x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector acosh(vector x) { __target_switch @@ -5659,6 +5666,7 @@ vector acosh(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Acosh $x }; + case wgsl: __intrinsic_asm "acosh"; default: VECTOR_MAP_UNARY(T, N, acosh, x); } @@ -6056,7 +6064,7 @@ matrix asfloat(matrix x) // Inverse sine (HLSL SM 1.0) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T asin(T x) { __target_switch @@ -6069,12 +6077,13 @@ T asin(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Asin $x }; + case wgsl: __intrinsic_asm "asin"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector asin(vector x) { __target_switch @@ -6085,6 +6094,7 @@ vector asin(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Asin $x }; + case wgsl: __intrinsic_asm "asin"; default: VECTOR_MAP_UNARY(T,N,asin,x); } @@ -6092,7 +6102,7 @@ vector asin(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix asin(matrix x) { __target_switch @@ -6108,7 +6118,7 @@ matrix asin(matrix x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T asinh(T x) { __target_switch @@ -6120,6 +6130,7 @@ T asinh(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Asinh $x }; + case wgsl: __intrinsic_asm "asinh"; default: return log(x + sqrt(x * x + T(1))); } @@ -6128,7 +6139,7 @@ T asinh(T x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector asinh(vector x) { __target_switch @@ -6138,6 +6149,7 @@ vector asinh(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Asinh $x }; + case wgsl: __intrinsic_asm "asinh"; default: VECTOR_MAP_UNARY(T, N, asinh, x); } @@ -6601,7 +6613,7 @@ matrix asfloat16(matrix va // Inverse tangent (HLSL SM 1.0) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T atan(T x) { __target_switch @@ -6614,12 +6626,13 @@ T atan(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Atan $x }; + case wgsl: __intrinsic_asm "atan"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector atan(vector x) { __target_switch @@ -6630,6 +6643,7 @@ vector atan(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Atan $x }; + case wgsl: __intrinsic_asm "atan"; default: VECTOR_MAP_UNARY(T, N, atan, x); } @@ -6637,7 +6651,7 @@ vector atan(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix atan(matrix x) { __target_switch @@ -6650,7 +6664,7 @@ matrix atan(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T atan2(T y, T x) { __target_switch @@ -6663,12 +6677,13 @@ T atan2(T y, T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Atan2 $y $x }; + case wgsl: __intrinsic_asm "atan2"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector atan2(vector y, vector x) { __target_switch @@ -6679,6 +6694,7 @@ vector atan2(vector y, vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Atan2 $y $x }; + case wgsl: __intrinsic_asm "atan2"; default: VECTOR_MAP_BINARY(T, N, atan2, y, x); } @@ -6686,7 +6702,7 @@ vector atan2(vector y, vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix atan2(matrix y, matrix x) { __target_switch @@ -6702,7 +6718,7 @@ matrix atan2(matrix y, matrix x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T atanh(T x) { __target_switch @@ -6714,6 +6730,7 @@ T atanh(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Atanh $x }; + case wgsl: __intrinsic_asm "atanh"; default: return T(0.5) * log((T(1) + x) / (T(1) - x)); } @@ -6722,7 +6739,7 @@ T atanh(T x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector atanh(vector x) { __target_switch @@ -6732,6 +6749,7 @@ vector atanh(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Atanh $x }; + case wgsl: __intrinsic_asm "atanh"; default: VECTOR_MAP_UNARY(T, N, atanh, x); } @@ -6740,7 +6758,7 @@ vector atanh(vector x) // Ceiling (HLSL SM 1.0) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T ceil(T x) { __target_switch @@ -6753,12 +6771,13 @@ T ceil(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Ceil $x }; + case wgsl: __intrinsic_asm "ceil"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector ceil(vector x) { __target_switch @@ -6769,6 +6788,7 @@ vector ceil(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Ceil $x }; + case wgsl: __intrinsic_asm "ceil"; default: VECTOR_MAP_UNARY(T, N, ceil, x); } @@ -6776,7 +6796,7 @@ vector ceil(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix ceil(matrix x) { __target_switch @@ -6883,7 +6903,7 @@ bool CheckAccessFullyMapped(out uint status) // Clamp (HLSL SM 1.0) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T clamp(T x, T minBound, T maxBound) { __target_switch @@ -6900,6 +6920,7 @@ T clamp(T x, T minBound, T maxBound) return spirv_asm { result:$$T = OpExtInst glsl450 UClamp $x $minBound $maxBound }; + case wgsl: __intrinsic_asm "clamp"; default: return min(max(x, minBound), maxBound); } @@ -6907,7 +6928,7 @@ T clamp(T x, T minBound, T maxBound) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector clamp(vector x, vector minBound, vector maxBound) { __target_switch @@ -6924,6 +6945,7 @@ vector clamp(vector x, vector minBound, vector maxBound) return spirv_asm { result:$$vector = OpExtInst glsl450 UClamp $x $minBound $maxBound }; + case wgsl: __intrinsic_asm "clamp"; default: return min(max(x, minBound), maxBound); } @@ -6931,7 +6953,7 @@ vector clamp(vector x, vector minBound, vector maxBound) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix clamp(matrix x, matrix minBound, matrix maxBound) { __target_switch @@ -6944,7 +6966,7 @@ matrix clamp(matrix x, matrix minBound, matrix maxBo __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T clamp(T x, T minBound, T maxBound) { __target_switch @@ -6955,6 +6977,7 @@ T clamp(T x, T minBound, T maxBound) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 FClamp $x $minBound $maxBound }; + case wgsl: __intrinsic_asm "clamp"; default: return min(max(x, minBound), maxBound); } @@ -6962,7 +6985,7 @@ T clamp(T x, T minBound, T maxBound) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector clamp(vector x, vector minBound, vector maxBound) { __target_switch @@ -6973,6 +6996,7 @@ vector clamp(vector x, vector minBound, vector maxBound) case spirv: return spirv_asm { result:$$vector = OpExtInst glsl450 FClamp $x $minBound $maxBound }; + case wgsl: __intrinsic_asm "clamp"; default: return min(max(x, minBound), maxBound); } @@ -6980,7 +7004,7 @@ vector clamp(vector x, vector minBound, vector maxBound) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix clamp(matrix x, matrix minBound, matrix maxBound) { __target_switch @@ -7041,16 +7065,16 @@ T cos(T x) case glsl: __intrinsic_asm "cos"; case hlsl: __intrinsic_asm "cos"; case metal: __intrinsic_asm "cos"; - case wgsl: __intrinsic_asm "cos"; case spirv: return spirv_asm { OpExtInst $$T result glsl450 Cos $x }; + case wgsl: __intrinsic_asm "cos"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector cos(vector x) { __target_switch @@ -7061,6 +7085,7 @@ vector cos(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Cos $x }; + case wgsl: __intrinsic_asm "cos"; default: VECTOR_MAP_UNARY(T,N, cos, x); } @@ -7068,7 +7093,7 @@ vector cos(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix cos(matrix x) { __target_switch @@ -7082,7 +7107,7 @@ matrix cos(matrix x) // Hyperbolic cosine __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T cosh(T x) { __target_switch @@ -7095,12 +7120,13 @@ T cosh(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Cosh $x }; + case wgsl: __intrinsic_asm "cosh"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector cosh(vector x) { __target_switch @@ -7111,6 +7137,7 @@ vector cosh(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Cosh $x }; + case wgsl: __intrinsic_asm "cosh"; default: VECTOR_MAP_UNARY(T,N, cosh, x); } @@ -7118,7 +7145,7 @@ vector cosh(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix cosh(matrix x) { __target_switch @@ -7133,7 +7160,7 @@ matrix cosh(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T cospi(T x) { __target_switch @@ -7146,7 +7173,7 @@ T cospi(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector cospi(vector x) { __target_switch @@ -7205,7 +7232,7 @@ vector countbits(vector value) // TODO: SPIRV does not support integer vectors. __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector cross(vector left, vector right) { __target_switch @@ -7216,6 +7243,7 @@ vector cross(vector left, vector right) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Cross $left $right }; + case wgsl: __intrinsic_asm "cross"; default: return vector( left.y * right.z - left.z * right.y, @@ -7226,7 +7254,7 @@ vector cross(vector left, vector right) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector cross(vector left, vector right) { __target_switch @@ -7236,6 +7264,7 @@ vector cross(vector left, vector right) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Cross $left $right }; + case wgsl: __intrinsic_asm "cross"; default: return vector( left.y * right.z - left.z * right.y, @@ -7436,7 +7465,7 @@ T degrees(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)] vector degrees(vector x) { __target_switch @@ -7446,6 +7475,7 @@ vector degrees(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Degrees $x }; + case wgsl: __intrinsic_asm "degrees"; default: VECTOR_MAP_UNARY(T, N, degrees, x); } @@ -7453,7 +7483,7 @@ vector degrees(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)] matrix degrees(matrix x) { __target_switch @@ -7469,7 +7499,7 @@ matrix degrees(matrix x) __generic [__readNone] [PreferCheckpoint] -[require(glsl_hlsl_metal_spirv)] +[require(glsl_hlsl_metal_spirv_wgsl)] T determinant(matrix m) { __target_switch @@ -7480,6 +7510,7 @@ T determinant(matrix m) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Determinant $m }; + case wgsl: __intrinsic_asm "determinant"; } } @@ -7522,7 +7553,7 @@ void DeviceMemoryBarrierWithGroupSync() __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T distance(vector x, vector y) { __target_switch @@ -7533,6 +7564,7 @@ T distance(vector x, vector y) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Distance $x $y }; + case wgsl: __intrinsic_asm "distance"; default: return length(x - y); } @@ -7540,7 +7572,7 @@ T distance(vector x, vector y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T distance(T x, T y) { __target_switch @@ -7549,6 +7581,7 @@ T distance(T x, T y) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Distance $x $y }; + case wgsl: __intrinsic_asm "distance"; default: return length(x - y); } @@ -7616,13 +7649,14 @@ vector divide(vector x, vector y) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T dot(T x, T y) { __target_switch { case glsl: __intrinsic_asm "dot"; case hlsl: __intrinsic_asm "dot"; + case wgsl: __intrinsic_asm "dot"; default: return x * y; } @@ -7630,7 +7664,7 @@ T dot(T x, T y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T dot(vector x, vector y) { __target_switch @@ -7641,6 +7675,7 @@ T dot(vector x, vector y) case spirv: return spirv_asm { OpDot $$T result $x $y }; + case wgsl: __intrinsic_asm "dot"; default: T result = T(0); for(int i = 0; i < N; ++i) @@ -7651,12 +7686,13 @@ T dot(vector x, vector y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T dot(vector x, vector y) { __target_switch { case hlsl: __intrinsic_asm "dot"; + case wgsl: __intrinsic_asm "dot"; default: T result = T(0); for(int i = 0; i < N; ++i) @@ -7841,7 +7877,7 @@ matrix EvaluateAttributeSnapped(matrix x, int2 offset) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T exp(T x) { __target_switch @@ -7854,12 +7890,13 @@ T exp(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Exp $x }; + case wgsl: __intrinsic_asm "exp"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector exp(vector x) { __target_switch @@ -7870,6 +7907,7 @@ vector exp(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Exp $x }; + case wgsl: __intrinsic_asm "exp"; default: VECTOR_MAP_UNARY(T, N, exp, x); } @@ -7877,7 +7915,7 @@ vector exp(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix exp(matrix x) { __target_switch @@ -7892,7 +7930,7 @@ matrix exp(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T exp2(T x) { __target_switch @@ -7918,13 +7956,15 @@ T exp2(T x) __intrinsic_asm "$P_exp2($0)"; case cuda: __intrinsic_asm "$P_exp2($0)"; + case wgsl: + __intrinsic_asm "exp2"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector exp2(vector x) { __target_switch @@ -7936,6 +7976,7 @@ vector exp2(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Exp2 $x }; + case wgsl: __intrinsic_asm "exp2"; default: VECTOR_MAP_UNARY(T, N, exp2, x); } @@ -7943,7 +7984,7 @@ vector exp2(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix exp2(matrix x) { __target_switch @@ -7958,7 +7999,7 @@ matrix exp2(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T exp10(T x) { __target_switch @@ -7972,7 +8013,7 @@ T exp10(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector exp10(vector x) { __target_switch @@ -8324,7 +8365,7 @@ vector firstbitlow(vector value) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T floor(T x) { __target_switch @@ -8337,12 +8378,13 @@ T floor(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Floor $x }; + case wgsl: __intrinsic_asm "floor"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector floor(vector x) { __target_switch @@ -8353,6 +8395,7 @@ vector floor(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Floor $x }; + case wgsl: __intrinsic_asm "floor"; default: VECTOR_MAP_UNARY(T, N, floor, x); } @@ -8360,7 +8403,7 @@ vector floor(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix floor(matrix x) { __target_switch @@ -8374,7 +8417,7 @@ matrix floor(matrix x) // Fused multiply-add __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_5_0)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] T fma(T a, T b, T c) { __target_switch @@ -8391,6 +8434,7 @@ T fma(T a, T b, T c) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Fma $a $b $c }; + case wgsl: __intrinsic_asm "fma"; default: return a*b + c; } @@ -8398,7 +8442,7 @@ T fma(T a, T b, T c) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_5_0)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] vector fma(vector a, vector b, vector c) { __target_switch @@ -8409,6 +8453,7 @@ vector fma(vector a, vector b, vector c) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Fma $a $b $c }; + case wgsl: __intrinsic_asm "fma"; default: VECTOR_MAP_TRINARY(T, N, fma, a, b, c); } @@ -8416,7 +8461,7 @@ vector fma(vector a, vector b, vector c) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_5_0)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] matrix fma(matrix a, matrix b, matrix c) { __target_switch @@ -8431,7 +8476,7 @@ matrix fma(matrix a, matrix b, matrix c) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T fmod(T x, T y) { // In HLSL, `fmod` returns a remainder. @@ -8496,13 +8541,15 @@ T fmod(T x, T y) { result:$$T = OpFRem $x $y }; + case wgsl: + __intrinsic_asm "(($0) % ($1))"; } } __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector fmod(vector x, vector y) { __target_switch @@ -8519,7 +8566,7 @@ vector fmod(vector x, vector y) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix fmod(matrix x, matrix y) { __target_switch @@ -8533,7 +8580,7 @@ matrix fmod(matrix x, matrix y) // Fractional part __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T frac(T x) { __target_switch @@ -8546,12 +8593,13 @@ T frac(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Fract $x }; + case wgsl: __intrinsic_asm "fract"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector frac(vector x) { __target_switch @@ -8562,6 +8610,7 @@ vector frac(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Fract $x }; + case wgsl: __intrinsic_asm "fract"; default: VECTOR_MAP_UNARY(T, N, frac, x); } @@ -8577,7 +8626,7 @@ matrix frac(matrix x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T fract(T x) { return frac(x); @@ -8586,7 +8635,7 @@ T fract(T x) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector fract(vector x) { return frac(x); @@ -8596,7 +8645,7 @@ vector fract(vector x) // Split float into mantissa and exponent __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T frexp(T x, out int exp) { __target_switch @@ -8609,12 +8658,13 @@ T frexp(T x, out int exp) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 Frexp $x &exp }; + case wgsl: __intrinsic_asm "frexp"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector frexp(vector x, out vector exp) { __target_switch @@ -8625,6 +8675,7 @@ vector frexp(vector x, out vector exp) case spirv: return spirv_asm { result:$$vector = OpExtInst glsl450 Frexp $x &exp }; + case wgsl: __intrinsic_asm "frexp"; default: VECTOR_MAP_BINARY(T, N, frexp, x, exp); } @@ -8632,7 +8683,7 @@ vector frexp(vector x, out vector exp) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix frexp(matrix x, out matrix exp) { __target_switch @@ -9993,12 +10044,13 @@ matrix isnan(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T ldexp(T x, T exp) { __target_switch { case hlsl: __intrinsic_asm "ldexp"; + case wgsl: __intrinsic_asm "ldexp"; default: return x * exp2(exp); } @@ -10006,12 +10058,13 @@ T ldexp(T x, T exp) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector ldexp(vector x, vector exp) { __target_switch { case hlsl: __intrinsic_asm "ldexp"; + case wgsl: __intrinsic_asm "ldexp"; default: return x * exp2(exp); } @@ -10019,7 +10072,7 @@ vector ldexp(vector x, vector exp) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix ldexp(matrix x, matrix exp) { __target_switch @@ -10032,7 +10085,7 @@ matrix ldexp(matrix x, matrix exp) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T ldexp(T x, E exp) { __target_switch @@ -10043,6 +10096,7 @@ T ldexp(T x, E exp) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Ldexp $x $exp }; + case wgsl: __intrinsic_asm "ldexp"; default: return ldexp(x, __realCast(exp)); } @@ -10050,7 +10104,7 @@ T ldexp(T x, E exp) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector ldexp(vector x, vector exp) { __target_switch @@ -10061,6 +10115,7 @@ vector ldexp(vector x, vector exp) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Ldexp $x $exp }; + case wgsl: __intrinsic_asm "ldexp"; default: vector temp; [ForceUnroll] @@ -10074,7 +10129,7 @@ vector ldexp(vector x, vector exp) // Vector length __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T length(vector x) { __target_switch @@ -10085,6 +10140,7 @@ T length(vector x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Length $x }; + case wgsl: __intrinsic_asm "length"; default: return sqrt(dot(x, x)); } @@ -10092,7 +10148,7 @@ T length(vector x) // Scalar float length __generic -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T length(T x) { __target_switch @@ -10101,6 +10157,7 @@ T length(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Length $x }; + case wgsl: __intrinsic_asm "length"; default: return abs(x); } @@ -10175,7 +10232,7 @@ float4 lit(float n_dot_l, float n_dot_h, float m) // Base-e logarithm __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T log(T x) { __target_switch @@ -10188,12 +10245,13 @@ T log(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Log $x }; + case wgsl: __intrinsic_asm "log"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector log(vector x) { __target_switch @@ -10204,6 +10262,7 @@ vector log(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Log $x }; + case wgsl: __intrinsic_asm "log"; default: VECTOR_MAP_UNARY(T, N, log, x); } @@ -10211,7 +10270,7 @@ vector log(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix log(matrix x) { __target_switch @@ -10285,7 +10344,7 @@ matrix log10(matrix x) // Base-2 logarithm __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T log2(T x) { __target_switch @@ -10298,12 +10357,13 @@ T log2(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Log2 $x }; + case wgsl: __intrinsic_asm "log2"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector log2(vector x) { __target_switch @@ -10314,6 +10374,7 @@ vector log2(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Log2 $x }; + case wgsl: __intrinsic_asm "log2"; default: VECTOR_MAP_UNARY(T, N, log2, x); } @@ -10321,7 +10382,7 @@ vector log2(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix log2(matrix x) { __target_switch @@ -10447,7 +10508,6 @@ T max(T x, T y) case hlsl: __intrinsic_asm "max"; case glsl: __intrinsic_asm "max"; case metal: __intrinsic_asm "max"; - case wgsl: __intrinsic_asm "max"; case cuda: __intrinsic_asm "$P_max($0, $1)"; case cpp: __intrinsic_asm "$P_max($0, $1)"; case spirv: @@ -10465,12 +10525,13 @@ T max(T x, T y) }; } } + case wgsl: __intrinsic_asm "max"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector max(vector x, vector y) { __target_switch @@ -10493,6 +10554,7 @@ vector max(vector x, vector y) }; } } + case wgsl: __intrinsic_asm "max"; default: VECTOR_MAP_BINARY(T, N, max, x, y); } @@ -10500,7 +10562,7 @@ vector max(vector x, vector y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix max(matrix x, matrix y) { __target_switch @@ -10513,7 +10575,7 @@ matrix max(matrix x, matrix y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T max(T x, T y) { __target_switch @@ -10526,12 +10588,13 @@ T max(T x, T y) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 FMax $x $y }; + case wgsl: __intrinsic_asm "max"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector max(vector x, vector y) { __target_switch @@ -10542,6 +10605,7 @@ vector max(vector x, vector y) case spirv: return spirv_asm { result:$$vector = OpExtInst glsl450 FMax $x $y }; + case wgsl: __intrinsic_asm "max"; default: VECTOR_MAP_BINARY(T, N, max, x, y); } @@ -10549,7 +10613,7 @@ vector max(vector x, vector y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix max(matrix x, matrix y) { __target_switch @@ -10672,7 +10736,6 @@ T min(T x, T y) case hlsl: case glsl: case metal: - case wgsl: __intrinsic_asm "min"; case cuda: case cpp: @@ -10688,12 +10751,13 @@ T min(T x, T y) result:$$T = OpExtInst glsl450 UMin $x $y }; } + case wgsl: __intrinsic_asm "min"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector min(vector x, vector y) { __target_switch @@ -10712,6 +10776,7 @@ vector min(vector x, vector y) result:$$vector = OpExtInst glsl450 UMin $x $y }; } + case wgsl: __intrinsic_asm "min"; default: VECTOR_MAP_BINARY(T, N, min, x, y); } @@ -10719,7 +10784,7 @@ vector min(vector x, vector y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix min(matrix x, matrix y) { __target_switch @@ -10732,7 +10797,7 @@ matrix min(matrix x, matrix y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T min(T x, T y) { __target_switch @@ -10745,12 +10810,13 @@ T min(T x, T y) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 FMin $x $y }; + case wgsl: __intrinsic_asm "min"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector min(vector x, vector y) { __target_switch @@ -10761,6 +10827,7 @@ vector min(vector x, vector y) case spirv: return spirv_asm { result:$$vector = OpExtInst glsl450 FMin $x $y }; + case wgsl: __intrinsic_asm "min"; default: VECTOR_MAP_BINARY(T, N, min, x, y); } @@ -10768,7 +10835,7 @@ vector min(vector x, vector y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix min(matrix x, matrix y) { __target_switch @@ -10975,7 +11042,7 @@ vector fmedian3(vector x, vector y, vector z) // split into integer and fractional parts (both with same sign) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T modf(T x, out T ip) { __target_switch @@ -10988,12 +11055,13 @@ T modf(T x, out T ip) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 Modf $x &ip }; + case wgsl: __intrinsic_asm "modf"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector modf(vector x, out vector ip) { __target_switch @@ -11004,6 +11072,7 @@ vector modf(vector x, out vector ip) case spirv: return spirv_asm { result:$$vector = OpExtInst glsl450 Modf $x &ip }; + case wgsl: __intrinsic_asm "modf"; default: VECTOR_MAP_BINARY(T, N, modf, x, ip); } @@ -11011,7 +11080,7 @@ vector modf(vector x, out vector ip) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix modf(matrix x, out matrix ip) { __target_switch @@ -11084,7 +11153,7 @@ matrix mul(T x, matrix y); // vector-vector (dot product) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T mul(vector x, vector y) { __target_switch @@ -11092,13 +11161,14 @@ T mul(vector x, vector y) case glsl: __intrinsic_asm "dot"; case metal: __intrinsic_asm "dot"; case hlsl: __intrinsic_asm "mul"; + case wgsl: __intrinsic_asm "dot"; default: return dot(x, y); } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T mul(vector x, vector y) { __target_switch @@ -11119,11 +11189,11 @@ vector mul(vector left, matrix right) { case glsl: __intrinsic_asm "($1 * $0)"; case metal: __intrinsic_asm "($1 * $0)"; - case wgsl: __intrinsic_asm "($1 * $0)"; case hlsl: __intrinsic_asm "mul"; case spirv: return spirv_asm { OpMatrixTimesVector $$vector result $right $left }; + case wgsl: __intrinsic_asm "($1 * $0)"; default: vector result; for( int j = 0; j < M; ++j ) @@ -11140,7 +11210,7 @@ vector mul(vector left, matrix right) } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector mul(vector left, matrix right) { __target_switch @@ -11148,6 +11218,7 @@ vector mul(vector left, matrix right) case glsl: __intrinsic_asm "($1 * $0)"; case metal: __intrinsic_asm "($1 * $0)"; case hlsl: __intrinsic_asm "mul"; + case wgsl: __intrinsic_asm "($1 * $0)"; default: vector result; for( int j = 0; j < M; ++j ) @@ -11164,7 +11235,7 @@ vector mul(vector left, matrix right) } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector mul(vector left, matrix right) { __target_switch @@ -11172,6 +11243,7 @@ vector mul(vector left, matrix right) case glsl: __intrinsic_asm "($1 * $0)"; case metal: __intrinsic_asm "($1 * $0)"; case hlsl: __intrinsic_asm "mul"; + case wgsl: __intrinsic_asm "($1 * $0)"; default: vector result; for( int j = 0; j < M; ++j ) @@ -11190,7 +11262,7 @@ vector mul(vector left, matrix right) // matrix-vector __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector mul(matrix left, vector right) { __target_switch @@ -11201,6 +11273,7 @@ vector mul(matrix left, vector right) case spirv: return spirv_asm { OpVectorTimesMatrix $$vector result $right $left }; + case wgsl: __intrinsic_asm "($1 * $0)"; default: vector result; for( int i = 0; i < N; ++i ) @@ -11217,7 +11290,7 @@ vector mul(matrix left, vector right) } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector mul(matrix left, vector right) { __target_switch @@ -11225,6 +11298,7 @@ vector mul(matrix left, vector right) case glsl: __intrinsic_asm "($1 * $0)"; case metal: __intrinsic_asm "($1 * $0)"; case hlsl: __intrinsic_asm "mul"; + case wgsl: __intrinsic_asm "($1 * $0)"; default: vector result; for( int i = 0; i < N; ++i ) @@ -11242,7 +11316,7 @@ vector mul(matrix left, vector right) __generic [__readNone] [OverloadRank(-1)] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector mul(matrix left, vector right) { __target_switch @@ -11250,6 +11324,7 @@ vector mul(matrix left, vector right) case glsl: __intrinsic_asm "($1 * $0)"; case metal: __intrinsic_asm "($1 * $0)"; case hlsl: __intrinsic_asm "mul"; + case wgsl: __intrinsic_asm "($1 * $0)"; default: vector result; for( int i = 0; i < N; ++i ) @@ -11268,7 +11343,7 @@ vector mul(matrix left, vector right) // matrix-matrix __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix mul(matrix left, matrix right) { __target_switch @@ -11279,6 +11354,7 @@ matrix mul(matrix left, matrix right) case spirv: return spirv_asm { OpMatrixTimesMatrix $$matrix result $right $left }; + case wgsl: __intrinsic_asm "($1 * $0)"; default: matrix result; for( int r = 0; r < R; ++r) @@ -11296,7 +11372,7 @@ matrix mul(matrix left, matrix right) } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix mul(matrix left, matrix right) { __target_switch @@ -11304,6 +11380,7 @@ matrix mul(matrix left, matrix right) case glsl: __intrinsic_asm "($1 * $0)"; case metal: __intrinsic_asm "($1 * $0)"; case hlsl: __intrinsic_asm "mul"; + case wgsl: __intrinsic_asm "($1 * $0)"; default: matrix result; for( int r = 0; r < R; ++r) @@ -11321,7 +11398,7 @@ matrix mul(matrix left, matrix right) } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix mul(matrix left, matrix right) { __target_switch @@ -11329,6 +11406,7 @@ matrix mul(matrix left, matrix right) case glsl: __intrinsic_asm "($1 * $0)"; case metal: __intrinsic_asm "($1 * $0)"; case hlsl: __intrinsic_asm "mul"; + case wgsl: __intrinsic_asm "($1 * $0)"; default: matrix result; for( int r = 0; r < R; ++r) @@ -11452,7 +11530,7 @@ T NonUniformResourceIndex(T value) { return value; } // Normalize a vector __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector normalize(vector x) { __target_switch @@ -11463,6 +11541,7 @@ vector normalize(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Normalize $x }; + case wgsl: __intrinsic_asm "normalize"; default: return x / length(x); } @@ -11470,7 +11549,7 @@ vector normalize(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T normalize(T x) { __target_switch @@ -11481,6 +11560,7 @@ T normalize(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Normalize $x }; + case wgsl: __intrinsic_asm "normalize"; default: return x / length(x); } @@ -11489,7 +11569,7 @@ T normalize(T x) // Raise to a power __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T pow(T x, T y) { __target_switch @@ -11502,12 +11582,13 @@ T pow(T x, T y) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Pow $x $y }; + case wgsl: __intrinsic_asm "pow"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector pow(vector x, vector y) { __target_switch @@ -11518,6 +11599,7 @@ vector pow(vector x, vector y) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Pow $x $y }; + case wgsl: __intrinsic_asm "pow"; default: VECTOR_MAP_BINARY(T, N, pow, x, y); } @@ -11525,7 +11607,7 @@ vector pow(vector x, vector y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix pow(matrix x, matrix y) { __target_switch @@ -11538,7 +11620,7 @@ matrix pow(matrix x, matrix y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T powr(T x, T y) { __target_switch @@ -11551,7 +11633,7 @@ T powr(T x, T y) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector powr(vector x, vector y) { __target_switch @@ -11697,7 +11779,7 @@ void ProcessTriTessFactorsMin( // Degrees to radians __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T radians(T x) { __target_switch @@ -11707,6 +11789,7 @@ T radians(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Radians $x }; + case wgsl: __intrinsic_asm "radians"; default: return x * (T.getPi() / T(180.0f)); } @@ -11714,7 +11797,7 @@ T radians(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector radians(vector x) { __target_switch @@ -11724,6 +11807,7 @@ vector radians(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Radians $x }; + case wgsl: __intrinsic_asm "radians"; default: return x * (T.getPi() / T(180.0f)); } @@ -11731,7 +11815,7 @@ vector radians(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix radians(matrix x) { __target_switch @@ -11745,7 +11829,7 @@ matrix radians(matrix x) // Approximate reciprocal __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T rcp(T x) { __target_switch @@ -11758,7 +11842,7 @@ T rcp(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector rcp(vector x) { __target_switch @@ -11766,6 +11850,7 @@ vector rcp(vector x) case hlsl: __intrinsic_asm "rcp"; case glsl: case spirv: + case wgsl: return T(1.0) / x; default: VECTOR_MAP_UNARY(T, N, rcp, x); @@ -11774,7 +11859,7 @@ vector rcp(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix rcp(matrix x) { __target_switch @@ -11788,7 +11873,7 @@ matrix rcp(matrix x) // Reflect incident vector across plane with given normal __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T reflect(T i, T n) { __target_switch @@ -11799,6 +11884,7 @@ T reflect(T i, T n) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Reflect $i $n }; + case wgsl: __intrinsic_asm "reflect"; default: return i - T(2) * dot(n,i) * n; } @@ -11806,7 +11892,7 @@ T reflect(T i, T n) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector reflect(vector i, vector n) { __target_switch @@ -11817,6 +11903,7 @@ vector reflect(vector i, vector n) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Reflect $i $n }; + case wgsl: __intrinsic_asm "reflect"; default: return i - T(2) * dot(n,i) * n; } @@ -11825,7 +11912,7 @@ vector reflect(vector i, vector n) // Refract incident vector given surface normal and index of refraction __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector refract(vector i, vector n, T eta) { __target_switch @@ -11836,6 +11923,7 @@ vector refract(vector i, vector n, T eta) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Refract $i $n $eta }; + case wgsl: __intrinsic_asm "refract"; default: let dotNI = dot(n,i); let k = T(1) - eta*eta*(T(1) - dotNI * dotNI); @@ -11846,7 +11934,7 @@ vector refract(vector i, vector n, T eta) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T refract(T i, T n, T eta) { __target_switch @@ -11857,6 +11945,7 @@ T refract(T i, T n, T eta) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Refract $i $n $eta }; + case wgsl: __intrinsic_asm "refract"; default: let dotNI = dot(n,i); let k = T(1) - eta*eta*(T(1) - dotNI * dotNI); @@ -11867,7 +11956,7 @@ T refract(T i, T n, T eta) // Reverse order of bits [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_5_0)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] uint reversebits(uint value) { __target_switch @@ -11883,12 +11972,13 @@ uint reversebits(uint value) __intrinsic_asm "reverse_bits"; case spirv: return spirv_asm {OpBitReverse $$uint result $value}; + case wgsl: __intrinsic_asm "reverseBits"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_5_0)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] vector reversebits(vector value) { __target_switch @@ -11901,6 +11991,7 @@ vector reversebits(vector value) __intrinsic_asm "reverse_bits"; case spirv: return spirv_asm {OpBitReverse $$vector result $value}; + case wgsl: __intrinsic_asm "reverseBits"; } } @@ -11957,7 +12048,7 @@ vector rint(vector x) // Round-to-nearest __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T round(T x) { __target_switch @@ -11970,12 +12061,13 @@ T round(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Round $x }; + case wgsl: __intrinsic_asm "round"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector round(vector x) { __target_switch @@ -11986,6 +12078,7 @@ vector round(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Round $x }; + case wgsl: __intrinsic_asm "round"; default: VECTOR_MAP_UNARY(T, N, round, x); } @@ -11993,7 +12086,7 @@ vector round(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix round(matrix x) { __target_switch @@ -12007,7 +12100,7 @@ matrix round(matrix x) // Reciprocal of square root __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T rsqrt(T x) { __target_switch @@ -12027,7 +12120,7 @@ T rsqrt(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector rsqrt(vector x) { __target_switch @@ -12045,7 +12138,7 @@ vector rsqrt(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix rsqrt(matrix x) { __target_switch @@ -12060,13 +12153,14 @@ matrix rsqrt(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T saturate(T x) { __target_switch { case hlsl: __intrinsic_asm "saturate"; case metal: __intrinsic_asm "saturate"; + case wgsl: __intrinsic_asm "saturate"; default: return clamp(x, T(0), T(1)); } @@ -12074,13 +12168,14 @@ T saturate(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector saturate(vector x) { __target_switch { case hlsl: __intrinsic_asm "saturate"; case metal: __intrinsic_asm "saturate"; + case wgsl: __intrinsic_asm "saturate"; default: return clamp(x, vector(T(0)), @@ -12090,7 +12185,7 @@ vector saturate(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix saturate(matrix x) { __target_switch @@ -12131,6 +12226,7 @@ int sign(T x) }; else return __int_cast(spirv_asm {OpExtInst $$T result glsl450 SSign $x}); + case wgsl: __intrinsic_asm "sign"; } } @@ -12154,6 +12250,7 @@ vector sign(vector x) }; else return __int_cast(spirv_asm {OpExtInst $$vector result glsl450 SSign $x}); + case wgsl: __intrinsic_asm "sign"; default: VECTOR_MAP_UNARY(int, N, sign, x); } @@ -12161,7 +12258,7 @@ vector sign(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_spirv_wgsl, sm_4_0_version)] matrix sign(matrix x) { __target_switch @@ -12186,16 +12283,16 @@ T sin(T x) case glsl: __intrinsic_asm "sin"; case hlsl: __intrinsic_asm "sin"; case metal: __intrinsic_asm "sin"; - case wgsl: __intrinsic_asm "sin"; case spirv: return spirv_asm { OpExtInst $$T result glsl450 Sin $x }; + case wgsl: __intrinsic_asm "sin"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector sin(vector x) { __target_switch @@ -12206,6 +12303,7 @@ vector sin(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Sin $x }; + case wgsl: __intrinsic_asm "sin"; default: VECTOR_MAP_UNARY(T, N, sin, x); } @@ -12213,7 +12311,7 @@ vector sin(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix sin(matrix x) { __target_switch @@ -12250,7 +12348,7 @@ vector __sincos_metal(vector x, out vector c) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] void sincos(T x, out T s, out T c) { __target_switch @@ -12270,7 +12368,7 @@ void sincos(T x, out T s, out T c) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] void sincos(vector x, out vector s, out vector c) { __target_switch @@ -12289,7 +12387,7 @@ void sincos(vector x, out vector s, out vector c) __generic [__readNone] [ForceInline] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] void sincos(matrix x, out matrix s, out matrix c) { __target_switch @@ -12304,7 +12402,7 @@ void sincos(matrix x, out matrix s, out matrix c) // Hyperbolic Sine __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T sinh(T x) { __target_switch @@ -12317,12 +12415,13 @@ T sinh(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Sinh $x }; + case wgsl: __intrinsic_asm "sinh"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector sinh(vector x) { __target_switch @@ -12333,6 +12432,7 @@ vector sinh(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Sinh $x }; + case wgsl: __intrinsic_asm "sinh"; default: VECTOR_MAP_UNARY(T, N, sinh, x); } @@ -12340,7 +12440,7 @@ vector sinh(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix sinh(matrix x) { __target_switch @@ -12355,7 +12455,7 @@ matrix sinh(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T sinpi(T x) { __target_switch @@ -12368,7 +12468,7 @@ T sinpi(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector sinpi(vector x) { __target_switch @@ -12383,7 +12483,7 @@ vector sinpi(vector x) // Smooth step (Hermite interpolation) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T smoothstep(T min, T max, T x) { __target_switch @@ -12394,6 +12494,7 @@ T smoothstep(T min, T max, T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 SmoothStep $min $max $x }; + case wgsl: __intrinsic_asm "smoothstep"; default: let t = saturate((x - min) / (max - min)); return t * t * (T(3.0f) - (t + t)); @@ -12402,7 +12503,7 @@ T smoothstep(T min, T max, T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector smoothstep(vector min, vector max, vector x) { __target_switch @@ -12413,6 +12514,7 @@ vector smoothstep(vector min, vector max, vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 SmoothStep $min $max $x }; + case wgsl: __intrinsic_asm "smoothstep"; default: VECTOR_MAP_TRINARY(T, N, smoothstep, min, max, x); } @@ -12420,7 +12522,7 @@ vector smoothstep(vector min, vector max, vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix smoothstep(matrix min, matrix max, matrix x) { __target_switch @@ -12434,7 +12536,7 @@ matrix smoothstep(matrix min, matrix max, matrix [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T sqrt(T x) { __target_switch @@ -12447,12 +12549,13 @@ T sqrt(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Sqrt $x }; + case wgsl: __intrinsic_asm "sqrt"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector sqrt(vector x) { __target_switch @@ -12463,6 +12566,7 @@ vector sqrt(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Sqrt $x }; + case wgsl: __intrinsic_asm "sqrt"; default: VECTOR_MAP_UNARY(T, N, sqrt, x); } @@ -12470,7 +12574,7 @@ vector sqrt(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix sqrt(matrix x) { __target_switch @@ -12484,7 +12588,7 @@ matrix sqrt(matrix x) // Step function __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T step(T y, T x) { __target_switch @@ -12495,6 +12599,7 @@ T step(T y, T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Step $y $x }; + case wgsl: __intrinsic_asm "step"; default: return x < y ? T(0.0f) : T(1.0f); } @@ -12502,7 +12607,7 @@ T step(T y, T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector step(vector y, vector x) { __target_switch @@ -12513,6 +12618,7 @@ vector step(vector y, vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Step $y $x }; + case wgsl: __intrinsic_asm "step"; default: VECTOR_MAP_BINARY(T, N, step, y, x); } @@ -12520,7 +12626,7 @@ vector step(vector y, vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix step(matrix y, matrix x) { __target_switch @@ -12534,7 +12640,7 @@ matrix step(matrix y, matrix x) // Tangent __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T tan(T x) { __target_switch @@ -12547,12 +12653,13 @@ T tan(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Tan $x }; + case wgsl: __intrinsic_asm "tan"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector tan(vector x) { __target_switch @@ -12563,6 +12670,7 @@ vector tan(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Tan $x }; + case wgsl: __intrinsic_asm "tan"; default: VECTOR_MAP_UNARY(T, N, tan, x); } @@ -12570,7 +12678,7 @@ vector tan(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix tan(matrix x) { __target_switch @@ -12584,7 +12692,7 @@ matrix tan(matrix x) // Hyperbolic tangent __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T tanh(T x) { __target_switch @@ -12597,12 +12705,13 @@ T tanh(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Tanh $x }; + case wgsl: __intrinsic_asm "tanh"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector tanh(vector x) { __target_switch @@ -12613,6 +12722,7 @@ vector tanh(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Tanh $x }; + case wgsl: __intrinsic_asm "tanh"; default: VECTOR_MAP_UNARY(T, N, tanh, x); } @@ -12620,7 +12730,7 @@ vector tanh(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix tanh(matrix x) { __target_switch @@ -12635,7 +12745,7 @@ matrix tanh(matrix x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T tanpi(T x) { __target_switch @@ -12648,7 +12758,7 @@ T tanpi(T x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector tanpi(vector x) { __target_switch @@ -12663,7 +12773,7 @@ vector tanpi(vector x) // Matrix transpose __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_spirv_wgsl, sm_4_0_version)] [PreferRecompute] matrix transpose(matrix x) { @@ -12674,6 +12784,7 @@ matrix transpose(matrix x) case spirv: return spirv_asm { OpTranspose $$matrix result $x }; + case wgsl: __intrinsic_asm "transpose"; default: matrix result; for(int r = 0; r < M; ++r) @@ -12684,7 +12795,7 @@ matrix transpose(matrix x) } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_spirv_wgsl, sm_4_0_version)] [PreferRecompute] matrix transpose(matrix x) { @@ -12695,6 +12806,7 @@ matrix transpose(matrix x) case spirv: return spirv_asm { OpTranspose $$matrix result $x }; + case wgsl: __intrinsic_asm "transpose"; default: matrix result; for (int r = 0; r < M; ++r) @@ -12705,7 +12817,7 @@ matrix transpose(matrix x) } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_spirv_wgsl, sm_4_0_version)] [PreferRecompute] [OverloadRank(-1)] matrix transpose(matrix x) @@ -12717,6 +12829,7 @@ matrix transpose(matrix x) case spirv: return spirv_asm { OpTranspose $$matrix result $x }; + case wgsl: __intrinsic_asm "transpose"; default: matrix result; for (int r = 0; r < M; ++r) @@ -12729,7 +12842,7 @@ matrix transpose(matrix x) // Truncate to integer __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] T trunc(T x) { __target_switch @@ -12742,12 +12855,13 @@ T trunc(T x) case spirv: return spirv_asm { OpExtInst $$T result glsl450 Trunc $x }; + case wgsl: __intrinsic_asm "trunc"; } } __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] vector trunc(vector x) { __target_switch @@ -12758,6 +12872,7 @@ vector trunc(vector x) case spirv: return spirv_asm { OpExtInst $$vector result glsl450 Trunc $x }; + case wgsl: __intrinsic_asm "trunc"; default: VECTOR_MAP_UNARY(T, N, trunc, x); } @@ -12765,7 +12880,7 @@ vector trunc(vector x) __generic [__readNone] -[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)] +[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] matrix trunc(matrix x) { __target_switch diff --git a/source/slang/slang-capabilities.capdef b/source/slang/slang-capabilities.capdef index 9e9b941513..3e17b3d19d 100644 --- a/source/slang/slang-capabilities.capdef +++ b/source/slang/slang-capabilities.capdef @@ -266,6 +266,10 @@ alias cpp_cuda_glsl_hlsl = cpp | cuda | glsl | hlsl; /// [Compound] alias cpp_cuda_glsl_hlsl_spirv = cpp | cuda | glsl | hlsl | spirv; +/// CPP, CUDA, GLSL, HLSL, SPIRV and WGSL code-gen targets +/// [Compound] +alias cpp_cuda_glsl_hlsl_spirv_wgsl = cpp | cuda | glsl | hlsl | spirv | wgsl; + /// CPP, CUDA, GLSL, HLSL, Metal and SPIRV code-gen targets /// [Compound] alias cpp_cuda_glsl_hlsl_metal_spirv = cpp | cuda | glsl | hlsl | metal | spirv; @@ -342,6 +346,10 @@ alias glsl_hlsl_spirv = glsl | hlsl | spirv; /// [Compound] alias glsl_hlsl_metal_spirv = glsl | hlsl | metal | spirv; +/// GLSL, HLSL, Metal, SPIRV and WGSL code-gen targets +/// [Compound] +alias glsl_hlsl_metal_spirv_wgsl = glsl | hlsl | metal | spirv | wgsl; + /// GLSL, Metal, and SPIRV code-gen targets /// [Compound] alias glsl_metal_spirv = glsl | metal | spirv; @@ -1207,6 +1215,7 @@ alias sm_4_1_version = _sm_4_1 | spirv_1_0 | _cuda_sm_6_0 | metal + | wgsl | cpp ; /// HLSL shader model 4.1 and related capabilities of other targets. @@ -1226,6 +1235,7 @@ alias sm_5_0_version = _sm_5_0 | spirv_1_0 | _cuda_sm_9_0 | metal + | wgsl | cpp ; /// HLSL shader model 5.0 and related capabilities of other targets. diff --git a/tests/wgsl/math.slang b/tests/wgsl/math.slang new file mode 100644 index 0000000000..d7f39ce43c --- /dev/null +++ b/tests/wgsl/math.slang @@ -0,0 +1,279 @@ +//TEST:SIMPLE(filecheck=WGSL): -stage compute -entry computeMain -target wgsl + +RWStructuredBuffer inputBuffer; +RWStructuredBuffer outputBuffer; + +__generic +bool Test_Scalar() +{ + // WGSL-LABEL: Test_Scalar + + const T zero = T(inputBuffer[0]); + const T one = T(inputBuffer[1]); + const int zeroInt = int(inputBuffer[0]); + + T outFloat1, outFloat2; + int outInt; + + return true + + // WGSL: acos( + && zero == acos(one) + + // WGSL: acosh( + && zero == acosh(one) + + // WGSL: asin( + && zero == asin(zero) + + // WGSL: asinh( + && zero == asinh(zero) + + // WGSL: atan( + && zero == atan(zero) + + // WGSL: atan2( + && zero == atan2(zero, zero) + + // WGSL: atanh( + && zero == atanh(zero) + + // WGSL: ceil( + && zero == ceil(zero) + + // WGSL: cos( + && one == cos(zero) + + // WGSL: cosh( + && one == cosh(zero) + + // WGSL: exp( + && one == exp(zero) + + // WGSL: exp2( + && one == exp2(zero) + + // WGSL: abs( + && zero == abs(zero) + + // WGSL: floor( + && zero == floor(zero) + + // WGSL: fma( + && zero == fma(zero, zero, zero) + + // WGSL: max( + && zero == max(zero, zero) + + // WGSL: min( + && zero == min(zero, zero) + + // WGSL: fract( + && zero == fract(zero) + + // WGSL: frexp( + && zero == frexp(zero, outInt) && zeroInt == outInt + + // WGSL: ldexp( + && zero == ldexp(zero, zeroInt) + + // WGSL: log( + && zero == log(one) + + // WGSL: log2( + && zero == log2(one) + + // WGSL: modf( + && zero == modf(zero, outFloat1) + + // WGSL: pow( + && zero == pow(zero, one) + + // WGSL: round( + && zero == round(zero) + + // WGSL: sin( + && zero == sin(zero) + + // WGSL: sinh( + && zero == sinh(zero) + + // WGSL: sqrt( + && zero == sqrt(zero) + + // WGSL: tan( + && zero == tan(zero) + + // WGSL: tanh( + && zero == tanh(zero) + + // WGSL: trunc( + && zero == trunc(zero) + ; +} + +__generic +bool Test_Vector() +{ + // WGSL-LABEL: Test_Vector_0 + const vector zero = T(inputBuffer[0]); + const vector one = T(inputBuffer[1]); + + const vector zeroInt = int(inputBuffer[0]); + + vector outFloat1, outFloat2; + vector outInt; + + return true + // WGSL: acos( + // WGSL-NOT: acos( + && zero == acos(one) + + // WGSL: acosh( + // WGSL-NOT: acosh( + && zero == acosh(one) + + // WGSL: asin( + // WGSL-NOT: asin( + && zero == asin(zero) + + // WGSL: asinh( + // WGSL-NOT: asinh( + && zero == asinh(zero) + + // WGSL: atan( + // WGSL-NOT: atan( + && zero == atan(zero) + + // WGSL: atan2( + // WGSL-NOT: atan2( + && zero == atan2(zero, zero) + + // WGSL: atanh( + // WGSL-NOT: atanh( + && zero == atanh(zero) + + // WGSL: ceil( + // WGSL-NOT: ceil( + && zero == ceil(zero) + + // WGSL: cos( + // WGSL-NOT: cos( + && one == cos(zero) + + // WGSL: cosh( + // WGSL-NOT: cosh( + && one == cosh(zero) + + // WGSL: exp( + // WGSL-NOT: exp( + && one == exp(zero) + + // WGSL: exp2( + // WGSL-NOT: exp2( + && one == exp2(zero) + + // WGSL: abs( + // WGSL-NOT: abs( + && zero == abs(zero) + + // WGSL: floor( + // WGSL-NOT: floor( + && zero == floor(zero) + + // WGSL: fma( + // WGSL-NOT: fma( + && zero == fma(zero, zero, zero) + + // WGSL: max( + // WGSL-NOT: max( + && zero == max(zero, zero) + + // WGSL: min( + // WGSL-NOT: min( + && zero == min(zero, zero) + + // WGSL: fract( + // WGSL-NOT: fract( + && zero == fract(zero) + + // WGSL: frexp( + // WGSL-NOT: frexp( + && zero == frexp(zero, outInt) && all(zeroInt == outInt) + + // WGSL: ldexp( + // WGSL-NOT: ldexp( + && zero == ldexp(zero, zeroInt) + + // WGSL: log( + // WGSL-NOT: log( + && zero == log(one) + + // WGSL: log2( + // WGSL-NOT: log2( + && zero == log2(one) + + // WGSL: modf( + // WGSL-NOT: modf( + && zero == modf(zero, outFloat1) + + // WGSL: pow( + // WGSL-NOT: pow( + && zero == pow(zero, one) + + // WGSL: round( + // WGSL-NOT: round( + && zero == round(zero) + + // WGSL: sin( + // WGSL-NOT: sin( + && zero == sin(zero) + + // WGSL: sinh( + // WGSL-NOT: sinh( + && zero == sinh(zero) + + // WGSL: sqrt( + // WGSL-NOT: sqrt( + && zero == sqrt(zero) + + // WGSL: tan( + // WGSL-NOT: tan( + && zero == tan(zero) + + // WGSL: tanh( + // WGSL-NOT: tanh( + && zero == tanh(zero) + + // WGSL: trunc( + // WGSL-NOT: trunc( + && zero == trunc(zero) + ; + + // WGSL-LABEL: Test_Vector_1 +} + +[numthreads(1,1,1)] +void computeMain() +{ + // GLSL: void main( + // GLSL_SPIRV: OpEntryPoint + // SPIR: OpEntryPoint + // HLSL: void computeMain( + // CUDA: void computeMain( + // CPP: void _computeMain( + + bool result = true + && Test_Scalar() + && Test_Vector() + && Test_Vector() + && Test_Vector() + && Test_Scalar() + && Test_Vector() + && Test_Vector() + && Test_Vector() + ; + + // BUF: 1 + outputBuffer[0] = int(result); +} diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index b49d7be73b..cac694f777 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -993,6 +993,11 @@ static PassThroughFlags _getPassThroughFlagsForTarget(SlangCompileTarget target) return PassThroughFlag::Metal; } + case SLANG_WGSL: + { + return PassThroughFlag::WGSL; + } + case SLANG_SHADER_HOST_CALLABLE: case SLANG_HOST_HOST_CALLABLE: diff --git a/tools/slang-test/test-context.h b/tools/slang-test/test-context.h index 28d39b064c..314ec2803a 100644 --- a/tools/slang-test/test-context.h +++ b/tools/slang-test/test-context.h @@ -37,7 +37,8 @@ struct PassThroughFlag Generic_C_CPP = 1 << int(SLANG_PASS_THROUGH_GENERIC_C_CPP), NVRTC = 1 << int(SLANG_PASS_THROUGH_NVRTC), LLVM = 1 << int(SLANG_PASS_THROUGH_LLVM), - Metal = 1 << int(SLANG_PASS_THROUGH_METAL) + Metal = 1 << int(SLANG_PASS_THROUGH_METAL), + WGSL = 1 << int(SLANG_PASS_THROUGH_WGSL) }; };