37. Acceleration Structures
37.1. Acceleration Structures
Acceleration structures are data structures used by the implementation to efficiently manage scene geometry as it is traversed during a ray tracing query. The application is responsible for managing acceleration structure objects (see Acceleration Structures), including allocation, destruction, executing builds or updates, and synchronizing resources used during ray tracing queries.
There are two types of acceleration structures, top level acceleration structures and bottom level acceleration structures.
An acceleration structure is considered to be constructed if an acceleration structure build command or copy command has been executed with the given acceleration structure as the destination.
37.1.2. Top Level Acceleration Structures
Opaque acceleration structure for an array of instances. The descriptor or device address referencing this is the starting point for traversal.
The top level acceleration structure takes a reference to any bottom level acceleration structure referenced by its instances. Those bottom level acceleration structure objects must be valid when the top level acceleration structure is accessed.
37.1.3. Bottom Level Acceleration Structures
Opaque acceleration structure for an array of geometries.
37.1.4. Acceleration Structure Update Rules
The API defines two types of operations to produce acceleration structures from geometry:
- 
A build operation is used to construct an acceleration structure. 
- 
An update operation is used to modify an existing acceleration structure. 
An update operation imposes certain constraints on the input, in exchange for considerably faster execution. When performing an update, the application is required to provide a full description of the acceleration structure, but is prohibited from changing anything other than instance definitions, transform matrices, and vertex or AABB positions. All other aspects of the description must exactly match the one from the original build.
More precisely, the application must not use an update operation to do any of the following:
- 
Change primitives or instances from active to inactive, or vice versa (as defined in Inactive Primitives and Instances). 
- 
Change the index or vertex formats of triangle geometry. 
- 
Change triangle geometry transform pointers from null to non-null or vice versa. 
- 
Change the number of geometries or instances in the structure. 
- 
Change the geometry flags for any geometry in the structure. 
- 
Change the number of vertices or primitives for any geometry in the structure. 
If the original acceleration structure was built using opacity micromaps and
VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_OPACITY_MICROMAP_DATA_UPDATE_EXT
was set in flags, the application must provide the corresponding
micromap information to the update operation.
The application is prohibited from changing anything other than the specific
opacity values assigned to the triangles.
More precisely, the application must not use an update operation to do any of the following:
- 
Remove micromaps or VkOpacityMicromapSpecialIndexEXT values from a geometry which previously had them, or vice versa. 
- 
Change between use of VkOpacityMicromapSpecialIndexEXT values and explicit micro-map triangles. 
- 
Change the subdivision level or format of the micromap triangle associated with any acceleration-structure triangle. 
If the original acceleration structure was built using opacity micromaps and
VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_OPACITY_MICROMAP_UPDATE_EXT was
set in flags, the application must provide a micromap to the update
operation.
If the original acceleration structure was built using opacity micromaps and neither opacity micromap update flag is set the application must provide the original micromap to the update operation.
37.1.5. Inactive Primitives and Instances
Acceleration structures allow the use of particular input values to signal inactive primitives or instances.
An inactive triangle is one for which the first (X) component of any vertex is NaN. If any other vertex component is NaN, and the first is not, the behavior is undefined. If the vertex format does not have a NaN representation, then all triangles are considered active.
An inactive instance is one whose acceleration structure reference is 0.
An inactive AABB is one for which the minimum X coordinate is NaN. If any other component is NaN, and the first is not, the behavior is undefined.
In the above definitions, “NaN” refers to any type of NaN. Signaling, non-signaling, quiet, loud, or otherwise.
An inactive object is considered invisible to all rays, and should not be represented in the acceleration structure. Implementations should ensure that the presence of inactive objects does not seriously degrade traversal performance.
Inactive objects are counted in the auto-generated index sequences which are
provided to shaders via InstanceId and PrimitiveId SPIR-V
decorations.
This allows objects in the scene to change freely between the active and
inactive states, without affecting the layout of any arrays which are being
indexed using the ID values.
Any transition between the active and inactive states requires a full acceleration structure rebuild. Applications must not perform an acceleration structure update where an object is active in the source acceleration structure but would be inactive in the destination, or vice versa.
37.1.6. Building Acceleration Structures
To build an acceleration structure call:
// Provided by VK_NV_ray_tracing
void vkCmdBuildAccelerationStructureNV(
    VkCommandBuffer                             commandBuffer,
    const VkAccelerationStructureInfoNV*        pInfo,
    VkBuffer                                    instanceData,
    VkDeviceSize                                instanceOffset,
    VkBool32                                    update,
    VkAccelerationStructureNV                   dst,
    VkAccelerationStructureNV                   src,
    VkBuffer                                    scratch,
    VkDeviceSize                                scratchOffset);- 
commandBufferis the command buffer into which the command will be recorded.
- 
pInfocontains the shared information for the acceleration structure’s structure.
- 
instanceDatais the buffer containing an array of VkAccelerationStructureInstanceKHR structures defining acceleration structures. This parameter must beNULLfor bottom level acceleration structures.
- 
instanceOffsetis the offset in bytes (relative to the start ofinstanceData) at which the instance data is located.
- 
updatespecifies whether to update thedstacceleration structure with the data insrc.
- 
dstis a pointer to the target acceleration structure for the build.
- 
srcis a pointer to an existing acceleration structure that is to be used to update thedstacceleration structure.
- 
scratchis the VkBuffer that will be used as scratch memory for the build.
- 
scratchOffsetis the offset in bytes relative to the start ofscratchthat will be used as a scratch memory.
Accesses to dst, src, and scratch must be
synchronized with the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage and an
access type of
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR or
VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR.
To build acceleration structures call:
// Provided by VK_KHR_acceleration_structure
void vkCmdBuildAccelerationStructuresKHR(
    VkCommandBuffer                             commandBuffer,
    uint32_t                                    infoCount,
    const VkAccelerationStructureBuildGeometryInfoKHR* pInfos,
    const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos);- 
commandBufferis the command buffer into which the command will be recorded.
- 
infoCountis the number of acceleration structures to build. It specifies the number of thepInfosstructures andppBuildRangeInfospointers that must be provided.
- 
pInfosis a pointer to an array ofinfoCountVkAccelerationStructureBuildGeometryInfoKHR structures defining the geometry used to build each acceleration structure.
- 
ppBuildRangeInfosis a pointer to an array ofinfoCountpointers to arrays of VkAccelerationStructureBuildRangeInfoKHR structures. EachppBuildRangeInfos[i] is a pointer to an array ofpInfos[i].geometryCountVkAccelerationStructureBuildRangeInfoKHR structures defining dynamic offsets to the addresses where geometry data is stored, as defined bypInfos[i].
The vkCmdBuildAccelerationStructuresKHR command provides the ability
to initiate multiple acceleration structures builds, however there is no
ordering or synchronization implied between any of the individual
acceleration structure builds.
| Note This means that an application cannot build a top-level acceleration structure in the same vkCmdBuildAccelerationStructuresKHR call as the associated bottom-level or instance acceleration structures are being built. There also cannot be any memory aliasing between any acceleration structure memories or scratch memories being used by any of the builds. | 
Accesses to the acceleration structure scratch buffers as identified by the
VkAccelerationStructureBuildGeometryInfoKHR::scratchData buffer
device addresses must be synchronized with
the VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage and an
access type of
(VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR |
VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR).
Accesses to each
VkAccelerationStructureBuildGeometryInfoKHR::srcAccelerationStructure
and
VkAccelerationStructureBuildGeometryInfoKHR::dstAccelerationStructure
must be synchronized with the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage and an
access type of
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR or
VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR, as appropriate.
Accesses to other input buffers as identified by any used values of
VkAccelerationStructureGeometryMotionTrianglesDataNV::vertexData,
VkAccelerationStructureGeometryTrianglesDataKHR::vertexData,
VkAccelerationStructureGeometryTrianglesDataKHR::indexData,
VkAccelerationStructureGeometryTrianglesDataKHR::transformData,
VkAccelerationStructureGeometryAabbsDataKHR::data, and
VkAccelerationStructureGeometryInstancesDataKHR::data must be
synchronized with the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage and an
access type of
VK_ACCESS_SHADER_READ_BIT.
To build acceleration structures with some parameters sourced on the device call:
// Provided by VK_KHR_acceleration_structure
void vkCmdBuildAccelerationStructuresIndirectKHR(
    VkCommandBuffer                             commandBuffer,
    uint32_t                                    infoCount,
    const VkAccelerationStructureBuildGeometryInfoKHR* pInfos,
    const VkDeviceAddress*                      pIndirectDeviceAddresses,
    const uint32_t*                             pIndirectStrides,
    const uint32_t* const*                      ppMaxPrimitiveCounts);- 
