When to Refit vs Rebuild a BLAS in DirectX

Refitting a Bottom-Level Acceleration Structure (BLAS) in DirectX Raytracing (DXR) is an optimization technique that updates existing bounding volume hierarchy (BVH) nodes without altering the underlying tree topology. While a full rebuild creates a globally optimized BVH from scratch, a refit merely adjusts the bounding boxes around displaced vertices. Choosing to refit rather than rebuild is cost-effective when the performance gained from faster BVH generation outweighs the potential rendering loss caused by degraded ray traversal efficiency, typically occurring in continuous, localized vertex motion such as skeletal animations and soft-body simulations.

The Mechanism: Refit vs. Rebuild

In DirectX 12, building a BLAS requires dispatching compute work via BuildRaytracingAccelerationStructure.

  • Rebuild: The GPU analyzes all primitive data, sorts triangles, and generates a new BVH tree. This produces optimal bounding volume overlap and density, ensuring the fastest ray-primitive intersection traversal during the ray dispatch stage. However, it carries high compute and memory bandwidth overhead each frame.
  • Refit (D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PERFORM_UPDATE): The GPU retains the pre-existing tree topology and recalculates only the Axis-Aligned Bounding Boxes (AABBs) for the leaf and internal nodes to enclose the moved vertices. This operation is dramatically faster—often requiring an order of magnitude less execution time than a full rebuild—and consumes minimal memory bandwidth.

When Refitting Is More Cost-Effective

Refitting becomes the superior choice under specific geometric and performance conditions:

1. Skeletal and Skinned Mesh Animation

Skinned characters exhibit local vertex movement driven by bone matrices. Because adjacent vertices generally move in unison, the underlying spatial structure of the triangles remains relatively consistent from frame to frame. In this scenario:

  • Rebuilding every frame introduces severe compute bottlenecks if multiple characters occupy the view.
  • Refitting handles vertex coordinate changes efficiently without significantly inflating the AABBs.

2. Cloth and Continuous Soft-Body Deformations

Simulations involving flags, clothing, or subtle surface ripple effects alter vertex coordinates continuously while preserving the overall mesh shape. Because the vertex displacements are localized and small, the bounding boxes stretch only slightly, keeping tree efficiency high while avoiding the heavy GPU cost of a full reconstruction.

3. Low-Impact or Distant Secondary Geometry

For dynamic objects located far from the camera or objects that contribute minimally to primary rays, reflections, or global illumination, the quality of ray traversal is less critical. The frame time saved on the compute queue by refitting easily outweighs any microscopic drop in traversal speed.

4. Hard GPU Frame Budgets

When a frame is compute-bound or GPU execution time is approaching its deadline (e.g., targeting high-refresh VR or 60/120 FPS targets), refitting allows dynamic geometry to remain ray-traceable without causing frame drops, trading minor traversal inefficiency for substantial BVH generation savings.

The Tipping Point: When Traversal Costs Overtake Refit Savings

A refit ceases to be cost-effective when mesh topology changes or extreme deformation causes bounding boxes to expand disproportionately:

  • Disjointed or High-Velocity Motion: If vertices cross over one another or undergo massive scaling/stretching, parent AABBs expand excessively. This creates large areas of empty space and heavy overlap between adjacent bounding boxes.
  • Topological Changes: If triangle count changes, or if primitives are added or removed, a refit is invalid in DirectX and a rebuild is mandatory.
  • Traversal Penalties: When AABB overlap becomes severe, rays must traverse multiple overlapping branches, testing dozens of false positives before finding an intersection. If ray query execution time increases by more than the time saved by skipping the rebuild, refitting becomes a net loss.

The standard industry approach is a hybrid cadence:

  • Use D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_ALLOW_UPDATE during the initial BLAS creation.
  • Refit the BLAS on dynamic skinned and simulated meshes every frame to preserve GPU compute time.
  • Force a full rebuild either periodically (e.g., every \(N\) frames), when an object undergoes rapid state changes (such as teleportation or explosive deformation), or dynamically when metric tracking detects that node overlap exceeds acceptable thresholds.