Skip to content

Commit 8975854

Browse files
author
Tim Foley
authored
Fix issue with outputting "static" in GLSL (shader-slang#1006)
This appears to be a regression introduced in shader-slang#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.
1 parent 9f33d3d commit 8975854

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

source/slang/slang-emit-c-like.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,20 @@ void CLikeSourceEmitter::emitInstResultDecl(IRInst* inst)
982982
if(as<IRModuleInst>(inst->getParent()))
983983
{
984984
// "Ordinary" instructions at module scope are constants
985-
m_writer->emit("static const ");
985+
986+
switch (getSourceStyle())
987+
{
988+
case SourceStyle::HLSL:
989+
case SourceStyle::C:
990+
case SourceStyle::CPP:
991+
m_writer->emit("static ");
992+
break;
993+
994+
default:
995+
break;
996+
}
997+
998+
m_writer->emit("const ");
986999
}
9871000

9881001
emitType(type, getName(inst));
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// glsl-static-const-array.slang
2+
3+
//TEST(compute):COMPARE_COMPUTE:-vk
4+
5+
static const int gData[4] =
6+
{
7+
0xA, 0xB, 0xC, 0xD,
8+
};
9+
10+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
11+
RWStructuredBuffer<int> gBuffer;
12+
13+
[numthreads(4,1,1)]
14+
void computeMain(uint3 tid : SV_DispatchThreadID)
15+
{
16+
gBuffer[tid.x] = gData[tid.x];
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
A
2+
B
3+
C
4+
D

0 commit comments

Comments
 (0)