Support arrays of TLAS bindings - #1305
Merged
Merged
Conversation
MarijnS95
force-pushed
the
tlas-array-bindings
branch
2 times, most recently
from
June 11, 2026 16:57
c2ae187 to
368c470
Compare
MarijnS95
marked this pull request as ready for review
June 11, 2026 16:57
bogner
approved these changes
Jun 26, 2026
MarijnS95
force-pushed
the
tlas-array-bindings
branch
3 times, most recently
from
July 1, 2026 13:46
cd78e9e to
c12c9a5
Compare
MarijnS95
force-pushed
the
tlas-array-bindings
branch
2 times, most recently
from
July 16, 2026 20:24
5176326 to
cc682ad
Compare
MarijnS95
force-pushed
the
tlas-array-bindings
branch
from
July 23, 2026 20:39
4703557 to
7180017
Compare
Mirror the existing buffer/texture array pattern (`ArraySize` plus an ArraySize-driven YAML field) for top-level acceleration structures so shaders can declare `RaytracingAccelerationStructure Scenes[N]` and bind N distinct TLASes through a single resource entry. Schema (`include/Support/Pipeline.h`, `lib/Support/Pipeline.cpp`): - `TLASDesc` gains `ArraySize` (default 1) and reshapes `Instances` from `SmallVector<InstanceDesc>` to `SmallVector<SmallVector<InstanceDesc>>` — outer vector indexed by array element, inner vector lists instances for that element. - `MappingTraits<TLASDesc>` dispatches on `ArraySize` the same way `setData()` does for CPUBuffer: flat `Instances: [...]` for the scalar case, list-of-lists for arrays, with an `ActualSize != ArraySize` validation error on mismatch. - `Resource::getArraySize()` returns `TLASPtr->ArraySize` for AS resources; moved out-of-line so it can dereference the (still forward-declared at the Resource definition) `TLASDesc`. - BLAS-name resolution in the pipeline post-process descends through the extra layer of nesting. Backend plumbing (VK / DX / MTL): - `createAS()` now takes `uint32_t InstanceCount` directly (no Resource / Pipeline / InvocationState access) — pure single-create that just sizes and allocates one TLAS. - The multi-create (`createBuffers` / `createResources`) loops `TD.ArraySize` and pushes one bundle entry per element plus N handles into `InvocationState::TLASes`, which becomes `StringMap<SmallVector<unique_ptr<AccelerationStructure>>>` (one vector per `TLASDesc::Name`, sized to `ArraySize`). - `buildPipelineAccelerationStructures()` walks `P.AccelStructs.TLAS` and, for each name with a pre-allocated vector, builds one `TLASBuildRequest` per element using `TD.Instances[Elt]` and `Handles[Elt]`. - Vulkan descriptor write iterates the bundle's `ResourceRefs` to fill N entries of `pAccelerationStructures` and sets `descriptorCount = R.getArraySize()` so the descriptor set sees the full array. - DX's `bindSRV` AS branch already loops `ResBundle`; with the new multi-entry bundle it now writes N RAYTRACING_ACCELERATION_STRUCTURE SRVs into consecutive heap slots automatically. Heap sizing already uses `getDescriptorCountWithFlattenedArrays()`. - Metal's AS descriptor-binding loop now builds one `IRRaytracingAccelerationStructureGPUHeader` + instance-contributions buffer pair per array element and writes a descriptor entry per element via `IRDescriptorTableSetAccelerationStructure`. `MarkASResident` descends into the per-name vector. Test: `test/Feature/InlineRT/tlas-array.test` declares `Scenes[2]`, each TLAS carries one triangle instance with a distinct `InstanceID` (10 and 20), and the shader writes each `CommittedInstanceID()` into `Output[i]`. Gated on `acceleration-structure`, `XFAIL: Clang`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
MarijnS95
force-pushed
the
tlas-array-bindings
branch
from
July 24, 2026 06:34
7180017 to
4423a42
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirror the existing buffer/texture array pattern (
ArraySizeplus anArraySize-driven YAML field) for top-level acceleration structures so shaders can declareRaytracingAccelerationStructure Scenes[N]and bind N distinct TLASes through a single resource entry.Support/Pipeline.{h,cpp}):TLASDescgainsArraySize(default 1) and reshapesInstancesfromSmallVector<InstanceDesc>toSmallVector<SmallVector<InstanceDesc>>.MappingTraits<TLASDesc>dispatches onArraySizeexactly likesetData()does forCPUBuffer: flatInstances: [...]for the scalar case, list-of-lists for arrays, with anActualSize != ArraySizevalidation error on mismatch.Resource::getArraySize()returnsTLASPtr->ArraySizefor AS resources (moved out-of-line so it can dereference the still-forward-declaredTLASDesc).uint32_t InstanceCountdirectly — pure single-create that sizes and allocates one TLAS. NoPipeline/Resource/InvocationStateparameters. The multi-create (createBuffers/createResources) loopsTD.ArraySizeand pushes one bundle entry per element plus N handles intoInvocationState::TLASes, which becomesStringMap<SmallVector<unique_ptr<AccelerationStructure>>>(one vector perTLASDesc::Name, sized toArraySize).buildPipelineAccelerationStructures()walksP.AccelStructs.TLASand, for each name with a pre-allocated vector, builds oneTLASBuildRequestper element usingTD.Instances[Elt]andHandles[Elt].ResourceRefsto fill N entries ofpAccelerationStructuresand setsdescriptorCount = R.getArraySize()so the descriptor set sees the full array. Pool sizing (ASDescriptorCount) and binding layout (ResourceBinding.DescriptorCount) already usedR.getArraySize()for AS resources — they just start returning the right number onceTLASDesc::ArraySizeflows through.bindSRV()'s AS branch already loopsResBundle; with the new multi-entry bundle it now writes NRAYTRACING_ACCELERATION_STRUCTURESRVs into consecutive heap slots automatically. Heap sizing already usesgetDescriptorCountWithFlattenedArrays().IRRaytracingAccelerationStructureGPUHeader+ instance-contributions buffer pair per array element and writes one descriptor entry per element viaIRDescriptorTableSetAccelerationStructure().MarkASResidentdescends into the per-name vector.New test
test/Feature/InlineRT/tlas-array.testdeclaresScenes[2], each TLAS carries one triangle instance with a distinctInstanceID(10 and 20), and the shader writes eachCommittedInstanceID()intoOutput[i]. Gated onacceleration-structure,XFAIL: Clang.Test plan
Local on an NVIDIA RTX 3060:
offloader)offloader.exe)offloader.exe)offloader.exe)CI (RT-capable runners):
RaytracingTier 1.2)VK_KHR_ray_tracing_pipeline)supportsRaytracing)