diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-07-29 14:55:04 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-29 14:55:04 -0700 |
| commit | 89758544c45a15e546a1eb08891e2787bb88de4a (patch) | |
| tree | 1a8628e76d6a859beef511c512d4a648e6d1a958 | |
| parent | 9f33d3d4eb81afde1b4445a4251979eeb5436e7f (diff) | |
Fix issue with outputting "static" in GLSL (#1006)
This appears to be a regression introduced in #1001, and missed because none of our existing tests covered `static const` arrays on the GLSL/SPIR-V targets.
The basic problem is that we cannot output a `static const` definition in GLSL because `static` is a reserved word and not a keyword. Instead for GLSL we just want a `const` array. This change makes the emission of `static` for global-scope constants key on the target language for code generation, and only emit it for HLSL, C, and C++.
This change also adds a test case specifically for running Slang input that has a `static const` array on the Vulkan target.
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 15 | ||||
| -rw-r--r-- | tests/bugs/glsl-static-const-array.slang | 17 | ||||
| -rw-r--r-- | tests/bugs/glsl-static-const-array.slang.expected.txt | 4 |
3 files changed, 35 insertions, 1 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index d7930130e..c7b5b602b 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -982,7 +982,20 @@ void CLikeSourceEmitter::emitInstResultDecl(IRInst* inst) if(as<IRModuleInst>(inst->getParent())) { // "Ordinary" instructions at module scope are constants - m_writer->emit("static const "); + + switch (getSourceStyle()) + { + case SourceStyle::HLSL: + case SourceStyle::C: + case SourceStyle::CPP: + m_writer->emit("static "); + break; + + default: + break; + } + + m_writer->emit("const "); } emitType(type, getName(inst)); diff --git a/tests/bugs/glsl-static-const-array.slang b/tests/bugs/glsl-static-const-array.slang new file mode 100644 index 000000000..fb573c690 --- /dev/null +++ b/tests/bugs/glsl-static-const-array.slang @@ -0,0 +1,17 @@ +// glsl-static-const-array.slang + +//TEST(compute):COMPARE_COMPUTE:-vk + +static const int gData[4] = +{ + 0xA, 0xB, 0xC, 0xD, +}; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +RWStructuredBuffer<int> gBuffer; + +[numthreads(4,1,1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + gBuffer[tid.x] = gData[tid.x]; +} diff --git a/tests/bugs/glsl-static-const-array.slang.expected.txt b/tests/bugs/glsl-static-const-array.slang.expected.txt new file mode 100644 index 000000000..8422d40f1 --- /dev/null +++ b/tests/bugs/glsl-static-const-array.slang.expected.txt @@ -0,0 +1,4 @@ +A +B +C +D |