commandBufferis the command buffer into which the command will be recorded.
- 
infoCountis the number of acceleration structures to build.
- 
pInfosis a pointer to an array ofinfoCountVkAccelerationStructureBuildGeometryInfoKHR structures defining the geometry used to build each acceleration structure.
- 
pIndirectDeviceAddressesis a pointer to an array ofinfoCountbuffer device addresses which point topInfos[i].geometryCountVkAccelerationStructureBuildRangeInfoKHR structures defining dynamic offsets to the addresses where geometry data is stored, as defined bypInfos[i].
- 
pIndirectStridesis a pointer to an array ofinfoCountbyte strides between elements ofpIndirectDeviceAddresses.
- 
ppMaxPrimitiveCountsis a pointer to an array ofinfoCountpointers to arrays ofpInfos[i].geometryCountvalues indicating the maximum number of primitives that will be built by this command for each geometry.
Accesses to acceleration structures, scratch buffers, vertex buffers, index buffers, and instance buffers must be synchronized as with vkCmdBuildAccelerationStructuresKHR.
Accesses to any element of pIndirectDeviceAddresses must be
synchronized with the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage and an
access type of
VK_ACCESS_INDIRECT_COMMAND_READ_BIT.
The VkAccelerationStructureBuildGeometryInfoKHR structure is defined
as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAccelerationStructureBuildGeometryInfoKHR {
    VkStructureType                                     sType;
    const void*                                         pNext;
    VkAccelerationStructureTypeKHR                      type;
    VkBuildAccelerationStructureFlagsKHR                flags;
    VkBuildAccelerationStructureModeKHR                 mode;
    VkAccelerationStructureKHR                          srcAccelerationStructure;
    VkAccelerationStructureKHR                          dstAccelerationStructure;
    uint32_t                                            geometryCount;
    const VkAccelerationStructureGeometryKHR*           pGeometries;
    const VkAccelerationStructureGeometryKHR* const*    ppGeometries;
    VkDeviceOrHostAddressKHR                            scratchData;
} VkAccelerationStructureBuildGeometryInfoKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
typeis a VkAccelerationStructureTypeKHR value specifying the type of acceleration structure being built.
- 
flagsis a bitmask of VkBuildAccelerationStructureFlagBitsKHR specifying additional parameters of the acceleration structure.
- 
modeis a VkBuildAccelerationStructureModeKHR value specifying the type of operation to perform.
- 
srcAccelerationStructureis a pointer to an existing acceleration structure that is to be used to update thedstacceleration structure whenmodeisVK_BUILD_ACCELERATION_STRUCTURE_MODE_UPDATE_KHR.
- 
dstAccelerationStructureis a pointer to the target acceleration structure for the build.
- 
geometryCountspecifies the number of geometries that will be built intodstAccelerationStructure.
- 
pGeometriesis a pointer to an array of VkAccelerationStructureGeometryKHR structures.
- 
ppGeometriesis a pointer to an array of pointers to VkAccelerationStructureGeometryKHR structures.
- 
scratchDatais the device or host address to memory that will be used as scratch memory for the build.
Only one of pGeometries or ppGeometries can be a valid pointer,
the other must be NULL.
Each element of the non-NULL array describes the data used to build each
acceleration structure geometry.
The index of each element of the pGeometries or ppGeometries
members of VkAccelerationStructureBuildGeometryInfoKHR is used as the
geometry index during ray traversal.
The geometry index is available in ray shaders via the
RayGeometryIndexKHR
built-in, and is used to
determine hit and intersection shaders executed during traversal.
The geometry index is available to ray queries via the
OpRayQueryGetIntersectionGeometryIndexKHR instruction.
Setting VK_BUILD_ACCELERATION_STRUCTURE_MOTION_BIT_NV in flags
indicates that this build is a motion top level acceleration structure.
A motion top level uses instances of format
VkAccelerationStructureMotionInstanceNV if
VkAccelerationStructureGeometryInstancesDataKHR::arrayOfPointers
is VK_FALSE.
If
VkAccelerationStructureGeometryInstancesDataKHR::arrayOfPointers
is VK_TRUE, the pointer for each element of the array of instance
pointers consists of 4 bits of
VkAccelerationStructureMotionInstanceTypeNV in the low 4 bits of the
pointer identifying the type of structure at the pointer.
The device address accessed is the value in the array with the low 4 bits
set to zero.
The structure at the pointer is one of
VkAccelerationStructureInstanceKHR,
VkAccelerationStructureMatrixMotionInstanceNV or
VkAccelerationStructureSRTMotionInstanceNV, depending on the type
value encoded in the low 4 bits.
A top level acceleration structure with either motion instances or vertex
motion in its instances must set
VK_BUILD_ACCELERATION_STRUCTURE_MOTION_BIT_NV in flags.
Members srcAccelerationStructure and dstAccelerationStructure
may be the same or different for an update operation (when mode is
VK_BUILD_ACCELERATION_STRUCTURE_MODE_UPDATE_KHR).
If they are the same, the update happens in-place.
Otherwise, the target acceleration structure is updated and the source is
not modified.
The VkBuildAccelerationStructureModeKHR enumeration is defined as:
// Provided by VK_KHR_acceleration_structure
typedef enum VkBuildAccelerationStructureModeKHR {
    VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR = 0,
    VK_BUILD_ACCELERATION_STRUCTURE_MODE_UPDATE_KHR = 1,
} VkBuildAccelerationStructureModeKHR;- 
VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHRspecifies that the destination acceleration structure will be built using the specified geometries.
- 
VK_BUILD_ACCELERATION_STRUCTURE_MODE_UPDATE_KHRspecifies that the destination acceleration structure will be built using data in a source acceleration structure, updated by the specified geometries.
The VkDeviceOrHostAddressKHR union is defined as:
// Provided by VK_KHR_acceleration_structure
typedef union VkDeviceOrHostAddressKHR {
    VkDeviceAddress    deviceAddress;
    void*              hostAddress;
} VkDeviceOrHostAddressKHR;- 
deviceAddressis a buffer device address as returned by the vkGetBufferDeviceAddressKHR command.
- 
hostAddressis a host memory address.
The VkDeviceOrHostAddressConstKHR union is defined as:
// Provided by VK_KHR_acceleration_structure
typedef union VkDeviceOrHostAddressConstKHR {
    VkDeviceAddress    deviceAddress;
    const void*        hostAddress;
} VkDeviceOrHostAddressConstKHR;- 
deviceAddressis a buffer device address as returned by the vkGetBufferDeviceAddressKHR command.
- 
hostAddressis a const host memory address.
The VkAccelerationStructureGeometryKHR structure is defined as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAccelerationStructureGeometryKHR {
    VkStructureType                           sType;
    const void*                               pNext;
    VkGeometryTypeKHR                         geometryType;
    VkAccelerationStructureGeometryDataKHR    geometry;
    VkGeometryFlagsKHR                        flags;
} VkAccelerationStructureGeometryKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
geometryTypedescribes which type of geometry thisVkAccelerationStructureGeometryKHRrefers to.
- 
geometryis a VkAccelerationStructureGeometryDataKHR union describing the geometry data for the relevant geometry type.
- 
flagsis a bitmask of VkGeometryFlagBitsKHR values describing additional properties of how the geometry should be built.
The VkAccelerationStructureGeometryDataKHR union is defined as:
// Provided by VK_KHR_acceleration_structure
typedef union VkAccelerationStructureGeometryDataKHR {
    VkAccelerationStructureGeometryTrianglesDataKHR    triangles;
    VkAccelerationStructureGeometryAabbsDataKHR        aabbs;
    VkAccelerationStructureGeometryInstancesDataKHR    instances;
} VkAccelerationStructureGeometryDataKHR;- 
trianglesis a VkAccelerationStructureGeometryTrianglesDataKHR structure.
- 
aabbsis a VkAccelerationStructureGeometryAabbsDataKHR structure.
- 
instancesis a VkAccelerationStructureGeometryInstancesDataKHR structure.
The VkAccelerationStructureGeometryTrianglesDataKHR structure is
defined as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAccelerationStructureGeometryTrianglesDataKHR {
    VkStructureType                  sType;
    const void*                      pNext;
    VkFormat                         vertexFormat;
    VkDeviceOrHostAddressConstKHR    vertexData;
    VkDeviceSize                     vertexStride;
    uint32_t                         maxVertex;
    VkIndexType                      indexType;
    VkDeviceOrHostAddressConstKHR    indexData;
    VkDeviceOrHostAddressConstKHR    transformData;
} VkAccelerationStructureGeometryTrianglesDataKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
vertexFormatis the VkFormat of each vertex element.
- 
vertexDatais a device or host address to memory containing vertex data for this geometry.
- 
maxVertexis the highest index of a vertex that will be addressed by a build command using this structure.
- 
vertexStrideis the stride in bytes between each vertex.
- 
indexTypeis the VkIndexType of each index element.
- 
indexDatais a device or host address to memory containing index data for this geometry.
- 
transformDatais a device or host address to memory containing an optional reference to a VkTransformMatrixKHR structure describing a transformation from the space in which the vertices in this geometry are described to the space in which the acceleration structure is defined.
| Note Unlike the stride for vertex buffers in
VkVertexInputBindingDescription for graphics pipelines which must not
exceed  | 
The VkAccelerationStructureGeometryMotionTrianglesDataNV structure is
defined as:
// Provided by VK_NV_ray_tracing_motion_blur
typedef struct VkAccelerationStructureGeometryMotionTrianglesDataNV {
    VkStructureType                  sType;
    const void*                      pNext;
    VkDeviceOrHostAddressConstKHR    vertexData;
} VkAccelerationStructureGeometryMotionTrianglesDataNV;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
vertexDatais a pointer to vertex data for this geometry at time 1.0
If VkAccelerationStructureGeometryMotionTrianglesDataNV is included in
the pNext chain of a
VkAccelerationStructureGeometryTrianglesDataKHR structure, the basic
vertex positions are used for the position of the triangles in the geometry
at time 0.0 and the vertexData in
VkAccelerationStructureGeometryMotionTrianglesDataNV is used for the
vertex positions at time 1.0, with positions linearly interpolated at
intermediate times.
Indexing for VkAccelerationStructureGeometryMotionTrianglesDataNV
vertexData is equivalent to the basic vertex position data.
The VkAccelerationStructureTrianglesOpacityMicromapEXT structure is
defined as:
// Provided by VK_EXT_opacity_micromap
typedef struct VkAccelerationStructureTrianglesOpacityMicromapEXT {
    VkStructureType                     sType;
    void*                               pNext;
    VkIndexType                         indexType;
    VkDeviceOrHostAddressConstKHR       indexBuffer;
    VkDeviceSize                        indexStride;
    uint32_t                            baseTriangle;
    uint32_t                            usageCountsCount;
    const VkMicromapUsageEXT*           pUsageCounts;
    const VkMicromapUsageEXT* const*    ppUsageCounts;
    VkMicromapEXT                       micromap;
} VkAccelerationStructureTrianglesOpacityMicromapEXT;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
indexTypeis the type of triangle indices used when indexing this micromap
- 
indexBufferis the address containing the triangle indices
- 
indexStrideis the byte stride between triangle indices
- 
baseTriangleis the base value added to the non-negative triangle indices
- 
usageCountsCountspecifies the number of usage counts structures that will be used to determine the size of this micromap.
- 
pUsageCountsis a pointer to an array of VkMicromapUsageEXT structures.
- 
ppUsageCountsis a pointer to an array of pointers to VkMicromapUsageEXT structures.
- 
micromapis the handle to the micromap object to include in this geometry
If VkAccelerationStructureTrianglesOpacityMicromapEXT is included in
the pNext chain of a
VkAccelerationStructureGeometryTrianglesDataKHR structure, that
geometry will reference that micromap.
For each triangle in the geometry, the acceleration structure build fetches
an index from indexBuffer using indexType and indexStride.
If that value is the unsigned cast of one of the values from
VkOpacityMicromapSpecialIndexEXT then that triangle behaves as
described for that special value in Ray Opacity
Micromap.
Otherwise that triangle uses the opacity micromap information from
micromap at that index plus baseTriangle.
Only one of pUsageCounts or ppUsageCounts can be a valid
pointer, the other must be NULL.
The elements of the non-NULL array describe the total count used to build
this geometry.
For a given format and subdivisionLevel the number of triangles
in this geometry matching those values after indirection and special index
handling must be equal to the sum of matching count provided.
If micromap is VK_NULL_HANDLE, then every value read from
indexBuffer must be one of the values in
VkOpacityMicromapSpecialIndexEXT.
The VkOpacityMicromapSpecialIndexEXT enumeration is defined as:
// Provided by VK_EXT_opacity_micromap
typedef enum VkOpacityMicromapSpecialIndexEXT {
    VK_OPACITY_MICROMAP_SPECIAL_INDEX_FULLY_TRANSPARENT_EXT = -1,
    VK_OPACITY_MICROMAP_SPECIAL_INDEX_FULLY_OPAQUE_EXT = -2,
    VK_OPACITY_MICROMAP_SPECIAL_INDEX_FULLY_UNKNOWN_TRANSPARENT_EXT = -3,
    VK_OPACITY_MICROMAP_SPECIAL_INDEX_FULLY_UNKNOWN_OPAQUE_EXT = -4,
} VkOpacityMicromapSpecialIndexEXT;- 
VK_OPACITY_MICROMAP_SPECIAL_INDEX_FULLY_TRANSPARENT_EXTspecifies that the entire triangle is fully transparent.
- 
VK_OPACITY_MICROMAP_SPECIAL_INDEX_FULLY_OPAQUE_EXTspecifies that the entire triangle is fully opaque.
- 
VK_OPACITY_MICROMAP_SPECIAL_INDEX_FULLY_UNKNOWN_TRANSPARENT_EXTspecifies that the entire triangle is unknown-transparent.
- 
VK_OPACITY_MICROMAP_SPECIAL_INDEX_FULLY_UNKNOWN_OPAQUE_EXTspecifies that the entire triangle is unknown-opaque.
The VkTransformMatrixKHR structure is defined as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkTransformMatrixKHR {
    float    matrix[3][4];
} VkTransformMatrixKHR;or the equivalent
// Provided by VK_NV_ray_tracing
typedef VkTransformMatrixKHR VkTransformMatrixNV;- 
matrixis a 3x4 row-major affine transformation matrix.
The VkAccelerationStructureGeometryAabbsDataKHR structure is defined
as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAccelerationStructureGeometryAabbsDataKHR {
    VkStructureType                  sType;
    const void*                      pNext;
    VkDeviceOrHostAddressConstKHR    data;
    VkDeviceSize                     stride;
} VkAccelerationStructureGeometryAabbsDataKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
datais a device or host address to memory containing VkAabbPositionsKHR structures containing position data for each axis-aligned bounding box in the geometry.
- 
strideis the stride in bytes between each entry indata. The stride must be a multiple of8.
The VkAabbPositionsKHR structure is defined as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAabbPositionsKHR {
    float    minX;
    float    minY;
    float    minZ;
    float    maxX;
    float    maxY;
    float    maxZ;
} VkAabbPositionsKHR;or the equivalent
// Provided by VK_NV_ray_tracing
typedef VkAabbPositionsKHR VkAabbPositionsNV;- 
minXis the x position of one opposing corner of a bounding box.
- 
minYis the y position of one opposing corner of a bounding box.
- 
minZis the z position of one opposing corner of a bounding box.
- 
maxXis the x position of the other opposing corner of a bounding box.
- 
maxYis the y position of the other opposing corner of a bounding box.
- 
maxZis the z position of the other opposing corner of a bounding box.
The VkAccelerationStructureGeometryInstancesDataKHR structure is
defined as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAccelerationStructureGeometryInstancesDataKHR {
    VkStructureType                  sType;
    const void*                      pNext;
    VkBool32                         arrayOfPointers;
    VkDeviceOrHostAddressConstKHR    data;
} VkAccelerationStructureGeometryInstancesDataKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
arrayOfPointersspecifies whetherdatais used as an array of addresses or just an array.
- 
datais either the address of an array of device or host addresses referencing individual VkAccelerationStructureInstanceKHR structures or packed motion instance information as described in motion instances ifarrayOfPointersisVK_TRUE, or the address of an array of VkAccelerationStructureInstanceKHR or VkAccelerationStructureMotionInstanceNV structures. Addresses and VkAccelerationStructureInstanceKHR structures are tightly packed. VkAccelerationStructureMotionInstanceNV structures have a stride of 160 bytes.
Acceleration structure instances can be built into top-level acceleration structures. Each acceleration structure instance is a separate entry in the top-level acceleration structure which includes all the geometry of a bottom-level acceleration structure at a transformed location. Multiple instances can point to the same bottom level acceleration structure.
An acceleration structure instance is defined by the structure:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAccelerationStructureInstanceKHR {
    VkTransformMatrixKHR          transform;
    uint32_t                      instanceCustomIndex:24;
    uint32_t                      mask:8;
    uint32_t                      instanceShaderBindingTableRecordOffset:24;
    VkGeometryInstanceFlagsKHR    flags:8;
    uint64_t                      accelerationStructureReference;
} VkAccelerationStructureInstanceKHR;or the equivalent
// Provided by VK_NV_ray_tracing
typedef VkAccelerationStructureInstanceKHR VkAccelerationStructureInstanceNV;- 
transformis a VkTransformMatrixKHR structure describing a transformation to be applied to the acceleration structure.
- 
instanceCustomIndexis a 24-bit user-specified index value accessible to ray shaders in theInstanceCustomIndexKHRbuilt-in.
- 
maskis an 8-bit visibility mask for the geometry. The instance may only be hit ifCull Mask & instance.mask != 0
- 
instanceShaderBindingTableRecordOffsetis a 24-bit offset used in calculating the hit shader binding table index.
- 
flagsis an 8-bit mask of VkGeometryInstanceFlagBitsKHR values to apply to this instance.
- 
accelerationStructureReferenceis either:- 
a device address containing the value obtained from vkGetAccelerationStructureDeviceAddressKHR or vkGetAccelerationStructureHandleNV (used by device operations which reference acceleration structures) or, 
- 
a VkAccelerationStructureKHR object (used by host operations which reference acceleration structures). 
 
