summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/rewriter.hlsl19
-rw-r--r--tests/compute/rewriter.hlsl.expected.txt4
-rw-r--r--tests/compute/rewriter.slang30
3 files changed, 53 insertions, 0 deletions
diff --git a/tests/compute/rewriter.hlsl b/tests/compute/rewriter.hlsl
new file mode 100644
index 000000000..35a630c62
--- /dev/null
+++ b/tests/compute/rewriter.hlsl
@@ -0,0 +1,19 @@
+//TEST(compute):HLSL_COMPUTE:-xslang -no-checking -xslang -use-ir
+//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):dxbinding(0),glbinding(0),out
+
+// Test that we can use Slang libraries that require IR cross-compilation
+// (e.g., libraries that use generics) while writing the main code in
+// vanilla HLSL/GLSL without checking enabled.
+
+import rewriter;
+
+RWStructuredBuffer<int> outputBuffer : register(u0);
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ int inVal = outputBuffer[tid];
+ int outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/rewriter.hlsl.expected.txt b/tests/compute/rewriter.hlsl.expected.txt
new file mode 100644
index 000000000..a0d427709
--- /dev/null
+++ b/tests/compute/rewriter.hlsl.expected.txt
@@ -0,0 +1,4 @@
+10
+11
+12
+13
diff --git a/tests/compute/rewriter.slang b/tests/compute/rewriter.slang
new file mode 100644
index 000000000..2895dfaca
--- /dev/null
+++ b/tests/compute/rewriter.slang
@@ -0,0 +1,30 @@
+//TEST_IGNORE_FILE:
+
+// This file is a "library" used by the `rewriter.hlsl` test.
+// It intentionally uses Slang features that can't be supported
+// by naive source-to-source translation.
+
+interface IHelper
+{
+ int help(int inVal);
+}
+
+struct MyHelper : IHelper
+{
+ int help(int inVal)
+ {
+ return 16 + inVal;
+ }
+};
+
+__generic<H : IHelper>
+int doTest(H helper, int inVal)
+{
+ return helper.help(inVal);
+}
+
+int test(int inVal)
+{
+ MyHelper helper;
+ return doTest<MyHelper>(helper, inVal);
+}