34. Ray Tracing

Ray tracing uses a separate rendering pipeline from both the graphics and compute pipelines (see Ray Tracing Pipeline).

image/svg+xml Any-Hit Intersection Hit? Closest Hit Miss Y N RayGeneration AccelerationStructureTraversal
Figure 24. Ray tracing pipeline execution
Caption

Interaction between the different shader stages in the ray tracing pipeline

Within the ray tracing pipeline, OpTraceRayKHR can be called to perform a ray traversal that invokes the various ray tracing shader stages during its execution. The relationship between the ray tracing pipeline object and the geometries present in the acceleration structure traversed is passed into the ray tracing command in a VkBuffer object known as a shader binding table. OpExecuteCallableKHR can also be used in ray tracing pipelines to invoke a callable shader.

During execution, control alternates between scheduling and other operations. The scheduling functionality is implementation-specific and is responsible for workload execution. The shader stages are programmable. Traversal, which refers to the process of traversing acceleration structures to find potential intersections of rays with geometry, is fixed function.

The programmable portions of the pipeline are exposed in a single-ray programming model, with each invocation handling one ray at a time. Memory operations can be synchronized using standard memory barriers. The Workgroup scope and variables with a storage class of Workgroup must not be used in the ray tracing pipeline.

34.1. Shader Call Instructions

A shader call is an instruction which may cause execution to continue elsewhere by creating one or more invocations that execute a different shader stage.

The shader call instructions are:

  • OpTraceRayKHR which may invoke intersection, any-hit, closest hit, or miss shaders,

  • OpReportIntersectionKHR which may invoke any-hit shaders, and

  • OpExecuteCallableKHR which will invoke a callable shader.

The invocations created by shader call instructions are grouped into subgroups by the implementation. Those subgroups may be unrelated to the subgroup of the parent invocation.

Pipeline trace ray instructions can be used recursively; invoked shaders can themselves execute pipeline trace ray instructions, to a maximum depth defined by the maxRayRecursionDepth limit.

Shaders directly invoked from the API always have a recursion depth of 0; each shader executed by a pipeline trace ray instruction has a recursion depth one higher than the recursion depth of the shader which invoked it. Applications must not invoke a shader with a recursion depth greater than the value of maxPipelineRayRecursionDepth specified in the pipeline.

There is no explicit recursion limit for other shader call instructions which may recurse (e.g. OpExecuteCallableKHR) but there is an upper bound determined by the stack size.

An invocation repack instruction is a ray tracing shader call instruction where the implementation may change the set of invocations that are executing. When a repack instruction is encountered, the invocation is suspended and a new invocation begins and executes the instruction. After executing the repack instruction (which may result in other ray tracing shader stages executing) the new invocation ends and the original invocation is resumed, but it may be resumed in a different subgroup or at a different SubgroupLocalInvocationId within the same subgroup. When a subset of invocations in a subgroup execute the invocation repack instruction, those that do not execute it remain in the same subgroup at the same SubgroupLocalInvocationId.

The OpTraceRayKHR, OpReportIntersectionKHR, and OpExecuteCallableKHR instructions are invocation repack instructions.

The invocations that are executing before an invocation repack instruction, after the instruction, or are created by the instruction, are shader-call-related.

If the implementation changes the composition of subgroups, the values of SubgroupSize, SubgroupLocalInvocationId, and builtin variables that are derived from them (SubgroupEqMask, SubgroupGeMask, SubgroupGtMask, SubgroupLeMask, SubgroupLtMask) must be changed accordingly by the invocation repack instruction. The application must use Volatile semantics on these BuiltIn variables when used in the ray generation, closest hit, miss, intersection, and callable shaders. Similarly, the application must use Volatile semantics on any RayTmaxKHR decorated Builtin used in an intersection shader.

Note

Subgroup operations are permitted in the programmable ray tracing shader stages. However, shader call instructions place a bound on where results of subgroup instructions or subgroup-scoped instructions that execute the dynamic instance of that instruction are potentially valid. For example, care must be taken when using the result of a ballot operation that was computed before an invocation repack instruction, after that repack instruction. The ballot may be incorrect as the set of invocations could have changed.

For clock operations, the value of a Subgroup scoped OpReadClockKHR read before the dynamic instance of a repack instruction should not be compared to the result of that clock instruction after the repack instruction.

When a ray tracing shader executes a dynamic instance of an invocation repack instruction which results in another ray tracing shader being invoked, their instructions are related by shader-call-order.

For ray tracing invocations that are shader-call-related:

  • memory operations on StorageBuffer, Image, and ShaderRecordBufferKHR storage classes can be synchronized using the ShaderCallKHR scope.

  • the CallableDataKHR, IncomingCallableDataKHR, RayPayloadKHR, HitAttributeKHR, and IncomingRayPayloadKHR storage classes are system-synchronized and no application availability and visibility operations are required.

  • memory operations within a single invocation before and after the invocation repack instruction are ordered by program-order and do not require explicit synchronzation.

34.2. Ray Tracing Commands

