# vkCmdBuildAccelerationStructureKHR(3) Manual Page

## Name

vkCmdBuildAccelerationStructureKHR - Build an acceleration structure

## C Specification

To build acceleration structures call:

    void vkCmdBuildAccelerationStructureKHR(
        VkCommandBuffer                             commandBuffer,
        uint32_t                                    infoCount,
        const VkAccelerationStructureBuildGeometryInfoKHR* pInfos,
        const VkAccelerationStructureBuildOffsetInfoKHR* const* ppOffsetInfos);

## Parameters

- `commandBuffer` is the command buffer into which the command will be recorded.

- `infoCount` is the number of acceleration structures to build. It specifies the number of the `pInfos` structures and `ppOffsetInfos` pointers that must be provided.

- `pInfos` is an array of `infoCount` VkAccelerationStructureBuildGeometryInfoKHR structures defining the geometry used to build each acceleration structure.

- `ppOffsetInfos` is an array of `infoCount` pointers to arrays of VkAccelerationStructureBuildOffsetInfoKHR structures. Each `ppOffsetInfos`[i] is an array of `pInfos`[i]→`geometryCount` VkAccelerationStructureBuildOffsetInfoKHR structures defining dynamic offsets to the addresses where geometry data is stored, as defined by `pInfos`[i].

## Description

The `vkCmdBuildAccelerationStructureKHR` 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 vkCmdBuildAccelerationStructureKHR 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.

Valid Usage

- [[VUID-{refpage}-pOffsetInfos-03402]] `pOffsetInfos`[i] must be a valid pointer to an array of `pInfos`[i]→`geometryCount` `VkAccelerationStructureBuildOffsetInfoKHR` structures

- [[VUID-{refpage}-pInfos-03403]] Each `pInfos`[i].`srcAccelerationStructure` must not refer to the same acceleration structure as any `pInfos`[i].`dstAccelerationStructure` that is provided to the same build command unless it is identical for an update

- [[VUID-{refpage}-pInfos-03404]] For each `pInfos`[i], `dstAccelerationStructure` must have been created with compatible VkAccelerationStructureCreateInfoKHR where VkAccelerationStructureCreateInfoKHR::`type` and VkAccelerationStructureCreateInfoKHR::`flags` are identical to VkAccelerationStructureBuildGeometryInfoKHR::`type` and VkAccelerationStructureBuildGeometryInfoKHR::`flags` respectively, VkAccelerationStructureBuildGeometryInfoKHR::`geometryCount` for `dstAccelerationStructure` are greater than or equal to the build size, and each geometry in VkAccelerationStructureBuildGeometryInfoKHR::`ppGeometries` for `dstAccelerationStructure` has greater than or equal to the number of vertices, indices, and AABBs, VkAccelerationStructureGeometryTrianglesDataKHR::`transformData` is both 0 or both non-zero, and all other parameters are the same.

- [[VUID-{refpage}-pInfos-03405]] For each `pInfos`[i], if `update` is `VK_TRUE`, then objects that were previously active for that acceleration structure must not be made inactive as per [acceleration-structure-inactive-prims]

- [[VUID-{refpage}-pInfos-03406]] For each `pInfos`[i], if `update` is `VK_TRUE`, then objects that were previously inactive for that acceleration structure must not be made active as per [acceleration-structure-inactive-prims]

- [[VUID-{refpage}-None-03407]] Any acceleration structure instance in any top level build in this command must not reference any bottom level acceleration structure built by this command

- [[VUID-{refpage}-pInfos-03408]] There must not be any memory aliasing between the scratch memories that are provided in all the `pInfos`[i].`scratchData` memories for the acceleration structure builds

- [[VUID-{refpage}-None-03409]] There must not be any memory aliasing between memory bound to any top level, bottom level, or instance acceleration structure accessed by this command

- If `update` is `VK_FALSE`, all addresses between `pInfos`[i].`scratchData` and `pInfos`[i].`scratchData` + N - 1 must be in the buffer device address range of the same buffer, where N is given by the `size` member of the VkMemoryRequirements structure returned from a call to vkGetAccelerationStructureMemoryRequirementsKHR with VkAccelerationStructureMemoryRequirementsInfoKHR::`accelerationStructure` set to `pInfos`[i].`dstAccelerationStructure` and VkAccelerationStructureMemoryRequirementsInfoKHR::`type` set to `VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_KHR`

- If `update` is `VK_TRUE`, all addresses between `pInfos`[i].`scratchData` and `pInfos`[i].`scratchData` + N - 1 must be in the buffer device address range of the same buffer, where N is given by the `size` member of the VkMemoryRequirements structure returned from a call to vkGetAccelerationStructureMemoryRequirementsKHR with VkAccelerationStructureMemoryRequirementsInfoKHR::`accelerationStructure` set to `pInfos`[i].`dstAccelerationStructure` and VkAccelerationStructureMemoryRequirementsInfoKHR::`type` set to `VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_KHR`

- The buffer from which the buffer device address `pInfos`[i].`scratchData` is queried must have been created with `VK_BUFFER_USAGE_RAY_TRACING_BIT_KHR` usage flag

- All VkDeviceOrHostAddressKHR or VkDeviceOrHostAddressConstKHR referenced by this command must contain valid device addresses

- All `VkAccelerationStructureKHR` objects referenced by this command must be bound to device memory

- The VkDeferredOperationInfoKHR structure must not be included in the `pNext` chain of any of the provided VkAccelerationStructureBuildGeometryInfoKHR structures.

Valid Usage (Implicit)

- `commandBuffer` must be a valid VkCommandBuffer handle

- `pInfos` must be a valid pointer to an array of `infoCount` valid VkAccelerationStructureBuildGeometryInfoKHR structures

- `ppOffsetInfos` must be a valid pointer to an array of `infoCount` VkAccelerationStructureBuildOffsetInfoKHR structures

- `commandBuffer` must be in the recording state

- The `VkCommandPool` that `commandBuffer` was allocated from must support compute operations

- This command must only be called outside of a render pass instance

- `infoCount` must be greater than `0`

Host Synchronization

- Host access to the `VkCommandPool` that `commandBuffer` was allocated from must be externally synchronized

Command Properties

Command Buffer Levels | Render Pass Scope | Supported Queue Types | Pipeline Type
--- | --- | --- | ---
Primary Secondary | Outside | Compute |

## See Also

VkAccelerationStructureBuildGeometryInfoKHR, VkAccelerationStructureBuildOffsetInfoKHR, VkCommandBuffer

## Document Notes

For more information, see the Vulkan Specification

This page is extracted from the Vulkan Specification. Fixes and changes should be made to the Specification, not directly.

## Copyright

Copyright (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.