1e5c31af7Sopenharmony_ci// Copyright 2018-2024 The Khronos Group Inc. 2e5c31af7Sopenharmony_ci// 3e5c31af7Sopenharmony_ci// SPDX-License-Identifier: CC-BY-4.0 4e5c31af7Sopenharmony_ci 5e5c31af7Sopenharmony_ci[[ray-tracing]] 6e5c31af7Sopenharmony_ci= Ray Tracing 7e5c31af7Sopenharmony_ci 8e5c31af7Sopenharmony_ciRay tracing uses a separate rendering pipeline from both the graphics and 9e5c31af7Sopenharmony_cicompute pipelines (see <<pipelines-ray-tracing,Ray Tracing Pipeline>>). 10e5c31af7Sopenharmony_ci 11e5c31af7Sopenharmony_ci[[fig-raypipe]] 12e5c31af7Sopenharmony_ciimage::{images}/ray_tracing_execution.svg[align="center",title="Ray tracing pipeline execution",opts="{imageopts}"] 13e5c31af7Sopenharmony_ci 14e5c31af7Sopenharmony_ci.Caption 15e5c31af7Sopenharmony_ci**** 16e5c31af7Sopenharmony_ciInteraction between the different shader stages in the ray tracing pipeline 17e5c31af7Sopenharmony_ci**** 18e5c31af7Sopenharmony_ci 19e5c31af7Sopenharmony_ciWithin the ray tracing pipeline, a <<glossary-pipeline-trace-ray, pipeline 20e5c31af7Sopenharmony_citrace ray>> instruction can: be called to perform a <<ray-traversal,ray 21e5c31af7Sopenharmony_citraversal>> that invokes the various ray tracing shader stages during its 22e5c31af7Sopenharmony_ciexecution. 23e5c31af7Sopenharmony_ciThe relationship between the ray tracing pipeline object and the geometries 24e5c31af7Sopenharmony_cipresent in the acceleration structure traversed is passed into the ray 25e5c31af7Sopenharmony_citracing command in a slink:VkBuffer object known as a _shader binding 26e5c31af7Sopenharmony_citable_. 27e5c31af7Sopenharmony_cicode:OpExecuteCallableKHR can also be used in ray tracing pipelines to 28e5c31af7Sopenharmony_ciinvoke a <<shaders-callable,callable shader>>. 29e5c31af7Sopenharmony_ci 30e5c31af7Sopenharmony_ciDuring execution, control alternates between scheduling and other 31e5c31af7Sopenharmony_cioperations. 32e5c31af7Sopenharmony_ciThe scheduling functionality is implementation-specific and is responsible 33e5c31af7Sopenharmony_cifor workload execution. 34e5c31af7Sopenharmony_ciThe shader stages are programmable. 35e5c31af7Sopenharmony_ci<<ray-traversal, _Traversal_>>, which refers to the process of traversing 36e5c31af7Sopenharmony_ciacceleration structures to find potential intersections of rays with 37e5c31af7Sopenharmony_cigeometry, is fixed function. 38e5c31af7Sopenharmony_ci 39e5c31af7Sopenharmony_ciThe programmable portions of the pipeline are exposed in a single-ray 40e5c31af7Sopenharmony_ciprogramming model, with each invocation handling one ray at a time. 41e5c31af7Sopenharmony_ciMemory operations can: be synchronized using standard memory barriers. 42e5c31af7Sopenharmony_ciThe code:Workgroup scope and variables with a storage class of 43e5c31af7Sopenharmony_cicode:Workgroup must: not be used in the ray tracing pipeline. 44e5c31af7Sopenharmony_ci 45e5c31af7Sopenharmony_ci 46e5c31af7Sopenharmony_ci[[ray-tracing-shader-call]] 47e5c31af7Sopenharmony_ci== Shader Call Instructions 48e5c31af7Sopenharmony_ci 49e5c31af7Sopenharmony_ciA _shader call_ is an instruction which may: cause execution to continue 50e5c31af7Sopenharmony_cielsewhere by creating one or more invocations that execute a different 51e5c31af7Sopenharmony_cishader stage. 52e5c31af7Sopenharmony_ci 53e5c31af7Sopenharmony_ciThe shader call instructions are: 54e5c31af7Sopenharmony_ci 55e5c31af7Sopenharmony_ci * code:OpTraceRayKHR which may: invoke intersection, any-hit, closest hit, 56e5c31af7Sopenharmony_ci or miss shaders, 57e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing_motion_blur[] 58e5c31af7Sopenharmony_ci * code:OpTraceRayMotionNV which may: invoke intersection, any-hit, closest 59e5c31af7Sopenharmony_ci hit, or miss shaders, 60e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing_motion_blur[] 61e5c31af7Sopenharmony_ci * code:OpReportIntersectionKHR which may: invoke any-hit shaders, and 62e5c31af7Sopenharmony_ci * code:OpExecuteCallableKHR which will invoke a callable shader. 63e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing_invocation_reorder[] 64e5c31af7Sopenharmony_ci * code:OpHitObjectTraceRayNV, code:OpHitObjectTraceRayMotionNV, and 65e5c31af7Sopenharmony_ci code:OpHitObjectExecuteShaderNV which may: invoke intersection, any-hit, 66e5c31af7Sopenharmony_ci closest hit, miss, or callable shaders. 67e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing_invocation_reorder[] 68e5c31af7Sopenharmony_ci 69e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 70e5c31af7Sopenharmony_ciThe invocations created by shader call instructions are grouped into 71e5c31af7Sopenharmony_cisubgroups by the implementation. 72e5c31af7Sopenharmony_ciThose subgroups may: be unrelated to the subgroup of the parent invocation. 73e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 74e5c31af7Sopenharmony_ci 75e5c31af7Sopenharmony_ci 76e5c31af7Sopenharmony_ci[[ray-tracing-recursion-depth]] 77e5c31af7Sopenharmony_ci_Pipeline trace ray instructions_ can: be used recursively; invoked shaders 78e5c31af7Sopenharmony_cican: themselves execute pipeline trace ray instructions, to a maximum depth 79e5c31af7Sopenharmony_cidefined by the 80e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 81e5c31af7Sopenharmony_ci<<limits-maxRecursionDepth, pname:maxRecursionDepth>> or 82e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 83e5c31af7Sopenharmony_ci<<limits-maxRayRecursionDepth, pname:maxRayRecursionDepth>> limit. 84e5c31af7Sopenharmony_ci 85e5c31af7Sopenharmony_ciShaders directly invoked from the API always have a recursion depth of 0; 86e5c31af7Sopenharmony_cieach shader executed by a pipeline trace ray instruction has a recursion 87e5c31af7Sopenharmony_cidepth one higher than the recursion depth of the shader which invoked it. 88e5c31af7Sopenharmony_ciApplications must: not invoke a shader with a recursion depth greater than 89e5c31af7Sopenharmony_cithe value of 90e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 91e5c31af7Sopenharmony_cipname:maxRecursionDepth or 92e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 93e5c31af7Sopenharmony_cipname:maxPipelineRayRecursionDepth specified in the pipeline. 94e5c31af7Sopenharmony_ci 95e5c31af7Sopenharmony_ciThere is no explicit recursion limit for other shader call instructions 96e5c31af7Sopenharmony_ciwhich may recurse (e.g. code:OpExecuteCallableKHR) but there is an upper 97e5c31af7Sopenharmony_cibound determined by the <<ray-tracing-pipeline-stack, stack size>>. 98e5c31af7Sopenharmony_ci 99e5c31af7Sopenharmony_ci[[ray-tracing-repack]] 100e5c31af7Sopenharmony_ciAn _invocation repack instruction_ is a ray tracing instruction where the 101e5c31af7Sopenharmony_ciimplementation may: change the set of invocations that are executing. 102e5c31af7Sopenharmony_ciWhen a repack instruction is encountered, the invocation is suspended and a 103e5c31af7Sopenharmony_cinew invocation begins and executes the instruction. 104e5c31af7Sopenharmony_ciAfter executing the repack instruction (which may: result in other ray 105e5c31af7Sopenharmony_citracing shader stages executing) the new invocation ends and the original 106e5c31af7Sopenharmony_ciinvocation is resumed, but it may: be resumed in a different subgroup or at 107e5c31af7Sopenharmony_cia different code:SubgroupLocalInvocationId within the same subgroup. 108e5c31af7Sopenharmony_ciWhen a subset of invocations in a subgroup execute the invocation repack 109e5c31af7Sopenharmony_ciinstruction, those that do not execute it remain in the same subgroup at the 110e5c31af7Sopenharmony_cisame code:SubgroupLocalInvocationId. 111e5c31af7Sopenharmony_ci 112e5c31af7Sopenharmony_ciThe code:OpTraceRayKHR, 113e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing_motion_blur[] 114e5c31af7Sopenharmony_cicode:OpTraceRayMotionNV, 115e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing_motion_blur[] 116e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing_invocation_reorder[] 117e5c31af7Sopenharmony_cicode:OpReorderThreadWithHintNV, code:OpReorderThreadWithHitObjectNV, 118e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing_invocation_reorder[] 119e5c31af7Sopenharmony_cicode:OpReportIntersectionKHR, and code:OpExecuteCallableKHR instructions are 120e5c31af7Sopenharmony_ciinvocation repack instructions. 121e5c31af7Sopenharmony_ci 122e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 123e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 124e5c31af7Sopenharmony_ciThe invocations that are executing before a shader call instruction, after 125e5c31af7Sopenharmony_cithe instruction, or are created by the instruction, are 126e5c31af7Sopenharmony_ci<<shader-call-related,shader-call-related>>. 127e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 128e5c31af7Sopenharmony_ci 129e5c31af7Sopenharmony_ciIf the implementation changes the composition of subgroups, the values of 130e5c31af7Sopenharmony_cicode:SubgroupSize, code:SubgroupLocalInvocationId, 131e5c31af7Sopenharmony_ciifdef::VK_NV_shader_sm_builtins[] 132e5c31af7Sopenharmony_cicode:SMIDNV, code:WarpIDNV, 133e5c31af7Sopenharmony_ciendif::VK_NV_shader_sm_builtins[] 134e5c31af7Sopenharmony_ciand builtin variables that are derived from them (code:SubgroupEqMask, 135e5c31af7Sopenharmony_cicode:SubgroupGeMask, code:SubgroupGtMask, code:SubgroupLeMask, 136e5c31af7Sopenharmony_cicode:SubgroupLtMask) must: be changed accordingly by the invocation repack 137e5c31af7Sopenharmony_ciinstruction. 138e5c31af7Sopenharmony_ciThe application must: use <<builtin-volatile-semantics,code:Volatile 139e5c31af7Sopenharmony_cisemantics>> on these code:BuiltIn variables when used in the ray generation, 140e5c31af7Sopenharmony_ciclosest hit, miss, intersection, and callable shaders. 141e5c31af7Sopenharmony_ciSimilarly, the application must: use code:Volatile semantics on any 142e5c31af7Sopenharmony_cicode:RayTmaxKHR decorated code:Builtin used in an intersection shader. 143e5c31af7Sopenharmony_ci 144e5c31af7Sopenharmony_ci[NOTE] 145e5c31af7Sopenharmony_ci.Note 146e5c31af7Sopenharmony_ci==== 147e5c31af7Sopenharmony_ci<<shaders-group-operations,Subgroup operations>> are permitted in the 148e5c31af7Sopenharmony_ciprogrammable ray tracing shader stages. 149e5c31af7Sopenharmony_ciHowever, shader call instructions place a bound on where results of subgroup 150e5c31af7Sopenharmony_ciinstructions or subgroup-scoped instructions that execute the dynamic 151e5c31af7Sopenharmony_ciinstance of that instruction are potentially valid. 152e5c31af7Sopenharmony_ciFor example, care must: be taken when using the result of a ballot operation 153e5c31af7Sopenharmony_cithat was computed before an invocation repack instruction, after that repack 154e5c31af7Sopenharmony_ciinstruction. 155e5c31af7Sopenharmony_ciThe ballot may: be incorrect as the set of invocations could have changed. 156e5c31af7Sopenharmony_ci 157e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_3,VK_EXT_subgroup_size_control[] 158e5c31af7Sopenharmony_ciWhile the code:SubgroupSize built-in is required to be declared 159e5c31af7Sopenharmony_cicode:Volatile, its value will never change unless 160e5c31af7Sopenharmony_ciename:VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT is set 161e5c31af7Sopenharmony_cion pipeline creation, as without that bit set, its value is required to 162e5c31af7Sopenharmony_cimatch that of slink:VkPhysicalDeviceSubgroupProperties::pname:subgroupSize. 163e5c31af7Sopenharmony_ciendif::VK_VERSION_1_3,VK_EXT_subgroup_size_control[] 164e5c31af7Sopenharmony_ci 165e5c31af7Sopenharmony_ciifdef::VK_KHR_shader_clock[] 166e5c31af7Sopenharmony_ciFor clock operations, the value of a code:Subgroup scoped 167e5c31af7Sopenharmony_cicode:OpReadClockKHR read before the dynamic instance of a repack instruction 168e5c31af7Sopenharmony_cishould: not be compared to the result of that clock instruction after the 169e5c31af7Sopenharmony_cirepack instruction. 170e5c31af7Sopenharmony_ciendif::VK_KHR_shader_clock[] 171e5c31af7Sopenharmony_ci==== 172e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 173e5c31af7Sopenharmony_ci 174e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 175e5c31af7Sopenharmony_ciWhen a ray tracing shader executes a dynamic instance of an invocation 176e5c31af7Sopenharmony_cirepack instruction which results in another ray tracing shader being 177e5c31af7Sopenharmony_ciinvoked, their instructions are related by 178e5c31af7Sopenharmony_ci<<shader-call-order,shader-call-order>>. 179e5c31af7Sopenharmony_ci 180e5c31af7Sopenharmony_ciFor ray tracing invocations that are 181e5c31af7Sopenharmony_ci<<shader-call-related,shader-call-related>>: 182e5c31af7Sopenharmony_ci 183e5c31af7Sopenharmony_ci * <<memory-model-memory-operation,memory operations>> on 184e5c31af7Sopenharmony_ci code:StorageBuffer, code:Image, and code:ShaderRecordBufferKHR storage 185e5c31af7Sopenharmony_ci classes can: be synchronized using the 186e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[code:ShaderCallKHR] 187e5c31af7Sopenharmony_ciifndef::VK_KHR_ray_tracing_pipeline[code:Device or code:QueueFamily] 188e5c31af7Sopenharmony_ci scope. 189e5c31af7Sopenharmony_ci 190e5c31af7Sopenharmony_ci * the code:CallableDataKHR, code:IncomingCallableDataKHR, 191e5c31af7Sopenharmony_ci code:RayPayloadKHR, code:HitAttributeKHR, and code:IncomingRayPayloadKHR 192e5c31af7Sopenharmony_ci storage classes are <<memory-model-shader-io,system-synchronized>> and 193e5c31af7Sopenharmony_ci no application availability and visibility operations are required. 194e5c31af7Sopenharmony_ci 195e5c31af7Sopenharmony_ci * memory operations within a single invocation before and after the shader 196e5c31af7Sopenharmony_ci call instruction are ordered by 197e5c31af7Sopenharmony_ci <<memory-model-program-order,program-order>> and do not require explicit 198e5c31af7Sopenharmony_ci synchronization. 199e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 200e5c31af7Sopenharmony_ci 201e5c31af7Sopenharmony_ci 202e5c31af7Sopenharmony_ci[[ray-tracing-commands]] 203e5c31af7Sopenharmony_ci== Ray Tracing Commands 204e5c31af7Sopenharmony_ci 205e5c31af7Sopenharmony_ci_Ray tracing commands_ provoke work in the ray tracing pipeline. 206e5c31af7Sopenharmony_ciRay tracing commands are recorded into a command buffer and when executed by 207e5c31af7Sopenharmony_cia queue will produce work that executes according to the currently bound ray 208e5c31af7Sopenharmony_citracing pipeline. 209e5c31af7Sopenharmony_ciA ray tracing pipeline must: be bound to a command buffer before any ray 210e5c31af7Sopenharmony_citracing commands are recorded in that command buffer. 211e5c31af7Sopenharmony_ci 212e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 213e5c31af7Sopenharmony_ci 214e5c31af7Sopenharmony_ci[open,refpage='vkCmdTraceRaysNV',desc='Initialize a ray tracing dispatch',type='protos'] 215e5c31af7Sopenharmony_ci-- 216e5c31af7Sopenharmony_ci:refpage: vkCmdTraceRaysNV 217e5c31af7Sopenharmony_ci 218e5c31af7Sopenharmony_ciTo dispatch ray tracing use: 219e5c31af7Sopenharmony_ci 220e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkCmdTraceRaysNV.adoc[] 221e5c31af7Sopenharmony_ci 222e5c31af7Sopenharmony_ci * pname:commandBuffer is the command buffer into which the command will be 223e5c31af7Sopenharmony_ci recorded. 224e5c31af7Sopenharmony_ci * pname:raygenShaderBindingTableBuffer is the buffer object that holds the 225e5c31af7Sopenharmony_ci shader binding table data for the ray generation shader stage. 226e5c31af7Sopenharmony_ci * pname:raygenShaderBindingOffset is the offset in bytes (relative to 227e5c31af7Sopenharmony_ci pname:raygenShaderBindingTableBuffer) of the ray generation shader being 228e5c31af7Sopenharmony_ci used for the trace. 229e5c31af7Sopenharmony_ci * pname:missShaderBindingTableBuffer is the buffer object that holds the 230e5c31af7Sopenharmony_ci shader binding table data for the miss shader stage. 231e5c31af7Sopenharmony_ci * pname:missShaderBindingOffset is the offset in bytes (relative to 232e5c31af7Sopenharmony_ci pname:missShaderBindingTableBuffer) of the miss shader being used for 233e5c31af7Sopenharmony_ci the trace. 234e5c31af7Sopenharmony_ci * pname:missShaderBindingStride is the size in bytes of each shader 235e5c31af7Sopenharmony_ci binding table record in pname:missShaderBindingTableBuffer. 236e5c31af7Sopenharmony_ci * pname:hitShaderBindingTableBuffer is the buffer object that holds the 237e5c31af7Sopenharmony_ci shader binding table data for the hit shader stages. 238e5c31af7Sopenharmony_ci * pname:hitShaderBindingOffset is the offset in bytes (relative to 239e5c31af7Sopenharmony_ci pname:hitShaderBindingTableBuffer) of the hit shader group being used 240e5c31af7Sopenharmony_ci for the trace. 241e5c31af7Sopenharmony_ci * pname:hitShaderBindingStride is the size in bytes of each shader binding 242e5c31af7Sopenharmony_ci table record in pname:hitShaderBindingTableBuffer. 243e5c31af7Sopenharmony_ci * pname:callableShaderBindingTableBuffer is the buffer object that holds 244e5c31af7Sopenharmony_ci the shader binding table data for the callable shader stage. 245e5c31af7Sopenharmony_ci * pname:callableShaderBindingOffset is the offset in bytes (relative to 246e5c31af7Sopenharmony_ci pname:callableShaderBindingTableBuffer) of the callable shader being 247e5c31af7Sopenharmony_ci used for the trace. 248e5c31af7Sopenharmony_ci * pname:callableShaderBindingStride is the size in bytes of each shader 249e5c31af7Sopenharmony_ci binding table record in pname:callableShaderBindingTableBuffer. 250e5c31af7Sopenharmony_ci * pname:width is the width of the ray trace query dimensions. 251e5c31af7Sopenharmony_ci * pname:height is height of the ray trace query dimensions. 252e5c31af7Sopenharmony_ci * pname:depth is depth of the ray trace query dimensions. 253e5c31af7Sopenharmony_ci 254e5c31af7Sopenharmony_ciWhen the command is executed, a ray generation group of [eq]#pname:width 255e5c31af7Sopenharmony_ci{times} pname:height {times} pname:depth# rays is assembled. 256e5c31af7Sopenharmony_ci 257e5c31af7Sopenharmony_ci.Valid Usage 258e5c31af7Sopenharmony_ci**** 259e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_common.adoc[] 260e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-commandBuffer-04624]] 261e5c31af7Sopenharmony_ci pname:commandBuffer must: not be a protected command buffer 262e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-maxRecursionDepth-03625]] 263e5c31af7Sopenharmony_ci This command must: not cause a pipeline trace ray instruction to be 264e5c31af7Sopenharmony_ci executed from a shader invocation with a <<ray-tracing-recursion-depth, 265e5c31af7Sopenharmony_ci recursion depth>> greater than the value of pname:maxRecursionDepth used 266e5c31af7Sopenharmony_ci to create the bound ray tracing pipeline 267e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-raygenShaderBindingTableBuffer-04042]] 268e5c31af7Sopenharmony_ci If pname:raygenShaderBindingTableBuffer is non-sparse then it must: be 269e5c31af7Sopenharmony_ci bound completely and contiguously to a single sname:VkDeviceMemory 270e5c31af7Sopenharmony_ci object 271e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-raygenShaderBindingOffset-02455]] 272e5c31af7Sopenharmony_ci pname:raygenShaderBindingOffset must: be less than the size of 273e5c31af7Sopenharmony_ci pname:raygenShaderBindingTableBuffer 274e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-raygenShaderBindingOffset-02456]] 275e5c31af7Sopenharmony_ci pname:raygenShaderBindingOffset must: be a multiple of 276e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:shaderGroupBaseAlignment 277e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-missShaderBindingTableBuffer-04043]] 278e5c31af7Sopenharmony_ci If pname:missShaderBindingTableBuffer is non-sparse then it must: be 279e5c31af7Sopenharmony_ci bound completely and contiguously to a single sname:VkDeviceMemory 280e5c31af7Sopenharmony_ci object 281e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-missShaderBindingOffset-02457]] 282e5c31af7Sopenharmony_ci pname:missShaderBindingOffset must: be less than the size of 283e5c31af7Sopenharmony_ci pname:missShaderBindingTableBuffer 284e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-missShaderBindingOffset-02458]] 285e5c31af7Sopenharmony_ci pname:missShaderBindingOffset must: be a multiple of 286e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:shaderGroupBaseAlignment 287e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-hitShaderBindingTableBuffer-04044]] 288e5c31af7Sopenharmony_ci If pname:hitShaderBindingTableBuffer is non-sparse then it must: be 289e5c31af7Sopenharmony_ci bound completely and contiguously to a single sname:VkDeviceMemory 290e5c31af7Sopenharmony_ci object 291e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-hitShaderBindingOffset-02459]] 292e5c31af7Sopenharmony_ci pname:hitShaderBindingOffset must: be less than the size of 293e5c31af7Sopenharmony_ci pname:hitShaderBindingTableBuffer 294e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-hitShaderBindingOffset-02460]] 295e5c31af7Sopenharmony_ci pname:hitShaderBindingOffset must: be a multiple of 296e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:shaderGroupBaseAlignment 297e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-callableShaderBindingTableBuffer-04045]] 298e5c31af7Sopenharmony_ci If pname:callableShaderBindingTableBuffer is non-sparse then it must: be 299e5c31af7Sopenharmony_ci bound completely and contiguously to a single sname:VkDeviceMemory 300e5c31af7Sopenharmony_ci object 301e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-callableShaderBindingOffset-02461]] 302e5c31af7Sopenharmony_ci pname:callableShaderBindingOffset must: be less than the size of 303e5c31af7Sopenharmony_ci pname:callableShaderBindingTableBuffer 304e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-callableShaderBindingOffset-02462]] 305e5c31af7Sopenharmony_ci pname:callableShaderBindingOffset must: be a multiple of 306e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:shaderGroupBaseAlignment 307e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-missShaderBindingStride-02463]] 308e5c31af7Sopenharmony_ci pname:missShaderBindingStride must: be a multiple of 309e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:shaderGroupHandleSize 310e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-hitShaderBindingStride-02464]] 311e5c31af7Sopenharmony_ci pname:hitShaderBindingStride must: be a multiple of 312e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:shaderGroupHandleSize 313e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-callableShaderBindingStride-02465]] 314e5c31af7Sopenharmony_ci pname:callableShaderBindingStride must: be a multiple of 315e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:shaderGroupHandleSize 316e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-missShaderBindingStride-02466]] 317e5c31af7Sopenharmony_ci pname:missShaderBindingStride must: be less than or equal to 318e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:maxShaderGroupStride 319e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-hitShaderBindingStride-02467]] 320e5c31af7Sopenharmony_ci pname:hitShaderBindingStride must: be less than or equal to 321e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:maxShaderGroupStride 322e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-callableShaderBindingStride-02468]] 323e5c31af7Sopenharmony_ci pname:callableShaderBindingStride must: be less than or equal to 324e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceRayTracingPropertiesNV::pname:maxShaderGroupStride 325e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-width-02469]] 326e5c31af7Sopenharmony_ci pname:width must: be less than or equal to 327e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceLimits::pname:maxComputeWorkGroupCount[0] 328e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-height-02470]] 329e5c31af7Sopenharmony_ci pname:height must: be less than or equal to 330e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceLimits::pname:maxComputeWorkGroupCount[1] 331e5c31af7Sopenharmony_ci * [[VUID-vkCmdTraceRaysNV-depth-02471]] 332e5c31af7Sopenharmony_ci pname:depth must: be less than or equal to 333e5c31af7Sopenharmony_ci sname:VkPhysicalDeviceLimits::pname:maxComputeWorkGroupCount[2] 334e5c31af7Sopenharmony_ci**** 335e5c31af7Sopenharmony_ci 336e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkCmdTraceRaysNV.adoc[] 337e5c31af7Sopenharmony_ci-- 338e5c31af7Sopenharmony_ci 339e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 340e5c31af7Sopenharmony_ci 341e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 342e5c31af7Sopenharmony_ci[open,refpage='vkCmdTraceRaysKHR',desc='Initialize a ray tracing dispatch',type='protos'] 343e5c31af7Sopenharmony_ci-- 344e5c31af7Sopenharmony_ci:refpage: vkCmdTraceRaysKHR 345e5c31af7Sopenharmony_ci 346e5c31af7Sopenharmony_ciTo dispatch ray tracing use: 347e5c31af7Sopenharmony_ci 348e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkCmdTraceRaysKHR.adoc[] 349e5c31af7Sopenharmony_ci 350e5c31af7Sopenharmony_ci * pname:commandBuffer is the command buffer into which the command will be 351e5c31af7Sopenharmony_ci recorded. 352e5c31af7Sopenharmony_ci * pname:pRaygenShaderBindingTable is a 353e5c31af7Sopenharmony_ci slink:VkStridedDeviceAddressRegionKHR that holds the shader binding 354e5c31af7Sopenharmony_ci table data for the ray generation shader stage. 355e5c31af7Sopenharmony_ci * pname:pMissShaderBindingTable is a slink:VkStridedDeviceAddressRegionKHR 356e5c31af7Sopenharmony_ci that holds the shader binding table data for the miss shader stage. 357e5c31af7Sopenharmony_ci * pname:pHitShaderBindingTable is a slink:VkStridedDeviceAddressRegionKHR 358e5c31af7Sopenharmony_ci that holds the shader binding table data for the hit shader stage. 359e5c31af7Sopenharmony_ci * pname:pCallableShaderBindingTable is a 360e5c31af7Sopenharmony_ci slink:VkStridedDeviceAddressRegionKHR that holds the shader binding 361e5c31af7Sopenharmony_ci table data for the callable shader stage. 362e5c31af7Sopenharmony_ci * pname:width is the width of the ray trace query dimensions. 363e5c31af7Sopenharmony_ci * pname:height is height of the ray trace query dimensions. 364e5c31af7Sopenharmony_ci * pname:depth is depth of the ray trace query dimensions. 365e5c31af7Sopenharmony_ci 366e5c31af7Sopenharmony_ciWhen the command is executed, a ray generation group of [eq]#pname:width 367e5c31af7Sopenharmony_ci{times} pname:height {times} pname:depth# rays is assembled. 368e5c31af7Sopenharmony_ci 369e5c31af7Sopenharmony_ci.Valid Usage 370e5c31af7Sopenharmony_ci**** 371e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_common.adoc[] 372e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_common_khr.adoc[] 373e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_binding_table_raygen_stride.adoc[] 374e5c31af7Sopenharmony_ci 375e5c31af7Sopenharmony_ci:rayGenShaderBindingTableAddress: pname:pRayGenShaderBindingTable->deviceAddress 376e5c31af7Sopenharmony_ci:rayGenShaderBindingTableStride: pname:pRayGenShaderBindingTable->stride 377e5c31af7Sopenharmony_ci:missShaderBindingTableAddress: pname:pMissShaderBindingTable->deviceAddress 378e5c31af7Sopenharmony_ci:missShaderBindingTableStride: pname:pMissShaderBindingTable->stride 379e5c31af7Sopenharmony_ci:hitShaderBindingTableAddress: pname:pHitShaderBindingTable->deviceAddress 380e5c31af7Sopenharmony_ci:hitShaderBindingTableStride: pname:pHitShaderBindingTable->stride 381e5c31af7Sopenharmony_ci:callableShaderBindingTableAddress: pname:pCallableShaderBindingTable->deviceAddress 382e5c31af7Sopenharmony_ci:callableShaderBindingTableStride: pname:pCallableShaderBindingTable->stride 383e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_binding_table.adoc[] 384e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_limits_common.adoc[] 385e5c31af7Sopenharmony_ci**** 386e5c31af7Sopenharmony_ci 387e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkCmdTraceRaysKHR.adoc[] 388e5c31af7Sopenharmony_ci-- 389e5c31af7Sopenharmony_ci 390e5c31af7Sopenharmony_ci[open,refpage='VkStridedDeviceAddressRegionKHR',desc='Structure specifying a region of device addresses with a stride',type='structs'] 391e5c31af7Sopenharmony_ci-- 392e5c31af7Sopenharmony_ci:refpage: VkStridedDeviceAddressRegionKHR 393e5c31af7Sopenharmony_ci 394e5c31af7Sopenharmony_ciThe sname:VkStridedDeviceAddressRegionKHR structure is defined as: 395e5c31af7Sopenharmony_ci 396e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkStridedDeviceAddressRegionKHR.adoc[] 397e5c31af7Sopenharmony_ci 398e5c31af7Sopenharmony_ci * pname:deviceAddress is the device address (as returned by the 399e5c31af7Sopenharmony_ci flink:vkGetBufferDeviceAddress command) at which the region starts, or 400e5c31af7Sopenharmony_ci zero if the region is unused. 401e5c31af7Sopenharmony_ci * pname:stride is the byte stride between consecutive elements. 402e5c31af7Sopenharmony_ci * pname:size is the size in bytes of the region starting at 403e5c31af7Sopenharmony_ci pname:deviceAddress. 404e5c31af7Sopenharmony_ci 405e5c31af7Sopenharmony_ci.Valid Usage 406e5c31af7Sopenharmony_ci**** 407e5c31af7Sopenharmony_ci * [[VUID-VkStridedDeviceAddressRegionKHR-size-04631]] 408e5c31af7Sopenharmony_ci If pname:size is not zero, all addresses between pname:deviceAddress and 409e5c31af7Sopenharmony_ci [eq]#pname:deviceAddress {plus} pname:size - 1# must: be in the buffer 410e5c31af7Sopenharmony_ci device address range of the same buffer 411e5c31af7Sopenharmony_ci * [[VUID-VkStridedDeviceAddressRegionKHR-size-04632]] 412e5c31af7Sopenharmony_ci If pname:size is not zero, pname:stride must: be less than or equal to 413e5c31af7Sopenharmony_ci the size of the buffer from which pname:deviceAddress was queried 414e5c31af7Sopenharmony_ci**** 415e5c31af7Sopenharmony_ci 416e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkStridedDeviceAddressRegionKHR.adoc[] 417e5c31af7Sopenharmony_ci-- 418e5c31af7Sopenharmony_ci 419e5c31af7Sopenharmony_ciifdef::VK_HUAWEI_invocation_mask[] 420e5c31af7Sopenharmony_ci[open,refpage='vkCmdBindInvocationMaskHUAWEI',desc='Bind an invocation mask image on a command buffer',type='protos'] 421e5c31af7Sopenharmony_ci-- 422e5c31af7Sopenharmony_ciWhen invocation mask image usage is enabled in the bound ray tracing 423e5c31af7Sopenharmony_cipipeline, the pipeline uses an invocation mask image specified by the 424e5c31af7Sopenharmony_cicommand: 425e5c31af7Sopenharmony_ci 426e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkCmdBindInvocationMaskHUAWEI.adoc[] 427e5c31af7Sopenharmony_ci 428e5c31af7Sopenharmony_ci * pname:commandBuffer is the command buffer into which the command will be 429e5c31af7Sopenharmony_ci recorded 430e5c31af7Sopenharmony_ci * pname:imageView is an image view handle specifying the invocation mask 431e5c31af7Sopenharmony_ci image pname:imageView may: be set to dlink:VK_NULL_HANDLE, which is 432e5c31af7Sopenharmony_ci equivalent to specifying a view of an image filled with ones value. 433e5c31af7Sopenharmony_ci * pname:imageLayout is the layout that the image subresources accessible 434e5c31af7Sopenharmony_ci from pname:imageView will be in when the invocation mask image is 435e5c31af7Sopenharmony_ci accessed 436e5c31af7Sopenharmony_ci 437e5c31af7Sopenharmony_ci.Valid Usage 438e5c31af7Sopenharmony_ci**** 439e5c31af7Sopenharmony_ci * [[VUID-vkCmdBindInvocationMaskHUAWEI-None-04976]] 440e5c31af7Sopenharmony_ci The <<features-invocationMask, pname:invocationMask>> feature must: be 441e5c31af7Sopenharmony_ci enabled 442e5c31af7Sopenharmony_ci * [[VUID-vkCmdBindInvocationMaskHUAWEI-imageView-04977]] 443e5c31af7Sopenharmony_ci If pname:imageView is not dlink:VK_NULL_HANDLE, it must: be a valid 444e5c31af7Sopenharmony_ci slink:VkImageView handle of type ename:VK_IMAGE_VIEW_TYPE_2D 445e5c31af7Sopenharmony_ci * [[VUID-vkCmdBindInvocationMaskHUAWEI-imageView-04978]] 446e5c31af7Sopenharmony_ci If pname:imageView is not dlink:VK_NULL_HANDLE, it must: have a format 447e5c31af7Sopenharmony_ci of ename:VK_FORMAT_R8_UINT 448e5c31af7Sopenharmony_ci * [[VUID-vkCmdBindInvocationMaskHUAWEI-imageView-04979]] 449e5c31af7Sopenharmony_ci If pname:imageView is not dlink:VK_NULL_HANDLE, it must: have been 450e5c31af7Sopenharmony_ci created with ename:VK_IMAGE_USAGE_INVOCATION_MASK_BIT_HUAWEI set 451e5c31af7Sopenharmony_ci * [[VUID-vkCmdBindInvocationMaskHUAWEI-imageView-04980]] 452e5c31af7Sopenharmony_ci If pname:imageView is not dlink:VK_NULL_HANDLE, pname:imageLayout must: 453e5c31af7Sopenharmony_ci be ename:VK_IMAGE_LAYOUT_GENERAL 454e5c31af7Sopenharmony_ci * [[VUID-vkCmdBindInvocationMaskHUAWEI-width-04981]] 455e5c31af7Sopenharmony_ci Thread mask image resolution must: match the pname:width and 456e5c31af7Sopenharmony_ci pname:height in flink:vkCmdTraceRaysKHR 457e5c31af7Sopenharmony_ci * [[VUID-vkCmdBindInvocationMaskHUAWEI-None-04982]] 458e5c31af7Sopenharmony_ci Each element in the invocation mask image must: have the value `0` or 459e5c31af7Sopenharmony_ci `1`. 460e5c31af7Sopenharmony_ci The value 1 means the invocation is active 461e5c31af7Sopenharmony_ci * [[VUID-vkCmdBindInvocationMaskHUAWEI-depth-04983]] 462e5c31af7Sopenharmony_ci pname:depth in flink:vkCmdTraceRaysKHR must: be 1 463e5c31af7Sopenharmony_ci**** 464e5c31af7Sopenharmony_ci 465e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkCmdBindInvocationMaskHUAWEI.adoc[] 466e5c31af7Sopenharmony_ci-- 467e5c31af7Sopenharmony_ciendif::VK_HUAWEI_invocation_mask[] 468e5c31af7Sopenharmony_ci 469e5c31af7Sopenharmony_ci[open,refpage='vkCmdTraceRaysIndirectKHR',desc='Initialize an indirect ray tracing dispatch',type='protos'] 470e5c31af7Sopenharmony_ci-- 471e5c31af7Sopenharmony_ci:refpage: vkCmdTraceRaysIndirectKHR 472e5c31af7Sopenharmony_ci 473e5c31af7Sopenharmony_ciTo dispatch ray tracing, with some parameters sourced on the device, use: 474e5c31af7Sopenharmony_ci 475e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkCmdTraceRaysIndirectKHR.adoc[] 476e5c31af7Sopenharmony_ci 477e5c31af7Sopenharmony_ci * pname:commandBuffer is the command buffer into which the command will be 478e5c31af7Sopenharmony_ci recorded. 479e5c31af7Sopenharmony_ci * pname:pRaygenShaderBindingTable is a 480e5c31af7Sopenharmony_ci slink:VkStridedDeviceAddressRegionKHR that holds the shader binding 481e5c31af7Sopenharmony_ci table data for the ray generation shader stage. 482e5c31af7Sopenharmony_ci * pname:pMissShaderBindingTable is a slink:VkStridedDeviceAddressRegionKHR 483e5c31af7Sopenharmony_ci that holds the shader binding table data for the miss shader stage. 484e5c31af7Sopenharmony_ci * pname:pHitShaderBindingTable is a slink:VkStridedDeviceAddressRegionKHR 485e5c31af7Sopenharmony_ci that holds the shader binding table data for the hit shader stage. 486e5c31af7Sopenharmony_ci * pname:pCallableShaderBindingTable is a 487e5c31af7Sopenharmony_ci slink:VkStridedDeviceAddressRegionKHR that holds the shader binding 488e5c31af7Sopenharmony_ci table data for the callable shader stage. 489e5c31af7Sopenharmony_ci * pname:indirectDeviceAddress is a buffer device address which is a 490e5c31af7Sopenharmony_ci pointer to a slink:VkTraceRaysIndirectCommandKHR structure containing 491e5c31af7Sopenharmony_ci the trace ray parameters. 492e5c31af7Sopenharmony_ci 493e5c31af7Sopenharmony_cifname:vkCmdTraceRaysIndirectKHR behaves similarly to flink:vkCmdTraceRaysKHR 494e5c31af7Sopenharmony_ciexcept that the ray trace query dimensions are read by the device from 495e5c31af7Sopenharmony_cipname:indirectDeviceAddress during execution. 496e5c31af7Sopenharmony_ci 497e5c31af7Sopenharmony_ci.Valid Usage 498e5c31af7Sopenharmony_ci**** 499e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_common.adoc[] 500e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_common_khr.adoc[] 501e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_binding_table_raygen_stride.adoc[] 502e5c31af7Sopenharmony_ci 503e5c31af7Sopenharmony_ci:rayGenShaderBindingTableAddress: pname:pRayGenShaderBindingTable->deviceAddress 504e5c31af7Sopenharmony_ci:rayGenShaderBindingTableStride: pname:pRayGenShaderBindingTable->stride 505e5c31af7Sopenharmony_ci:missShaderBindingTableAddress: pname:pMissShaderBindingTable->deviceAddress 506e5c31af7Sopenharmony_ci:missShaderBindingTableStride: pname:pMissShaderBindingTable->stride 507e5c31af7Sopenharmony_ci:hitShaderBindingTableAddress: pname:pHitShaderBindingTable->deviceAddress 508e5c31af7Sopenharmony_ci:hitShaderBindingTableStride: pname:pHitShaderBindingTable->stride 509e5c31af7Sopenharmony_ci:callableShaderBindingTableAddress: pname:pCallableShaderBindingTable->deviceAddress 510e5c31af7Sopenharmony_ci:callableShaderBindingTableStride: pname:pCallableShaderBindingTable->stride 511e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_binding_table.adoc[] 512e5c31af7Sopenharmony_ci 513e5c31af7Sopenharmony_ci:cmdstruct: VkTraceRaysIndirectCommandKHR 514e5c31af7Sopenharmony_ci:feature: rayTracingPipelineTraceRaysIndirect 515e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_indirect_common.adoc[] 516e5c31af7Sopenharmony_ci**** 517e5c31af7Sopenharmony_ci 518e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkCmdTraceRaysIndirectKHR.adoc[] 519e5c31af7Sopenharmony_ci-- 520e5c31af7Sopenharmony_ci 521e5c31af7Sopenharmony_ci[open,refpage='VkTraceRaysIndirectCommandKHR',desc='Structure specifying the parameters of an indirect ray tracing command',type='structs'] 522e5c31af7Sopenharmony_ci-- 523e5c31af7Sopenharmony_ci:refpage: VkTraceRaysIndirectCommandKHR 524e5c31af7Sopenharmony_ci 525e5c31af7Sopenharmony_ciThe sname:VkTraceRaysIndirectCommandKHR structure is defined as: 526e5c31af7Sopenharmony_ci 527e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkTraceRaysIndirectCommandKHR.adoc[] 528e5c31af7Sopenharmony_ci 529e5c31af7Sopenharmony_ci * pname:width is the width of the ray trace query dimensions. 530e5c31af7Sopenharmony_ci * pname:height is height of the ray trace query dimensions. 531e5c31af7Sopenharmony_ci * pname:depth is depth of the ray trace query dimensions. 532e5c31af7Sopenharmony_ci 533e5c31af7Sopenharmony_ciThe members of sname:VkTraceRaysIndirectCommandKHR have the same meaning as 534e5c31af7Sopenharmony_cithe similarly named parameters of flink:vkCmdTraceRaysKHR. 535e5c31af7Sopenharmony_ci 536e5c31af7Sopenharmony_ci.Valid Usage 537e5c31af7Sopenharmony_ci**** 538e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_limits_common.adoc[] 539e5c31af7Sopenharmony_ci**** 540e5c31af7Sopenharmony_ci 541e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkTraceRaysIndirectCommandKHR.adoc[] 542e5c31af7Sopenharmony_ci-- 543e5c31af7Sopenharmony_ci 544e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_maintenance1[] 545e5c31af7Sopenharmony_ci[open,refpage='vkCmdTraceRaysIndirect2KHR',desc='Initialize an indirect ray tracing dispatch with indirect shader binding tables',type='protos'] 546e5c31af7Sopenharmony_ci-- 547e5c31af7Sopenharmony_ci:refpage: vkCmdTraceRaysIndirect2KHR 548e5c31af7Sopenharmony_ci 549e5c31af7Sopenharmony_ciTo dispatch ray tracing, with some parameters sourced on the device, use: 550e5c31af7Sopenharmony_ci 551e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkCmdTraceRaysIndirect2KHR.adoc[] 552e5c31af7Sopenharmony_ci 553e5c31af7Sopenharmony_ci * pname:commandBuffer is the command buffer into which the command will be 554e5c31af7Sopenharmony_ci recorded. 555e5c31af7Sopenharmony_ci * pname:indirectDeviceAddress is a buffer device address which is a 556e5c31af7Sopenharmony_ci pointer to a slink:VkTraceRaysIndirectCommand2KHR structure containing 557e5c31af7Sopenharmony_ci the trace ray parameters. 558e5c31af7Sopenharmony_ci 559e5c31af7Sopenharmony_cifname:vkCmdTraceRaysIndirect2KHR behaves similarly to 560e5c31af7Sopenharmony_ciflink:vkCmdTraceRaysIndirectKHR except that shader binding table parameters 561e5c31af7Sopenharmony_cias well as dispatch dimensions are read by the device from 562e5c31af7Sopenharmony_cipname:indirectDeviceAddress during execution. 563e5c31af7Sopenharmony_ci 564e5c31af7Sopenharmony_ci.Valid Usage 565e5c31af7Sopenharmony_ci**** 566e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_common.adoc[] 567e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_common_khr.adoc[] 568e5c31af7Sopenharmony_ci 569e5c31af7Sopenharmony_ci:cmdstruct: VkTraceRaysIndirectCommand2KHR 570e5c31af7Sopenharmony_ci:feature: rayTracingPipelineTraceRaysIndirect2 571e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_indirect_common.adoc[] 572e5c31af7Sopenharmony_ci**** 573e5c31af7Sopenharmony_ci 574e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkCmdTraceRaysIndirect2KHR.adoc[] 575e5c31af7Sopenharmony_ci-- 576e5c31af7Sopenharmony_ci 577e5c31af7Sopenharmony_ci[open,refpage='VkTraceRaysIndirectCommand2KHR',desc='Structure specifying the parameters of an indirect trace ray command with indirect shader binding tables',type='structs'] 578e5c31af7Sopenharmony_ci-- 579e5c31af7Sopenharmony_ci:refpage: VkTraceRaysIndirectCommand2KHR 580e5c31af7Sopenharmony_ci 581e5c31af7Sopenharmony_ciThe sname:VkTraceRaysIndirectCommand2KHR structure is defined as: 582e5c31af7Sopenharmony_ci 583e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkTraceRaysIndirectCommand2KHR.adoc[] 584e5c31af7Sopenharmony_ci 585e5c31af7Sopenharmony_ci * pname:raygenShaderRecordAddress is a basetype:VkDeviceAddress of the ray 586e5c31af7Sopenharmony_ci generation shader binding table record used by this command. 587e5c31af7Sopenharmony_ci * pname:raygenShaderRecordSize is a basetype:VkDeviceSize number of bytes 588e5c31af7Sopenharmony_ci corresponding to the ray generation shader binding table record at base 589e5c31af7Sopenharmony_ci address pname:raygenShaderRecordAddress. 590e5c31af7Sopenharmony_ci * pname:missShaderBindingTableAddress is a basetype:VkDeviceAddress of the 591e5c31af7Sopenharmony_ci first record in the miss shader binding table used by this command. 592e5c31af7Sopenharmony_ci * pname:missShaderBindingTableSize is a basetype:VkDeviceSize number of 593e5c31af7Sopenharmony_ci bytes corresponding to the total size of the miss shader binding table 594e5c31af7Sopenharmony_ci at pname:missShaderBindingTableAddress that may be accessed by this 595e5c31af7Sopenharmony_ci command. 596e5c31af7Sopenharmony_ci * pname:missShaderBindingTableStride is a basetype:VkDeviceSize number of 597e5c31af7Sopenharmony_ci bytes between records of the miss shader binding table. 598e5c31af7Sopenharmony_ci * pname:hitShaderBindingTableAddress is a basetype:VkDeviceAddress of the 599e5c31af7Sopenharmony_ci first record in the hit shader binding table used by this command. 600e5c31af7Sopenharmony_ci * pname:hitShaderBindingTableSize is a basetype:VkDeviceSize number of 601e5c31af7Sopenharmony_ci bytes corresponding to the total size of the hit shader binding table at 602e5c31af7Sopenharmony_ci pname:hitShaderBindingTableAddress that may be accessed by this command. 603e5c31af7Sopenharmony_ci * pname:hitShaderBindingTableStride is a basetype:VkDeviceSize number of 604e5c31af7Sopenharmony_ci bytes between records of the hit shader binding table. 605e5c31af7Sopenharmony_ci * pname:callableShaderBindingTableAddress is a basetype:VkDeviceAddress of 606e5c31af7Sopenharmony_ci the first record in the callable shader binding table used by this 607e5c31af7Sopenharmony_ci command. 608e5c31af7Sopenharmony_ci * pname:callableShaderBindingTableSize is a basetype:VkDeviceSize number 609e5c31af7Sopenharmony_ci of bytes corresponding to the total size of the callable shader binding 610e5c31af7Sopenharmony_ci table at pname:callableShaderBindingTableAddress that may be accessed by 611e5c31af7Sopenharmony_ci this command. 612e5c31af7Sopenharmony_ci * pname:callableShaderBindingTableStride is a basetype:VkDeviceSize number 613e5c31af7Sopenharmony_ci of bytes between records of the callable shader binding table. 614e5c31af7Sopenharmony_ci * pname:width is the width of the ray trace query dimensions. 615e5c31af7Sopenharmony_ci * pname:height is height of the ray trace query dimensions. 616e5c31af7Sopenharmony_ci * pname:depth is depth of the ray trace query dimensions. 617e5c31af7Sopenharmony_ci 618e5c31af7Sopenharmony_ciThe members of sname:VkTraceRaysIndirectCommand2KHR have the same meaning as 619e5c31af7Sopenharmony_cithe similarly named parameters of flink:vkCmdTraceRaysKHR. 620e5c31af7Sopenharmony_ci 621e5c31af7Sopenharmony_ciIndirect shader binding table buffer parameters must satisfy the same memory 622e5c31af7Sopenharmony_cialignment and binding requirements as their counterparts in 623e5c31af7Sopenharmony_ciflink:vkCmdTraceRaysIndirectKHR and flink:vkCmdTraceRaysKHR. 624e5c31af7Sopenharmony_ci 625e5c31af7Sopenharmony_ci.Valid Usage 626e5c31af7Sopenharmony_ci**** 627e5c31af7Sopenharmony_ci:rayGenShaderBindingTableAddress: pname:raygenShaderRecordAddress 628e5c31af7Sopenharmony_ci:rayGenShaderBindingTableSize: pname:raygenShaderRecordSize 629e5c31af7Sopenharmony_ci:missShaderBindingTableAddress: pname:missShaderBindingTableAddress 630e5c31af7Sopenharmony_ci:missShaderBindingTableStride: pname:missShaderBindingTableStride 631e5c31af7Sopenharmony_ci:hitShaderBindingTableAddress: pname:hitShaderBindingTableAddress 632e5c31af7Sopenharmony_ci:hitShaderBindingTableStride: pname:hitShaderBindingTableStride 633e5c31af7Sopenharmony_ci:callableShaderBindingTableAddress: pname:callableShaderBindingTableAddress 634e5c31af7Sopenharmony_ci:callableShaderBindingTableStride: pname:callableShaderBindingTableStride 635e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_binding_table.adoc[] 636e5c31af7Sopenharmony_ciinclude::{chapters}/commonvalidity/trace_rays_limits_common.adoc[] 637e5c31af7Sopenharmony_ci**** 638e5c31af7Sopenharmony_ci 639e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkTraceRaysIndirectCommand2KHR.adoc[] 640e5c31af7Sopenharmony_ci-- 641e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_maintenance1[] 642e5c31af7Sopenharmony_ci 643e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 644e5c31af7Sopenharmony_ci 645e5c31af7Sopenharmony_ci 646e5c31af7Sopenharmony_ci[[shader-binding-table]] 647e5c31af7Sopenharmony_ci== Shader Binding Table 648e5c31af7Sopenharmony_ci 649e5c31af7Sopenharmony_ciA _shader binding table_ is a resource which establishes the relationship 650e5c31af7Sopenharmony_cibetween the ray tracing pipeline and the acceleration structures that were 651e5c31af7Sopenharmony_cibuilt for the ray tracing pipeline. 652e5c31af7Sopenharmony_ciIt indicates the shaders that operate on each geometry in an acceleration 653e5c31af7Sopenharmony_cistructure. 654e5c31af7Sopenharmony_ciIn addition, it contains the resources accessed by each shader, including 655e5c31af7Sopenharmony_ciindices of textures, buffer device addresses, and constants. 656e5c31af7Sopenharmony_ciThe application allocates and manages _shader binding tables_ as 657e5c31af7Sopenharmony_cislink:VkBuffer objects. 658e5c31af7Sopenharmony_ci 659e5c31af7Sopenharmony_ciEach entry in the shader binding table consists of 660e5c31af7Sopenharmony_cipname:shaderGroupHandleSize bytes of data, either as queried by 661e5c31af7Sopenharmony_ciflink:vkGetRayTracingShaderGroupHandlesKHR to refer to those specified 662e5c31af7Sopenharmony_cishaders, or all zeros to refer to a zero shader group. 663e5c31af7Sopenharmony_ciA zero shader group behaves as though it is a shader group consisting 664e5c31af7Sopenharmony_cientirely of ename:VK_SHADER_UNUSED_KHR. 665e5c31af7Sopenharmony_ciThe remainder of the data specified by the stride is application-visible 666e5c31af7Sopenharmony_cidata that can be referenced by a code:ShaderRecordBufferKHR block in the 667e5c31af7Sopenharmony_cishader. 668e5c31af7Sopenharmony_ci 669e5c31af7Sopenharmony_ciThe shader binding tables to use in a ray tracing pipeline are passed to the 670e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 671e5c31af7Sopenharmony_ciflink:vkCmdTraceRaysNV, 672e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 673e5c31af7Sopenharmony_ciflink:vkCmdTraceRaysKHR, or flink:vkCmdTraceRaysIndirectKHR commands. 674e5c31af7Sopenharmony_ciShader binding tables are read-only in shaders that are executing on the ray 675e5c31af7Sopenharmony_citracing pipeline. 676e5c31af7Sopenharmony_ci 677e5c31af7Sopenharmony_ciShader variables identified with the code:ShaderRecordBufferKHR storage 678e5c31af7Sopenharmony_ciclass are used to access the provided shader binding table. 679e5c31af7Sopenharmony_ciSuch variables must: be: 680e5c31af7Sopenharmony_ci 681e5c31af7Sopenharmony_ci * typed as code:OpTypeStruct, or an array of this type, 682e5c31af7Sopenharmony_ci * identified with a code:Block decoration, and 683e5c31af7Sopenharmony_ci * laid out explicitly using the code:Offset, code:ArrayStride, and 684e5c31af7Sopenharmony_ci code:MatrixStride decorations as specified in 685e5c31af7Sopenharmony_ci <<interfaces-resources-layout,Offset and Stride Assignment>>. 686e5c31af7Sopenharmony_ci 687e5c31af7Sopenharmony_ciThe code:Offset decoration for any member of a code:Block-decorated variable 688e5c31af7Sopenharmony_ciin the code:ShaderRecordBufferKHR storage class must: not cause the space 689e5c31af7Sopenharmony_cirequired for that variable to extend outside the range [eq]#[0, 690e5c31af7Sopenharmony_cipname:maxStorageBufferRange)#. 691e5c31af7Sopenharmony_ci 692e5c31af7Sopenharmony_ciAccesses to the shader binding table from ray tracing pipelines must: be 693e5c31af7Sopenharmony_ci<<synchronization-dependencies,synchronized>> with the 694e5c31af7Sopenharmony_ciename:VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR 695e5c31af7Sopenharmony_ci<<synchronization-pipeline-stages, pipeline stage>> and an 696e5c31af7Sopenharmony_ci<<synchronization-access-types, access type>> of 697e5c31af7Sopenharmony_ciename:VK_ACCESS_SHADER_READ_BIT. 698e5c31af7Sopenharmony_ci 699e5c31af7Sopenharmony_ci[NOTE] 700e5c31af7Sopenharmony_ci.Note 701e5c31af7Sopenharmony_ci==== 702e5c31af7Sopenharmony_ciBecause different shader record buffers can be associated with the same 703e5c31af7Sopenharmony_cishader, a shader variable with code:ShaderRecordBufferKHR storage class will 704e5c31af7Sopenharmony_cinot be dynamically uniform if different invocations of the same shader can 705e5c31af7Sopenharmony_cireference different data in the shader record buffer, such as if the same 706e5c31af7Sopenharmony_cishader occurs twice in the shader binding table with a different shader 707e5c31af7Sopenharmony_cirecord buffer. 708e5c31af7Sopenharmony_ciIn this case, indexing resources based on values in the 709e5c31af7Sopenharmony_cicode:ShaderRecordBufferKHR storage class, the index should be decorated as 710e5c31af7Sopenharmony_cicode:NonUniform. 711e5c31af7Sopenharmony_ci==== 712e5c31af7Sopenharmony_ci 713e5c31af7Sopenharmony_ci 714e5c31af7Sopenharmony_ci[[shader-binding-table-indexing-rules]] 715e5c31af7Sopenharmony_ci=== Indexing Rules 716e5c31af7Sopenharmony_ci 717e5c31af7Sopenharmony_ciIn order to execute the correct shaders and access the correct resources 718e5c31af7Sopenharmony_ciduring a ray tracing dispatch, the implementation must: be able to locate 719e5c31af7Sopenharmony_cishader binding table entries at various stages of execution. 720e5c31af7Sopenharmony_ciThis is accomplished by defining a set of indexing rules that compute shader 721e5c31af7Sopenharmony_cibinding table record positions relative to the buffer's base address in 722e5c31af7Sopenharmony_cimemory. 723e5c31af7Sopenharmony_ciThe application must: organize the contents of the shader binding table's 724e5c31af7Sopenharmony_cimemory in a way that application of the indexing rules will lead to correct 725e5c31af7Sopenharmony_cirecords. 726e5c31af7Sopenharmony_ci 727e5c31af7Sopenharmony_ci 728e5c31af7Sopenharmony_ci==== Ray Generation Shaders 729e5c31af7Sopenharmony_ci 730e5c31af7Sopenharmony_ciOnly one ray generation shader is executed per ray tracing dispatch. 731e5c31af7Sopenharmony_ci 732e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 733e5c31af7Sopenharmony_ciFor flink:vkCmdTraceRaysKHR, the location of the ray generation shader is 734e5c31af7Sopenharmony_cispecified by the pname:pRaygenShaderBindingTable->deviceAddress parameter 735e5c31af7Sopenharmony_ci-- there is no indexing. 736e5c31af7Sopenharmony_ciAll data accessed must: be less than pname:pRaygenShaderBindingTable->size 737e5c31af7Sopenharmony_cibytes from pname:deviceAddress. 738e5c31af7Sopenharmony_cipname:pRaygenShaderBindingTable->stride is unused, and must: be equal to 739e5c31af7Sopenharmony_cipname:pRaygenShaderBindingTable->size. 740e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 741e5c31af7Sopenharmony_ci 742e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 743e5c31af7Sopenharmony_ciFor flink:vkCmdTraceRaysNV, the location of the ray generation shader is 744e5c31af7Sopenharmony_cispecified by the pname:raygenShaderBindingTableBuffer and 745e5c31af7Sopenharmony_cipname:raygenShaderBindingOffset parameters -- there is no indexing. 746e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 747e5c31af7Sopenharmony_ci 748e5c31af7Sopenharmony_ci 749e5c31af7Sopenharmony_ci[[shader-binding-table-hit-shader-indexing]] 750e5c31af7Sopenharmony_ci==== Hit Shaders 751e5c31af7Sopenharmony_ci 752e5c31af7Sopenharmony_ciThe base for the computation of intersection, any-hit, and closest hit 753e5c31af7Sopenharmony_cishader locations is the code:instanceShaderBindingTableRecordOffset value 754e5c31af7Sopenharmony_cistored with each instance of a top-level acceleration structure 755e5c31af7Sopenharmony_ci(slink:VkAccelerationStructureInstanceKHR). 756e5c31af7Sopenharmony_ciThis value determines the beginning of the shader binding table records for 757e5c31af7Sopenharmony_cia given instance. 758e5c31af7Sopenharmony_ci 759e5c31af7Sopenharmony_ciIn the following rule, code:geometryIndex refers to the 760e5c31af7Sopenharmony_ci<<acceleration-structure-geometry-index, geometry index>> of the intersected 761e5c31af7Sopenharmony_cigeometry within the instance. 762e5c31af7Sopenharmony_ci 763e5c31af7Sopenharmony_ciThe code:sbtRecordOffset and code:sbtRecordStride values are passed in as 764e5c31af7Sopenharmony_ciparameters to 765e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[code:traceNV()] 766e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing+VK_KHR_ray_tracing_pipeline[ or ] 767e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[code:traceRayEXT()] 768e5c31af7Sopenharmony_cicalls made in the shaders. 769e5c31af7Sopenharmony_ciSee Section 8.19 (Ray Tracing Functions) of the OpenGL Shading Language 770e5c31af7Sopenharmony_ciSpecification for more details. 771e5c31af7Sopenharmony_ciIn SPIR-V, these correspond to the code:SBTOffset and code:SBTStride 772e5c31af7Sopenharmony_ciparameters to the <<glossary-pipeline-trace-ray, pipeline trace ray>> 773e5c31af7Sopenharmony_ciinstructions. 774e5c31af7Sopenharmony_ci 775e5c31af7Sopenharmony_ciThe result of this computation is then added to 776e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 777e5c31af7Sopenharmony_cipname:pHitShaderBindingTable->deviceAddress, a device address passed to 778e5c31af7Sopenharmony_ciflink:vkCmdTraceRaysKHR 779e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 780e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing+VK_KHR_ray_tracing_pipeline[, or ] 781e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 782e5c31af7Sopenharmony_cipname:hitShaderBindingOffset, a base offset passed to flink:vkCmdTraceRaysNV 783e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 784e5c31af7Sopenharmony_ci. 785e5c31af7Sopenharmony_ci 786e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 787e5c31af7Sopenharmony_ciFor flink:vkCmdTraceRaysKHR, the complete rule to compute a hit shader 788e5c31af7Sopenharmony_cibinding table record address in the pname:pHitShaderBindingTable is: 789e5c31af7Sopenharmony_ci 790e5c31af7Sopenharmony_ci {empty}:: [eq]#pname:pHitShaderBindingTable->deviceAddress {plus} 791e5c31af7Sopenharmony_ci pname:pHitShaderBindingTable->stride {times} ( 792e5c31af7Sopenharmony_ci code:instanceShaderBindingTableRecordOffset {plus} 793e5c31af7Sopenharmony_ci code:geometryIndex {times} code:sbtRecordStride {plus} 794e5c31af7Sopenharmony_ci code:sbtRecordOffset )# 795e5c31af7Sopenharmony_ci 796e5c31af7Sopenharmony_ciAll data accessed must: be less than pname:pHitShaderBindingTable->size 797e5c31af7Sopenharmony_cibytes from the base address. 798e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 799e5c31af7Sopenharmony_ci 800e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 801e5c31af7Sopenharmony_ciFor flink:vkCmdTraceRaysNV, the offset and stride come from direct 802e5c31af7Sopenharmony_ciparameters, so the full rule to compute a hit shader binding table record 803e5c31af7Sopenharmony_ciaddress in the pname:hitShaderBindingTableBuffer is: 804e5c31af7Sopenharmony_ci 805e5c31af7Sopenharmony_ci {empty}:: [eq]#pname:hitShaderBindingOffset {plus} 806e5c31af7Sopenharmony_ci pname:hitShaderBindingStride {times} ( 807e5c31af7Sopenharmony_ci code:instanceShaderBindingTableRecordOffset {plus} 808e5c31af7Sopenharmony_ci code:geometryIndex {times} code:sbtRecordStride {plus} 809e5c31af7Sopenharmony_ci code:sbtRecordOffset )# 810e5c31af7Sopenharmony_ci 811e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 812e5c31af7Sopenharmony_ci 813e5c31af7Sopenharmony_ci 814e5c31af7Sopenharmony_ci==== Miss Shaders 815e5c31af7Sopenharmony_ci 816e5c31af7Sopenharmony_ciA miss shader is executed whenever a ray query fails to find an intersection 817e5c31af7Sopenharmony_cifor the given scene geometry. 818e5c31af7Sopenharmony_ciMultiple miss shaders may: be executed throughout a ray tracing dispatch. 819e5c31af7Sopenharmony_ci 820e5c31af7Sopenharmony_ciThe base for the computation of miss shader locations is 821e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 822e5c31af7Sopenharmony_cipname:pMissShaderBindingTable->deviceAddress, a device address passed into 823e5c31af7Sopenharmony_ciflink:vkCmdTraceRaysKHR 824e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 825e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing+VK_KHR_ray_tracing_pipeline[, or ] 826e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 827e5c31af7Sopenharmony_cipname:missShaderBindingOffset, a base offset passed into 828e5c31af7Sopenharmony_ciflink:vkCmdTraceRaysNV 829e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 830e5c31af7Sopenharmony_ci. 831e5c31af7Sopenharmony_ci 832e5c31af7Sopenharmony_ciThe code:missIndex value is passed in as a parameter to 833e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[code:traceNV()] 834e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing+VK_KHR_ray_tracing_pipeline[ or ] 835e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[code:traceRayEXT()] 836e5c31af7Sopenharmony_cicalls made in the shaders. 837e5c31af7Sopenharmony_ciSee Section 8.19 (Ray Tracing Functions) of the OpenGL Shading Language 838e5c31af7Sopenharmony_ciSpecification for more details. 839e5c31af7Sopenharmony_ciIn SPIR-V, this corresponds to the code:MissIndex parameter to the 840e5c31af7Sopenharmony_ci<<glossary-pipeline-trace-ray, pipeline trace ray>> instructions. 841e5c31af7Sopenharmony_ci 842e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 843e5c31af7Sopenharmony_ciFor flink:vkCmdTraceRaysKHR, the complete rule to compute a miss shader 844e5c31af7Sopenharmony_cibinding table record address in the pname:pMissShaderBindingTable is: 845e5c31af7Sopenharmony_ci 846e5c31af7Sopenharmony_ci {empty}:: [eq]#pname:pMissShaderBindingTable->deviceAddress {plus} 847e5c31af7Sopenharmony_ci pname:pMissShaderBindingTable->stride {times} code:missIndex# 848e5c31af7Sopenharmony_ci 849e5c31af7Sopenharmony_ciAll data accessed must: be less than pname:pMissShaderBindingTable->size 850e5c31af7Sopenharmony_cibytes from the base address. 851e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 852e5c31af7Sopenharmony_ci 853e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 854e5c31af7Sopenharmony_ciFor flink:vkCmdTraceRaysNV, the offset and stride come from direct 855e5c31af7Sopenharmony_ciparameters, so the full rule to compute a miss shader binding table record 856e5c31af7Sopenharmony_ciaddress in the pname:missShaderBindingTableBuffer is: 857e5c31af7Sopenharmony_ci 858e5c31af7Sopenharmony_ci {empty}:: [eq]#pname:missShaderBindingOffset {plus} 859e5c31af7Sopenharmony_ci pname:missShaderBindingStride {times} code:missIndex# 860e5c31af7Sopenharmony_ci 861e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 862e5c31af7Sopenharmony_ci 863e5c31af7Sopenharmony_ci 864e5c31af7Sopenharmony_ci==== Callable Shaders 865e5c31af7Sopenharmony_ci 866e5c31af7Sopenharmony_ciA callable shader is executed when requested by a ray tracing shader. 867e5c31af7Sopenharmony_ciMultiple callable shaders may: be executed throughout a ray tracing 868e5c31af7Sopenharmony_cidispatch. 869e5c31af7Sopenharmony_ci 870e5c31af7Sopenharmony_ciThe base for the computation of callable shader locations is 871e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 872e5c31af7Sopenharmony_cipname:pCallableShaderBindingTable->deviceAddress, a device address passed 873e5c31af7Sopenharmony_ciinto flink:vkCmdTraceRaysKHR 874e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 875e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing+VK_KHR_ray_tracing_pipeline[, or ] 876e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 877e5c31af7Sopenharmony_cipname:callableShaderBindingOffset, a base offset passed into 878e5c31af7Sopenharmony_ciflink:vkCmdTraceRaysNV 879e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 880e5c31af7Sopenharmony_ci. 881e5c31af7Sopenharmony_ci 882e5c31af7Sopenharmony_ciThe code:sbtRecordIndex value is passed in as a parameter to 883e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[code:executeCallableNV()] 884e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing+VK_KHR_ray_tracing_pipeline[ or ] 885e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[code:executeCallableEXT()] 886e5c31af7Sopenharmony_cicalls made in the shaders. 887e5c31af7Sopenharmony_ciSee Section 8.19 (Ray Tracing Functions) of the OpenGL Shading Language 888e5c31af7Sopenharmony_ciSpecification for more details. 889e5c31af7Sopenharmony_ciIn SPIR-V, this corresponds to the code:SBTIndex parameter to the 890e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[code:OpExecuteCallableNV] 891e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing+VK_KHR_ray_tracing_pipeline[ or ] 892e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[code:OpExecuteCallableKHR] 893e5c31af7Sopenharmony_ciinstruction. 894e5c31af7Sopenharmony_ci 895e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 896e5c31af7Sopenharmony_ciFor flink:vkCmdTraceRaysKHR, the complete rule to compute a callable shader 897e5c31af7Sopenharmony_cibinding table record address in the pname:pCallableShaderBindingTable is: 898e5c31af7Sopenharmony_ci 899e5c31af7Sopenharmony_ci {empty}:: [eq]#pname:pCallableShaderBindingTable->deviceAddress {plus} 900e5c31af7Sopenharmony_ci pname:pCallableShaderBindingTable->stride {times} 901e5c31af7Sopenharmony_ci code:sbtRecordIndex# 902e5c31af7Sopenharmony_ci 903e5c31af7Sopenharmony_ciAll data accessed must: be less than pname:pCallableShaderBindingTable->size 904e5c31af7Sopenharmony_cibytes from the base address. 905e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 906e5c31af7Sopenharmony_ci 907e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing[] 908e5c31af7Sopenharmony_ciFor flink:vkCmdTraceRaysNV, the offset and stride come from direct 909e5c31af7Sopenharmony_ciparameters, so the full rule to compute a callable shader binding table 910e5c31af7Sopenharmony_cirecord address in the pname:callableShaderBindingTableBuffer is: 911e5c31af7Sopenharmony_ci 912e5c31af7Sopenharmony_ci {empty}:: [eq]#pname:callableShaderBindingOffset {plus} 913e5c31af7Sopenharmony_ci pname:callableShaderBindingStride {times} code:sbtRecordIndex# 914e5c31af7Sopenharmony_ci 915e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing[] 916e5c31af7Sopenharmony_ci 917e5c31af7Sopenharmony_ci 918e5c31af7Sopenharmony_ci[[ray-tracing-pipeline-stack]] 919e5c31af7Sopenharmony_ci== Ray Tracing Pipeline Stack 920e5c31af7Sopenharmony_ci 921e5c31af7Sopenharmony_ciRay tracing pipelines have a potentially large set of shaders which may: be 922e5c31af7Sopenharmony_ciinvoked in various call chain combinations to perform ray tracing. 923e5c31af7Sopenharmony_ciTo store parameters for a given shader execution, an implementation may: use 924e5c31af7Sopenharmony_cia stack of data in memory. 925e5c31af7Sopenharmony_ciThis stack must: be sized to the sum of the stack sizes of all shaders in 926e5c31af7Sopenharmony_ciany call chain executed by the application. 927e5c31af7Sopenharmony_ci 928e5c31af7Sopenharmony_ciIf the stack size is not set explicitly, the stack size for a pipeline is: 929e5c31af7Sopenharmony_ci 930e5c31af7Sopenharmony_ci {empty}:: [eq]#rayGenStackMax {plus} min(1, 931e5c31af7Sopenharmony_ci pname:maxPipelineRayRecursionDepth) {times} 932e5c31af7Sopenharmony_ci max(closestHitStackMax, missStackMax, intersectionStackMax 933e5c31af7Sopenharmony_ci {plus} anyHitStackMax) {plus} max(0, 934e5c31af7Sopenharmony_ci pname:maxPipelineRayRecursionDepth-1) {times} 935e5c31af7Sopenharmony_ci max(closestHitStackMax, missStackMax) {plus} 2 {times} 936e5c31af7Sopenharmony_ci callableStackMax# 937e5c31af7Sopenharmony_ci 938e5c31af7Sopenharmony_ciwhere [eq]#rayGenStackMax#, [eq]#closestHitStackMax#, [eq]#missStackMax#, 939e5c31af7Sopenharmony_ci[eq]#anyHitStackMax#, [eq]#intersectionStackMax#, and [eq]#callableStackMax# 940e5c31af7Sopenharmony_ciare the maximum stack values queried by the respective shader stages for any 941e5c31af7Sopenharmony_cishaders in any shader groups defined by the pipeline. 942e5c31af7Sopenharmony_ci 943e5c31af7Sopenharmony_ciThis stack size is potentially significant, so an application may: want to 944e5c31af7Sopenharmony_ciprovide a more accurate stack size after pipeline compilation. 945e5c31af7Sopenharmony_ciThe value that the application provides is the maximum value of the sum of 946e5c31af7Sopenharmony_ciall shaders in a call chain across all possible call chains, taking into 947e5c31af7Sopenharmony_ciaccount any application specific knowledge about the properties of the call 948e5c31af7Sopenharmony_cichains. 949e5c31af7Sopenharmony_ci 950e5c31af7Sopenharmony_ci[NOTE] 951e5c31af7Sopenharmony_ci.Note 952e5c31af7Sopenharmony_ci==== 953e5c31af7Sopenharmony_ciFor example, if an application has two types of closest hit and miss shaders 954e5c31af7Sopenharmony_cithat it can use but the first level of rays will only use the first kind 955e5c31af7Sopenharmony_ci(possibly reflection) and the second level will only use the second kind 956e5c31af7Sopenharmony_ci(occlusion or shadow ray, for example) then the application can compute the 957e5c31af7Sopenharmony_cistack size by something similar to: 958e5c31af7Sopenharmony_ci 959e5c31af7Sopenharmony_ci {empty}:: [eq]#code:rayGenStack {plus} max(code:closestHit1Stack, 960e5c31af7Sopenharmony_ci code:miss1Stack) {plus} max(code:closestHit2Stack, 961e5c31af7Sopenharmony_ci code:miss2Stack)# 962e5c31af7Sopenharmony_ci 963e5c31af7Sopenharmony_ciThis is guaranteed to be no larger than the default stack size computation 964e5c31af7Sopenharmony_ciwhich assumes that both call levels may be the larger of the two. 965e5c31af7Sopenharmony_ci==== 966e5c31af7Sopenharmony_ci 967e5c31af7Sopenharmony_ci 968e5c31af7Sopenharmony_ci[[ray-tracing-capture-replay]] 969e5c31af7Sopenharmony_ci== Ray Tracing Capture Replay 970e5c31af7Sopenharmony_ci 971e5c31af7Sopenharmony_ciIn a similar way to 972e5c31af7Sopenharmony_ci<<features-bufferDeviceAddressCaptureReplay,bufferDeviceAddressCaptureReplay>>, 973e5c31af7Sopenharmony_cithe <<features-rayTracingPipelineShaderGroupHandleCaptureReplay, 974e5c31af7Sopenharmony_cipname:rayTracingPipelineShaderGroupHandleCaptureReplay>> feature allows the 975e5c31af7Sopenharmony_ciquerying of opaque data which can: be used in a future replay. 976e5c31af7Sopenharmony_ci 977e5c31af7Sopenharmony_ciDuring the capture phase, capture/replay tools are expected to query opaque 978e5c31af7Sopenharmony_cidata for shader group handle replay using 979e5c31af7Sopenharmony_ciflink:vkGetRayTracingCaptureReplayShaderGroupHandlesKHR. 980e5c31af7Sopenharmony_ci 981e5c31af7Sopenharmony_ciProviding the opaque data during replay, using 982e5c31af7Sopenharmony_cislink:VkRayTracingShaderGroupCreateInfoKHR::pname:pShaderGroupCaptureReplayHandle 983e5c31af7Sopenharmony_ciat pipeline creation time, causes the implementation to generate identical 984e5c31af7Sopenharmony_cishader group handles to those in the capture phase, allowing capture/replay 985e5c31af7Sopenharmony_citools to reuse previously recorded shader binding table buffer contents or 986e5c31af7Sopenharmony_cito obtain the same handles by calling 987e5c31af7Sopenharmony_ciflink:vkGetRayTracingCaptureReplayShaderGroupHandlesKHR again. 988e5c31af7Sopenharmony_ci 989e5c31af7Sopenharmony_ci 990e5c31af7Sopenharmony_ci 991