summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-08-26 01:42:34 +0800
committerGitHub <noreply@github.com>2023-08-25 10:42:34 -0700
commitef4c9f1f1c297f1a33be95795a7a7561e0cc3bde (patch)
tree9ea81689432040905772aeec447adad88f212e01 /tests
parent036abc85ba1db9c8c06289f0a0492e9a95a228b9 (diff)
Initial version of spirv_asm block (#3151)
* Initial version of spirv_asm block * Correct indentation of parent instruction dumping * neater dumping for spirv_asm instructions * Add $$ DollarDollar token * Allow passing addresses to spirv_asm blocks * spirv OpUndef * String literals in spirv asm * OpName for spirv_asm ids * Correct failure in lower spirv_asm * correct position for spirv_asm idents * comment correct * several more tests for spirv_asm blocks * Fill out some unimplemented functions for spirv_asm expressions --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/language-feature/spirv-asm/addr.slang41
-rw-r--r--tests/language-feature/spirv-asm/bad-addr.slang18
-rw-r--r--tests/language-feature/spirv-asm/instructions-at-end.slang25
-rw-r--r--tests/language-feature/spirv-asm/opname.slang27
-rw-r--r--tests/language-feature/spirv-asm/simple.slang25
-rw-r--r--tests/language-feature/spirv-asm/specialized-generic.slang32
-rw-r--r--tests/language-feature/spirv-asm/void-type.slang25
7 files changed, 193 insertions, 0 deletions
diff --git a/tests/language-feature/spirv-asm/addr.slang b/tests/language-feature/spirv-asm/addr.slang
new file mode 100644
index 000000000..ae692433c
--- /dev/null
+++ b/tests/language-feature/spirv-asm/addr.slang
@@ -0,0 +1,41 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly -output-using-type
+
+//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+// CHECK: 4
+// CHECK-NEXT: 8
+// CHECK-NEXT: 12
+// CHECK-NEXT: 16
+
+//
+// This test tests that addresses of variables and inout parameters can be
+// passed into a spirv_asm block
+//
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int i = dispatchThreadID.x;
+ int n = outputBuffer[i];
+ int r;
+ spirv_asm
+ {
+ OpLoad $$int %n &n;
+ OpConstant $$int %two 2;
+ OpIMul $$int %r $n %two;
+ OpStore &r %r;
+ };
+ foo(r);
+ outputBuffer[i] = r;
+}
+
+func foo(inout int x)
+{
+ spirv_asm
+ {
+ OpLoad $$int %x &x;
+ OpIAdd $$int %added %x %x;
+ OpStore &x %added;
+ };
+}
+
diff --git a/tests/language-feature/spirv-asm/bad-addr.slang b/tests/language-feature/spirv-asm/bad-addr.slang
new file mode 100644
index 000000000..4fc29a921
--- /dev/null
+++ b/tests/language-feature/spirv-asm/bad-addr.slang
@@ -0,0 +1,18 @@
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
+
+RWStructuredBuffer<float> buf;
+
+//
+// This test checks that we correctly diagnose trying to use the address of
+// something without one
+//
+int foo(const int constParam)
+{
+ return spirv_asm
+ {
+ OpLoad $$int %foo &buf;
+ // CHECK: bad-addr.slang([[#@LINE-1]]): note 29103: unable to take the address of this address-of asm operand
+ OpLoad $$int result &constParam;
+ // CHECK: bad-addr.slang([[#@LINE-1]]): note 29103: unable to take the address of this address-of asm operand
+ };
+}
diff --git a/tests/language-feature/spirv-asm/instructions-at-end.slang b/tests/language-feature/spirv-asm/instructions-at-end.slang
new file mode 100644
index 000000000..b39fa6da1
--- /dev/null
+++ b/tests/language-feature/spirv-asm/instructions-at-end.slang
@@ -0,0 +1,25 @@
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):-emit-spirv-directly -target spirv-asm -entry computeMain -stage compute
+
+//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+//
+// This test checks that we correctly diagnose using 'result' in an instruction
+// not in the last position.
+//
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int i = dispatchThreadID.x;
+ int n = outputBuffer[i];
+ int r = spirv_asm
+ {
+ OpConstant $$int %two 2;
+ OpIMul $$int result $n %two;
+ // CHECK: instructions-at-end.slang([[#@LINE-1]]): error 29101: the result-id marker must only be used in the last instruction of a spriv_asm expression
+ // CHECK: note 29102: consider adding an OpCopyObject instruction to the end of the spirv_asm expression
+
+ OpIAdd $$uint %something %two %two;
+ };
+ outputBuffer[i] = r;
+}
diff --git a/tests/language-feature/spirv-asm/opname.slang b/tests/language-feature/spirv-asm/opname.slang
new file mode 100644
index 000000000..8c82276d2
--- /dev/null
+++ b/tests/language-feature/spirv-asm/opname.slang
@@ -0,0 +1,27 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly
+
+//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+// CHECK: 2
+// CHECK-NEXT: 4
+// CHECK-NEXT: 6
+// CHECK-NEXT: 8
+
+//
+// This test tests that the implicit `OpName` inserted for spirv_asm IDs can
+// coexist with an explicit OpName instruction
+//
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int i = dispatchThreadID.x;
+ int n = outputBuffer[i];
+ int r = spirv_asm
+ {
+ OpConstant $$int %two 2;
+ OpName %two "TWO";
+ OpIMul $$int result $n %two
+ };
+ outputBuffer[i] = r;
+}
diff --git a/tests/language-feature/spirv-asm/simple.slang b/tests/language-feature/spirv-asm/simple.slang
new file mode 100644
index 000000000..28257341d
--- /dev/null
+++ b/tests/language-feature/spirv-asm/simple.slang
@@ -0,0 +1,25 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly
+
+//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+// CHECK: 2
+// CHECK-NEXT: 4
+// CHECK-NEXT: 6
+// CHECK-NEXT: 8
+
+//
+// This test tests a basic application of the spirv_asm block
+//
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int i = dispatchThreadID.x;
+ int n = outputBuffer[i];
+ int r = spirv_asm
+ {
+ OpConstant $$int %two 2;
+ OpIMul $$int result $n %two
+ };
+ outputBuffer[i] = r;
+}
diff --git a/tests/language-feature/spirv-asm/specialized-generic.slang b/tests/language-feature/spirv-asm/specialized-generic.slang
new file mode 100644
index 000000000..c362e8c7a
--- /dev/null
+++ b/tests/language-feature/spirv-asm/specialized-generic.slang
@@ -0,0 +1,32 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly -output-using-type
+
+//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+// CHECK: 10
+// CHECK-NEXT: 20
+// CHECK-NEXT: 30
+// CHECK-NEXT: 40
+
+//
+// This test checks that although we have a generic function and the spirv_asm
+// block references the type parameter 'T', specialization resolves this before
+// the SPIR-V is rendered.
+//
+func foo<T : __BuiltinFloatingPointType>(T x) -> T
+{
+ return spirv_asm
+ {
+ OpConstant $$int %int_10 10;
+ OpConvertSToF $$T %float_10 %int_10;
+ OpFMul $$T result $x %float_10;
+ };
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int i = dispatchThreadID.x;
+ int n = outputBuffer[i];
+ outputBuffer[i] = int(foo<float>(n));
+}
diff --git a/tests/language-feature/spirv-asm/void-type.slang b/tests/language-feature/spirv-asm/void-type.slang
new file mode 100644
index 000000000..1c5a7abd0
--- /dev/null
+++ b/tests/language-feature/spirv-asm/void-type.slang
@@ -0,0 +1,25 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly
+
+//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+// CHECK: 2
+// CHECK-NEXT: 4
+// CHECK-NEXT: 6
+// CHECK-NEXT: 8
+
+//
+// This test tests a basic application of the spirv_asm block including
+//
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int i = dispatchThreadID.x;
+ int n = outputBuffer[i];
+ int r = spirv_asm
+ {
+ OpConstant $$int %two 2;
+ OpIMul $$int result $n %two
+ };
+ outputBuffer[i] = r;
+}