- 
The C language specification does not define the ordering of bit-fields, but in practice, this struct produces the correct layout with existing compilers. The intended bit pattern is for the following:
- 
instanceCustomIndexandmaskoccupy the same memory as if a singleuint32_twas specified in their place- 
instanceCustomIndexoccupies the 24 least significant bits of that memory
- 
maskoccupies the 8 most significant bits of that memory
 
- 
- 
instanceShaderBindingTableRecordOffsetandflagsoccupy the same memory as if a singleuint32_twas specified in their place- 
instanceShaderBindingTableRecordOffsetoccupies the 24 least significant bits of that memory
- 
flagsoccupies the 8 most significant bits of that memory
 
- 
If a compiler produces code that diverges from that pattern, applications must employ another method to set values according to the correct bit pattern.
Possible values of flags in the instance modifying the behavior of
that instance are:
// Provided by VK_KHR_acceleration_structure
typedef enum VkGeometryInstanceFlagBitsKHR {
    VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR = 0x00000001,
    VK_GEOMETRY_INSTANCE_TRIANGLE_FLIP_FACING_BIT_KHR = 0x00000002,
    VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR = 0x00000004,
    VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR = 0x00000008,
  // Provided by VK_EXT_opacity_micromap
    VK_GEOMETRY_INSTANCE_FORCE_OPACITY_MICROMAP_2_STATE_EXT = 0x00000010,
  // Provided by VK_EXT_opacity_micromap
    VK_GEOMETRY_INSTANCE_DISABLE_OPACITY_MICROMAPS_EXT = 0x00000020,
    VK_GEOMETRY_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE_BIT_KHR = VK_GEOMETRY_INSTANCE_TRIANGLE_FLIP_FACING_BIT_KHR,
  // Provided by VK_NV_ray_tracing
    VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR,
  // Provided by VK_NV_ray_tracing
    VK_GEOMETRY_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE_BIT_NV = VK_GEOMETRY_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE_BIT_KHR,
  // Provided by VK_NV_ray_tracing
    VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_NV = VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR,
  // Provided by VK_NV_ray_tracing
    VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_NV = VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR,
} VkGeometryInstanceFlagBitsKHR;or the equivalent
// Provided by VK_NV_ray_tracing
typedef VkGeometryInstanceFlagBitsKHR VkGeometryInstanceFlagBitsNV;- 
VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHRdisables face culling for this instance.
- 
VK_GEOMETRY_INSTANCE_TRIANGLE_FLIP_FACING_BIT_KHRindicates that the facing determination for geometry in this instance is inverted. Because the facing is determined in object space, an instance transform does not change the winding, but a geometry transform does.
- 
VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHRcauses this instance to act as thoughVK_GEOMETRY_OPAQUE_BIT_KHRwere specified on all geometries referenced by this instance. This behavior can be overridden by the SPIR-VNoOpaqueKHRray flag.
- 
VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHRcauses this instance to act as thoughVK_GEOMETRY_OPAQUE_BIT_KHRwere not specified on all geometries referenced by this instance. This behavior can be overridden by the SPIR-VOpaqueKHRray flag.
VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR and
VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR must not be used in the
same flag.
// Provided by VK_KHR_acceleration_structure
typedef VkFlags VkGeometryInstanceFlagsKHR;or the equivalent
// Provided by VK_NV_ray_tracing
typedef VkGeometryInstanceFlagsKHR VkGeometryInstanceFlagsNV;VkGeometryInstanceFlagsKHR is a bitmask type for setting a mask of
zero or more VkGeometryInstanceFlagBitsKHR.
Acceleration structure motion instances can be built into top-level acceleration structures. Each acceleration structure instance is a separate entry in the top-level acceleration structure which includes all the geometry of a bottom-level acceleration structure at a transformed location including a type of motion and parameters to determine the motion of the instance over time.
An acceleration structure motion instance is defined by the structure:
// Provided by VK_NV_ray_tracing_motion_blur
typedef struct VkAccelerationStructureMotionInstanceNV {
    VkAccelerationStructureMotionInstanceTypeNV     type;
    VkAccelerationStructureMotionInstanceFlagsNV    flags;
    VkAccelerationStructureMotionInstanceDataNV     data;
} VkAccelerationStructureMotionInstanceNV;- 
typeis a VkAccelerationStructureMotionInstanceTypeNV enumerant identifying which type of motion instance this is and which type of the union is valid.
- 
flagsis currently unused, but is required to keep natural alignment ofdata.
- 
datais a VkAccelerationStructureMotionInstanceDataNV containing motion instance data for this instance.
| Note If writing this other than with a standard C compiler, note that the final structure should be 152 bytes in size. | 
Acceleration structure motion instance is defined by the union:
// Provided by VK_NV_ray_tracing_motion_blur
typedef union VkAccelerationStructureMotionInstanceDataNV {
    VkAccelerationStructureInstanceKHR               staticInstance;
    VkAccelerationStructureMatrixMotionInstanceNV    matrixMotionInstance;
    VkAccelerationStructureSRTMotionInstanceNV       srtMotionInstance;
} VkAccelerationStructureMotionInstanceDataNV;- 
staticInstanceis a VkAccelerationStructureInstanceKHR structure containing data for a static instance.
- 
matrixMotionInstanceis a VkAccelerationStructureMatrixMotionInstanceNV structure containing data for a matrix motion instance.
- 
srtMotionInstanceis a VkAccelerationStructureSRTMotionInstanceNV structure containing data for an SRT motion instance.
// Provided by VK_NV_ray_tracing_motion_blur
typedef VkFlags VkAccelerationStructureMotionInstanceFlagsNV;VkAccelerationStructureMotionInstanceFlagsNV is a bitmask type for
setting a mask, but is currently reserved for future use.
The VkAccelerationStructureMotionInstanceTypeNV enumeration is defined
as:
// Provided by VK_NV_ray_tracing_motion_blur
typedef enum VkAccelerationStructureMotionInstanceTypeNV {
    VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_STATIC_NV = 0,
    VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_MATRIX_MOTION_NV = 1,
    VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_SRT_MOTION_NV = 2,
} VkAccelerationStructureMotionInstanceTypeNV;- 
VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_STATIC_NVspecifies that the instance is a static instance with no instance motion.
- 
VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_MATRIX_MOTION_NVspecifies that the instance is a motion instance with motion specified by interpolation between two matrices.
- 
VK_ACCELERATION_STRUCTURE_MOTION_INSTANCE_TYPE_SRT_MOTION_NVspecifies that the instance is a motion instance with motion specified by interpolation in the SRT decomposition.
An acceleration structure matrix motion instance is defined by the structure:
// Provided by VK_NV_ray_tracing_motion_blur
typedef struct VkAccelerationStructureMatrixMotionInstanceNV {
    VkTransformMatrixKHR          transformT0;
    VkTransformMatrixKHR          transformT1;
    uint32_t                      instanceCustomIndex:24;
    uint32_t                      mask:8;
    uint32_t                      instanceShaderBindingTableRecordOffset:24;
    VkGeometryInstanceFlagsKHR    flags:8;
    uint64_t                      accelerationStructureReference;
} VkAccelerationStructureMatrixMotionInstanceNV;- 
transformT0is a VkTransformMatrixKHR structure describing a transformation to be applied to the acceleration structure at time 0.
- 
transformT1is a VkTransformMatrixKHR structure describing a transformation to be applied to the acceleration structure at time 1.
- 
instanceCustomIndexis a 24-bit user-specified index value accessible to ray shaders in theInstanceCustomIndexKHRbuilt-in.
- 
maskis an 8-bit visibility mask for the geometry. The instance may only be hit ifCull Mask & instance.mask != 0
- 
instanceShaderBindingTableRecordOffsetis a 24-bit offset used in calculating the hit shader binding table index.
- 
flagsis an 8-bit mask of VkGeometryInstanceFlagBitsKHR values to apply to this instance.
- 
accelerationStructureReferenceis either:- 
a device address containing the value obtained from vkGetAccelerationStructureDeviceAddressKHR or vkGetAccelerationStructureHandleNV (used by device operations which reference acceleration structures) or, 
- 
a VkAccelerationStructureKHR object (used by host operations which reference acceleration structures). 
 
