Vulkan Logo

36. 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 25. Ray tracing pipeline execution
Caption

Interaction between the different shader stages in the ray tracing pipeline

Within the ray tracing pipeline, a pipeline trace ray instruction 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.

36.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 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 a shader call 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.

While the SubgroupSize built-in is required to be declared Volatile, its value will never change unless VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT is set on pipeline creation, as without that bit set, its value is required to match that of VkPhysicalDeviceSubgroupProperties::subgroupSize.

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 shader call instruction are ordered by program-order and do not require explicit synchronization.

36.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, reductionMode equal to VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, 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-magFilter-09598
    If a VkSampler created with magFilter or minFilter equal to VK_FILTER_LINEAR and reductionMode equal to either VK_SAMPLER_REDUCTION_MODE_MIN or VK_SAMPLER_REDUCTION_MODE_MAX 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_MINMAX_BIT

  • VUID-vkCmdTraceRaysKHR-mipmapMode-04770
    If a VkSampler created with mipmapMode equal to VK_SAMPLER_MIPMAP_MODE_LINEAR, reductionMode equal to VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, 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-09599
    If a VkSampler created with mipmapMode equal to VK_SAMPLER_MIPMAP_MODE_LINEAR and reductionMode equal to either VK_SAMPLER_REDUCTION_MODE_MIN or VK_SAMPLER_REDUCTION_MODE_MAX 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_MINMAX_BIT

  • VUID-vkCmdTraceRaysKHR-None-06479
    If a VkImageView is sampled with depth comparison, the image view’s format features must contain VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_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-07888
    If a VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER descriptor is accessed using atomic operations as a result of this command, then the storage texel buffer’s format features must contain VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT

  • VUID-vkCmdTraceRaysKHR-OpTypeImage-07027
    For any VkImageView being written as a storage image where the image format field of the OpTypeImage is Unknown, the view’s format features must contain VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysKHR-OpTypeImage-07028
    For any VkImageView being read as a storage image where the image format field of the OpTypeImage is Unknown, the view’s format features must contain VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysKHR-OpTypeImage-07029
    For any VkBufferView being written as a storage texel buffer where the image format field of the OpTypeImage is Unknown, the view’s buffer features must contain VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysKHR-OpTypeImage-07030
    Any VkBufferView being read as a storage texel buffer where the image format field of the OpTypeImage is Unknown then the view’s buffer features must contain VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysKHR-None-08600
    For each set n that is statically used by a bound shader, 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 or the VkDescriptorSetLayout array used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysKHR-None-08601
    For each push constant that is statically used by a bound shader, 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 or the VkDescriptorSetLayout array used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysKHR-maintenance4-08602
    If the maintenance4 feature is not enabled, then for each push constant that is statically used by a bound shader, 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 or the VkDescriptorSetLayout and VkPushConstantRange arrays used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysKHR-None-08114
    Descriptors in each bound descriptor set, specified via vkCmdBindDescriptorSets, must be valid as described by descriptor validity if they are statically used by a bound shader

  • VUID-vkCmdTraceRaysKHR-None-08606
    If the shaderObject feature is not enabled, a valid pipeline must be bound to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysKHR-None-08608
    If a pipeline is bound to the pipeline bind point used by this command, 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-08609
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-08610
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-08611
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-08607
    If the shaderObject is enabled, either a valid pipeline must be bound to the pipeline bind point used by this command, or a valid combination of valid and VK_NULL_HANDLE shader objects must be bound to every supported shader stage corresponding to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysKHR-uniformBuffers-06935
    If any stage of the VkPipeline object bound to the pipeline bind point used by this command accesses a uniform buffer, and the robustBufferAccess feature is not enabled, that stage 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-08612
    If the robustBufferAccess feature is not enabled, and any VkShaderEXT bound to a stage corresponding 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-storageBuffers-06936
    If any stage of the VkPipeline object bound to the pipeline bind point used by this command accesses a storage buffer, and the robustBufferAccess feature is not enabled, that stage 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-08613
    If the robustBufferAccess feature is not enabled, and any VkShaderEXT bound to a stage corresponding 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 and protectedNoFault is not supported, any resource accessed by bound shaders must not be a protected resource

  • VUID-vkCmdTraceRaysKHR-None-06550
    If a bound shader accesses a VkSampler or VkImageView object that enables sampler Y′CBCR conversion, that object must only be used with OpImageSample* or OpImageSparseSample* instructions

  • VUID-vkCmdTraceRaysKHR-ConstOffset-06551
    If a bound shader accesses a VkSampler or VkImageView object that enables sampler Y′CBCR conversion, that object must not use the ConstOffset and Offset operands

  • VUID-vkCmdTraceRaysKHR-viewType-07752
    If a VkImageView is accessed as a result of this command, then the image view’s viewType must match the Dim operand of the OpTypeImage as described in Instruction/Sampler/Image View Validation

  • VUID-vkCmdTraceRaysKHR-format-07753
    If a VkImageView is accessed as a result of this command, then the numeric type of the image view’s format and the Sampled Type operand of the OpTypeImage must match

  • VUID-vkCmdTraceRaysKHR-OpImageWrite-08795
    If a VkImageView created with a format other than VK_FORMAT_A8_UNORM_KHR 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-08796
    If a VkImageView created with the format VK_FORMAT_A8_UNORM_KHR is accessed using OpImageWrite as a result of this command, then the Type of the Texel operand of that instruction must have four components

  • 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-07288
    Any shader invocation executed by this command must terminate

  • VUID-vkCmdTraceRaysKHR-None-09600
    If a descriptor with type equal to any of VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT is accessed as a result of this command, the image subresource identified by that descriptor must be in the image layout identified when the descriptor was written

  • 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-None-09458
    If the bound ray tracing pipeline state was created with the VK_DYNAMIC_STATE_RAY_TRACING_PIPELINE_STACK_SIZE_KHR dynamic state enabled then vkCmdSetRayTracingPipelineStackSizeKHR must have been called in the current command buffer prior to this trace command

  • 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-commandBuffer-03635
    commandBuffer must not be a protected command buffer

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

  • 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-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
    pMissShaderBindingTable->stride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysKHR-stride-04029
    pMissShaderBindingTable->stride 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
    pHitShaderBindingTable->stride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysKHR-stride-04035
    pHitShaderBindingTable->stride 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
    pCallableShaderBindingTable->stride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysKHR-stride-04041
    pCallableShaderBindingTable->stride 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, pHitShaderBindingTable->deviceAddress 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, pHitShaderBindingTable->deviceAddress 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->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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-width-03638
    width must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0] × VkPhysicalDeviceLimits::maxComputeWorkGroupSize[0]

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

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

  • VUID-vkCmdTraceRaysKHR-width-03641
    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

  • VUID-vkCmdTraceRaysKHR-videocoding
    This command must only be called outside of a video coding scope

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 Video Coding Scope Supported Queue Types Command Type

