summaryrefslogtreecommitdiffstats
path: root/tests/compute
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2024-01-23 16:57:44 -0800
committerGitHub <noreply@github.com>2024-01-23 16:57:44 -0800
commit4d217907665180537ea217f9f2213c9d53a22b99 (patch)
tree02de5405c4fc4cd3cdd3b4ef4496b7c33a4e9728 /tests/compute
parentaf91e770f99da18ae97d6b601c706343cece11e9 (diff)
Fix incorrect behavior of operator% (#3470)
* Fix incorrect behavior of operator% Fixes #1059. This change fixes the incorrect translation of "operator%" from HLSL to SPIRV. The issue stems from the fact that the behavior of "operator%" in GLSL differs from that in HLSL. In HLSL it behaves as "remainder" where as it behaves as "modulus" in GLSL. We have been using SpvOpFMod for operator% when Slang compiles from HLSL to SPRIV, which is incorrect. This change switches it to SpvOpFRem. The tests are slightly modified to reveal any potential issues. * Change output type of test/compute/frem For testing the operator%, we are using "int" as the output type of the test, "test/compute/frem.slang". Since the operands are in float type, it is more preferable to have a float type as the resulting type. This can be done with an option, "-output-using-type". --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests/compute')
-rw-r--r--tests/compute/frem.slang12
-rw-r--r--tests/compute/frem.slang.2.expected.txt9
-rw-r--r--tests/compute/frem.slang.expected.txt9
3 files changed, 16 insertions, 14 deletions
diff --git a/tests/compute/frem.slang b/tests/compute/frem.slang
index 7890b9c9a..893f29794 100644
--- a/tests/compute/frem.slang
+++ b/tests/compute/frem.slang
@@ -1,13 +1,13 @@
// frem.slang
-//TEST(compute):COMPARE_COMPUTE: -shaderobj
-//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj
-//TEST(compute):COMPARE_COMPUTE:-vk -shaderobj
+//TEST(compute):COMPARE_COMPUTE: -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE:-vk -shaderobj -emit-spirv-directly -output-using-type
// Test uses of floating-point `%` operator.
RWStructuredBuffer<float> gInput;
-//TEST_INPUT:ubuffer(data=[2.0 1.0 5.0 2.0 2.0 -4.0 -5.0 2.0], stride=4):name=gInput
+//TEST_INPUT:ubuffer(data=[2.0 1.0 5.0 2.0 1.0 -4.0 -5.0 4.0], stride=4):name=gInput
int test(int inVal)
{
@@ -17,7 +17,7 @@ int test(int inVal)
}
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
-RWStructuredBuffer<int> outputBuffer;
+RWStructuredBuffer<float> outputBuffer;
[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
@@ -26,4 +26,4 @@ void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
int inVal = tid;
int outVal = test(inVal);
outputBuffer[tid] = outVal;
-} \ No newline at end of file
+}
diff --git a/tests/compute/frem.slang.2.expected.txt b/tests/compute/frem.slang.2.expected.txt
index f22b9c805..15ca0db0b 100644
--- a/tests/compute/frem.slang.2.expected.txt
+++ b/tests/compute/frem.slang.2.expected.txt
@@ -1,4 +1,5 @@
-0
-1
-FFFFFFFE
-1
+type: float
+0.000000
+1.000000
+1.000000
+-1.000000
diff --git a/tests/compute/frem.slang.expected.txt b/tests/compute/frem.slang.expected.txt
index bafada4d1..15ca0db0b 100644
--- a/tests/compute/frem.slang.expected.txt
+++ b/tests/compute/frem.slang.expected.txt
@@ -1,4 +1,5 @@
-0
-1
-2
-FFFFFFFF
+type: float
+0.000000
+1.000000
+1.000000
+-1.000000