- 
The C language specification does not define the ordering of bit-fields, but in practice, this struct produces the correct layout with existing compilers. The intended bit pattern is for the following:
- 
instanceCustomIndexandmaskoccupy the same memory as if a singleuint32_twas specified in their place- 
instanceCustomIndexoccupies the 24 least significant bits of that memory
- 
maskoccupies the 8 most significant bits of that memory
 
- 
- 
instanceShaderBindingTableRecordOffsetandflagsoccupy the same memory as if a singleuint32_twas specified in their place- 
instanceShaderBindingTableRecordOffsetoccupies the 24 least significant bits of that memory
- 
flagsoccupies the 8 most significant bits of that memory
 
- 
If a compiler produces code that diverges from that pattern, applications must employ another method to set values according to the correct bit pattern.
The transform for a matrix motion instance at a point in time is derived by
component-wise linear interpolation of the two transforms.
That is, for a time in [0,1] the resulting transform is
- 
transformT0× (1 -time) +transformT1×time
An acceleration structure SRT motion instance is defined by the structure:
// Provided by VK_NV_ray_tracing_motion_blur
typedef struct VkAccelerationStructureSRTMotionInstanceNV {
    VkSRTDataNV                   transformT0;
    VkSRTDataNV                   transformT1;
    uint32_t                      instanceCustomIndex:24;
    uint32_t                      mask:8;
    uint32_t                      instanceShaderBindingTableRecordOffset:24;
    VkGeometryInstanceFlagsKHR    flags:8;
    uint64_t                      accelerationStructureReference;
} VkAccelerationStructureSRTMotionInstanceNV;- 
transformT0is a VkSRTDataNV structure describing a transformation to be applied to the acceleration structure at time 0.
- 
transformT1is a VkSRTDataNV structure describing a transformation to be applied to the acceleration structure at time 1.
- 
instanceCustomIndexis a 24-bit user-specified index value accessible to ray shaders in theInstanceCustomIndexKHRbuilt-in.
- 
maskis an 8-bit visibility mask for the geometry. The instance may only be hit ifCull Mask & instance.mask != 0
- 
instanceShaderBindingTableRecordOffsetis a 24-bit offset used in calculating the hit shader binding table index.
- 
flagsis an 8-bit mask of VkGeometryInstanceFlagBitsKHR values to apply to this instance.
- 
accelerationStructureReferenceis either:- 
a device address containing the value obtained from vkGetAccelerationStructureDeviceAddressKHR or vkGetAccelerationStructureHandleNV (used by device operations which reference acceleration structures) or, 
- 
a VkAccelerationStructureKHR object (used by host operations which reference acceleration structures). 
 