Ray tracing commands provoke work in the ray tracing pipeline. Ray tracing commands are recorded into a command buffer and when executed by a queue will produce work that executes according to the currently bound ray tracing pipeline. A ray tracing pipeline must be bound to a command buffer before any ray tracing commands are recorded in that command buffer.

To dispatch ray tracing use:

// Provided by VK_KHR_ray_tracing_pipeline
void vkCmdTraceRaysKHR(
    VkCommandBuffer                             commandBuffer,
    const VkStridedDeviceAddressRegionKHR*      pRaygenShaderBindingTable,
    const VkStridedDeviceAddressRegionKHR*      pMissShaderBindingTable,
    const VkStridedDeviceAddressRegionKHR*      pHitShaderBindingTable,
    const VkStridedDeviceAddressRegionKHR*      pCallableShaderBindingTable,
    uint32_t                                    width,
    uint32_t                                    height,
    uint32_t                                    depth);
  • commandBuffer is the command buffer into which the command will be recorded.

  • pRaygenShaderBindingTable is a VkStridedDeviceAddressRegionKHR that holds the shader binding table data for the ray generation shader stage.

  • pMissShaderBindingTable is a VkStridedDeviceAddressRegionKHR that holds the shader binding table data for the miss shader stage.

  • pHitShaderBindingTable is a VkStridedDeviceAddressRegionKHR that holds the shader binding table data for the hit shader stage.

  • pCallableShaderBindingTable is a VkStridedDeviceAddressRegionKHR that holds the shader binding table data for the callable shader stage.

  • width is the width of the ray trace query dimensions.

  • height is height of the ray trace query dimensions.

  • depth is depth of the ray trace query dimensions.

When the command is executed, a ray generation group of width × height × depth rays is assembled.

