summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-11-05 07:32:49 -0600
committerGitHub <noreply@github.com>2024-11-05 21:32:49 +0800
commit53dd5928c35d5a5cb1f7d2a563348fd1fa87d672 (patch)
tree861ecbb07d61ed85c4e9d9e0e5387eb386560b3e
parent7c2ff54758d26b73074fd14143ecd843ba685e0d (diff)
Fixing the wrong implementation of some math intrinsic (#5491)
* Fixing the wrong implementation of some math intrinsic Close the issue #5282 The root cause of the issue is that log10 is not supported in wgsl. So add the implementation. Also ldexp in wgsl doesn't support float type exponent, so fix the implementation of the intrinsic. * re-enable the tests
-rw-r--r--source/slang/hlsl.meta.slang12
-rw-r--r--tests/expected-failure-github.txt2
-rw-r--r--tests/hlsl-intrinsic/scalar-float.slang2
-rw-r--r--tests/hlsl-intrinsic/vector-float.slang2
4 files changed, 10 insertions, 8 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 525b666ab..6ac0b7fb9 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -9498,7 +9498,8 @@ T ldexp(T x, T exp)
__target_switch
{
case hlsl: __intrinsic_asm "ldexp";
- case wgsl: __intrinsic_asm "ldexp";
+ // In WGSL spec, ldexp can only take integer as the exponent.
+ case wgsl: __intrinsic_asm "($0 * exp2($1))";
default:
return x * exp2(exp);
}
@@ -9512,7 +9513,8 @@ vector<T, N> ldexp(vector<T, N> x, vector<T, N> exp)
__target_switch
{
case hlsl: __intrinsic_asm "ldexp";
- case wgsl: __intrinsic_asm "ldexp";
+ // In WGSL spec, ldexp can only take integer as the exponent.
+ case wgsl: __intrinsic_asm "($0 * exp2($1))";
default:
return x * exp2(exp);
}
@@ -9737,13 +9739,14 @@ matrix<T, N, M> log(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)]
T log10(T x)
{
__target_switch
{
case hlsl: __intrinsic_asm "log10";
case metal: __intrinsic_asm "log10";
+ case wgsl: __intrinsic_asm "(log( $0 ) * $S0( 0.43429448190325182765112891891661) )";
case glsl: __intrinsic_asm "(log( $0 ) * $S0( 0.43429448190325182765112891891661) )";
case cuda: __intrinsic_asm "$P_log10($0)";
case cpp: __intrinsic_asm "$P_log10($0)";
@@ -9760,13 +9763,14 @@ T log10(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<T,N> log10(vector<T,N> x)
{
__target_switch
{
case hlsl: __intrinsic_asm "log10";
case metal: __intrinsic_asm "log10";
+ case wgsl: __intrinsic_asm "(log( $0 ) * $S0(0.43429448190325182765112891891661) )";
case glsl: __intrinsic_asm "(log( $0 ) * $S0(0.43429448190325182765112891891661) )";
case spirv:
{
diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt
index b064af9ad..3c318993a 100644
--- a/tests/expected-failure-github.txt
+++ b/tests/expected-failure-github.txt
@@ -69,8 +69,6 @@ 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)
-tests/hlsl-intrinsic/scalar-float.slang.5 syn (wgpu)
-tests/hlsl-intrinsic/vector-float.slang.5 syn (wgpu)
tests/ir/string-literal-hash.slang.2 syn (wgpu)
tests/language-feature/anonymous-struct.slang.1 syn (wgpu)
tests/language-feature/constants/constexpr-loop.slang.2 syn (wgpu)
diff --git a/tests/hlsl-intrinsic/scalar-float.slang b/tests/hlsl-intrinsic/scalar-float.slang
index 148e1b696..a32fe8f6c 100644
--- a/tests/hlsl-intrinsic/scalar-float.slang
+++ b/tests/hlsl-intrinsic/scalar-float.slang
@@ -4,7 +4,7 @@
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
//DISABLED_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
+//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -shaderobj
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
RWStructuredBuffer<int> outputBuffer;
diff --git a/tests/hlsl-intrinsic/vector-float.slang b/tests/hlsl-intrinsic/vector-float.slang
index de5decfec..380131a89 100644
--- a/tests/hlsl-intrinsic/vector-float.slang
+++ b/tests/hlsl-intrinsic/vector-float.slang
@@ -3,7 +3,7 @@
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -output-using-type -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj
-//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu
+//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -output-using-type -shaderobj
//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
RWStructuredBuffer<float4> outputBuffer;