Docs / Ray tracing

Glossary: GpuAccelerationStructure

The members of GpuAccelerationStructure, in alphabetical order.

Color legend plain property method

The scene on the GPU: a Tlas and every MeshBlas it uses, in the four structured buffers RayTraversal.fxh walks.

A sealed class that implements IDisposable. Its buffers come in two halves: the geometry, sent when a mesh is first used or refitted, and the scene, sent when the tree or the flags change. A frame with no changes sends nothing. The GPU page shows it in context, with code. Upload from the thread that owns the device.

Names are colored by what they are: a property or a method; values and fields keep the plain color.

Properties

BlasNodes →

StructuredBuffer? · Read-only. Every BLAS’s nodes, one after the other, as BvhNodes with their indexes made absolute: a leaf’s first triangle indexes Triangles, an interior node’s skip this buffer. Made with room to spare, and null until the first upload of a scene with something in it.

Instances →

StructuredBuffer? · Read-only. One GpuInstance per instance, in the order of the scene tree’s leaves. null until the first upload of a scene with something in it.

IsDisposed →

bool · Read-only. Dispose has been called.

IsReady →

bool · Read-only. There is a scene on the GPU to trace against: an upload has made the buffers, and the scene isn’t empty. Gate every traced pass on it.

TlasNodeCount →

int · Read-only. How many nodes the scene’s tree has, which is where the shader’s walk stops. 0 before the first upload and for an empty scene.

TlasNodes →

StructuredBuffer? · Read-only. The scene’s tree, its BvhNodes copied as they are. null until the first upload of a scene with something in it.

Triangles →

StructuredBuffer? · Read-only. Every BLAS’s triangles, as GpuTriangles in their tree’s order, one BLAS after the other. Made with room to spare, and null until the first upload of a scene with something in it.

Version →

int · Read-only. Moves whenever what the buffers describe changes: an upload that sent either half, or the scene emptying. A pass that keeps its result while nothing it reads has changed compares it with the version it last traced against.

Methods

GpuAccelerationStructure() →

GpuAccelerationStructure(GraphicsDevice graphicsDevice) · An empty copy on the device: no buffers until the first upload. The first use of the class checks that BvhNode, GpuInstance and GpuTriangle have the sizes RayTraversal.fxh reads them at, 32, 64 and 36 bytes, and fails with an InvalidOperationException, wrapped in a TypeInitializationException, when they don’t: a bug in the library, not in your code.

Parameter Type Description
graphicsDevice GraphicsDevice The device the buffers are made on: the compute fork’s, with the HiDef profile.

Bind() →

Bind(Effect effect) · Sets TlasNodes, Instances, BlasNodes, Triangles and TlasNodeCount on an effect that includes RayTraversal.fxh, under the names it declares them by. A parameter the effect doesn’t have, one the compiler stripped say, is skipped. Bind before every dispatch or draw: the node count changes with the scene, and an upload may replace a buffer.

Parameter Type Description
effect Effect The effect that traces.

Dispose() →

Dispose() · Frees the four buffers. A second call does nothing.

Upload() →

Upload(Tlas tlas) · Brings the buffers in line with the scene. A BLAS they don’t hold goes after the others; when there is no room for it, everything is laid out afresh in bigger buffers, and the BLASes no instance uses any more are dropped. A BLAS refitted since it was sent is sent again in place. The scene half is sent when the tree’s Version or FlagsVersion has moved, or the geometry has. A frame with no change sends nothing, and an empty scene sends nothing and turns IsReady false. Call it after the scene’s EndUpdate, on the device’s thread.

Parameter Type Description
tlas Tlas The scene, as of its last EndUpdate.