Valid Usage
  • VUID-vkCmdTraceRaysKHR-magFilter-04553
    If a VkSampler created with magFilter or minFilter equal to VK_FILTER_LINEAR and compareEnable equal to VK_FALSE is used to sample a VkImageView as a result of this command, then the image view’s format features must contain VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT

  • VUID-vkCmdTraceRaysKHR-mipmapMode-04770
    If a VkSampler created with mipmapMode equal to VK_SAMPLER_MIPMAP_MODE_LINEAR and compareEnable equal to VK_FALSE is used to sample a VkImageView as a result of this command, then the image view’s format features must contain VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT

  • VUID-vkCmdTraceRaysKHR-None-02691
    If a VkImageView is accessed using atomic operations as a result of this command, then the image view’s format features must contain VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT

  • VUID-vkCmdTraceRaysKHR-None-02697
    For each set n that is statically used by the VkPipeline bound to the pipeline bind point used by this command, a descriptor set must have been bound to n at the same pipeline bind point, with a VkPipelineLayout that is compatible for set n, with the VkPipelineLayout used to create the current VkPipeline, as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysKHR-None-02698
    For each push constant that is statically used by the VkPipeline bound to the pipeline bind point used by this command, a push constant value must have been set for the same pipeline bind point, with a VkPipelineLayout that is compatible for push constants, with the VkPipelineLayout used to create the current VkPipeline, as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysKHR-None-02699
    Descriptors in each bound descriptor set, specified via vkCmdBindDescriptorSets, must be valid if they are statically used by the VkPipeline bound to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysKHR-None-02700
    A valid pipeline must be bound to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysKHR-commandBuffer-02701
    If the VkPipeline object bound to the pipeline bind point used by this command requires any dynamic state, that state must have been set or inherited (if the [VK_NV_inherited_viewport_scissor] extension is enabled) for commandBuffer, and done so after any previously bound pipeline with the corresponding state not specified as dynamic

  • VUID-vkCmdTraceRaysKHR-None-02859
    There must not have been any calls to dynamic state setting commands for any state not specified as dynamic in the VkPipeline object bound to the pipeline bind point used by this command, since that pipeline was bound

  • VUID-vkCmdTraceRaysKHR-None-02702
    If the VkPipeline object bound to the pipeline bind point used by this command accesses a VkSampler object that uses unnormalized coordinates, that sampler must not be used to sample from any VkImage with a VkImageView of the type VK_IMAGE_VIEW_TYPE_3D, VK_IMAGE_VIEW_TYPE_CUBE, VK_IMAGE_VIEW_TYPE_1D_ARRAY, VK_IMAGE_VIEW_TYPE_2D_ARRAY or VK_IMAGE_VIEW_TYPE_CUBE_ARRAY, in any shader stage

  • VUID-vkCmdTraceRaysKHR-None-02703
    If the VkPipeline object bound to the pipeline bind point used by this command accesses a VkSampler object that uses unnormalized coordinates, that sampler must not be used with any of the SPIR-V OpImageSample* or OpImageSparseSample* instructions with ImplicitLod, Dref or Proj in their name, in any shader stage

  • VUID-vkCmdTraceRaysKHR-None-02704
    If the VkPipeline object bound to the pipeline bind point used by this command accesses a VkSampler object that uses unnormalized coordinates, that sampler must not be used with any of the SPIR-V OpImageSample* or OpImageSparseSample* instructions that includes a LOD bias or any offset values, in any shader stage

  • VUID-vkCmdTraceRaysKHR-None-02705
    If the robust buffer access feature is not enabled, and if the VkPipeline object bound to the pipeline bind point used by this command accesses a uniform buffer, it must not access values outside of the range of the buffer as specified in the descriptor set bound to the same pipeline bind point

  • VUID-vkCmdTraceRaysKHR-None-02706
    If the robust buffer access feature is not enabled, and if the VkPipeline object bound to the pipeline bind point used by this command accesses a storage buffer, it must not access values outside of the range of the buffer as specified in the descriptor set bound to the same pipeline bind point

  • VUID-vkCmdTraceRaysKHR-commandBuffer-02707
    If commandBuffer is an unprotected command buffer, any resource accessed by the VkPipeline object bound to the pipeline bind point used by this command must not be a protected resource

  • VUID-vkCmdTraceRaysKHR-None-04115
    If a VkImageView is accessed using OpImageWrite as a result of this command, then the Type of the Texel operand of that instruction must have at least as many components as the image view’s format

  • VUID-vkCmdTraceRaysKHR-OpImageWrite-04469
    If a VkBufferView is accessed using OpImageWrite as a result of this command, then the Type of the Texel operand of that instruction must have at least as many components as the buffer view’s format

  • VUID-vkCmdTraceRaysKHR-None-03429
    Any shader group handle referenced by this call must have been queried from the currently bound ray tracing pipeline

  • VUID-vkCmdTraceRaysKHR-maxPipelineRayRecursionDepth-03679
    This command must not cause a shader call instruction to be executed from a shader invocation with a recursion depth greater than the value of maxPipelineRayRecursionDepth used to create the bound ray tracing pipeline

  • VUID-vkCmdTraceRaysKHR-pRayGenShaderBindingTable-03680
    If the buffer from which pRayGenShaderBindingTable->deviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysKHR-pRayGenShaderBindingTable-03681
    The buffer from which the pRayGenShaderBindingTable->deviceAddress is queried must have been created with the VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR usage flag

  • VUID-vkCmdTraceRaysKHR-pRayGenShaderBindingTable-03682
    pRayGenShaderBindingTable->deviceAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-vkCmdTraceRaysKHR-size-04023
    The size member of pRayGenShaderBindingTable must be equal to its stride member

  • VUID-vkCmdTraceRaysKHR-pMissShaderBindingTable-03683
    If the buffer from which pMissShaderBindingTable->deviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysKHR-pMissShaderBindingTable-03684
    The buffer from which the pMissShaderBindingTable->deviceAddress is queried must have been created with the VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR usage flag

  • VUID-vkCmdTraceRaysKHR-pMissShaderBindingTable-03685
    pMissShaderBindingTable->deviceAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-vkCmdTraceRaysKHR-stride-03686
    The stride member of pMissShaderBindingTable must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysKHR-stride-04029
    The stride member of pMissShaderBindingTable must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

  • VUID-vkCmdTraceRaysKHR-pHitShaderBindingTable-03687
    If the buffer from which pHitShaderBindingTable->deviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysKHR-pHitShaderBindingTable-03688
    The buffer from which the pHitShaderBindingTable->deviceAddress is queried must have been created with the VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR usage flag

  • VUID-vkCmdTraceRaysKHR-pHitShaderBindingTable-03689
    pHitShaderBindingTable->deviceAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-vkCmdTraceRaysKHR-stride-03690
    The stride member of pHitShaderBindingTable must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysKHR-stride-04035
    The stride member of pHitShaderBindingTable must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

  • VUID-vkCmdTraceRaysKHR-pCallableShaderBindingTable-03691
    If the buffer from which pCallableShaderBindingTable->deviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysKHR-pCallableShaderBindingTable-03692
    The buffer from which the pCallableShaderBindingTable->deviceAddress is queried must have been created with the VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR usage flag

  • VUID-vkCmdTraceRaysKHR-pCallableShaderBindingTable-03693
    pCallableShaderBindingTable->deviceAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-vkCmdTraceRaysKHR-stride-03694
    The stride member of pCallableShaderBindingTable must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysKHR-stride-04041
    The stride member of pCallableShaderBindingTable must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

  • VUID-vkCmdTraceRaysKHR-flags-03696
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR, the deviceAddress member of pHitShaderBindingTable must not be zero

  • VUID-vkCmdTraceRaysKHR-flags-03697
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR, the deviceAddress member of pHitShaderBindingTable must not be zero

  • VUID-vkCmdTraceRaysKHR-flags-03511
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR, the shader group handle identified by pMissShaderBindingTable must not be set to zero

  • VUID-vkCmdTraceRaysKHR-flags-03512
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR, entries in pHitShaderBindingTable accessed as a result of this command in order to execute an any-hit shader must not be set to zero

  • VUID-vkCmdTraceRaysKHR-flags-03513
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR, entries in pHitShaderBindingTable accessed as a result of this command in order to execute a closest hit shader must not be set to zero

  • VUID-vkCmdTraceRaysKHR-flags-03514
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR, entries in pHitShaderBindingTable accessed as a result of this command in order to execute an intersection shader must not be set to zero

  • VUID-vkCmdTraceRaysKHR-pHitShaderBindingTable-04735
    Any non-zero hit shader group entries in pHitShaderBindingTable accessed by this call from a geometry with a geometryType of VK_GEOMETRY_TYPE_TRIANGLES_KHR must have been created with VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR

  • VUID-vkCmdTraceRaysKHR-pHitShaderBindingTable-04736
    Any non-zero hit shader group entries in pHitShaderBindingTable accessed by this call from a geometry with a geometryType of VK_GEOMETRY_TYPE_AABBS_KHR must have been created with VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR

  • VUID-vkCmdTraceRaysKHR-commandBuffer-04625
    commandBuffer must not be a protected command buffer

  • VUID-vkCmdTraceRaysKHR-width-03626
    width must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0] × VkPhysicalDeviceLimits::maxComputeWorkGroupSize[0]

  • VUID-vkCmdTraceRaysKHR-height-03627
    height must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[1] × VkPhysicalDeviceLimits::maxComputeWorkGroupSize[1]

  • VUID-vkCmdTraceRaysKHR-depth-03628
    depth must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2] × VkPhysicalDeviceLimits::maxComputeWorkGroupSize[2]

  • VUID-vkCmdTraceRaysKHR-width-03629
    width × height × depth must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxRayDispatchInvocationCount

