summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-07-31 10:03:39 -0700
committerGitHub <noreply@github.com>2024-07-31 10:03:39 -0700
commit134f8ccc930a8da28808c2e288344c21c67a577e (patch)
tree483c09957f94aa626c2e866ebc7634591d725657 /tests
parent6e4b82741893be55f6216c31e19650029c667078 (diff)
Fix IR lowering for generic interface types. (#4761)
* Fix IR lowering for generic interface types. * Fix. * Fix.
Diffstat (limited to 'tests')
-rw-r--r--tests/language-feature/constants/static-const-in-generic-interface.slang33
-rw-r--r--tests/language-feature/interfaces/generic-interface-conformance.slang31
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/language-feature/constants/static-const-in-generic-interface.slang b/tests/language-feature/constants/static-const-in-generic-interface.slang
new file mode 100644
index 000000000..87d8e3be8
--- /dev/null
+++ b/tests/language-feature/constants/static-const-in-generic-interface.slang
@@ -0,0 +1,33 @@
+// static-const-in-generic-interface.slang
+
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
+
+// Test that `static const` variable declarations inside of
+// a generic `interface` type correctly translate to interface requirements.
+
+interface ITest<T:__BuiltinIntegerType>
+{
+ static const T kUserDefinedValue;
+}
+
+struct Impl : ITest<int>
+{
+ static const int kUserDefinedValue = 4;
+}
+
+struct EnsureCompileTimeEval<T : __BuiltinIntegerType>
+{
+ static T getValue<U : ITest<T>>() { return U.kUserDefinedValue; }
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
+{
+ static const int result = EnsureCompileTimeEval<int>.getValue<Impl>();
+ int outVal = result;
+ // CHECK: 4
+ outputBuffer[0] = outVal;
+}
diff --git a/tests/language-feature/interfaces/generic-interface-conformance.slang b/tests/language-feature/interfaces/generic-interface-conformance.slang
new file mode 100644
index 000000000..9e0510125
--- /dev/null
+++ b/tests/language-feature/interfaces/generic-interface-conformance.slang
@@ -0,0 +1,31 @@
+// Test that we allow type conformances whose base interface is generic.
+
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-dx11 -compute -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -output-using-type
+
+public interface ITestInterface<Real : IFloat> {
+ Real sample();
+}
+
+struct TestInterfaceImpl<Real : IFloat> : ITestInterface<Real> {
+ Real sample() {
+ return x;
+ }
+ Real x;
+}
+
+//TEST_INPUT: set data = new StructuredBuffer<ITestInterface<float> >[new TestInterfaceImpl<float>{1.0}];
+StructuredBuffer<ITestInterface<float>> data;
+
+//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4);
+RWStructuredBuffer<int> outputBuffer;
+
+//TEST_INPUT: type_conformance TestInterfaceImpl<float>:ITestInterface<float> = 3
+
+[numthreads(1, 1, 1)]
+void computeMain()
+{
+ let obj = data[0];
+ // CHECK: 1
+ outputBuffer[0] = int(obj.sample());
+} \ No newline at end of file