diff options
| author | Yong He <yonghe@outlook.com> | 2025-08-06 15:56:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-06 22:56:27 +0000 |
| commit | de7ccaf127d8bb847a0ad25f45e8d1902dc1b958 (patch) | |
| tree | 77cf9c35e6f04a416da7932adc1aa23ff7b25a1e | |
| parent | b9f999b74301665d793357e8b78da3b8de9473da (diff) | |
Fix unused space discovery for bindless heap. (#8075)
| -rw-r--r-- | source/compiler-core/slang-artifact-associated-impl.h | 1 | ||||
| -rw-r--r-- | source/slang/slang-ir-lower-dynamic-resource-heap.cpp | 2 | ||||
| -rw-r--r-- | tests/spirv/descriptor-heap-space.slang | 41 |
3 files changed, 43 insertions, 1 deletions
diff --git a/source/compiler-core/slang-artifact-associated-impl.h b/source/compiler-core/slang-artifact-associated-impl.h index 6ae01626a..9f60c51b6 100644 --- a/source/compiler-core/slang-artifact-associated-impl.h +++ b/source/compiler-core/slang-artifact-associated-impl.h @@ -166,6 +166,7 @@ struct ShaderBindingRange case slang::VaryingInput: case slang::VaryingOutput: case slang::SpecializationConstant: + case slang::SubElementRegisterSpace: return true; default: return false; diff --git a/source/slang/slang-ir-lower-dynamic-resource-heap.cpp b/source/slang/slang-ir-lower-dynamic-resource-heap.cpp index b2199a174..495795cca 100644 --- a/source/slang/slang-ir-lower-dynamic-resource-heap.cpp +++ b/source/slang/slang-ir-lower-dynamic-resource-heap.cpp @@ -11,7 +11,7 @@ UInt findUnusedSpaceIndex(TargetProgram* targetProgram, IRModule* module) auto processVarLayout = [&](IRVarLayout* varLayout) { UInt spaceOffset = 0; - if (auto spaceAttr = varLayout->findOffsetAttr(LayoutResourceKind::RegisterSpace)) + if (auto spaceAttr = varLayout->findOffsetAttr(LayoutResourceKind::SubElementRegisterSpace)) { spaceOffset = spaceAttr->getOffset(); } diff --git a/tests/spirv/descriptor-heap-space.slang b/tests/spirv/descriptor-heap-space.slang new file mode 100644 index 000000000..8ab905b87 --- /dev/null +++ b/tests/spirv/descriptor-heap-space.slang @@ -0,0 +1,41 @@ +//TEST:SIMPLE(filecheck=CHECK): -target glsl -entry main + +// Test that we can find the correct unused descriptor set index when there is `ParameterBlock` in the shader. + +//CHECK: layout(binding = 2, set = 2) +//CHECK-NEXT: uniform texture2D _slang_resource_heap + +struct VSInput{ + float3 position; +} + +struct VSOutput{ + float4 position : SV_Position; +} + +struct CameraData{ + float3 position; +} + +ParameterBlock<CameraData> cameraData; + + +struct Material{ + DescriptorHandle<Texture2D> texture; + DescriptorHandle<SamplerState> samplerState; +} + +StructuredBuffer<Material> materials; + +struct FSOutput{ + float4 outColor : SV_Target0; +} + + +[shader("fragment")] +FSOutput main(){ + FSOutput output; + output.outColor = materials[0].texture.Sample(materials[0].samplerState, float2(0)); + output.outColor.x *= cameraData.position.x; + return output; +}
\ No newline at end of file |