Valid Usage (Implicit)
  • VUID-vkCmdTraceRaysKHR-commandBuffer-parameter
    commandBuffer must be a valid VkCommandBuffer handle

  • VUID-vkCmdTraceRaysKHR-pRaygenShaderBindingTable-parameter
    pRaygenShaderBindingTable must be a valid pointer to a valid VkStridedDeviceAddressRegionKHR structure

  • VUID-vkCmdTraceRaysKHR-pMissShaderBindingTable-parameter
    pMissShaderBindingTable must be a valid pointer to a valid VkStridedDeviceAddressRegionKHR structure

  • VUID-vkCmdTraceRaysKHR-pHitShaderBindingTable-parameter
    pHitShaderBindingTable must be a valid pointer to a valid VkStridedDeviceAddressRegionKHR structure

  • VUID-vkCmdTraceRaysKHR-pCallableShaderBindingTable-parameter
    pCallableShaderBindingTable must be a valid pointer to a valid VkStridedDeviceAddressRegionKHR structure

  • VUID-vkCmdTraceRaysKHR-commandBuffer-recording
    commandBuffer must be in the recording state

  • VUID-vkCmdTraceRaysKHR-commandBuffer-cmdpool
    The VkCommandPool that commandBuffer was allocated from must support compute operations

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

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

Primary
Secondary

Outside

Compute

The VkStridedDeviceAddressRegionKHR structure is defined as:

// Provided by VK_KHR_ray_tracing_pipeline
typedef struct VkStridedDeviceAddressRegionKHR {
    VkDeviceAddress    deviceAddress;
    VkDeviceSize       stride;
    VkDeviceSize       size;
} VkStridedDeviceAddressRegionKHR;
  • deviceAddress is the device address (as returned by the vkGetBufferDeviceAddress command) at which the region starts, or zero if the region is unused.

  • stride is the byte stride between consecutive elements.

  • size is the size in bytes of the region starting at deviceAddress.

Valid Usage
  • VUID-VkStridedDeviceAddressRegionKHR-size-04631
    If size is not zero, all addresses between deviceAddress and deviceAddress + size - 1 must be in the buffer device address range of the same buffer

  • VUID-VkStridedDeviceAddressRegionKHR-size-04632
    If size is not zero, stride must be less than or equal to the size of the buffer from which deviceAddress was queried

To dispatch ray tracing, with some parameters sourced on the device, use:

// Provided by VK_KHR_ray_tracing_pipeline
void vkCmdTraceRaysIndirectKHR(
    VkCommandBuffer                             commandBuffer,
    const VkStridedDeviceAddressRegionKHR*      pRaygenShaderBindingTable,
    const VkStridedDeviceAddressRegionKHR*      pMissShaderBindingTable,
    const VkStridedDeviceAddressRegionKHR*      pHitShaderBindingTable,
    const VkStridedDeviceAddressRegionKHR*      pCallableShaderBindingTable,
    VkDeviceAddress                             indirectDeviceAddress);

vkCmdTraceRaysIndirectKHR behaves similarly to vkCmdTraceRaysKHR except that the ray trace query dimensions are read by the device from indirectDeviceAddress during execution.

