Managing Acceleration Structures in Vulkan Ray Tracing
Implementing VK_KHR_ray_tracing_pipeline requires a shift from rasterization logic to spatial indexing. Learn how to manage BLAS/TLAS and the memory constraints involved.
01 Feb 2026, 11:56 UTC

The Challenge: Moving Beyond the Rasterization Pipeline
Adding hardware-accelerated ray tracing to a Vulkan engine isn't as simple as swapping a shader. While rasterization processes primitives as a stream of triangles, ray tracing requires a spatial index—an Acceleration Structure (AS)—to efficiently determine which objects a ray intersects. The primary technical hurdle is managing the lifecycle of these structures and the specific memory alignment requirements of the VK_KHR_ray_tracing_pipeline extension without introducing significant frame stutters.
The Hierarchy: BLAS and TLAS
Vulkan implements a two-level hierarchy to balance memory usage and update speed. Understanding this distinction is critical for maintaining a stable frame rate.
- Bottom-Level Acceleration Structure (BLAS): This contains the actual vertex and index data for a specific mesh. Because building a BLAS is computationally expensive, you typically build one per unique asset and reuse it across multiple instances.
- Top-Level Acceleration Structure (TLAS): This acts as a scene-level index. It doesn't contain geometry but instead contains instances that point to BLAS objects, including transformation matrices. Updating a TLAS is much faster than updating a BLAS, making it the primary target for per-frame object movement.
Implementation: Building a BLAS
To implement this in Vulkan 1.3, you must first verify that the device supports VK_KHR_ray_tracing_pipeline and VK_KHR_acceleration_structure via vkEnumerateDeviceExtensionProperties. If supported, enable them during vkCreateDevice.
Building a BLAS requires a scratch buffer for the GPU to use during the build process. A common failure point is memory alignment; all acceleration structure allocations must be aligned to 64 bytes to avoid validation errors.
// Run on GPU device with VK_KHR_acceleration_structure enabled
// Step 1: Query the required sizes for the AS and the scratch buffer
VkAccelerationStructureBuildSizesInfoKHR sizeInfo = {
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR
};
VkAccelerationStructureBuildSizesKHR buildSizes;
vkGetAccelerationStructureBuildSizesKHR(device, VK_ACCELERATION_STRUCTURE_BUILD_SIZES_KHR_VERSION, &sizeInfo, &buildSizes);
// Step 2: Allocate the AS buffer and scratch buffer
// RISK: Ensure alignment is exactly 64 bytes or greater
VkMemoryRequirements memReqs = {
.size = buildSizes.buildAccelerationStructureSize,
.alignment = 64
};
// Step 3: Define the build geometry (e.g., for a triangle mesh)
VkAccelerationStructureGeometryKHR geometry = {
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR,
.geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR,
.geometry.triangles = {
.vertexData.deviceAddress = vertexBufferAddress,
.vertexData.stride = sizeof(Vertex),
.indexData.deviceAddress = indexBufferAddress,
.indexData.stride = sizeof(uint32_t)
}
};
// Step 4: Execute the build command
VkAccelerationStructureBuildGeometryInfoKHR buildInfo = {
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR,
.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR,
.geometryCount = 1,
.pGeometries = &geometry,
.destinationAccelerationStructure = blasHandle
};
vkCmdBuildAccelerationStructuresKHR(commandBuffer, 1, &buildInfo, &buildRangeInfo);
Engineering Trade-offs and Limitations
While the performance gains for reflections and shadows are significant, the overhead is not negligible. Developers must weigh the following trade-offs:
- Memory Bandwidth: Ray tracing is heavy on memory bandwidth. On integrated GPUs or mobile hardware, the cost of traversing the AS can outweigh the visual benefits, leading to inconsistent frame rates.
- Build Latency: Building a BLAS for a complex mesh can cause a visible hitch. To mitigate this, implement asynchronous builds on a transfer queue or pre-build structures during loading screens.
- Synchronization: You must ensure a memory barrier exists between the
vkCmdBuildAccelerationStructuresKHRcall and the subsequent ray-tracing pipeline execution to prevent the GPU from tracing against an incomplete structure.
Verification and Results
To verify the implementation, enable the VK_LAYER_KHRONOS_validation layer. This will immediately flag any alignment errors (e.g., buffers not aligned to 64 bytes) or synchronization hazards. To quantify the impact, measure the frame time specifically during the TLAS update phase versus the ray-tracing dispatch phase. If the TLAS update exceeds 2ms, consider reducing the number of active instances or implementing a more aggressive culling system for the acceleration structure.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.