summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/types
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-03-04 21:57:50 -0800
committerGitHub <noreply@github.com>2024-03-04 21:57:50 -0800
commitbb017e6aa8ddbfac6b9a78a66f4706964fbeaff4 (patch)
treee902a0c319a326a035f815e6ac16a3d19fc860d3 /tests/language-feature/types
parent2297623aad4c249bccae3fe363ada31e308131ac (diff)
Extend `as` and `is` operator to work on generic types. (#3672)
Diffstat (limited to 'tests/language-feature/types')
-rw-r--r--tests/language-feature/types/as-is-generic.slang33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/language-feature/types/as-is-generic.slang b/tests/language-feature/types/as-is-generic.slang
new file mode 100644
index 000000000..6790eda37
--- /dev/null
+++ b/tests/language-feature/types/as-is-generic.slang
@@ -0,0 +1,33 @@
+// optional.slang
+
+// Test that `is` and `as` operator works on generic types.
+
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -vk -compute -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -cpu -compute -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+T compute<T>(T a1, T a2)
+{
+ if (a1 is float)
+ {
+ return reinterpret<T>((a1 as float).value + (a2 as float).value);
+ }
+ else if (T is int)
+ {
+ return reinterpret<T>((a1 as int).value - (a2 as int).value);
+ }
+ return T();
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ // CHECK: 3.0
+ outputBuffer[0] = compute(1.0f, 2.0f);
+
+ // CHECK: 1.0
+ outputBuffer[1] = compute(2, 1);
+}