Primary
Secondary

Outside

Outside

Compute

Action

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, reductionMode equal to VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, 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-magFilter-09598
    If a VkSampler created with magFilter or minFilter equal to VK_FILTER_LINEAR and reductionMode equal to either VK_SAMPLER_REDUCTION_MODE_MIN or VK_SAMPLER_REDUCTION_MODE_MAX 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_MINMAX_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-mipmapMode-04770
    If a VkSampler created with mipmapMode equal to VK_SAMPLER_MIPMAP_MODE_LINEAR, reductionMode equal to VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, 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-09599
    If a VkSampler created with mipmapMode equal to VK_SAMPLER_MIPMAP_MODE_LINEAR and reductionMode equal to either VK_SAMPLER_REDUCTION_MODE_MIN or VK_SAMPLER_REDUCTION_MODE_MAX 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_MINMAX_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-None-06479
    If a VkImageView is sampled with depth comparison, the image view’s format features must contain VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_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-07888
    If a VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER descriptor is accessed using atomic operations as a result of this command, then the storage texel buffer’s format features must contain VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-OpTypeImage-07027
    For any VkImageView being written as a storage image where the image format field of the OpTypeImage is Unknown, the view’s format features must contain VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-OpTypeImage-07028
    For any VkImageView being read as a storage image where the image format field of the OpTypeImage is Unknown, the view’s format features must contain VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-OpTypeImage-07029
    For any VkBufferView being written as a storage texel buffer where the image format field of the OpTypeImage is Unknown, the view’s buffer features must contain VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-OpTypeImage-07030
    Any VkBufferView being read as a storage texel buffer where the image format field of the OpTypeImage is Unknown then the view’s buffer features must contain VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysIndirectKHR-None-08600
    For each set n that is statically used by a bound shader, 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 or the VkDescriptorSetLayout array used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysIndirectKHR-None-08601
    For each push constant that is statically used by a bound shader, 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 or the VkDescriptorSetLayout array used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysIndirectKHR-maintenance4-08602
    If the maintenance4 feature is not enabled, then for each push constant that is statically used by a bound shader, 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 or the VkDescriptorSetLayout and VkPushConstantRange arrays used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysIndirectKHR-None-08114
    Descriptors in each bound descriptor set, specified via vkCmdBindDescriptorSets, must be valid as described by descriptor validity if they are statically used by a bound shader

  • VUID-vkCmdTraceRaysIndirectKHR-None-08606
    If the shaderObject feature is not enabled, a valid pipeline must be bound to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysIndirectKHR-None-08608
    If a pipeline is bound to the pipeline bind point used by this command, 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-08609
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-08610
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-08611
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-08607
    If the shaderObject is enabled, either a valid pipeline must be bound to the pipeline bind point used by this command, or a valid combination of valid and VK_NULL_HANDLE shader objects must be bound to every supported shader stage corresponding to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysIndirectKHR-uniformBuffers-06935
    If any stage of the VkPipeline object bound to the pipeline bind point used by this command accesses a uniform buffer, and the robustBufferAccess feature is not enabled, that stage 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-08612
    If the robustBufferAccess feature is not enabled, and any VkShaderEXT bound to a stage corresponding 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-storageBuffers-06936
    If any stage of the VkPipeline object bound to the pipeline bind point used by this command accesses a storage buffer, and the robustBufferAccess feature is not enabled, that stage 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-08613
    If the robustBufferAccess feature is not enabled, and any VkShaderEXT bound to a stage corresponding 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 and protectedNoFault is not supported, any resource accessed by bound shaders must not be a protected resource

  • VUID-vkCmdTraceRaysIndirectKHR-None-06550
    If a bound shader accesses a VkSampler or VkImageView object that enables sampler Y′CBCR conversion, that object must only be used with OpImageSample* or OpImageSparseSample* instructions

  • VUID-vkCmdTraceRaysIndirectKHR-ConstOffset-06551
    If a bound shader accesses a VkSampler or VkImageView object that enables sampler Y′CBCR conversion, that object must not use the ConstOffset and Offset operands

  • VUID-vkCmdTraceRaysIndirectKHR-viewType-07752
    If a VkImageView is accessed as a result of this command, then the image view’s viewType must match the Dim operand of the OpTypeImage as described in Instruction/Sampler/Image View Validation

  • VUID-vkCmdTraceRaysIndirectKHR-format-07753
    If a VkImageView is accessed as a result of this command, then the numeric type of the image view’s format and the Sampled Type operand of the OpTypeImage must match

  • VUID-vkCmdTraceRaysIndirectKHR-OpImageWrite-08795
    If a VkImageView created with a format other than VK_FORMAT_A8_UNORM_KHR 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-08796
    If a VkImageView created with the format VK_FORMAT_A8_UNORM_KHR is accessed using OpImageWrite as a result of this command, then the Type of the Texel operand of that instruction must have four components

  • 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-07288
    Any shader invocation executed by this command must terminate

  • VUID-vkCmdTraceRaysIndirectKHR-None-09600
    If a descriptor with type equal to any of VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT is accessed as a result of this command, the image subresource identified by that descriptor must be in the image layout identified when the descriptor was written

  • 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-None-09458
    If the bound ray tracing pipeline state was created with the VK_DYNAMIC_STATE_RAY_TRACING_PIPELINE_STACK_SIZE_KHR dynamic state enabled then vkCmdSetRayTracingPipelineStackSizeKHR must have been called in the current command buffer prior to this trace command

  • 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-commandBuffer-03635
    commandBuffer must not be a protected command buffer

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

  • 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-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
    pMissShaderBindingTable->stride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-04029
    pMissShaderBindingTable->stride 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
    pHitShaderBindingTable->stride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-04035
    pHitShaderBindingTable->stride 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
    pCallableShaderBindingTable->stride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-vkCmdTraceRaysIndirectKHR-stride-04041
    pCallableShaderBindingTable->stride 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, pHitShaderBindingTable->deviceAddress 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, pHitShaderBindingTable->deviceAddress 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->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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 the table identified by pHitShaderBindingTable->deviceAddress 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-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 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

  • VUID-vkCmdTraceRaysIndirectKHR-videocoding
    This command must only be called outside of a video coding scope

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 Video Coding Scope Supported Queue Types Command Type

