Inline ray tracing: acceleration structures¶
What it does¶
Inline ray tracing lets any shader cast rays with HLSL RayQuery against an
acceleration structure. It is available when
device.limits.rayTracing is true: on Vulkan, VK_KHR_acceleration_structure and
VK_KHR_ray_query must be enabled and the driver must accept acceleration structures in the
mutable descriptor heap; on D3D12, the device must support raytracing tier 1.1 or higher.
Known limitation: no Vulkan ray tracing on AMD's Windows driver
On Vulkan, shaders read acceleration structures from the same descriptor heap binding as every
other descriptor because DXC places every ResourceDescriptorHeap access there. The driver
must therefore accept acceleration structures among the heap's mutable descriptor types. RI
checks support with vkGetDescriptorSetLayoutSupport at device creation; if the driver
refuses, even for a heap of one slot, RI omits acceleration structures from the mutable
descriptor list and sets device.limits.rayTracing to false.
| GPU | Driver | Vulkan ray tracing in RI |
|---|---|---|
| AMD RDNA2 integrated GPU ("AMD Radeon(TM) Graphics"), Windows | Adrenalin 26.8.1, Vulkan driver 2.0.353 | off: no mutable heap with acceleration structures, at any size |
| NVIDIA GeForce RTX 3080, Windows | 617.42 | on |
| AMD Radeon 680M (RDNA2), Linux | Mesa 26.2.2 (RADV) | on |
Checked 2026-10-11 (logs: docs/measurements/windows/verify/3f13bfb/heap_probe.txt in the repository). D3D12 ray
tracing on the same AMD GPU is unaffected. Newer drivers may lift this restriction: RI queries
the driver at each device creation, so your code does not need to change.
Building and using an acceleration structure follows five explicit steps:
- Describe the geometry: a bottom-level acceleration structure (BLAS) holds triangle
geometry described by
BlasDesc(BlasTriangles:float3positions at a buffer GPU address, optionally indexed). A top-level acceleration structure (TLAS) holds instances of bottom-level structures described byTlasDesc, which points to a buffer ofAccelerationStructureInstancerecords in the 64-byte layout shared by both APIs (a row-major 3x4 transform,instanceId,mask,contributionOffset,flags, and the bottom-level structure'sgpuAddressinblasAddress). - Query the sizes:
RI::blasSizesandRI::tlasSizesreturnAccelerationStructureSizes, giving the structure size and the scratch buffer sizes needed for a full build and for an update. - Place the structure in your memory: call
RI::accelerationStructureRequirements(device, size)for the alignment and allowed memory kinds, then callRI::createAccelerationStructure(device, memory, offset, size, topLevel)(topLevelisfalsefor a BLAS andtruefor a TLAS). - Build in a command list: record
RI::cmdBuildBlasorRI::cmdBuildTlaswith a scratch buffer created withBufferUsage::eReadWrite. Passingupdate = truerefits a structure that was built withAccelerationStructureFlags::eAllowUpdatein its descriptor after its vertices or instances move. - Trace: bind the top-level structure to a descriptor heap slot with
RI::writeDescriptorsusingAccelerationStructureView{.tlas = tlas}, and read it in HLSL withRaytracingAccelerationStructure tlas = ResourceDescriptorHeap[slot];.
One-call building with memory and scratch management is left to helpers; compaction is not in v1.
Signature¶
// <RI/RI.hpp>, namespace RI
AccelerationStructure createAccelerationStructure(Device &device, const Memory &memory, uint64 offset, uint64 size, bool topLevel, std::string_view name = {});
// <RI/RI.hpp>, namespace RI
void cmdBuildBlas(CommandList &cmd, const AccelerationStructure &dst, const BlasDesc &desc, const Buffer &scratch,
uint64 scratchOffset, bool update = false);
From the header: Acceleration structure builds (P49): update refits a structure built with eAllowUpdate from the same geometry. Scratch at scratchOffset (a multiple of DeviceLimits::accelerationStructureScratchAlignment) of a buffer with eReadWrite. Builds count as Stage::eAccelerationStructure.
// <RI/RI.hpp>, namespace RI
void cmdBuildTlas(CommandList &cmd, const AccelerationStructure &dst, const TlasDesc &desc, const Buffer &scratch,
uint64 scratchOffset, bool update = false);
// <RI/RI.hpp>, namespace RI
struct BlasTriangles {
uint64 vertexAddress = 0;
uint32 vertexStride = 12;
uint32 vertexCount = 0;
uint64 indexAddress = 0; // 0: not indexed (vertexCount / 3 triangles)
IndexFormat indexFormat = IndexFormat::eUint32;
uint32 indexCount = 0;
bool opaque = true; // no any-hit processing
};
From the header: Triangles of a bottom level: float3 positions (vertexStride bytes apart), optionally indexed. Addresses are buffer GPU addresses (P61) of buffers with BufferUsage::eAccelerationStructureInput.
| Field | Type | Default | Description |
|---|---|---|---|
vertexAddress |
uint64 |
0 |
|
vertexStride |
uint32 |
12 |
|
vertexCount |
uint32 |
0 |
|
indexAddress |
uint64 |
0 |
0: not indexed (vertexCount / 3 triangles) |
indexFormat |
IndexFormat |
IndexFormat::eUint32 |
|
indexCount |
uint32 |
0 |
|
opaque |
bool |
true |
no any-hit processing |
// <RI/RI.hpp>, namespace RI
struct AccelerationStructureInstance {
float transform[3][4]; // row-major 3x4: object to world
uint32 instanceId : 24; // InstanceID() in shaders
uint32 mask : 8; // ANDed with the ray's mask
uint32 contributionOffset : 24; // hit-group offset (unused by inline ray tracing)
uint32 flags : 8; // instance flags (e.g. 0x4: force opaque)
uint64 blasAddress; // AccelerationStructure::gpuAddress of the bottom level
};
From the header: The 64-byte instance record, the same on D3D12 and Vulkan (P49).
| Field | Type | Default | Description |
|---|---|---|---|
24 |
uint32 instanceId : |
InstanceID() in shaders | |
8 |
uint32 mask : |
ANDed with the ray's mask | |
24 |
uint32 contributionOffset : |
hit-group offset (unused by inline ray tracing) | |
8 |
uint32 flags : |
instance flags (e.g. 0x4: force opaque) | |
blasAddress |
uint64 |
AccelerationStructure::gpuAddress of the bottom level |
Example¶
RI::cmdBuildBlas(cmd, blas, blasDesc, scratch, 0);
RI::cmdBarrier(cmd, RI::Stage::eAccelerationStructure, RI::Stage::eAccelerationStructure);
RI::cmdBuildTlas(cmd, tlas, tlasDesc, scratch, 0);
RI::cmdBarrier(cmd, RI::Stage::eAccelerationStructure, RI::Stage::eCompute);
RI::cmdDispatch(cmd, groupsX, groupsY, 1); // a shader with RayQuery
RaytracingAccelerationStructure tlas = ResourceDescriptorHeap[root.tlasSlot];
RayQuery<RAY_FLAG_FORCE_OPAQUE> query;
query.TraceRayInline(tlas, RAY_FLAG_NONE, 0xff, ray);
query.Proceed();
const bool hit = query.CommittedStatus() == COMMITTED_TRIANGLE_HIT;
How RI does it¶
- Vulkan:
RI::createAccelerationStructurecreates aVkBufferwithVK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHRplaced in your memory and creates aVkAccelerationStructureKHRon it; builds recordvkCmdBuildAccelerationStructuresKHR. When ray tracing is enabled, the resource heap's mutable descriptor types includeVK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR. - D3D12:
RI::createAccelerationStructureplaces a buffer resource withD3D12_RESOURCE_FLAG_RAYTRACING_ACCELERATION_STRUCTUREandD3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; builds recordBuildRaytracingAccelerationStructure, andAccelerationStructureViewwrites an acceleration-structure SRV into the heap slot.
Rules and errors¶
- Vertex, index, and instance buffers used as build inputs must be created with
BufferUsage::eAccelerationStructureInput. - The scratch address (
scratch.gpuAddress + scratchOffset) must be a multiple ofdevice.limits.accelerationStructureScratchAlignment, and the scratch range fromscratchOffsetmust fitbuildScratchSize(orupdateScratchSizewhenupdateistrue). Place scratch buffers on that alignment becausebufferRequirementsforBufferUsage::eReadWritedoes not include it; otherwise validation builds report a programmer error. - Builds must be recorded outside rendering sections (programmer error otherwise) and belong
to
Stage::eAccelerationStructure. Place acmdBarrierbetween a bottom-level build and any top-level build that reads it, and between the top-level build and the shaders that trace it. - Building into an acceleration structure while shaders trace it is a data race, as with any write.
- Destroy an acceleration structure with
RI::destroyAccelerationStructureonly after the GPU has finished all work that uses it, and before freeing its backingmemory. - Calling any ray-tracing function when
device.limits.rayTracingisfalsereports an unsupported error.