diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-02-08 14:46:12 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-08 14:46:12 -0800 |
| commit | c7c97ad4bb62b83efd6e26cdd4f38ebf164ec40e (patch) | |
| tree | db419221788d50dd1e8940b547713e5dcfceb48d /tests/compute/static-const-array.slang | |
| parent | 112caca00ba9bfd9e1051bb94969efa9e74c6c03 (diff) | |
Basic IR support for `static const` globals (#404)
* Basic IR support for `static const` globals
Our strategy for lowering global *variables* can fall back to putting their initialization into a function, but that isn't really appropriate for global constants (it also isn't appropriate for arrays, but we'll need to deal with that seaprately).
This change adds a distinct case for global constants (rather than treating them as variables), and forces the emission logic to always emit them as a single expression.
Doing this makes assumptions about how the IR for these constants gets emitted (and what optimziations might do to it).
In order to make things work, I had to switch the handling of initializer-list expressions to not be lowered via temporaries and mutation (since that isn't a good fit for reverting to a single expression).
I've added a single test case to ensure that this works in the simplest scenario. My next priority will be to see if this unblocks my work in Falcor.
* Fixup: bug fixes
Diffstat (limited to 'tests/compute/static-const-array.slang')
| -rw-r--r-- | tests/compute/static-const-array.slang | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/compute/static-const-array.slang b/tests/compute/static-const-array.slang new file mode 100644 index 000000000..242cfb096 --- /dev/null +++ b/tests/compute/static-const-array.slang @@ -0,0 +1,23 @@ +// static-const-array.slang + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST_DISABLED(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute + + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +RWStructuredBuffer<int> outputBuffer; + +static const int kArray[] = { 16, 1, 32, 2 }; + +int test(int val) +{ + return kArray[val]; +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + int inVal = tid.x; + int outVal = test(inVal); + outputBuffer[inVal] = outVal; +}
\ No newline at end of file |
