summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/generics/dependent-generic-3.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-08-20 20:51:57 -0700
committerGitHub <noreply@github.com>2024-08-20 20:51:57 -0700
commitf9f6a28df40f418ddd0c8ff3b9cacccdb085e202 (patch)
treea6bafa63cee4f9bbcfe496de54af6e5727bb021e /tests/language-feature/generics/dependent-generic-3.slang
parent03e1e17745920c8e3a7b6f4e3b1e64062589604a (diff)
Support dependent generic constraints. (#4870)
* Support dependent generic constraints. * Fix warning. * Update comment. * Fix. * Add a test case to verify fix of #3804. * Address review.
Diffstat (limited to 'tests/language-feature/generics/dependent-generic-3.slang')
-rw-r--r--tests/language-feature/generics/dependent-generic-3.slang32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/language-feature/generics/dependent-generic-3.slang b/tests/language-feature/generics/dependent-generic-3.slang
new file mode 100644
index 000000000..024d09285
--- /dev/null
+++ b/tests/language-feature/generics/dependent-generic-3.slang
@@ -0,0 +1,32 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+interface IOperation<T : __BuiltinFloatingPointType>
+{
+ static T apply(T lhs, T rhs);
+};
+
+T applyOp<T:__BuiltinFloatingPointType, TOp:IOperation<T>>(T lhs, T rhs)
+{
+ return TOp::apply(lhs, rhs);
+}
+
+struct AddOp<T : __BuiltinFloatingPointType> : IOperation<T>
+{
+ static T apply(T lhs, T rhs)
+ {
+ return lhs + rhs;
+ }
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
+{
+ let result = applyOp<float, AddOp<float>>(1.0, 2.0);
+
+ // CHECK: 3
+ outputBuffer[0] = (int)result;
+}