From ed123a9ca901cdffdeeb61b761eeb8c199a70d04 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Wed, 20 Nov 2024 10:41:03 +0200 Subject: [PATCH] WGSL: Support isnan, isinf, etc.. (#5609) --- source/slang/hlsl.meta.slang | 22 +++++++++++++--------- tests/expected-failure-github.txt | 1 - tests/hlsl-intrinsic/classify-float.slang | 1 - 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 395ea5012a..7dd97a4368 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -9445,7 +9445,7 @@ void InterlockedCompareStoreFloatBitwise(__ref T dest, T compar /// @category math __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)] bool isfinite(T x) { __target_switch @@ -9463,7 +9463,7 @@ bool isfinite(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 isfinite(vector x) { __target_switch @@ -9481,7 +9481,7 @@ vector isfinite(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 isfinite(matrix x) { __target_switch @@ -9498,7 +9498,7 @@ matrix isfinite(matrix x) /// @category math __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)] bool isinf(T x) { __target_switch @@ -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 [__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 isinf(vector x) { __target_switch @@ -9535,7 +9537,7 @@ vector isinf(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 isinf(matrix x) { __target_switch @@ -9552,7 +9554,7 @@ matrix isinf(matrix x) /// @category math __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)] bool isnan(T x) { __target_switch @@ -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 [__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 isnan(vector x) { __target_switch @@ -9589,7 +9593,7 @@ vector isnan(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 isnan(matrix x) { __target_switch diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt index 117a0372ad..5d345b9e4c 100644 --- a/tests/expected-failure-github.txt +++ b/tests/expected-failure-github.txt @@ -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) diff --git a/tests/hlsl-intrinsic/classify-float.slang b/tests/hlsl-intrinsic/classify-float.slang index 0ca5918cd0..ca7c5a8c77 100644 --- a/tests/hlsl-intrinsic/classify-float.slang +++ b/tests/hlsl-intrinsic/classify-float.slang @@ -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