summaryrefslogtreecommitdiffstats
path: root/tests/compute
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2025-02-07 18:27:23 -0800
committerGitHub <noreply@github.com>2025-02-07 18:27:23 -0800
commit57b09a8986668626c37055e431fa0ac6449d7214 (patch)
tree8a96d7ea01a150d22ba47818655239b21d4ac25e /tests/compute
parent79aebc18d54db3f0be8bd6529c0d79f4d8d4fc58 (diff)
Use and() and or() functions for logical-AND and OR (#6310)
* Use and() and or() functions for logical-AND and OR With this commit, Slang will emit function calls to `and()` and `or()` for the logical-AND and logical-OR when the operands are non-scalar and the target profile is SM6.0 and above. This is required change from SM6.0. For WGSL, there is no operator overloadings of `&&` and `||` when the operands are non-scalar. Unlike HLSL, WGSL also don't have `and()` nor `or()`. Alternatively, we can use `select()`.
Diffstat (limited to 'tests/compute')
-rw-r--r--tests/compute/logic-no-short-circuit-evaluation.slang66
-rw-r--r--tests/compute/logic-short-circuit-evaluation.slang15
-rw-r--r--tests/compute/logic-short-circuit-evaluation.slang.expected.txt16
3 files changed, 76 insertions, 21 deletions
diff --git a/tests/compute/logic-no-short-circuit-evaluation.slang b/tests/compute/logic-no-short-circuit-evaluation.slang
new file mode 100644
index 000000000..74351a505
--- /dev/null
+++ b/tests/compute/logic-no-short-circuit-evaluation.slang
@@ -0,0 +1,66 @@
+//TEST(compute):SIMPLE(filecheck=SM5):-target hlsl -profile cs_5_1 -entry computeMain
+//TEST(compute):SIMPLE(filecheck=SM6):-target hlsl -profile cs_6_0 -entry computeMain
+//TEST(compute):SIMPLE(filecheck=WGS):-target wgsl -stage compute -entry computeMain
+//TEST(compute):SIMPLE(filecheck=MTL):-target metal -stage compute -entry computeMain
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHK):-slang -compute -shaderobj -output-using-type -xslang -Wno-30056
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHK):-vk -compute -shaderobj -output-using-type -xslang -Wno-30056
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHK):-mtl -compute -shaderobj -output-using-type -xslang -Wno-30056
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-cuda -compute -shaderobj -output-using-type -xslang -Wno-30056
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-cpu -compute -shaderobj -output-using-type -xslang -Wno-30056
+
+// Testnig logical-AND, logical-OR and ternary operator with non-scalar operands
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+static int result = 0;
+
+bool2 assignFunc(int index)
+{
+ result += 10;
+ return bool2(true);
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int index = dispatchThreadID.x;
+
+ // No short-circuiting for vector types
+
+ //SM5:(all({{.*}}&&
+ //SM6:(all(and(
+ //WGS:(all(select(vec2<bool>(false),
+ //MTL:(all({{.*}}&&
+ if (all(bool2(index >= 1) && assignFunc(index)))
+ {
+ result++;
+ }
+
+ // Intentionally using non-boolean type for testing.
+
+ //SM5:(all({{.*}}||
+ //SM6:(or(vector<bool,2>(
+ //WGS:(select({{.*}}, vec2<bool>(true), vec2<bool>(
+ //MTL:(all(bool2({{.*}}||
+ if (all(int2(index >= 2) || !assignFunc(index)))
+ {
+ result++;
+ }
+
+ //SM5:(all({{.*}}?{{.*}}:
+ //SM6:(all(select(
+ //WGS:(all(select(vec2<bool>(false),
+ //MTL:(all(select(bool2(false)
+ if (all(bool2(index >= 3) ? assignFunc(index) : bool2(false)))
+ {
+ result++;
+ }
+
+ outputBuffer[index] = result;
+
+ //CHK:30
+ //CHK-NEXT:31
+ //CHK-NEXT:32
+ //CHK-NEXT:33
+}
diff --git a/tests/compute/logic-short-circuit-evaluation.slang b/tests/compute/logic-short-circuit-evaluation.slang
index 585a04770..eed30898f 100644
--- a/tests/compute/logic-short-circuit-evaluation.slang
+++ b/tests/compute/logic-short-circuit-evaluation.slang
@@ -1,8 +1,9 @@
-//TEST(compute):COMPARE_COMPUTE:-dx12 -compute -shaderobj
-//TEST(compute):COMPARE_COMPUTE:-vk -compute -shaderobj
-//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj
-//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -compile-arg -O3 -shaderobj
-//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHK):-dx12 -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHK):-vk -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHK):-mtl -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-cuda -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-cpu -compute -compile-arg -O3 -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -shaderobj
// Test doing vector comparisons
@@ -25,4 +26,8 @@ void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
// Only the last 4 elements will be 1.
(index < 12) || assignFunc(index);
+
+ //CHK-COUNT-4: 1
+ //CHK-COUNT-8: 0
+ //CHK-COUNT-4: 1
}
diff --git a/tests/compute/logic-short-circuit-evaluation.slang.expected.txt b/tests/compute/logic-short-circuit-evaluation.slang.expected.txt
deleted file mode 100644
index 945f08f2c..000000000
--- a/tests/compute/logic-short-circuit-evaluation.slang.expected.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-1
-1
-1
-1
-0
-0
-0
-0
-0
-0
-0
-0
-1
-1
-1
-1