diff options
| -rw-r--r-- | tests/language-feature/constants/static-const-in-struct.slang | 59 | ||||
| -rw-r--r-- | tests/language-feature/constants/static-const-in-struct.slang.expected.txt | 4 |
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 |