Valid Usage
  • VUID-vkCmdTraceRaysIndirectKHR-magFilter-04553
    If a VkSampler created with magFilter or minFilter equal to VK_FILTER_LINEAR and compareEnable equal to VK_FALSE is used to sample a VkImageView as a result of this command, then the image view’s format features must contain VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-mipmapMode-04770
    If a VkSampler created with mipmapMode equal to VK_SAMPLER_MIPMAP_MODE_LINEAR and compareEnable equal to VK_FALSE is used to sample a VkImageView as a result of this command, then the image view’s format features must contain VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-None-02691
    If a VkImageView is accessed using atomic operations as a result of this command, then the image view’s format features must contain VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-None-02697
    For each set n that is statically used by the VkPipeline bound to the pipeline bind point used by this command, a descriptor set must have been bound to n at the same pipeline bind point, with a VkPipelineLayout that is compatible for set n, with the VkPipelineLayout used to create the current VkPipeline, as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysIndirectKHR-None-02698
    For each push constant that is statically used by the VkPipeline bound to the pipeline bind point used by this command, a push constant value must have been set for the same pipeline bind point, with a VkPipelineLayout that is compatible for push constants, with the VkPipelineLayout used to create the current VkPipeline, as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysIndirectKHR-None-02699
    Descriptors in each bound descriptor set, specified via vkCmdBindDescriptorSets, must be valid if they are statically used by the VkPipeline bound to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysIndirectKHR-None-02700
    A valid pipeline must be bound to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysIndirectKHR-commandBuffer-02701
    If the VkPipeline object bound to the pipeline bind point used by this command requires any dynamic state, that state must have been set or inherited (if the [VK_NV_inherited_viewport_scissor] extension is enabled) for commandBuffer, and done so after any previously bound pipeline with the corresponding state not specified as dynamic

  • VUID-vkCmdTraceRaysIndirectKHR-None-02859
    There must not have been any calls to dynamic state setting commands for any state not specified as dynamic in the VkPipeline object bound to the pipeline bind point used by this command, since that pipeline was bound

  • VUID-vkCmdTraceRaysIndirectKHR-None-02702
    If the VkPipeline object bound to the pipeline bind point used by this command accesses a VkSampler object that uses unnormalized coordinates, that sampler must not be used to sample from any VkImage with a VkImageView of the type VK_IMAGE_VIEW_TYPE_3D, VK_IMAGE_VIEW_TYPE_CUBE, VK_IMAGE_VIEW_TYPE_1D_ARRAY, VK_IMAGE_VIEW_TYPE_2D_ARRAY or VK_IMAGE_VIEW_TYPE_CUBE_ARRAY, in any shader stage

  • VUID-vkCmdTraceRaysIndirectKHR-None-02703
    If the VkPipeline object bound to the pipeline bind point used by this command accesses a VkSampler object that uses unnormalized coordinates, that sampler must not be used with any of the SPIR-V OpImageSample* or OpImageSparseSample* instructions with ImplicitLod, Dref or Proj in their name, in any shader stage

  • VUID-vkCmdTraceRaysIndirectKHR-None-02704
    If the VkPipeline object bound to the pipeline bind point used by this command accesses a VkSampler object that uses unnormalized coordinates, that sampler must not be used with any of the SPIR-V OpImageSample* or OpImageSparseSample* instructions that includes a LOD bias or any offset values, in any shader stage

  • VUID-vkCmdTraceRaysIndirectKHR-None-02705
    If the robust buffer access feature is not enabled, and if the VkPipeline object bound to the pipeline bind point used by this command accesses a uniform buffer, it must not access values outside of the range of the buffer as specified in the descriptor set bound to the same pipeline bind point

  • VUID-vkCmdTraceRaysIndirectKHR-None-02706
    If the robust buffer access feature is not enabled, and if the VkPipeline object bound to the pipeline bind point used by this command accesses a storage buffer, it must not access values outside of the range of the buffer as specified in the descriptor set bound to the same pipeline bind point

  • VUID-vkCmdTraceRaysIndirectKHR-commandBuffer-02707
    If commandBuffer is an unprotected command buffer, any resource accessed by the VkPipeline object bound to the pipeline bind point used by this command must not be a protected resource

  • VUID-vkCmdTraceRaysIndirectKHR-None-04115
    If a VkImageView is accessed using OpImageWrite as a result of this command, then the Type of the Texel operand of that instruction must have at least as many components as the image view’s format

  • VUID-vkCmdTraceRaysIndirectKHR-OpImageWrite-04469
    If a VkBufferView is accessed using OpImageWrite as a result of this command, then the Type of the Texel operand of that instruction must have at least as many components as the buffer view’s format

  • VUID-vkCmdTraceRaysIndirectKHR-None-03429
    Any shader group handle referenced by this call must have been queried from the currently bound ray tracing pipeline

  • VUID-vkCmdTraceRaysIndirectKHR-maxPipelineRayRecursionDepth-03679
    This command must not cause a shader call instruction to be executed from a shader invocation with a recursion depth greater than the value of maxPipelineRayRecursionDepth used to create the bound ray tracing pipeline

  • VUID-vkCmdTraceRaysIndirectKHR-pRayGenShaderBindingTable-03680
    If the buffer from which pRayGenShaderBindingTable->deviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysIndirectKHR-pRayGenShaderBindingTable-03681
    The buffer from which the pRayGenShaderBindingTable->deviceAddress is queried must have been created with the VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR usage flag

  • VUID-vkCmdTraceRaysIndirectKHR-pRayGenShaderBindingTable-03682
    pRayGenShaderBindingTable->deviceAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-size-04023
    The size member of pRayGenShaderBindingTable must be equal to its stride member

  • VUID-vkCmdTraceRaysIndirectKHR-pMissShaderBindingTable-03683
    If the buffer from which pMissShaderBindingTable->deviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysIndirectKHR-pMissShaderBindingTable-03684
    The buffer from which the pMissShaderBindingTable->deviceAddress is queried must have been created with the VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR usage flag

  • VUID-vkCmdTraceRaysIndirectKHR-pMissShaderBindingTable-03685
    pMissShaderBindingTable->deviceAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-03686
    The stride member of pMissShaderBindingTable must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-04029
    The stride member of pMissShaderBindingTable must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

  • VUID-vkCmdTraceRaysIndirectKHR-pHitShaderBindingTable-03687
    If the buffer from which pHitShaderBindingTable->deviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysIndirectKHR-pHitShaderBindingTable-03688
    The buffer from which the pHitShaderBindingTable->deviceAddress is queried must have been created with the VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR usage flag

  • VUID-vkCmdTraceRaysIndirectKHR-pHitShaderBindingTable-03689
    pHitShaderBindingTable->deviceAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-03690
    The stride member of pHitShaderBindingTable must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-04035
    The stride member of pHitShaderBindingTable must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

  • VUID-vkCmdTraceRaysIndirectKHR-pCallableShaderBindingTable-03691
    If the buffer from which pCallableShaderBindingTable->deviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysIndirectKHR-pCallableShaderBindingTable-03692
    The buffer from which the pCallableShaderBindingTable->deviceAddress is queried must have been created with the VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR usage flag

  • VUID-vkCmdTraceRaysIndirectKHR-pCallableShaderBindingTable-03693
    pCallableShaderBindingTable->deviceAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-03694
    The stride member of pCallableShaderBindingTable must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-04041
    The stride member of pCallableShaderBindingTable must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

  • VUID-vkCmdTraceRaysIndirectKHR-flags-03696
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR, the deviceAddress member of pHitShaderBindingTable must not be zero

  • VUID-vkCmdTraceRaysIndirectKHR-flags-03697
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR, the deviceAddress member of pHitShaderBindingTable must not be zero

  • VUID-vkCmdTraceRaysIndirectKHR-flags-03511
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR, the shader group handle identified by pMissShaderBindingTable must not be set to zero

  • VUID-vkCmdTraceRaysIndirectKHR-flags-03512
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR, entries in pHitShaderBindingTable accessed as a result of this command in order to execute an any-hit shader must not be set to zero

  • VUID-vkCmdTraceRaysIndirectKHR-flags-03513
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR, entries in pHitShaderBindingTable accessed as a result of this command in order to execute a closest hit shader must not be set to zero

  • VUID-vkCmdTraceRaysIndirectKHR-flags-03514
    If the currently bound ray tracing pipeline was created with flags that included VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR, entries in pHitShaderBindingTable accessed as a result of this command in order to execute an intersection shader must not be set to zero

  • VUID-vkCmdTraceRaysIndirectKHR-pHitShaderBindingTable-04735
    Any non-zero hit shader group entries in pHitShaderBindingTable accessed by this call from a geometry with a geometryType of VK_GEOMETRY_TYPE_TRIANGLES_KHR must have been created with VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR

  • VUID-vkCmdTraceRaysIndirectKHR-pHitShaderBindingTable-04736
    Any non-zero hit shader group entries in pHitShaderBindingTable accessed by this call from a geometry with a geometryType of VK_GEOMETRY_TYPE_AABBS_KHR must have been created with VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR

  • VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03632
    If the buffer from which indirectDeviceAddress was queried is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object

  • VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03633
    The buffer from which indirectDeviceAddress was queried must have been created with the VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT bit set

  • VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03634
    indirectDeviceAddress must be a multiple of 4

  • VUID-vkCmdTraceRaysIndirectKHR-commandBuffer-03635
    commandBuffer must not be a protected command buffer

  • VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03636
    All device addresses between indirectDeviceAddress and indirectDeviceAddress + sizeof(VkTraceRaysIndirectCommandKHR) - 1 must be in the buffer device address range of the same buffer

  • VUID-vkCmdTraceRaysIndirectKHR-rayTracingPipelineTraceRaysIndirect-03637
    The VkPhysicalDeviceRayTracingPipelineFeaturesKHR::rayTracingPipelineTraceRaysIndirect feature must be enabled