Primary
Secondary

Outside

Outside

Compute

Action

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

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

// Provided by VK_KHR_ray_tracing_maintenance1 with VK_KHR_ray_tracing_pipeline
void vkCmdTraceRaysIndirect2KHR(
    VkCommandBuffer                             commandBuffer,
    VkDeviceAddress                             indirectDeviceAddress);
  • commandBuffer is the command buffer into which the command will be recorded.

  • indirectDeviceAddress is a buffer device address which is a pointer to a VkTraceRaysIndirectCommand2KHR structure containing the trace ray parameters.

vkCmdTraceRaysIndirect2KHR behaves similarly to vkCmdTraceRaysIndirectKHR except that shader binding table parameters as well as dispatch dimensions are read by the device from indirectDeviceAddress during execution.

Valid Usage
  • VUID-vkCmdTraceRaysIndirect2KHR-magFilter-04553
    If a VkSampler created with magFilter or minFilter equal to VK_FILTER_LINEAR, reductionMode equal to VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, 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-vkCmdTraceRaysIndirect2KHR-magFilter-09598
    If a VkSampler created with magFilter or minFilter equal to VK_FILTER_LINEAR and reductionMode equal to either VK_SAMPLER_REDUCTION_MODE_MIN or VK_SAMPLER_REDUCTION_MODE_MAX 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_MINMAX_BIT

  • VUID-vkCmdTraceRaysIndirect2KHR-mipmapMode-04770
    If a VkSampler created with mipmapMode equal to VK_SAMPLER_MIPMAP_MODE_LINEAR, reductionMode equal to VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, 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-vkCmdTraceRaysIndirect2KHR-mipmapMode-09599
    If a VkSampler created with mipmapMode equal to VK_SAMPLER_MIPMAP_MODE_LINEAR and reductionMode equal to either VK_SAMPLER_REDUCTION_MODE_MIN or VK_SAMPLER_REDUCTION_MODE_MAX 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_MINMAX_BIT

  • VUID-vkCmdTraceRaysIndirect2KHR-None-06479
    If a VkImageView is sampled with depth comparison, the image view’s format features must contain VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT

  • VUID-vkCmdTraceRaysIndirect2KHR-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-vkCmdTraceRaysIndirect2KHR-None-07888
    If a VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER descriptor is accessed using atomic operations as a result of this command, then the storage texel buffer’s format features must contain VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT

  • VUID-vkCmdTraceRaysIndirect2KHR-OpTypeImage-07027
    For any VkImageView being written as a storage image where the image format field of the OpTypeImage is Unknown, the view’s format features must contain VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysIndirect2KHR-OpTypeImage-07028
    For any VkImageView being read as a storage image where the image format field of the OpTypeImage is Unknown, the view’s format features must contain VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysIndirect2KHR-OpTypeImage-07029
    For any VkBufferView being written as a storage texel buffer where the image format field of the OpTypeImage is Unknown, the view’s buffer features must contain VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysIndirect2KHR-OpTypeImage-07030
    Any VkBufferView being read as a storage texel buffer where the image format field of the OpTypeImage is Unknown then the view’s buffer features must contain VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT

  • VUID-vkCmdTraceRaysIndirect2KHR-None-08600
    For each set n that is statically used by a bound shader, 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 or the VkDescriptorSetLayout array used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysIndirect2KHR-None-08601
    For each push constant that is statically used by a bound shader, 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 or the VkDescriptorSetLayout array used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysIndirect2KHR-maintenance4-08602
    If the maintenance4 feature is not enabled, then for each push constant that is statically used by a bound shader, 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 or the VkDescriptorSetLayout and VkPushConstantRange arrays used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility

  • VUID-vkCmdTraceRaysIndirect2KHR-None-08114
    Descriptors in each bound descriptor set, specified via vkCmdBindDescriptorSets, must be valid as described by descriptor validity if they are statically used by a bound shader

  • VUID-vkCmdTraceRaysIndirect2KHR-None-08606
    If the shaderObject feature is not enabled, a valid pipeline must be bound to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysIndirect2KHR-None-08608
    If a pipeline is bound to the pipeline bind point used by this command, 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-vkCmdTraceRaysIndirect2KHR-None-08609
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-vkCmdTraceRaysIndirect2KHR-None-08610
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-vkCmdTraceRaysIndirect2KHR-None-08611
    If the VkPipeline object bound to the pipeline bind point used by this command or any VkShaderEXT bound to a stage corresponding 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-vkCmdTraceRaysIndirect2KHR-None-08607
    If the shaderObject is enabled, either a valid pipeline must be bound to the pipeline bind point used by this command, or a valid combination of valid and VK_NULL_HANDLE shader objects must be bound to every supported shader stage corresponding to the pipeline bind point used by this command

  • VUID-vkCmdTraceRaysIndirect2KHR-uniformBuffers-06935
    If any stage of the VkPipeline object bound to the pipeline bind point used by this command accesses a uniform buffer, and the robustBufferAccess feature is not enabled, that stage 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-vkCmdTraceRaysIndirect2KHR-None-08612
    If the robustBufferAccess feature is not enabled, and any VkShaderEXT bound to a stage corresponding 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-vkCmdTraceRaysIndirect2KHR-storageBuffers-06936
    If any stage of the VkPipeline object bound to the pipeline bind point used by this command accesses a storage buffer, and the robustBufferAccess feature is not enabled, that stage 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-vkCmdTraceRaysIndirect2KHR-None-08613
    If the robustBufferAccess feature is not enabled, and any VkShaderEXT bound to a stage corresponding 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-vkCmdTraceRaysIndirect2KHR-commandBuffer-02707
    If commandBuffer is an unprotected command buffer and protectedNoFault is not supported, any resource accessed by bound shaders must not be a protected resource

  • VUID-vkCmdTraceRaysIndirect2KHR-None-06550
    If a bound shader accesses a VkSampler or VkImageView object that enables sampler Y′CBCR conversion, that object must only be used with OpImageSample* or OpImageSparseSample* instructions

  • VUID-vkCmdTraceRaysIndirect2KHR-ConstOffset-06551
    If a bound shader accesses a VkSampler or VkImageView object that enables sampler Y′CBCR conversion, that object must not use the ConstOffset and Offset operands

  • VUID-vkCmdTraceRaysIndirect2KHR-viewType-07752
    If a VkImageView is accessed as a result of this command, then the image view’s viewType must match the Dim operand of the OpTypeImage as described in Instruction/Sampler/Image View Validation

  • VUID-vkCmdTraceRaysIndirect2KHR-format-07753
    If a VkImageView is accessed as a result of this command, then the numeric type of the image view’s format and the Sampled Type operand of the OpTypeImage must match

  • VUID-vkCmdTraceRaysIndirect2KHR-OpImageWrite-08795
    If a VkImageView created with a format other than VK_FORMAT_A8_UNORM_KHR 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-vkCmdTraceRaysIndirect2KHR-OpImageWrite-08796
    If a VkImageView created with the format VK_FORMAT_A8_UNORM_KHR is accessed using OpImageWrite as a result of this command, then the Type of the Texel operand of that instruction must have four components

  • VUID-vkCmdTraceRaysIndirect2KHR-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-vkCmdTraceRaysIndirect2KHR-None-07288
    Any shader invocation executed by this command must terminate

  • VUID-vkCmdTraceRaysIndirect2KHR-None-09600
    If a descriptor with type equal to any of VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT is accessed as a result of this command, the image subresource identified by that descriptor must be in the image layout identified when the descriptor was written

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

  • VUID-vkCmdTraceRaysIndirect2KHR-None-09458
    If the bound ray tracing pipeline state was created with the VK_DYNAMIC_STATE_RAY_TRACING_PIPELINE_STACK_SIZE_KHR dynamic state enabled then vkCmdSetRayTracingPipelineStackSizeKHR must have been called in the current command buffer prior to this trace command

  • VUID-vkCmdTraceRaysIndirect2KHR-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-vkCmdTraceRaysIndirect2KHR-commandBuffer-03635
    commandBuffer must not be a protected command buffer

  • VUID-vkCmdTraceRaysIndirect2KHR-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-vkCmdTraceRaysIndirect2KHR-indirectDeviceAddress-03633
    The buffer from which indirectDeviceAddress was queried must have been created with the VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT bit set

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

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

  • VUID-vkCmdTraceRaysIndirect2KHR-rayTracingPipelineTraceRaysIndirect2-03637
    The rayTracingPipelineTraceRaysIndirect2 feature must be enabled

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

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

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

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

  • VUID-vkCmdTraceRaysIndirect2KHR-videocoding
    This command must only be called outside of a video coding scope

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 Video Coding Scope Supported Queue Types Command Type

