vkCmdBuildAccelerationStructureKHR(3)

# vkCmdBuildAccelerationStructureKHR(3) Manual Page

## Name

vkCmdBuildAccelerationStructureKHR - Build an acceleration structure

Loading… please wait.

## C Specification

To build acceleration structures call:

    // Provided by VK_KHR_ray_tracing
    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.

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` or `VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR`.

Valid Usage

- VUID-vkCmdBuildAccelerationStructureKHR-pOffsetInfos-03402
  Each element of `ppOffsetInfos`[i] must be a valid pointer to an array of `pInfos`[i].`geometryCount` `VkAccelerationStructureBuildOffsetInfoKHR` structures

- VUID-vkCmdBuildAccelerationStructureKHR-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-vkCmdBuildAccelerationStructureKHR-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-vkCmdBuildAccelerationStructureKHR-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-vkCmdBuildAccelerationStructureKHR-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-vkCmdBuildAccelerationStructureKHR-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-vkCmdBuildAccelerationStructureKHR-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-vkCmdBuildAccelerationStructureKHR-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

- VUID-vkCmdBuildAccelerationStructureKHR-update-03527
  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`

- VUID-vkCmdBuildAccelerationStructureKHR-update-03528
  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`

- VUID-vkCmdBuildAccelerationStructureKHR-pInfos-03529
  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

- VUID-vkCmdBuildAccelerationStructureKHR-None-04046
  All VkDeviceOrHostAddressKHR or VkDeviceOrHostAddressConstKHR referenced by this command must contain valid device addresses for a buffer bound to device memory. If the buffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

- VUID-vkCmdBuildAccelerationStructureKHR-None-03531
  All `VkAccelerationStructureKHR` objects referenced by this command must be bound to device memory

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

Valid Usage (Implicit)

- VUID-vkCmdBuildAccelerationStructureKHR-commandBuffer-parameter
  `commandBuffer` must be a valid VkCommandBuffer handle

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

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

- VUID-vkCmdBuildAccelerationStructureKHR-commandBuffer-recording
  `commandBuffer` must be in the recording state

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

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

- VUID-vkCmdBuildAccelerationStructureKHR-infoCount-arraylength
  `infoCount` must be greater than `0`

Host Synchronization

- Host access to `commandBuffer` must be externally synchronized

- 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 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0