diff options
| author | Yong He <yonghe@outlook.com> | 2023-08-22 23:21:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-22 23:21:50 -0700 |
| commit | 036a2b78151816075f1c86221028f0ebdff3c8a5 (patch) | |
| tree | 24c69f2d0a89f1bdb1024e7798aefaa7061b2acb | |
| parent | e2e10fb6b065ff78f40ff19e01a7fdd234b1b560 (diff) | |
Make `-fvk-u-shift` work on AppendStructuredBuffer. (#3144)
Co-authored-by: Yong He <yhe@nvidia.com>
| -rw-r--r-- | source/slang/slang-ir-lower-append-consume-structured-buffer.cpp | 16 | ||||
| -rw-r--r-- | tests/hlsl/append-structured-buffer.slang | 6 |
2 files changed, 19 insertions, 3 deletions
diff --git a/source/slang/slang-ir-lower-append-consume-structured-buffer.cpp b/source/slang/slang-ir-lower-append-consume-structured-buffer.cpp index fa9f16223..eeafd1866 100644 --- a/source/slang/slang-ir-lower-append-consume-structured-buffer.cpp +++ b/source/slang/slang-ir-lower-append-consume-structured-buffer.cpp @@ -177,13 +177,29 @@ namespace Slang IRBuilder subBuilder(typeUser); IRVarLayout::Builder newVarLayoutBuilder(&subBuilder, typeLayout); newVarLayoutBuilder.cloneEverythingButOffsetsFrom(varLayout); + IRVarOffsetAttr* uavOffsetAttr = nullptr; + IRVarOffsetAttr* descriptorTableSlotOffsetAttr = nullptr; + for (auto offsetAttr : varLayout->getOffsetAttrs()) { + if (offsetAttr->getResourceKind() == LayoutResourceKind::UnorderedAccess) + uavOffsetAttr = offsetAttr; + else if (offsetAttr->getResourceKind() == LayoutResourceKind::DescriptorTableSlot) + descriptorTableSlotOffsetAttr = offsetAttr; auto info = newVarLayoutBuilder.findOrAddResourceInfo(offsetAttr->getResourceKind()); info->offset = offsetAttr->getOffset(); info->space = offsetAttr->getSpace(); info->kind = offsetAttr->getResourceKind(); } + // If the user provided an layout offset for UAV but not for descriptor table slot, then + // we use the UAV offset for the descriptor table slot offset. + if (uavOffsetAttr && !descriptorTableSlotOffsetAttr) + { + auto info = newVarLayoutBuilder.findOrAddResourceInfo(LayoutResourceKind::DescriptorTableSlot); + info->offset = uavOffsetAttr->getOffset(); + info->space = uavOffsetAttr->getSpace(); + info->kind = LayoutResourceKind::DescriptorTableSlot; + } auto newVarLayout = newVarLayoutBuilder.build(); subBuilder.addLayoutDecoration(typeUser, newVarLayout); varLayout->removeAndDeallocate(); diff --git a/tests/hlsl/append-structured-buffer.slang b/tests/hlsl/append-structured-buffer.slang index 8d0352e85..52c657b86 100644 --- a/tests/hlsl/append-structured-buffer.slang +++ b/tests/hlsl/append-structured-buffer.slang @@ -1,5 +1,5 @@ -//TEST:SIMPLE(filecheck=GLSL):-target glsl -profile glsl_450 -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=GLSL):-target glsl -profile glsl_450 -stage compute -entry computeMain -fvk-u-shift 10 0 //TEST:SIMPLE(filecheck=SPIRV):-target spirv -profile glsl_450 -stage compute -entry computeMain //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; AppendStructuredBuffer<float2> appendBuffer; -// GLSL: layout(std430, binding = 1) buffer StructuredBuffer_float2_t +// GLSL: layout(std430, binding = 11) buffer StructuredBuffer_float2_t // GLSL: vec2 _data[]; // GLSL: } appendBuffer_elements_0 -// GLSL: layout(std430, binding = 2) buffer StructuredBuffer_int_t +// GLSL: layout(std430, binding = 12) buffer StructuredBuffer_int_t // GLSL: int _data[]; // GLSL: } appendBuffer_counter |
