Skip to content

Commit

Permalink
WGSL: Support isnan, isinf, etc.. (#5609)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleino-nv authored Nov 20, 2024
1 parent 1e7f541 commit ed123a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
22 changes: 13 additions & 9 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -9445,7 +9445,7 @@ void InterlockedCompareStoreFloatBitwise<T:IAtomicable>(__ref T dest, T compar
/// @category math
__generic<T : __BuiltinFloatingPointType>
[__readNone]
[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]
[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]
bool isfinite(T x)
{
__target_switch
Expand All @@ -9463,7 +9463,7 @@ bool isfinite(T x)

__generic<T : __BuiltinFloatingPointType, let N : int>
[__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<bool, N> isfinite(vector<T, N> x)
{
__target_switch
Expand All @@ -9481,7 +9481,7 @@ vector<bool, N> isfinite(vector<T, N> x)

__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
[__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<bool, N, M> isfinite(matrix<T, N, M> x)
{
__target_switch
Expand All @@ -9498,7 +9498,7 @@ matrix<bool, N, M> isfinite(matrix<T, N, M> x)
/// @category math
__generic<T : __BuiltinFloatingPointType>
[__readNone]
[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]
[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]
bool isinf(T x)
{
__target_switch
Expand All @@ -9512,12 +9512,14 @@ bool isinf(T x)
__intrinsic_asm "$P_isinf($0)";
case spirv:
return spirv_asm { result:$$bool = OpIsInf $x};
case wgsl:
__intrinsic_asm "($0 > 0x1.fffffep+127f) || ($0 < -0x1.fffffep+127f)";
}
}

__generic<T : __BuiltinFloatingPointType, let N : int>
[__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<bool, N> isinf(vector<T, N> x)
{
__target_switch
Expand All @@ -9535,7 +9537,7 @@ vector<bool, N> isinf(vector<T, N> x)

__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
[__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<bool, N, M> isinf(matrix<T, N, M> x)
{
__target_switch
Expand All @@ -9552,7 +9554,7 @@ matrix<bool, N, M> isinf(matrix<T, N, M> x)
/// @category math
__generic<T : __BuiltinFloatingPointType>
[__readNone]
[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]
[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]
bool isnan(T x)
{
__target_switch
Expand All @@ -9566,12 +9568,14 @@ bool isnan(T x)
__intrinsic_asm "$P_isnan($0)";
case spirv:
return spirv_asm { result:$$bool = OpIsNan $x};
case wgsl:
__intrinsic_asm "$0 != $0";
}
}

__generic<T : __BuiltinFloatingPointType, let N : int>
[__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<bool, N> isnan(vector<T, N> x)
{
__target_switch
Expand All @@ -9589,7 +9593,7 @@ vector<bool, N> isnan(vector<T, N> x)

__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
[__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<bool, N, M> isnan(matrix<T, N, M> x)
{
__target_switch
Expand Down
1 change: 0 additions & 1 deletion tests/expected-failure-github.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ tests/compute/texture-simple (wgpu)
tests/compute/transcendental-double (wgpu)
tests/hlsl-intrinsic/byte-address-buffer/byte-address-struct.slang.5 syn (wgpu)
tests/hlsl-intrinsic/classify-double.slang.6 syn (wgpu)
tests/hlsl-intrinsic/classify-float.slang.5 syn (wgpu)
tests/hlsl-intrinsic/matrix-float.slang.6 syn (wgpu)
tests/hlsl-intrinsic/matrix-int.slang.6 syn (wgpu)
tests/hlsl-intrinsic/scalar-double-simple.slang.7 syn (wgpu)
Expand Down
1 change: 0 additions & 1 deletion tests/hlsl-intrinsic/classify-float.slang
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu

// inf, -inf, nan, finite
//TEST_INPUT:ubuffer(data=[ 0x7f800000 0xff800000 0x7fffffff 1 ], stride=4):name inputBuffer
Expand Down

0 comments on commit ed123a9

Please sign in to comment.