Primary
Secondary

Outside

Outside

Compute

Action

The VkTraceRaysIndirectCommand2KHR structure is defined as:

// Provided by VK_KHR_ray_tracing_maintenance1 with VK_KHR_ray_tracing_pipeline
typedef struct VkTraceRaysIndirectCommand2KHR {
    VkDeviceAddress    raygenShaderRecordAddress;
    VkDeviceSize       raygenShaderRecordSize;
    VkDeviceAddress    missShaderBindingTableAddress;
    VkDeviceSize       missShaderBindingTableSize;
    VkDeviceSize       missShaderBindingTableStride;
    VkDeviceAddress    hitShaderBindingTableAddress;
    VkDeviceSize       hitShaderBindingTableSize;
    VkDeviceSize       hitShaderBindingTableStride;
    VkDeviceAddress    callableShaderBindingTableAddress;
    VkDeviceSize       callableShaderBindingTableSize;
    VkDeviceSize       callableShaderBindingTableStride;
    uint32_t           width;
    uint32_t           height;
    uint32_t           depth;
} VkTraceRaysIndirectCommand2KHR;
  • raygenShaderRecordAddress is a VkDeviceAddress of the ray generation shader binding table record used by this command.

  • raygenShaderRecordSize is a VkDeviceSize number of bytes corresponding to the ray generation shader binding table record at base address raygenShaderRecordAddress.

  • missShaderBindingTableAddress is a VkDeviceAddress of the first record in the miss shader binding table used by this command.

  • missShaderBindingTableSize is a VkDeviceSize number of bytes corresponding to the total size of the miss shader binding table at missShaderBindingTableAddress that may be accessed by this command.

  • missShaderBindingTableStride is a VkDeviceSize number of bytes between records of the miss shader binding table.

  • hitShaderBindingTableAddress is a VkDeviceAddress of the first record in the hit shader binding table used by this command.

  • hitShaderBindingTableSize is a VkDeviceSize number of bytes corresponding to the total size of the hit shader binding table at hitShaderBindingTableAddress that may be accessed by this command.

  • hitShaderBindingTableStride is a VkDeviceSize number of bytes between records of the hit shader binding table.

  • callableShaderBindingTableAddress is a VkDeviceAddress of the first record in the callable shader binding table used by this command.

  • callableShaderBindingTableSize is a VkDeviceSize number of bytes corresponding to the total size of the callable shader binding table at callableShaderBindingTableAddress that may be accessed by this command.

  • callableShaderBindingTableStride is a VkDeviceSize number of bytes between records of the callable shader binding table.

  • 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 VkTraceRaysIndirectCommand2KHR have the same meaning as the similarly named parameters of vkCmdTraceRaysKHR.

