From ad5b60c8b5868c69a979779f201748fb7837fdc9 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 30 Mar 2020 12:47:43 -0700 Subject: 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. --- .../constants/static-const-in-struct.slang | 59 ++++++++++++++++++++++ .../static-const-in-struct.slang.expected.txt | 4 ++ 2 files changed, 63 insertions(+) create mode 100644 tests/language-feature/constants/static-const-in-struct.slang create mode 100644 tests/language-feature/constants/static-const-in-struct.slang.expected.txt 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 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 -- cgit v1.2.3