summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-lower-dynamic-resource-heap.cpp
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2025-05-16 11:57:17 -0700
committerGitHub <noreply@github.com>2025-05-16 18:57:17 +0000
commit0244c96d637f47fa264d441a82d3dca78889373b (patch)
tree86bf0a8922ebdfd727494bc06e3069df464fe682 /source/slang/slang-ir-lower-dynamic-resource-heap.cpp
parent0651ffb6489282f0f902ec5f630821a7b9d848bb (diff)
Fix correct bindings for bindless resource model [SPIRV and GLSL] (#7131)
Fix correct bindings for bindless resource model [spirv and glsl] fixes: #6952 Problem: * Currently all bindless objects are placed in the same set (fine) and same binding (incorrect behavior for vulkan). This is incorrect since as per [spec](https://registry.khronos.org/vulkan/specs/latest/man/html/VkDescriptorType.html), only 1 resource type may be written to each index inside a set (these rules are loosened with VK_EXT_mutable_descriptor_type) * This means currently generated bindings do not work in practice if we (for example) use `Sampler2D.Handle` and `Texture1D.Handle` in a shader since we would place 2 incompatible objects in the same binding-index and set. Solution: * `__getDynamicResourceHeap` was modified to allow bindings to chosen dynamically for a descriptor * use `IOpaqueDescriptor` to check compile-time information of resource types so that we can identify different resources * Using this information of `IOpaqueDescriptor`, we modify `defaultGetDescriptorFromHandle` to provide a binding model (1 resource per binding-index) which produces legal spirv/glsl. * To support `VK_EXT_mutable_descriptor_type` the function `defaultGetDescriptorFromHandle` has a set of options (`BindlessDescriptorOptions`) for a user to pick-from to support their binding model. Capabilities are not used here for flexibility purposes (specifically old shaders mixed with modern vulkan extensions). Other changes: * Added `TexelBuffer` DescriptorKind to aid in generating correct bindings * format code * Add to docs bindless changes, make AccelerationStructure use its handle directly, adjust tests accordingly --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-ir-lower-dynamic-resource-heap.cpp')
-rw-r--r--source/slang/slang-ir-lower-dynamic-resource-heap.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/source/slang/slang-ir-lower-dynamic-resource-heap.cpp b/source/slang/slang-ir-lower-dynamic-resource-heap.cpp
index 60ec688a0..b2199a174 100644
--- a/source/slang/slang-ir-lower-dynamic-resource-heap.cpp
+++ b/source/slang/slang-ir-lower-dynamic-resource-heap.cpp
@@ -58,10 +58,11 @@ UInt findUnusedSpaceIndex(TargetProgram* targetProgram, IRModule* module)
return index;
}
-IRVarLayout* createResourceHeapVarLayoutWithSpace(
+IRVarLayout* createResourceHeapVarLayoutWithSpaceAndBinding(
IRBuilder& builder,
IRInst* param,
- UInt spaceIndex)
+ UInt spaceIndex,
+ UInt bindingIndex)
{
SLANG_UNUSED(param);
IRTypeLayout::Builder typeLayoutBuilder(&builder);
@@ -71,7 +72,8 @@ IRVarLayout* createResourceHeapVarLayoutWithSpace(
auto typeLayout = typeLayoutBuilder.build();
IRVarLayout::Builder varLayoutBuilder(&builder, typeLayout);
varLayoutBuilder.findOrAddResourceInfo(LayoutResourceKind::RegisterSpace)->offset = spaceIndex;
- varLayoutBuilder.findOrAddResourceInfo(LayoutResourceKind::DescriptorTableSlot)->offset = 0;
+ varLayoutBuilder.findOrAddResourceInfo(LayoutResourceKind::DescriptorTableSlot)->offset =
+ bindingIndex;
return varLayoutBuilder.build();
}
@@ -93,8 +95,14 @@ void lowerDynamicResourceHeap(TargetProgram* targetProgram, IRModule* module, Di
IRBuilder builder(inst);
builder.setInsertBefore(inst);
+ auto bindingIndex = (UInt)as<IRIntLit>(inst->getOperand(0))->getValue();
+
auto param = builder.createGlobalParam(arrayType);
- auto varLayout = createResourceHeapVarLayoutWithSpace(builder, param, unusedSpaceIndex);
+ auto varLayout = createResourceHeapVarLayoutWithSpaceAndBinding(
+ builder,
+ param,
+ unusedSpaceIndex,
+ bindingIndex);
builder.addLayoutDecoration(param, varLayout);
builder.addNameHintDecoration(param, toSlice("__slang_resource_heap"));
inst->replaceUsesWith(param);