Indirect shader binding table buffer parameters must satisfy the same memory alignment and binding requirements as their counterparts in vkCmdTraceRaysIndirectKHR and vkCmdTraceRaysKHR.

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

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

  • VUID-VkTraceRaysIndirectCommand2KHR-pRayGenShaderBindingTable-03682
    raygenShaderRecordAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

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

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

  • VUID-VkTraceRaysIndirectCommand2KHR-pMissShaderBindingTable-03685
    missShaderBindingTableAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-VkTraceRaysIndirectCommand2KHR-stride-03686
    missShaderBindingTableStride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-VkTraceRaysIndirectCommand2KHR-stride-04029
    missShaderBindingTableStride must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

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

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

  • VUID-VkTraceRaysIndirectCommand2KHR-pHitShaderBindingTable-03689
    hitShaderBindingTableAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-VkTraceRaysIndirectCommand2KHR-stride-03690
    hitShaderBindingTableStride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-VkTraceRaysIndirectCommand2KHR-stride-04035
    hitShaderBindingTableStride must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

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

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

  • VUID-VkTraceRaysIndirectCommand2KHR-pCallableShaderBindingTable-03693
    callableShaderBindingTableAddress must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment

  • VUID-VkTraceRaysIndirectCommand2KHR-stride-03694
    callableShaderBindingTableStride must be a multiple of VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupHandleAlignment

  • VUID-VkTraceRaysIndirectCommand2KHR-stride-04041
    callableShaderBindingTableStride must be less than or equal to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxShaderGroupStride

  • VUID-VkTraceRaysIndirectCommand2KHR-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, hitShaderBindingTableAddress must not be zero

  • VUID-VkTraceRaysIndirectCommand2KHR-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, hitShaderBindingTableAddress must not be zero

  • VUID-VkTraceRaysIndirectCommand2KHR-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 missShaderBindingTableAddress must not be set to zero

  • VUID-VkTraceRaysIndirectCommand2KHR-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 the table identified by hitShaderBindingTableAddress accessed as a result of this command in order to execute an any-hit shader must not be set to zero

  • VUID-VkTraceRaysIndirectCommand2KHR-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 the table identified by hitShaderBindingTableAddress accessed as a result of this command in order to execute a closest hit shader must not be set to zero

  • VUID-VkTraceRaysIndirectCommand2KHR-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 the table identified by hitShaderBindingTableAddress accessed as a result of this command in order to execute an intersection shader must not be set to zero

  • VUID-VkTraceRaysIndirectCommand2KHR-pHitShaderBindingTable-04735
    Any non-zero hit shader group entries in the table identified by hitShaderBindingTableAddress 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-VkTraceRaysIndirectCommand2KHR-pHitShaderBindingTable-04736
    Any non-zero hit shader group entries in the table identified by hitShaderBindingTableAddress 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-VkTraceRaysIndirectCommand2KHR-width-03638
    width must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0] × VkPhysicalDeviceLimits::maxComputeWorkGroupSize[0]

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

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

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

36.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.

36.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 pipeline trace ray instructions.

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 pipeline trace ray instructions.

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.

36.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.

36.5. Ray Tracing Capture Replay

In a similar way to bufferDeviceAddressCaptureReplay, the rayTracingPipelineShaderGroupHandleCaptureReplay feature allows the querying of opaque data which can be used in a future replay.

During the capture phase, capture/replay tools are expected to query opaque data for shader group handle replay using vkGetRayTracingCaptureReplayShaderGroupHandlesKHR.

Providing the opaque data during replay, using VkRayTracingShaderGroupCreateInfoKHR::pShaderGroupCaptureReplayHandle at pipeline creation time, causes the implementation to generate identical shader group handles to those in the capture phase, allowing capture/replay tools to reuse previously recorded shader binding table buffer contents or to obtain the same handles by calling vkGetRayTracingCaptureReplayShaderGroupHandlesKHR again.