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