Add ComputeEncoder::batchBuildAS() and shared AS-build orchestration helper#1244
Open
MarijnS95 wants to merge 1 commit into
Open
Add ComputeEncoder::batchBuildAS() and shared AS-build orchestration helper#1244MarijnS95 wants to merge 1 commit into
MarijnS95 wants to merge 1 commit into
Conversation
2 tasks
72e0f02 to
87674fe
Compare
6a080ef to
566d0ba
Compare
4 tasks
8cd0059 to
0089566
Compare
0089566 to
8460666
Compare
…helper
Move acceleration-structure build commands behind the abstract
ComputeEncoder interface so the orchestration (data upload, build-request
creation, AS allocation, build recording) can live in one place rather
than splitting across three backends.
ComputeEncoder gains a single batchBuildAS(ArrayRef<ASBuildItem>) method.
Each item carries an AccelerationStructure plus a BLAS or TLAS build
request via PointerUnion. The caller guarantees no inter-item memory
dependencies inside a batch — backends record the whole batch with one
barrier slot, no per-element barriers.
- Vulkan: single vkCmdBuildAccelerationStructuresKHR call covering the
whole batch. TLAS items serialize VkAccelerationStructureInstanceKHR
into a device-address upload buffer, BLAS items pull addresses from
each VulkanBuffer (new getDeviceAddress accessor). Storage buffers
transparently gain SHADER_DEVICE_ADDRESS + ACCEL_BUILD_INPUT_READ_ONLY
flags when ray tracing is supported, with the matching
VkMemoryAllocateFlagsInfo chained on every allocation.
- DX12: loop calling BuildRaytracingAccelerationStructure per item with
no intermediate barriers; D3D12_RAYTRACING_INSTANCE_DESC is
bit-identical to the Vulkan instance struct.
- Metal: lazy transition to MTL::AccelerationStructureCommandEncoder,
deduplicates BLAS handles into the
MTL::InstanceAccelerationStructureDescriptor's instancedAccelera-
tionStructures array (Metal references BLASes by index, not GPU
address).
Each backend's CommandBuffer now carries a back-pointer to its owning
Device so the encoder can reach device-loaded entry points and helpers,
plus a keep-alive list for AS scratch and instance buffers.
A shared helper buildPipelineAccelerationStructures in lib/API/Device.cpp
walks Pipeline::AccelStructs, uploads vertex/index data via the new
createBufferWithData, builds requests, allocates AS objects, and issues
two batchBuildAS calls (BLAS batch then TLAS batch — VUID-03403 forbids
referencing a sibling dstAccelerationStructure in one command). Each
backend's executeProgram calls this helper to build the pipeline's AS
objects.
Descriptor binding for AS resources is intentionally still missing — the
tests progress past AS-build now and surface only the descriptor-write
gap.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
8460666 to
601f893
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.
Depends on #1232
For #1158
Move acceleration-structure build commands behind the abstract
ComputeEncoderinterface so the orchestration (data upload, build-request creation, AS allocation, build recording) can live in one place rather than splitting across three backends.ComputeEncodergains a singlebatchBuildAS(ArrayRef<ASBuildItem>)method. Each item carries anAccelerationStructureplus a BLAS or TLAS build request viaPointerUnion. The caller guarantees no inter-item memory dependencies inside a batch — backends record the whole batch with one barrier slot, no per-element barriers.vkCmdBuildAccelerationStructuresKHRcall covering the whole batch. TLAS items serializeVkAccelerationStructureInstanceKHRinto a device-address upload buffer; BLAS items pull addresses from eachVulkanBuffer(newgetDeviceAddressaccessor). Storage buffers transparently gainSHADER_DEVICE_ADDRESS+ACCEL_BUILD_INPUT_READ_ONLYflags when ray tracing is supported, with the matchingVkMemoryAllocateFlagsInfochained on every allocation.BuildRaytracingAccelerationStructureper item with no intermediate barriers;D3D12_RAYTRACING_INSTANCE_DESCis bit-identical to the Vulkan instance struct.MTL::AccelerationStructureCommandEncoder, deduplicates BLAS handles into theMTL::InstanceAccelerationStructureDescriptor'sinstancedAccelerationStructuresarray (Metal references BLASes by index, not GPU address).A shared helper
buildPipelineAccelerationStructuresinlib/API/Device.cppwalksPipeline::AccelStructs, uploads vertex/index data via the newcreateBufferWithData, builds requests, allocates AS objects, and issues twobatchBuildAScalls (BLAS batch then TLAS batch — VUID-03403 forbids referencing a siblingdstAccelerationStructurein one command). Each backend'sexecuteProgramcalls this helper to build the pipeline's AS objects.Descriptor binding for AS resources lands in the next PR — the tests progress past AS-build but still need the descriptor-write step.