- 
The C language specification does not define the ordering of bit-fields, but in practice, this struct produces the correct layout with existing compilers. The intended bit pattern is for the following:
- 
instanceCustomIndexandmaskoccupy the same memory as if a singleuint32_twas specified in their place- 
instanceCustomIndexoccupies the 24 least significant bits of that memory
- 
maskoccupies the 8 most significant bits of that memory
 
- 
- 
instanceShaderBindingTableRecordOffsetandflagsoccupy the same memory as if a singleuint32_twas specified in their place- 
instanceShaderBindingTableRecordOffsetoccupies the 24 least significant bits of that memory
- 
flagsoccupies the 8 most significant bits of that memory
 
- 
If a compiler produces code that diverges from that pattern, applications must employ another method to set values according to the correct bit pattern.
The transform for a SRT motion instance at a point in time is derived from
component-wise linear interpolation of the two SRT transforms.
That is, for a time in [0,1] the resulting transform is
- 
transformT0× (1 -time) +transformT1×time
An acceleration structure SRT transform is defined by the structure:
// Provided by VK_NV_ray_tracing_motion_blur
typedef struct VkSRTDataNV {
    float    sx;
    float    a;
    float    b;
    float    pvx;
    float    sy;
    float    c;
    float    pvy;
    float    sz;
    float    pvz;
    float    qx;
    float    qy;
    float    qz;
    float    qw;
    float    tx;
    float    ty;
    float    tz;
} VkSRTDataNV;- 
sxis the x component of the scale of the transform
- 
ais one component of the shear for the transform
- 
bis one component of the shear for the transform
- 
pvxis the x component of the pivot point of the transform
- 
syis the y component of the scale of the transform
- 
cis one component of the shear for the transform
- 
pvyis the y component of the pivot point of the transform
- 
szis the z component of the scale of the transform
- 
pvzis the z component of the pivot point of the transform
- 
qxis the x component of the rotation quaternion
- 
qyis the y component of the rotation quaternion
- 
qzis the z component of the rotation quaternion
- 
qwis the w component of the rotation quaternion
- 
txis the x component of the post-rotation translation
- 
tyis the y component of the post-rotation translation
- 
tzis the z component of the post-rotation translation
This transform decomposition consists of three elements. The first is a matrix S, consisting of a scale, shear, and translation, usually used to define the pivot point of the following rotation. This matrix is constructed from the parameters above by:
The rotation quaternion is defined as:
- 
R= [qx,qy,qz,qw]
This is a rotation around a conceptual normalized axis [ ax, ay, az ]
of amount theta such that:
- 
[ qx,qy,qz] = sin(theta/2) × [ax,ay,az]
and
- 
qw= cos(theta/2)
Finally, the transform has a translation T constructed from the parameters above by:
The effective derived transform is then given by
- 
T×R×S
VkAccelerationStructureBuildRangeInfoKHR is defined as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAccelerationStructureBuildRangeInfoKHR {
    uint32_t    primitiveCount;
    uint32_t    primitiveOffset;
    uint32_t    firstVertex;
    uint32_t    transformOffset;
} VkAccelerationStructureBuildRangeInfoKHR;- 
primitiveCountdefines the number of primitives for a corresponding acceleration structure geometry.
- 
primitiveOffsetdefines an offset in bytes into the memory where primitive data is defined.
- 
firstVertexis the index of the first vertex to build from for triangle geometry.
- 
transformOffsetdefines an offset in bytes into the memory where a transform matrix is defined.
The primitive count and primitive offset are interpreted differently depending on the VkGeometryTypeKHR used:
- 
For geometries of type VK_GEOMETRY_TYPE_TRIANGLES_KHR,primitiveCountis the number of triangles to be built, where each triangle is treated as 3 vertices.- 
If the geometry uses indices, primitiveCount× 3 indices are consumed from VkAccelerationStructureGeometryTrianglesDataKHR::indexData, starting at an offset ofprimitiveOffset. The value offirstVertexis added to the index values before fetching vertices.
- 
If the geometry does not use indices, primitiveCount× 3 vertices are consumed from VkAccelerationStructureGeometryTrianglesDataKHR::vertexData, starting at an offset ofprimitiveOffset+ VkAccelerationStructureGeometryTrianglesDataKHR::vertexStride×firstVertex.
- 
If VkAccelerationStructureGeometryTrianglesDataKHR:: transformDatais notNULL, a single VkTransformMatrixKHR structure is consumed from VkAccelerationStructureGeometryTrianglesDataKHR::transformData, at an offset oftransformOffset. This matrix describes a transformation from the space in which the vertices for all triangles in this geometry are described to the space in which the acceleration structure is defined.
 
