Module vulkano::acceleration_structure
source · Expand description
An opaque data structure that is used to accelerate spatial queries on geometry data.
Acceleration structures contain geometry data, arranged in such a way that the device can easily search through the data and check for intersections between the geometry and rays (lines). The geometry data can consist of either triangles, or axis-aligned bounding boxes (AABBs).
Acceleration structures come in two forms: top-level and bottom-level. A bottom-level acceleration structure holds the actual geometry data, while a top-level structure contains instances of (references to) one or more bottom-level structures. A top-level structure is intended to contain the whole rendered scene (or the relevant parts of it), while a bottom-level structure may contain individual objects within the scene. This two-level arrangement allows you to easily rearrange the scene, adding and removing parts of it as needed.
Building an acceleration structure
When an acceleration structure object is created, it is in an uninitialized state and contains
garbage data. To be able to use it for anything, you must first build the structure on the
device, using the build_acceleration_structure
or build_acceleration_structure_indirect
command buffer commands. You use BuildAccelerationStructureMode::Build
to build a structure
from scratch.
When specifying geometry data for an acceleration structure build, certain triangle, AABB or instance values mark that item as inactive. An inactive item is completely ignored within the acceleration structure, and acts as if it’s not there. The following special values make an item inactive:
- For triangles, if the vertex format is a floating-point type, then the triangle is inactive if any of its vertices have NaN as their first coordinate. For integer vertex formats, it is not possible to mark triangles as inactive.
- For AABBs, if
AabbPositions::min[0]
is NaN. - For instances, if
AccelerationStructureInstance::acceleration_structure_reference
is 0.
Updating an acceleration structure
Once an acceleration structure is built, if it was built previously with the
BuildAccelerationStructureFlags::ALLOW_UPDATE
flag, then it is possible to update the
structure with new data. You use BuildAccelerationStructureMode::Update
for this, which
specifies the source acceleration structure to use as a starting point for the update.
This can be the same as the destination structure (the update will happen in-place), or a
different one.
An update operation is limited in which parts of the data it may change. You may change most buffers and their contents, as well as strides and offsets:
AccelerationStructureBuildGeometryInfo::scratch_data
AccelerationStructureGeometryTrianglesData::vertex_data
AccelerationStructureGeometryTrianglesData::vertex_stride
AccelerationStructureGeometryTrianglesData::transform_data
(but the variant ofOption
must not change)AccelerationStructureGeometryAabbsData::data
AccelerationStructureGeometryAabbsData::stride
AccelerationStructureGeometryInstancesData::data
AccelerationStructureBuildRangeInfo::primitive_offset
AccelerationStructureBuildRangeInfo::first_vertex
if no index buffer is usedAccelerationStructureBuildRangeInfo::transform_offset
No other values may be changed, including in particular the variant or number of elements in
AccelerationStructureBuildGeometryInfo::geometries
, and the value of
AccelerationStructureBuildRangeInfo::primitive_count
.
The enum variants and data in AccelerationStructureGeometryTrianglesData::index_data
must
not be changed, but it is allowed to specify a new index buffer, as long as it contains the
exact same indices as the old one.
An update operation may not change the inactive status of an item: active items must remain active in the update and inactive items must remain inactive.
Accessing an acceleration structure in a shader
Acceleration structures can be bound to and accessed in any shader type. They are accessed as descriptors, like buffers and images, and are declared in GLSL with
layout (set = N, binding = N) uniform accelerationStructureEXT nameOfTheVariable;
You must enable either the GL_EXT_ray_query
or the GL_EXT_ray_tracing
GLSL extensions in
the shader to use this.
On the Vulkano side, you can then create a descriptor set layout using
DescriptorType::AccelerationStructure
as a descriptor type, and write the
acceleration structure to a descriptor set using WriteDescriptorSet::acceleration_structure
.
Structs
- Specifies two opposing corners of an axis-aligned bounding box.
- An opaque data structure that is used to accelerate spatial queries on geometry data.
- Geometries and other parameters for an acceleration structure build operation.
- Counts and offsets for an acceleration structure build operation.
- The minimum sizes needed for various resources during an acceleration structure build operation.
- Flags that control how an acceleration structure is created.
- Parameters to create a new
AccelerationStructure
. - A bottom-level geometry consisting of axis-aligned bounding boxes.
- A top-level geometry consisting of instances of bottom-level acceleration structures.
- A bottom-level geometry consisting of triangles.
- Specifies a bottom-level acceleration structure instance when building a top-level structure.
- Flags to control how an acceleration structure should be built.
- Parameters for copying an acceleration structure.
- Parameters for copying from an acceleration structure into memory.
- Parameters for copying from memory into an acceleration structure.
- Flags to control how an acceleration structure geometry should be built.
- Flags for an instance in a top-level acceleration structure.
Enums
- Where the building of an acceleration structure will take place.
- The type of geometry data in an acceleration structure.
- The data type of an instances geometry.
- The type of an acceleration structure.
- What mode an acceleration structure build command should operate in.
- What mode an acceleration structure copy command should operate in.
Type Aliases
- A 3x4 transformation matrix.