Valid Usage (Implicit)
  • VUID-vkCmdTraceRaysIndirectKHR-commandBuffer-parameter
    commandBuffer must be a valid VkCommandBuffer handle

  • VUID-vkCmdTraceRaysIndirectKHR-pRaygenShaderBindingTable-parameter
    pRaygenShaderBindingTable must be a valid pointer to a valid VkStridedDeviceAddressRegionKHR structure

  • VUID-vkCmdTraceRaysIndirectKHR-pMissShaderBindingTable-parameter
    pMissShaderBindingTable must be a valid pointer to a valid VkStridedDeviceAddressRegionKHR structure

  • VUID-vkCmdTraceRaysIndirectKHR-pHitShaderBindingTable-parameter
    pHitShaderBindingTable must be a valid pointer to a valid VkStridedDeviceAddressRegionKHR structure

  • VUID-vkCmdTraceRaysIndirectKHR-pCallableShaderBindingTable-parameter
    pCallableShaderBindingTable must be a valid pointer to a valid VkStridedDeviceAddressRegionKHR structure

  • VUID-vkCmdTraceRaysIndirectKHR-commandBuffer-recording
    commandBuffer must be in the recording state

  • VUID-vkCmdTraceRaysIndirectKHR-commandBuffer-cmdpool
    The VkCommandPool that commandBuffer was allocated from must support compute operations

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

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

