summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-03-30 12:47:43 -0700
committerGitHub <noreply@github.com>2020-03-30 12:47:43 -0700
commitad5b60c8b5868c69a979779f201748fb7837fdc9 (patch)
tree967c5eeb5d2a49dce2484c586453e5aef48ecb87
parent6f43b2698a99cc4f4bb4e905749fb87f24bf391b (diff)
Add a test for static const declarations in structure types (#1300)
The functionality already appears to work, and this test is just to make sure we don't regress on it. The most interesting thing here is that I'm using this change to pitch a new organization for tests around what part of the language they cover (rather than the kind of test they are), since the `tests/compute/` directory is getting overly full and is hard to navigate. We can consider moving individual tests into more of a hierarchy at some later point.
-rw-r--r--tests/language-feature/constants/static-const-in-struct.slang59
-rw-r--r--tests/language-feature/constants/static-const-in-struct.slang.expected.txt4
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/language-feature/constants/static-const-in-struct.slang b/tests/language-feature/constants/static-const-in-struct.slang
new file mode 100644
index 000000000..d01e58289
--- /dev/null
+++ b/tests/language-feature/constants/static-const-in-struct.slang
@@ -0,0 +1,59 @@
+// static-const-in-struct.slang
+
+//TEST(compute):COMPARE_COMPUTE:
+
+// Test that `static const` variable declarations inside of
+// a `struct` type correctly translate to constants in
+// the output.
+
+struct Test
+{
+ static const int kArraySize = 4;
+
+ // First case: test that a `static const` can
+ // be used as a constant inside the scope of
+ // methods on the type.
+ //
+ int method(int val)
+ {
+ int a[kArraySize] = {};
+
+ for(int i = 0; i < kArraySize; ++i)
+ a[i] = i;
+
+ return val * 16 + a[val];
+ }
+}
+
+// Second case: test that a global function can
+// reference and use a constant scoped within
+// a structure type.
+//
+int globalFunc(int val)
+{
+ int a[Test.kArraySize] = {};
+
+ for(int i = 0; i < Test::kArraySize; ++i)
+ a[i] = i;
+
+ return val * 16 + a[val];
+}
+
+int test(int val)
+{
+ Test t;
+ return t.method(val) * 256 + globalFunc(val);
+}
+
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ int inVal = tid;
+ int outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/language-feature/constants/static-const-in-struct.slang.expected.txt b/tests/language-feature/constants/static-const-in-struct.slang.expected.txt
new file mode 100644
index 000000000..6dbd5c939
--- /dev/null
+++ b/tests/language-feature/constants/static-const-in-struct.slang.expected.txt
@@ -0,0 +1,4 @@
+0
+1111
+2222
+3333