diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2024-09-17 19:43:52 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-17 19:43:52 -0700 |
| commit | 2f455d3cc825ce8bcf000b2e462159fec81882ab (patch) | |
| tree | d3d0b1752735d8007a05757f81ab4da3a210541c /source | |
| parent | 07166468c6fa706b7f35d3422e4966f62e7b86d2 (diff) | |
Fix WGSL frexp and modf that returns a struct (#5096)
Two WGSL functions have little different behavior compared to other
shader languages: frexp and modf. They return a struct to return
two values.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/hlsl.meta.slang | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 7c68a641c..2df66c1f7 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -8658,10 +8658,21 @@ T frexp(T x, out int exp) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 Frexp $x &exp }; - case wgsl: __intrinsic_asm "frexp"; + case wgsl: + T fract; + __wgsl_frexp<T>(x, fract, exp); + return fract; } } +__generic<T : __BuiltinFloatingPointType> +[__readNone] +[require(wgsl)] +void __wgsl_frexp(T x, out T fract, out int exp) +{ + __intrinsic_asm "{ var s = frexp($0); $1 = s.fract; $2 = s.exp; }"; +} + __generic<T : __BuiltinFloatingPointType, let N : int> [__readNone] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] @@ -8675,7 +8686,6 @@ vector<T, N> frexp(vector<T, N> x, out vector<int, N> exp) case spirv: return spirv_asm { result:$$vector<T, N> = OpExtInst glsl450 Frexp $x &exp }; - case wgsl: __intrinsic_asm "frexp"; default: VECTOR_MAP_BINARY(T, N, frexp, x, exp); } @@ -11055,10 +11065,21 @@ T modf(T x, out T ip) case spirv: return spirv_asm { result:$$T = OpExtInst glsl450 Modf $x &ip }; - case wgsl: __intrinsic_asm "modf"; + case wgsl: + T fract; + __wgsl_modf<T>(x, fract, ip); + return fract; } } +__generic<T : __BuiltinFloatingPointType> +[__readNone] +[require(wgsl)] +void __wgsl_modf(T x, out T fract, out T whole) +{ + __intrinsic_asm "{ var s = modf($0); $1 = s.fract; $2 = s.whole; }"; +} + __generic<T : __BuiltinFloatingPointType, let N : int> [__readNone] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)] @@ -11072,7 +11093,6 @@ vector<T,N> modf(vector<T,N> x, out vector<T,N> ip) case spirv: return spirv_asm { result:$$vector<T,N> = OpExtInst glsl450 Modf $x &ip }; - case wgsl: __intrinsic_asm "modf"; default: VECTOR_MAP_BINARY(T, N, modf, x, ip); } |
