Skip to content

Commit 0f67d92

Browse files
authored
Bug fix - vk::binding on structured buffers (shader-slang#720)
* Fix output of binding of structured buffer on GLSL. * Added test to check vk binding is coming thru. * Fix closethit binding inconsistency.
1 parent cfb1f61 commit 0f67d92

4 files changed

+66
-3
lines changed

source/slang/emit.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -5951,8 +5951,28 @@ struct EmitVisitor
59515951
// TODO: we should require either the extension or the version...
59525952
requireGLSLVersion(430);
59535953

5954-
emit("layout(std430) buffer ");
5954+
Emit("layout(std430");
59555955

5956+
auto layout = getVarLayout(ctx, varDecl);
5957+
if (layout)
5958+
{
5959+
LayoutResourceKind kind = LayoutResourceKind::DescriptorTableSlot;
5960+
EmitVarChain chain(layout);
5961+
5962+
const UInt index = getBindingOffset(&chain, kind);
5963+
const UInt space = getBindingSpace(&chain, kind);
5964+
5965+
Emit(", binding = ");
5966+
Emit(index);
5967+
if (space)
5968+
{
5969+
Emit(", set = ");
5970+
Emit(space);
5971+
}
5972+
}
5973+
5974+
emit(") buffer ");
5975+
59565976
// Generate a dummy name for the block
59575977
emit("_S");
59585978
Emit(ctx->shared->uniqueIDCounter++);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//TEST:SIMPLE: -profile ps_4_0 -entry main -target glsl
2+
///////TEST:REFLECTION:-profile ps_4_0 -target spirv
3+
4+
[[vk::binding(3, 4)]]
5+
RWStructuredBuffer<uint> gDoneGroups : register(u3);
6+
7+
float4 main(
8+
float3 uv : UV)
9+
: SV_Target
10+
{
11+
return gDoneGroups[int(uv.z)];
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
result code = 0
2+
standard error = {
3+
}
4+
standard output = {
5+
#version 450
6+
layout(row_major) uniform;
7+
layout(row_major) buffer;
8+
9+
#line 5 0
10+
layout(std430, binding = 3, set = 4) buffer _S1 {
11+
uint gDoneGroups_0[];
12+
};
13+
14+
#line 7
15+
layout(location = 0)
16+
out vec4 _S2;
17+
18+
19+
#line 7
20+
layout(location = 0)
21+
in vec3 _S3;
22+
23+
24+
#line 7
25+
void main()
26+
{
27+
_S2 = vec4(gDoneGroups_0[uint(int(_S3.z))]);
28+
return;
29+
}
30+
31+
}

tests/vkray/closesthit.slang.glsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#version 460
33
#extension GL_NV_ray_tracing : require
44

5-
layout(std430) buffer _S1
5+
layout(std430, binding = 0) buffer _S1
66
{
77
vec4 colors_0[];
88
};
9-
9+
1010
struct BuiltInTriangleIntersectionAttributes_0
1111
{
1212
vec2 barycentrics_0;

0 commit comments

Comments
 (0)