- 
- 
For geometries of type VK_GEOMETRY_TYPE_AABBS_KHR,primitiveCountis the number of axis-aligned bounding boxes.primitiveCountVkAabbPositionsKHR structures are consumed from VkAccelerationStructureGeometryAabbsDataKHR::data, starting at an offset ofprimitiveOffset.
- 
For geometries of type VK_GEOMETRY_TYPE_INSTANCES_KHR,primitiveCountis the number of acceleration structures.primitiveCountVkAccelerationStructureInstanceKHR or VkAccelerationStructureMotionInstanceNV structures are consumed from VkAccelerationStructureGeometryInstancesDataKHR::data, starting at an offset ofprimitiveOffset.
37.1.7. Copying Acceleration Structures
An additional command exists for copying acceleration structures without updating their contents. The acceleration structure object can be compacted in order to improve performance. Before copying, an application must query the size of the resulting acceleration structure.
To query acceleration structure size parameters call:
// Provided by VK_KHR_acceleration_structure
void vkCmdWriteAccelerationStructuresPropertiesKHR(
    VkCommandBuffer                             commandBuffer,
    uint32_t                                    accelerationStructureCount,
    const VkAccelerationStructureKHR*           pAccelerationStructures,
    VkQueryType                                 queryType,
    VkQueryPool                                 queryPool,
    uint32_t                                    firstQuery);- 
commandBufferis the command buffer into which the command will be recorded.
- 
accelerationStructureCountis the count of acceleration structures for which to query the property.
- 
pAccelerationStructuresis a pointer to an array of existing previously built acceleration structures.
- 
queryTypeis a VkQueryType value specifying the type of queries managed by the pool.
- 
queryPoolis the query pool that will manage the results of the query.
- 
firstQueryis the first query index within the query pool that will contain theaccelerationStructureCountnumber of results.
Accesses to any of the acceleration structures listed in
pAccelerationStructures must be synchronized with the
VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_COPY_BIT_KHR
pipeline stage or the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage, and an
access type of
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR.
- 
If queryTypeisVK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR, then the value written out is the number of bytes required by a compacted acceleration structure.
- 
If queryTypeisVK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR, then the value written out is the number of bytes required by a serialized acceleration structure.
To query acceleration structure size parameters call:
// Provided by VK_NV_ray_tracing
void vkCmdWriteAccelerationStructuresPropertiesNV(
    VkCommandBuffer                             commandBuffer,
    uint32_t                                    accelerationStructureCount,
    const VkAccelerationStructureNV*            pAccelerationStructures,
    VkQueryType                                 queryType,
    VkQueryPool                                 queryPool,
    uint32_t                                    firstQuery);- 
commandBufferis the command buffer into which the command will be recorded.
- 
accelerationStructureCountis the count of acceleration structures for which to query the property.
- 
pAccelerationStructuresis a pointer to an array of existing previously built acceleration structures.
- 
queryTypeis a VkQueryType value specifying the type of queries managed by the pool.
- 
queryPoolis the query pool that will manage the results of the query.
- 
firstQueryis the first query index within the query pool that will contain theaccelerationStructureCountnumber of results.
Accesses to any of the acceleration structures listed in
pAccelerationStructures must be synchronized with the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage and an
access type of
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR.
To copy an acceleration structure call:
// Provided by VK_NV_ray_tracing
void vkCmdCopyAccelerationStructureNV(
    VkCommandBuffer                             commandBuffer,
    VkAccelerationStructureNV                   dst,
    VkAccelerationStructureNV                   src,
    VkCopyAccelerationStructureModeKHR          mode);- 
commandBufferis the command buffer into which the command will be recorded.
- 
dstis the target acceleration structure for the copy.
- 
srcis the source acceleration structure for the copy.
- 
modeis a VkCopyAccelerationStructureModeKHR value specifying additional operations to perform during the copy.
Accesses to src and dst must be synchronized with the
VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_COPY_BIT_KHR
pipeline stage or the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage, and an
access type of
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR or
VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR as appropriate.
To copy an acceleration structure call:
// Provided by VK_KHR_acceleration_structure
void vkCmdCopyAccelerationStructureKHR(
    VkCommandBuffer                             commandBuffer,
    const VkCopyAccelerationStructureInfoKHR*   pInfo);- 
