Skip to content

Commit 036a2b7

Browse files
authored
Make -fvk-u-shift work on AppendStructuredBuffer. (shader-slang#3144)
Co-authored-by: Yong He <yhe@nvidia.com>
1 parent e2e10fb commit 036a2b7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

source/slang/slang-ir-lower-append-consume-structured-buffer.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,29 @@ namespace Slang
177177
IRBuilder subBuilder(typeUser);
178178
IRVarLayout::Builder newVarLayoutBuilder(&subBuilder, typeLayout);
179179
newVarLayoutBuilder.cloneEverythingButOffsetsFrom(varLayout);
180+
IRVarOffsetAttr* uavOffsetAttr = nullptr;
181+
IRVarOffsetAttr* descriptorTableSlotOffsetAttr = nullptr;
182+
180183
for (auto offsetAttr : varLayout->getOffsetAttrs())
181184
{
185+
if (offsetAttr->getResourceKind() == LayoutResourceKind::UnorderedAccess)
186+
uavOffsetAttr = offsetAttr;
187+
else if (offsetAttr->getResourceKind() == LayoutResourceKind::DescriptorTableSlot)
188+
descriptorTableSlotOffsetAttr = offsetAttr;
182189
auto info = newVarLayoutBuilder.findOrAddResourceInfo(offsetAttr->getResourceKind());
183190
info->offset = offsetAttr->getOffset();
184191
info->space = offsetAttr->getSpace();
185192
info->kind = offsetAttr->getResourceKind();
186193
}
194+
// If the user provided an layout offset for UAV but not for descriptor table slot, then
195+
// we use the UAV offset for the descriptor table slot offset.
196+
if (uavOffsetAttr && !descriptorTableSlotOffsetAttr)
197+
{
198+
auto info = newVarLayoutBuilder.findOrAddResourceInfo(LayoutResourceKind::DescriptorTableSlot);
199+
info->offset = uavOffsetAttr->getOffset();
200+
info->space = uavOffsetAttr->getSpace();
201+
info->kind = LayoutResourceKind::DescriptorTableSlot;
202+
}
187203
auto newVarLayout = newVarLayoutBuilder.build();
188204
subBuilder.addLayoutDecoration(typeUser, newVarLayout);
189205
varLayout->removeAndDeallocate();

tests/hlsl/append-structured-buffer.slang

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
//TEST:SIMPLE(filecheck=GLSL):-target glsl -profile glsl_450 -stage compute -entry computeMain
2+
//TEST:SIMPLE(filecheck=GLSL):-target glsl -profile glsl_450 -stage compute -entry computeMain -fvk-u-shift 10 0
33
//TEST:SIMPLE(filecheck=SPIRV):-target spirv -profile glsl_450 -stage compute -entry computeMain
44

55
//DISABLED_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type -xslang -fvk-use-gl-layout
@@ -9,11 +9,11 @@ RWStructuredBuffer<float> outputBuffer;
99

1010
AppendStructuredBuffer<float2> appendBuffer;
1111

12-
// GLSL: layout(std430, binding = 1) buffer StructuredBuffer_float2_t
12+
// GLSL: layout(std430, binding = 11) buffer StructuredBuffer_float2_t
1313
// GLSL: vec2 _data[];
1414
// GLSL: } appendBuffer_elements_0
1515

16-
// GLSL: layout(std430, binding = 2) buffer StructuredBuffer_int_t
16+
// GLSL: layout(std430, binding = 12) buffer StructuredBuffer_int_t
1717
// GLSL: int _data[];
1818
// GLSL: } appendBuffer_counter
1919

0 commit comments

Comments
 (0)