Skip to content

LiteFX::Rendering::Backends::DirectX12BottomLevelAccelerationStructure::build

Performs a complete build of the acceleration structure.

Synopsis

Declared in <litefx/backends/dx12.hpp>

[[dllimport, dllexport]] void build(
    DirectX12CommandBuffer const& commandBuffer,
    SharedPtr<IDirectX12Buffer const> const& scratchBuffer = nullptr,
    SharedPtr<IDirectX12Buffer const> const& buffer = nullptr,
    UInt64 offset = 0,
    UInt64 maxSize = 0);

Description

This method builds or rebuilds the entire acceleration structure. If called without any further arguments beside commandBuffer, a new buffer and scratch buffer will be allocated from the IGraphicsDevice that created the command buffer. Alternatively, it is possible to provide a pre-allocated buffer in the buffer parameter. This allows to re-use memory from another acceleration structure, that no longer uses the memory. It is possible to store the buffer from an acceleration structure (acquired by calling buffer) and destroy it afterwards, which enables re-use scenarios for example for caching. Alternatively, it is possible store multiple acceleration structures within the same buffer, reducing overall memory consumption. This is done by also providing the offset and maxSize parameters to address a range within the buffer itself, the acceleration structure may be written into. Note that the pointer passed to the buffer parameter must have been initialized with the BufferType::AccelerationStructure buffer type and must be writable (ResourceUsage::AllowWrite).

By providing a scratchBuffer, it is possible to re-use temporary memory while building. This can lower memory consumption when building multiple acceleration structures. However, this also requires proper barriers to be executed between two build commands, as they are not allowed to access the same scratch memory simultaneously. Note that the pointer passed to the scratchBuffer parameter must have been initialized on the ResourceHeap::Resource heap and must be writable (ResourceUsage::AllowWrite).

After a successful build, the buffer pointer is stored by the acceleration structure and can be accessed by calling buffer on it.

Parameters

NameDescription
commandBufferThe command buffer used to record the acceleration structure build commands.
scratchBufferThe scratch buffer used during the acceleration structure build, or nullptr if a temporary buffer should be created.
bufferThe buffer that stores the acceleration structure after building, or nullptr if a new buffer should be created.
offsetThe offset into buffer at which the acceleration structure should be stored. Must be a multiple of 256. Ignored if buffer is nullptr.
maxSizeThe maximum available size within buffer at offset. Ignored if buffer is nullptr.

See Also

update