commandBufferis the command buffer into which the command will be recorded.
- 
pInfois a pointer to a VkCopyAccelerationStructureInfoKHR structure defining the copy operation.
This command copies the pInfo->src acceleration structure to the
pInfo->dst acceleration structure in the manner specified by
pInfo->mode.
Accesses to pInfo->src and pInfo->dst must be
synchronized with the
VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_COPY_BIT_KHR
pipeline stage or the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage, and an
access type of
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR or
VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR as appropriate.
The VkCopyAccelerationStructureInfoKHR structure is defined as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkCopyAccelerationStructureInfoKHR {
    VkStructureType                       sType;
    const void*                           pNext;
    VkAccelerationStructureKHR            src;
    VkAccelerationStructureKHR            dst;
    VkCopyAccelerationStructureModeKHR    mode;
} VkCopyAccelerationStructureInfoKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
srcis the source acceleration structure for the copy.
- 
dstis the target acceleration structure for the copy.
- 
modeis a VkCopyAccelerationStructureModeKHR value specifying additional operations to perform during the copy.
Possible values of mode specifying additional operations to perform
during the copy, are:
// Provided by VK_KHR_acceleration_structure
typedef enum VkCopyAccelerationStructureModeKHR {
    VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR = 0,
    VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR = 1,
    VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHR = 2,
    VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHR = 3,
  // Provided by VK_NV_ray_tracing
    VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_NV = VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR,
  // Provided by VK_NV_ray_tracing
    VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_NV = VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR,
} VkCopyAccelerationStructureModeKHR;or the equivalent
// Provided by VK_NV_ray_tracing
typedef VkCopyAccelerationStructureModeKHR VkCopyAccelerationStructureModeNV;- 
VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHRcreates a direct copy of the acceleration structure specified insrcinto the one specified bydst. Thedstacceleration structure must have been created with the same parameters assrc. Ifsrccontains references to other acceleration structures,dstwill reference the same acceleration structures.
- 
VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHRcreates a more compact version of an acceleration structuresrcintodst. The acceleration structuredstmust have been created with a size at least as large as that returned by vkCmdWriteAccelerationStructuresPropertiesKHR or vkWriteAccelerationStructuresPropertiesKHR after the build of the acceleration structure specified bysrc. Ifsrccontains references to other acceleration structures,dstwill reference the same acceleration structures.
- 
VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHRserializes the acceleration structure to a semi-opaque format which can be reloaded on a compatible implementation.
- 
VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHRdeserializes the semi-opaque serialization format in the buffer to the acceleration structure.
To copy an acceleration structure to device memory call:
// Provided by VK_KHR_acceleration_structure
void vkCmdCopyAccelerationStructureToMemoryKHR(
    VkCommandBuffer                             commandBuffer,
    const VkCopyAccelerationStructureToMemoryInfoKHR* pInfo);- 
commandBufferis the command buffer into which the command will be recorded.
- 
pInfois an a pointer to a VkCopyAccelerationStructureToMemoryInfoKHR structure defining the copy operation.
Accesses to pInfo->src must be synchronized with the
VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_COPY_BIT_KHR
pipeline stage or the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage, and an
access type of
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR.
Accesses to the buffer indicated by pInfo->dst.deviceAddress must be
synchronized with the
VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_COPY_BIT_KHR
pipeline stage or the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage, and an and an access
type of VK_ACCESS_TRANSFER_WRITE_BIT.
This command produces the same results as vkCopyAccelerationStructureToMemoryKHR, but writes its result to a device address, and is executed on the device rather than the host. The output may not necessarily be bit-for-bit identical, but it can be equally used by either vkCmdCopyMemoryToAccelerationStructureKHR or vkCopyMemoryToAccelerationStructureKHR.
The defined header structure for the serialized data consists of:
- 
VK_UUID_SIZEbytes of data matchingVkPhysicalDeviceIDProperties::driverUUID
- 
VK_UUID_SIZEbytes of data identifying the compatibility for comparison using vkGetDeviceAccelerationStructureCompatibilityKHR
- 
A 64-bit integer of the total size matching the value queried using VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR
- 
A 64-bit integer of the deserialized size to be passed in to VkAccelerationStructureCreateInfoKHR::size
- 
A 64-bit integer of the count of the number of acceleration structure handles following. This value matches the value queried using VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_BOTTOM_LEVEL_POINTERS_KHR. This will be zero for a bottom-level acceleration structure. For top-level acceleration structures this number is implementation-dependent; the number of and ordering of the handles may not match the instance descriptions which were used to build the acceleration structure.
The corresponding handles matching the values returned by vkGetAccelerationStructureDeviceAddressKHR or vkGetAccelerationStructureHandleNV are tightly packed in the buffer following the count. The application is expected to store a mapping between those handles and the original application-generated bottom-level acceleration structures to provide when deserializing. The serialized data is written to the buffer (or read from the buffer) according to the host endianness.
// Provided by VK_KHR_acceleration_structure
typedef struct VkCopyAccelerationStructureToMemoryInfoKHR {
    VkStructureType                       sType;
    const void*                           pNext;
    VkAccelerationStructureKHR            src;
    VkDeviceOrHostAddressKHR              dst;
    VkCopyAccelerationStructureModeKHR    mode;
} VkCopyAccelerationStructureToMemoryInfoKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
srcis the source acceleration structure for the copy
- 
dstis the device or host address to memory which is the target for the copy
- 
modeis a VkCopyAccelerationStructureModeKHR value specifying additional operations to perform during the copy.
To copy device memory to an acceleration structure call:
// Provided by VK_KHR_acceleration_structure
void vkCmdCopyMemoryToAccelerationStructureKHR(
    VkCommandBuffer                             commandBuffer,
    const VkCopyMemoryToAccelerationStructureInfoKHR* pInfo);- 
commandBufferis the command buffer into which the command will be recorded.
- 
pInfois a pointer to a VkCopyMemoryToAccelerationStructureInfoKHR structure defining the copy operation.
Accesses to pInfo->dst must be synchronized with the
VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_COPY_BIT_KHR
pipeline stage or the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage, and an
access type of
VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR.
Accesses to the buffer indicated by pInfo->src.deviceAddress must be
synchronized with the
VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_COPY_BIT_KHR
pipeline stage or the
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR
pipeline stage, and an access type of
VK_ACCESS_TRANSFER_READ_BIT.
This command can accept acceleration structures produced by either vkCmdCopyAccelerationStructureToMemoryKHR or vkCopyAccelerationStructureToMemoryKHR.
The structure provided as input to deserialize is as described in vkCmdCopyAccelerationStructureToMemoryKHR, with any acceleration structure handles filled in with the newly-queried handles to bottom level acceleration structures created before deserialization. These do not need to be built at deserialize time, but must be created.
The VkCopyMemoryToAccelerationStructureInfoKHR structure is defined
as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkCopyMemoryToAccelerationStructureInfoKHR {
    VkStructureType                       sType;
    const void*                           pNext;
    VkDeviceOrHostAddressConstKHR         src;
    VkAccelerationStructureKHR            dst;
    VkCopyAccelerationStructureModeKHR    mode;
} VkCopyMemoryToAccelerationStructureInfoKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
srcis the device or host address to memory containing the source data for the copy.
- 
dstis the target acceleration structure for the copy.
- 
modeis a VkCopyAccelerationStructureModeKHR value specifying additional operations to perform during the copy.
To check if a serialized acceleration structure is compatible with the current device call:
// Provided by VK_KHR_acceleration_structure
void vkGetDeviceAccelerationStructureCompatibilityKHR(
    VkDevice                                    device,
    const VkAccelerationStructureVersionInfoKHR* pVersionInfo,
    VkAccelerationStructureCompatibilityKHR*    pCompatibility);- 
deviceis the device to check the version against.
- 
pVersionInfois a pointer to a VkAccelerationStructureVersionInfoKHR structure specifying version information to check against the device.
- 
pCompatibilityis a pointer to a VkAccelerationStructureCompatibilityKHR value in which compatibility information is returned.
The VkAccelerationStructureVersionInfoKHR structure is defined as:
// Provided by VK_KHR_acceleration_structure
typedef struct VkAccelerationStructureVersionInfoKHR {
    VkStructureType    sType;
    const void*        pNext;
    const uint8_t*     pVersionData;
} VkAccelerationStructureVersionInfoKHR;- 
sTypeis a VkStructureType value identifying this structure.
- 
pNextisNULLor a pointer to a structure extending this structure.
- 
pVersionDatais a pointer to the version header of an acceleration structure as defined in vkCmdCopyAccelerationStructureToMemoryKHR
| Note 
 | 
