summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-08-24 12:05:19 -0700
committerGitHub <noreply@github.com>2022-08-24 12:05:19 -0700
commitba6f55ed9481960b4f6c7f0a6b8f1cf7d450c752 (patch)
treebd92bf3cca5614585f8be6ad6f57510b18565b47 /tests
parent3746a47ce407b14c4afbfc5b625513cf81b5e890 (diff)
Allow `static const` interface requirements. (#2378)
Diffstat (limited to 'tests')
-rw-r--r--tests/language-feature/constants/static-const-in-interface.slang44
-rw-r--r--tests/language-feature/constants/static-const-in-interface.slang.expected.txt4
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/language-feature/constants/static-const-in-interface.slang b/tests/language-feature/constants/static-const-in-interface.slang
new file mode 100644
index 000000000..48737564f
--- /dev/null
+++ b/tests/language-feature/constants/static-const-in-interface.slang
@@ -0,0 +1,44 @@
+// static-const-in-interface.slang
+
+//TEST(compute):COMPARE_COMPUTE: -shaderobj
+
+// Test that `static const` variable declarations inside of
+// a `interface` type correctly translate to interface requirements.
+
+interface ITest
+{
+ static const int kUserDefinedValue;
+}
+
+extension int : ITest
+{
+ static const int kUserDefinedValue = 4;
+}
+
+extension int16_t : ITest
+{
+ static const int kUserDefinedValue = 2;
+}
+
+struct GetValue<T : ITest>
+{
+ static const int value = T.kUserDefinedValue;
+}
+
+struct EnsureCompileTimeEval<let u : int>
+{
+ static const int value = u;
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int tid = dispatchThreadID.x;
+ int inVal = tid;
+ static const int result = EnsureCompileTimeEval<GetValue<int>.value - GetValue<int16_t>.value>.value;
+ int outVal = result;
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/language-feature/constants/static-const-in-interface.slang.expected.txt b/tests/language-feature/constants/static-const-in-interface.slang.expected.txt
new file mode 100644
index 000000000..487b11653
--- /dev/null
+++ b/tests/language-feature/constants/static-const-in-interface.slang.expected.txt
@@ -0,0 +1,4 @@
+2
+2
+2
+2