Primary
Secondary

Outside

Compute

The VkTraceRaysIndirectCommandKHR structure is defined as:

// Provided by VK_KHR_ray_tracing_pipeline
typedef struct VkTraceRaysIndirectCommandKHR {
    uint32_t    width;
    uint32_t    height;
    uint32_t    depth;
} VkTraceRaysIndirectCommandKHR;
  • width is the width of the ray trace query dimensions.

  • height is height of the ray trace query dimensions.

  • depth is depth of the ray trace query dimensions.

The members of VkTraceRaysIndirectCommandKHR have the same meaning as the similarly named parameters of vkCmdTraceRaysKHR.

Valid Usage
  • VUID-VkTraceRaysIndirectCommandKHR-width-03638
    width must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0] × VkPhysicalDeviceLimits::maxComputeWorkGroupSize[0]

  • VUID-VkTraceRaysIndirectCommandKHR-height-03639
    height must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[1] × VkPhysicalDeviceLimits::maxComputeWorkGroupSize[1]

  • VUID-VkTraceRaysIndirectCommandKHR-depth-03640
    depth must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2] × VkPhysicalDeviceLimits::maxComputeWorkGroupSize[2]

  • VUID-VkTraceRaysIndirectCommandKHR-width-03641
    width × height × depth must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxRayDispatchInvocationCount

34.3. Shader Binding Table

A shader binding table is a resource which establishes the relationship between the ray tracing pipeline and the acceleration structures that were built for the ray tracing pipeline. It indicates the shaders that operate on each geometry in an acceleration structure. In addition, it contains the resources accessed by each shader, including indices of textures, buffer device addresses, and constants. The application allocates and manages shader binding tables as VkBuffer objects.

Each entry in the shader binding table consists of shaderGroupHandleSize bytes of data, either as queried by vkGetRayTracingShaderGroupHandlesKHR to refer to those specified shaders, or all zeros to refer to a zero shader group. A zero shader group behaves as though it is a shader group consisting entirely of VK_SHADER_UNUSED_KHR. The remainder of the data specified by the stride is application-visible data that can be referenced by a ShaderRecordBufferKHR block in the shader.

The shader binding tables to use in a ray tracing pipeline are passed to the vkCmdTraceRaysKHR, or vkCmdTraceRaysIndirectKHR commands. Shader binding tables are read-only in shaders that are executing on the ray tracing pipeline.

Shader variables identified with the ShaderRecordBufferKHR storage class are used to access the provided shader binding table. Such variables must be:

  • typed as OpTypeStruct, or an array of this type,

  • identified with a Block decoration, and

  • laid out explicitly using the Offset, ArrayStride, and MatrixStride decorations as specified in Offset and Stride Assignment.

The Offset decoration for any member of a Block-decorated variable in the ShaderRecordBufferKHR storage class must not cause the space required for that variable to extend outside the range [0, maxStorageBufferRange).

Accesses to the shader binding table from ray tracing pipelines must be synchronized with the VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR pipeline stage and an access type of VK_ACCESS_SHADER_READ_BIT.

Note

Because different shader record buffers can be associated with the same shader, a shader variable with ShaderRecordBufferKHR storage class will not be dynamically uniform if different invocations of the same shader can reference different data in the shader record buffer, such as if the same shader occurs twice in the shader binding table with a different shader record buffer. In this case, indexing resources based on values in the ShaderRecordBufferKHR storage class, the index should be decorated as NonUniform.

34.3.1. Indexing Rules

In order to execute the correct shaders and access the correct resources during a ray tracing dispatch, the implementation must be able to locate shader binding table entries at various stages of execution. This is accomplished by defining a set of indexing rules that compute shader binding table record positions relative to the buffer’s base address in memory. The application must organize the contents of the shader binding table’s memory in a way that application of the indexing rules will lead to correct records.

Ray Generation Shaders

