summaryrefslogtreecommitdiff
path: root/tests/experiments/generic/explicit-specialization.slang
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-02-03 09:28:54 -0500
committerGitHub <noreply@github.com>2022-02-03 09:28:54 -0500
commit3aaa586c90a688e035e2941a2e0327bd96a681cb (patch)
tree31f73cb42bdb1bca65b294124f37e6109011b533 /tests/experiments/generic/explicit-specialization.slang
parent5deb82929d289d6341e1919ee95b18b10f6db789 (diff)
'Explicit specialization' experiments with extensions (#2099)
* #include an absolute path didn't work - because paths were taken to always be relative. * Explicit specialization with multiple parameters. * Fix tabs. * Small improvements in test comments.
Diffstat (limited to 'tests/experiments/generic/explicit-specialization.slang')
-rw-r--r--tests/experiments/generic/explicit-specialization.slang38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/experiments/generic/explicit-specialization.slang b/tests/experiments/generic/explicit-specialization.slang
new file mode 100644
index 000000000..0eaa1da27
--- /dev/null
+++ b/tests/experiments/generic/explicit-specialization.slang
@@ -0,0 +1,38 @@
+//DISABLE_TEST:SIMPLE:-target hlsl -entry computeMain -profile cs_6_2
+
+/* Slang doesn't have explicit template specialization.
+Here's an attempt to use the extension mechanism.
+
+This doesn't work and produces 9 errors of the form
+> error 30052: invalid swizzle pattern 'rotateLeft' on type 'uint'
+> let v = tid.rotateLeft();
+
+Presumably for each letter of 'rotateLeft' after r, thinking it's a swizzle?
+*/
+
+RWStructuredBuffer<int> outputBuffer;
+
+interface IRotatable
+{
+ This rotateLeft();
+};
+
+extension int : IRotatable
+{
+ This rotateLeft() { const uint u = this; return This((u << 1) | (u >> 31)); }
+};
+
+extension uint : IRotatable
+{
+ This rotateLeft() { let u = this; return This((u << 1) | (u >> 31)); }
+};
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ uint v = tid.rotateLeft();
+
+ outputBuffer[tid] = v;
+}