What Is DirectX Raytracing (DXR)? From BLAS and TLAS to Direct3D 12 Ray Dispatch
DirectX Raytracing (DXR) is a Direct3D 12 feature that lets an application trace rays through scene geometry and use the intersections for effects such as reflections and shadows. The application organizes geometry into BLAS and TLAS structures, connects shaders through a state object and shader tables, then runs rays with `DispatchRays` or inline `RayQuery`. Support depends on the device's DXR tier and the runtime, driver, and Agility SDK combination.
What Is DirectX Raytracing (DXR)? From BLAS and TLAS to Direct3D 12 Ray Dispatch
DirectX Raytracing (DXR) is a Direct3D 12 feature that lets an application trace rays through scene geometry and use the intersections for effects such as reflections and shadows. The application organizes geometry into BLAS and TLAS structures, connects shaders through a state object and shader tables, then runs rays with DispatchRays or inline RayQuery. Support depends on the device's DXR tier and the runtime, driver, and Agility SDK combination.
How DXR connects scene data and shaders
Rasterization turns triangles into screen pixels and evaluates materials and lighting. With DXR, a shader sends a ray from an origin in a chosen direction and searches for an intersection. For example, a shader can send a shadow ray from a visible surface toward a light. Whether another object blocks that ray determines whether the light reaches the point. Rays can travel in many directions, which is useful for reflections, shadows, and transparency, but the application still pays for ray generation and shading.
Checking every triangle for every ray would be expensive. An acceleration structure organizes space so the GPU can narrow the candidates. A bottom-level acceleration structure (BLAS) contains geometries such as triangles or bounding boxes. A top-level acceleration structure (TLAS) contains instances of BLASes and their transforms. The same mesh can therefore be reused at several positions without copying its geometry. These structures do not contain all material or final-color data; the application binds those resources separately. BLAS and TLAS definitions
Build structures with Direct3D 12 commands. Reuse a BLAS for static geometry. For moving objects, update a TLAS transform or rebuild/update a BLAS when its geometry changes. A structure must be built with ALLOW_UPDATE before it can use PERFORM_UPDATE. An update can be faster than rebuilding, but large geometry changes can reduce tracing performance; update-capable builds can also cost more memory and initial build time. Measure build and trace costs for the scene before choosing. Acceleration-structure build flags
A state object groups ray shaders, hit groups, shader settings, and root signatures. Shader tables connect the ray-generation, miss, and hit-group records used by a dispatch to their shader identifiers and local arguments. C++ uses interfaces such as ID3D12Device5 and ID3D12GraphicsCommandList4, plus structures including D3D12_DISPATCH_RAYS_DESC. Direct3D 12 DXR interfaces
How one ray becomes an output pixel
In a typical DispatchRays path, a ray-generation shader runs over a grid matching the output region. Each invocation uses its location to create a ray and calls HLSL TraceRay to search the TLAS. D3D12_DISPATCH_RAYS_DESC supplies the ray-generation record, miss and hit-group tables, and the width, height, and depth of the dispatch. Dispatch descriptor
If there is no accepted intersection, the miss shader runs. When the closest accepted hit is known, the closest-hit shader evaluates the surface. An any-hit shader can inspect or reject non-opaque candidates; an intersection shader can calculate intersections for custom geometry; a callable shader is an optional function invoked by another shader. These roles are combined as needed in the state object and hit groups; a pipeline does not need every shader type. DXR HLSL shader roles TraceRay and intersection-control intrinsics
As an illustrative scenario, suppose a renderer adds a simple shadow. After rasterization provides a surface point, a shader traces toward the light. If the TLAS reports an object before the light, the renderer darkens the point; a miss means the light is visible. This is a teaching example, not a report of a tested engine or measured result. Rasterization can create the main surface while DXR answers only the ray query needed for the effect.
Choosing DispatchRays or inline RayQuery
DispatchRays runs a separate ray-generation and hit/miss shader pipeline. DXR 1.1 inline ray tracing uses a RayQuery inside a regular pixel or compute shader. Microsoft PIX documents that RayQuery::TraceRayInline executes in a regular shader stage and does not appear as a separate DispatchRays event. Neither path is always faster: choose based on renderer design, query count, and measured frame time. PIX DXR analysis and tier features
| Decision point | DispatchRays pipeline | Inline RayQuery |
|---|---|---|
| Where it runs | Separate dispatch started by a ray-generation shader | Inside a regular pixel or compute shader |
| Good fit | Reflections or path tracing with dedicated ray shaders and several hit/miss responses | A limited intersection query mixed into raster or compute work |
| Implementation focus | State object, shader tables, payload, and hit groups | Start the query and handle candidate/committed hits in shader logic |
| Support and debugging | Check the DXR tier and table contract | Check DXR 1.1 support; in PIX inspect the regular shader invocation |
DXR support does not mean every DXR feature is available. Call ID3D12Device::CheckFeatureSupport with D3D12_FEATURE_DATA_D3D12_OPTIONS5 and inspect the reported D3D12_RAYTRACING_TIER. The enum defines unsupported, 1.0, 1.1, and 1.2 tiers. Also check whether the runtime and Agility SDK expose the feature you intend to use; treat the tier reported by the actual device, driver, and runtime as authoritative. D3D12 ray-tracing tier
D3D12_FEATURE_DATA_D3D12_OPTIONS5 options5 = {};
HRESULT hr = device->CheckFeatureSupport(
D3D12_FEATURE_D3D12_OPTIONS5, &options5, sizeof(options5));
const bool supportsDxr = SUCCEEDED(hr) &&
options5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;This checks for basic DXR support, not every feature. For inline RayQuery, also require the application's target tier to be at least 1.1 before choosing that path.
Bringing up a DXR path and debugging it
Use this sequence to add one ray effect to a Direct3D 12 application. The steps summarize the documented API flow; no sample was built or run for this article.
**Check the supported path.** Create the D3D12 device and query its DXR tier. Confirm the target tier, Agility SDK, and shader model. If the device lacks a required feature, skip its initialization and use rasterization or another supported path.
**Prepare geometry and acceleration structures.** Define triangle buffers and BLAS inputs, then TLAS instances and transforms. Query prebuild memory requirements, allocate scratch and result buffers, and record the build. Confirm later shaders reference the structure and input resources with the expected state and lifetime.
**Connect shaders and records.** Create a state object with the ray-generation shader, miss shader, required hit groups, and root signatures. Make each shader-table record point to the right shader identifier and local arguments. Check table address and stride alignment and resource states against `D3D12_DISPATCH_RAYS_DESC`.
**Run one effect.** Start with a bounded task such as a shadow or reflection. Use `DispatchRays` for a separate ray pipeline, or `RayQuery` for a limited query inside existing pixel or compute work after checking its tier. Bind the TLAS SRV and output texture, synchronize commands, and connect the result to the renderer.
**Capture and narrow failures.** In a PIX GPU Capture, inspect `BuildRaytracingAccelerationStructure` and `DispatchRays`, build inputs and outputs, TLAS instances, state objects, and shader-table records. If events are missing, check the call path and tier. If every ray misses, check TLAS binding, instance masks, and ray range. For black output or wrong materials, check hit groups, payload, and resource bindings, then reproduce with a smaller scene. Find inline queries in the pixel or compute shader that contains them, not as a `DispatchRays` event.
This sequence separates feature availability, acceleration-structure inputs, shader wiring, and ray results. Compare quality and performance with the scene, resolution, ray count, and effect settings held constant, and record build cost separately from tracing cost. A reported DXR tier alone does not guarantee a frame rate or visual result for a particular scene.
References
- Microsoft Learn D3D12 raytracing acceleration structure types
- Microsoft Learn D3D12 raytracing acceleration structure build flags
- Microsoft Learn Direct3D 12 Raytracing reference
- Microsoft Learn D3D12_DISPATCH_RAYS_DESC
- Microsoft Learn Direct3D 12 Raytracing HLSL Shaders
- Microsoft Learn Direct3D 12 Raytracing HLSL Intrinsics