Only one ray generation shader is executed per ray tracing dispatch.

For vkCmdTraceRaysKHR, the location of the ray generation shader is specified by the pRaygenShaderBindingTable->deviceAddress parameter — there is no indexing. All data accessed must be less than pRaygenShaderBindingTable->size bytes from deviceAddress. pRaygenShaderBindingTable->stride is unused, and must be equal to pRaygenShaderBindingTable->size.

Hit Shaders

The base for the computation of intersection, any-hit, and closest hit shader locations is the instanceShaderBindingTableRecordOffset value stored with each instance of a top-level acceleration structure (VkAccelerationStructureInstanceKHR). This value determines the beginning of the shader binding table records for a given instance.

In the following rule, geometryIndex refers to the geometry index of the intersected geometry within the instance.

The sbtRecordOffset and sbtRecordStride values are passed in as parameters to traceRayEXT() calls made in the shaders. See Section 8.19 (Ray Tracing Functions) of the OpenGL Shading Language Specification for more details. In SPIR-V, these correspond to the SBTOffset and SBTStride parameters to the OpTraceRayKHR instruction.

The result of this computation is then added to pHitShaderBindingTable->deviceAddress, a device address passed to vkCmdTraceRaysKHR .

For vkCmdTraceRaysKHR, the complete rule to compute a hit shader binding table record address in the pHitShaderBindingTable is:

pHitShaderBindingTable->deviceAddress + pHitShaderBindingTable->stride × ( instanceShaderBindingTableRecordOffset + geometryIndex × sbtRecordStride + sbtRecordOffset )

All data accessed must be less than pHitShaderBindingTable->size bytes from the base address.

Miss Shaders

A miss shader is executed whenever a ray query fails to find an intersection for the given scene geometry. Multiple miss shaders may be executed throughout a ray tracing dispatch.

The base for the computation of miss shader locations is pMissShaderBindingTable->deviceAddress, a device address passed into vkCmdTraceRaysKHR .

The missIndex value is passed in as a parameter to traceRayEXT() calls made in the shaders. See Section 8.19 (Ray Tracing Functions) of the OpenGL Shading Language Specification for more details. In SPIR-V, this corresponds to the MissIndex parameter to the OpTraceRayKHR instruction.

For vkCmdTraceRaysKHR, the complete rule to compute a miss shader binding table record address in the pMissShaderBindingTable is:

pMissShaderBindingTable->deviceAddress + pMissShaderBindingTable->stride × missIndex

All data accessed must be less than pMissShaderBindingTable->size bytes from the base address.

Callable Shaders

A callable shader is executed when requested by a ray tracing shader. Multiple callable shaders may be executed throughout a ray tracing dispatch.

The base for the computation of callable shader locations is pCallableShaderBindingTable->deviceAddress, a device address passed into vkCmdTraceRaysKHR .

The sbtRecordIndex value is passed in as a parameter to executeCallableEXT() calls made in the shaders. See Section 8.19 (Ray Tracing Functions) of the OpenGL Shading Language Specification for more details. In SPIR-V, this corresponds to the SBTIndex parameter to the OpExecuteCallableKHR instruction.

For vkCmdTraceRaysKHR, the complete rule to compute a callable shader binding table record address in the pCallableShaderBindingTable is:

pCallableShaderBindingTable->deviceAddress + pCallableShaderBindingTable->stride × sbtRecordIndex

All data accessed must be less than pCallableShaderBindingTable->size bytes from the base address.

34.4. Ray Tracing Pipeline Stack

Ray tracing pipelines have a potentially large set of shaders which may be invoked in various call chain combinations to perform ray tracing. To store parameters for a given shader execution, an implementation may use a stack of data in memory. This stack must be sized to the sum of the stack sizes of all shaders in any call chain executed by the application.

If the stack size is not set explicitly, the stack size for a pipeline is:

rayGenStackMax + min(1, maxPipelineRayRecursionDepth) × max(closestHitStackMax, missStackMax, intersectionStackMax + anyHitStackMax) + max(0, maxPipelineRayRecursionDepth-1) × max(closestHitStackMax, missStackMax) + 2 × callableStackMax

where rayGenStackMax, closestHitStackMax, missStackMax, anyHitStackMax, intersectionStackMax, and callableStackMax are the maximum stack values queried by the respective shader stages for any shaders in any shader groups defined by the pipeline.

This stack size is potentially significant, so an application may want to provide a more accurate stack size after pipeline compilation. The value that the application provides is the maximum value of the sum of all shaders in a call chain across all possible call chains, taking into account any application specific knowledge about the properties of the call chains.

Note

For example, if an application has two types of closest hit and miss shaders that it can use but the first level of rays will only use the first kind (possibly reflection) and the second level will only use the second kind (occlusion or shadow ray, for example) then the application can compute the stack size by something similar to:

rayGenStack + max(closestHit1Stack, miss1Stack) + max(closestHit2Stack, miss2Stack)

This is guaranteed to be no larger than the default stack size computation which assumes that both call levels may be the larger of the two.