Possible values of pCompatibility returned by
vkGetDeviceAccelerationStructureCompatibilityKHR are:
// Provided by VK_KHR_acceleration_structure
typedef enum VkAccelerationStructureCompatibilityKHR {
    VK_ACCELERATION_STRUCTURE_COMPATIBILITY_COMPATIBLE_KHR = 0,
    VK_ACCELERATION_STRUCTURE_COMPATIBILITY_INCOMPATIBLE_KHR = 1,
} VkAccelerationStructureCompatibilityKHR;- 
VK_ACCELERATION_STRUCTURE_COMPATIBILITY_COMPATIBLE_KHRif thepVersionDataversion acceleration structure is compatible withdevice.
- 
VK_ACCELERATION_STRUCTURE_COMPATIBILITY_INCOMPATIBLE_KHRif thepVersionDataversion acceleration structure is not compatible withdevice.
37.2. Host Acceleration Structure Operations
Implementations are also required to provide host implementations of the
acceleration structure operations if the
accelerationStructureHostCommands feature is enabled:
- 
vkBuildAccelerationStructuresKHR corresponding to vkCmdBuildAccelerationStructuresKHR 
- 
vkCopyAccelerationStructureKHR corresponding to vkCmdCopyAccelerationStructureKHR 
- 
vkCopyAccelerationStructureToMemoryKHR corresponding to vkCmdCopyAccelerationStructureToMemoryKHR 
- 
vkCopyMemoryToAccelerationStructureKHR corresponding to vkCmdCopyMemoryToAccelerationStructureKHR 
- 
vkWriteAccelerationStructuresPropertiesKHR corresponding to vkCmdWriteAccelerationStructuresPropertiesKHR 
These commands are functionally equivalent to their device counterparts, except that they are executed on the host timeline, rather than being enqueued into command buffers.
All acceleration structures used by the host commands must be bound to host-visible memory, and all input data for acceleration structure builds must be referenced using host addresses instead of device addresses. Applications are not required to map acceleration structure memory when using the host commands.
| Note The vkBuildAccelerationStructuresKHR and vkCmdBuildAccelerationStructuresKHR may use different algorithms, and thus are not required to produce identical structures. The structures produced by these two commands may exhibit different memory footprints or traversal performance, but should strive to be similar where possible. Apart from these details, the host and device operations are interchangeable. For example, an application can use vkBuildAccelerationStructuresKHR to build a structure, compact it on the device using vkCmdCopyAccelerationStructureKHR, and serialize the result using vkCopyAccelerationStructureToMemoryKHR. | 
| Note For efficient execution, acceleration structures manipulated using these commands should always be bound to host cached memory, as the implementation may need to repeatedly read and write this memory during the execution of the command. | 
To build acceleration structures on the host, call:
// Provided by VK_KHR_acceleration_structure
VkResult vkBuildAccelerationStructuresKHR(
    VkDevice                                    device,
    VkDeferredOperationKHR                      deferredOperation,
    uint32_t                                    infoCount,
    const VkAccelerationStructureBuildGeometryInfoKHR* pInfos,
    const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos);- 
deviceis theVkDevicefor which the acceleration structures are being built.
- 
deferredOperationis an optional VkDeferredOperationKHR to request deferral for this command.
- 
infoCountis the number of acceleration structures to build. It specifies the number of thepInfosstructures andppBuildRangeInfospointers that must be provided.
- 
pInfosis a pointer to an array ofinfoCountVkAccelerationStructureBuildGeometryInfoKHR structures defining the geometry used to build each acceleration structure.
- 
ppBuildRangeInfosis a pointer to an array ofinfoCountpointers to arrays of VkAccelerationStructureBuildRangeInfoKHR structures. EachppBuildRangeInfos[i] is a pointer to an array ofpInfos[i].geometryCountVkAccelerationStructureBuildRangeInfoKHR structures defining dynamic offsets to the addresses where geometry data is stored, as defined bypInfos[i].
This command fulfills the same task as vkCmdBuildAccelerationStructuresKHR but is executed by the host.
The vkBuildAccelerationStructuresKHR command provides the ability to
initiate multiple acceleration structures builds, however there is no
ordering or synchronization implied between any of the individual
acceleration structure builds.
| Note This means that an application cannot build a top-level acceleration structure in the same vkBuildAccelerationStructuresKHR call as the associated bottom-level or instance acceleration structures are being built. There also cannot be any memory aliasing between any acceleration structure memories or scratch memories being used by any of the builds. | 
To copy or compact an acceleration structure on the host, call:
// Provided by VK_KHR_acceleration_structure
VkResult vkCopyAccelerationStructureKHR(
    VkDevice                                    device,
    VkDeferredOperationKHR                      deferredOperation,
    const VkCopyAccelerationStructureInfoKHR*   pInfo);- 
deviceis the device which owns the acceleration structures.
- 
deferredOperationis an optional VkDeferredOperationKHR to request deferral for this command.
- 
pInfois a pointer to a VkCopyAccelerationStructureInfoKHR structure defining the copy operation.
This command fulfills the same task as vkCmdCopyAccelerationStructureKHR but is executed by the host.
To copy host accessible memory to an acceleration structure, call:
// Provided by VK_KHR_acceleration_structure
VkResult vkCopyMemoryToAccelerationStructureKHR(
    VkDevice                                    device,
    VkDeferredOperationKHR                      deferredOperation,
    const VkCopyMemoryToAccelerationStructureInfoKHR* pInfo);- 
deviceis the device which ownspInfo->dst.
- 
deferredOperationis an optional VkDeferredOperationKHR to request deferral for this command.
- 
pInfois a pointer to a VkCopyMemoryToAccelerationStructureInfoKHR structure defining the copy operation.
This command fulfills the same task as vkCmdCopyMemoryToAccelerationStructureKHR but is executed by the host.
This command can accept acceleration structures produced by either vkCmdCopyAccelerationStructureToMemoryKHR or vkCopyAccelerationStructureToMemoryKHR.
To copy an acceleration structure to host accessible memory, call:
// Provided by VK_KHR_acceleration_structure
VkResult vkCopyAccelerationStructureToMemoryKHR(
    VkDevice                                    device,
    VkDeferredOperationKHR                      deferredOperation,
    const VkCopyAccelerationStructureToMemoryInfoKHR* pInfo);- 
deviceis the device which ownspInfo->src.
- 
deferredOperationis an optional VkDeferredOperationKHR to request deferral for this command.
- 
pInfois a pointer to a VkCopyAccelerationStructureToMemoryInfoKHR structure defining the copy operation.
This command fulfills the same task as vkCmdCopyAccelerationStructureToMemoryKHR but is executed by the host.
This command produces the same results as vkCmdCopyAccelerationStructureToMemoryKHR, but writes its result directly to a host pointer, and is executed on the host rather than the device. The output may not necessarily be bit-for-bit identical, but it can be equally used by either vkCmdCopyMemoryToAccelerationStructureKHR or vkCopyMemoryToAccelerationStructureKHR.
To query acceleration structure size parameters on the host, call:
// Provided by VK_KHR_acceleration_structure
VkResult vkWriteAccelerationStructuresPropertiesKHR(
    VkDevice                                    device,
    uint32_t                                    accelerationStructureCount,
    const VkAccelerationStructureKHR*           pAccelerationStructures,
    VkQueryType                                 queryType,
    size_t                                      dataSize,
    void*                                       pData,
    size_t                                      stride);- 
deviceis the device which owns the acceleration structures inpAccelerationStructures.
- 
accelerationStructureCountis the count of acceleration structures for which to query the property.
- 
pAccelerationStructuresis a pointer to an array of existing previously built acceleration structures.
- 
queryTypeis a VkQueryType value specifying the property to be queried.
- 
dataSizeis the size in bytes of the buffer pointed to bypData.
- 
pDatais a pointer to a user-allocated buffer where the results will be written.
- 
strideis the stride in bytes between results for individual queries withinpData.
This command fulfills the same task as vkCmdWriteAccelerationStructuresPropertiesKHR but is executed by the host.