1e5c31af7Sopenharmony_ci// Copyright 2015-2021 The Khronos Group, Inc. 2e5c31af7Sopenharmony_ci// 3e5c31af7Sopenharmony_ci// SPDX-License-Identifier: CC-BY-4.0 4e5c31af7Sopenharmony_ci 5e5c31af7Sopenharmony_ci[[shaders]] 6e5c31af7Sopenharmony_ci= Shaders 7e5c31af7Sopenharmony_ci 8e5c31af7Sopenharmony_ciA shader specifies programmable operations that execute for each vertex, 9e5c31af7Sopenharmony_cicontrol point, tessellated vertex, primitive, fragment, or workgroup in the 10e5c31af7Sopenharmony_cicorresponding stage(s) of the graphics and compute pipelines. 11e5c31af7Sopenharmony_ci 12e5c31af7Sopenharmony_ciGraphics pipelines include vertex shader execution as a result of 13e5c31af7Sopenharmony_ci<<drawing,primitive assembly>>, followed, if enabled, by tessellation 14e5c31af7Sopenharmony_cicontrol and evaluation shaders operating on <<drawing-patch-lists,patches>>, 15e5c31af7Sopenharmony_cigeometry shaders, if enabled, operating on primitives, and fragment shaders, 16e5c31af7Sopenharmony_ciif present, operating on fragments generated by <<primsrast,Rasterization>>. 17e5c31af7Sopenharmony_ciIn this specification, vertex, tessellation control, tessellation evaluation 18e5c31af7Sopenharmony_ciand geometry shaders are collectively referred to as 19e5c31af7Sopenharmony_ci<<pipeline-graphics-subsets-pre-rasterization,pre-rasterization shader 20e5c31af7Sopenharmony_cistage>>s and occur in the logical pipeline before rasterization. 21e5c31af7Sopenharmony_ciThe fragment shader occurs logically after rasterization. 22e5c31af7Sopenharmony_ci 23e5c31af7Sopenharmony_ciOnly the compute shader stage is included in a compute pipeline. 24e5c31af7Sopenharmony_ciCompute shaders operate on compute invocations in a workgroup. 25e5c31af7Sopenharmony_ci 26e5c31af7Sopenharmony_ciShaders can: read from input variables, and read from and write to output 27e5c31af7Sopenharmony_civariables. 28e5c31af7Sopenharmony_ciInput and output variables can: be used to transfer data between shader 29e5c31af7Sopenharmony_cistages, or to allow the shader to interact with values that exist in the 30e5c31af7Sopenharmony_ciexecution environment. 31e5c31af7Sopenharmony_ciSimilarly, the execution environment provides constants describing 32e5c31af7Sopenharmony_cicapabilities. 33e5c31af7Sopenharmony_ci 34e5c31af7Sopenharmony_ciShader variables are associated with execution environment-provided inputs 35e5c31af7Sopenharmony_ciand outputs using _built-in_ decorations in the shader. 36e5c31af7Sopenharmony_ciThe available decorations for each stage are documented in the following 37e5c31af7Sopenharmony_cisubsections. 38e5c31af7Sopenharmony_ci 39e5c31af7Sopenharmony_ci 40e5c31af7Sopenharmony_ci[[shader-modules]] 41e5c31af7Sopenharmony_ci== Shader Modules 42e5c31af7Sopenharmony_ci 43e5c31af7Sopenharmony_ci[open,refpage='VkShaderModule',desc='Opaque handle to a shader module object',type='handles'] 44e5c31af7Sopenharmony_ci-- 45e5c31af7Sopenharmony_ci_Shader modules_ contain _shader code_ and one or more entry points. 46e5c31af7Sopenharmony_ciShaders are selected from a shader module by specifying an entry point as 47e5c31af7Sopenharmony_cipart of <<pipelines,pipeline>> creation. 48e5c31af7Sopenharmony_ciThe stages of a pipeline can: use shaders that come from different modules. 49e5c31af7Sopenharmony_ciThe shader code defining a shader module must: be in the SPIR-V format, as 50e5c31af7Sopenharmony_cidescribed by the <<spirvenv,Vulkan Environment for SPIR-V>> appendix. 51e5c31af7Sopenharmony_ci 52e5c31af7Sopenharmony_ciShader modules are represented by sname:VkShaderModule handles: 53e5c31af7Sopenharmony_ci 54e5c31af7Sopenharmony_ciinclude::{generated}/api/handles/VkShaderModule.txt[] 55e5c31af7Sopenharmony_ci-- 56e5c31af7Sopenharmony_ci 57e5c31af7Sopenharmony_ci[open,refpage='vkCreateShaderModule',desc='Creates a new shader module object',type='protos'] 58e5c31af7Sopenharmony_ci-- 59e5c31af7Sopenharmony_ciTo create a shader module, call: 60e5c31af7Sopenharmony_ci 61e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkCreateShaderModule.txt[] 62e5c31af7Sopenharmony_ci 63e5c31af7Sopenharmony_ci * pname:device is the logical device that creates the shader module. 64e5c31af7Sopenharmony_ci * pname:pCreateInfo is a pointer to a slink:VkShaderModuleCreateInfo 65e5c31af7Sopenharmony_ci structure. 66e5c31af7Sopenharmony_ci * pname:pAllocator controls host memory allocation as described in the 67e5c31af7Sopenharmony_ci <<memory-allocation, Memory Allocation>> chapter. 68e5c31af7Sopenharmony_ci * pname:pShaderModule is a pointer to a slink:VkShaderModule handle in 69e5c31af7Sopenharmony_ci which the resulting shader module object is returned. 70e5c31af7Sopenharmony_ci 71e5c31af7Sopenharmony_ciOnce a shader module has been created, any entry points it contains can: be 72e5c31af7Sopenharmony_ciused in pipeline shader stages as described in <<pipelines-compute,Compute 73e5c31af7Sopenharmony_ciPipelines>> and <<pipelines-graphics,Graphics Pipelines>>. 74e5c31af7Sopenharmony_ci 75e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkCreateShaderModule.txt[] 76e5c31af7Sopenharmony_ci-- 77e5c31af7Sopenharmony_ci 78e5c31af7Sopenharmony_ci[open,refpage='VkShaderModuleCreateInfo',desc='Structure specifying parameters of a newly created shader module',type='structs'] 79e5c31af7Sopenharmony_ci-- 80e5c31af7Sopenharmony_ciThe sname:VkShaderModuleCreateInfo structure is defined as: 81e5c31af7Sopenharmony_ci 82e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkShaderModuleCreateInfo.txt[] 83e5c31af7Sopenharmony_ci 84e5c31af7Sopenharmony_ci * pname:sType is the type of this structure. 85e5c31af7Sopenharmony_ci * pname:pNext is `NULL` or a pointer to a structure extending this 86e5c31af7Sopenharmony_ci structure. 87e5c31af7Sopenharmony_ci * pname:flags is reserved for future use. 88e5c31af7Sopenharmony_ci * pname:codeSize is the size, in bytes, of the code pointed to by 89e5c31af7Sopenharmony_ci pname:pCode. 90e5c31af7Sopenharmony_ci * pname:pCode is a pointer to code that is used to create the shader 91e5c31af7Sopenharmony_ci module. 92e5c31af7Sopenharmony_ci The type and format of the code is determined from the content of the 93e5c31af7Sopenharmony_ci memory addressed by pname:pCode. 94e5c31af7Sopenharmony_ci 95e5c31af7Sopenharmony_ci.Valid Usage 96e5c31af7Sopenharmony_ci**** 97e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-codeSize-01085]] 98e5c31af7Sopenharmony_ci pname:codeSize must: be greater than 0 99e5c31af7Sopenharmony_ciifndef::VK_NV_glsl_shader[] 100e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-codeSize-01086]] 101e5c31af7Sopenharmony_ci pname:codeSize must: be a multiple of 4 102e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01087]] 103e5c31af7Sopenharmony_ci pname:pCode must: point to valid SPIR-V code, formatted and packed as 104e5c31af7Sopenharmony_ci described by the <<spirv-spec,Khronos SPIR-V Specification>> 105e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01088]] 106e5c31af7Sopenharmony_ci pname:pCode must: adhere to the validation rules described by the 107e5c31af7Sopenharmony_ci <<spirvenv-module-validation, Validation Rules within a Module>> section 108e5c31af7Sopenharmony_ci of the <<spirvenv-capabilities,SPIR-V Environment>> appendix 109e5c31af7Sopenharmony_ciendif::VK_NV_glsl_shader[] 110e5c31af7Sopenharmony_ciifdef::VK_NV_glsl_shader[] 111e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01376]] 112e5c31af7Sopenharmony_ci If pname:pCode is a pointer to SPIR-V code, pname:codeSize must: be a 113e5c31af7Sopenharmony_ci multiple of 4 114e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01377]] 115e5c31af7Sopenharmony_ci pname:pCode must: point to either valid SPIR-V code, formatted and 116e5c31af7Sopenharmony_ci packed as described by the <<spirv-spec,Khronos SPIR-V Specification>> 117e5c31af7Sopenharmony_ci or valid GLSL code which must: be written to the `GL_KHR_vulkan_glsl` 118e5c31af7Sopenharmony_ci extension specification 119e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01378]] 120e5c31af7Sopenharmony_ci If pname:pCode is a pointer to SPIR-V code, that code must: adhere to 121e5c31af7Sopenharmony_ci the validation rules described by the <<spirvenv-module-validation, 122e5c31af7Sopenharmony_ci Validation Rules within a Module>> section of the 123e5c31af7Sopenharmony_ci <<spirvenv-capabilities,SPIR-V Environment>> appendix 124e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01379]] 125e5c31af7Sopenharmony_ci If pname:pCode is a pointer to GLSL code, it must: be valid GLSL code 126e5c31af7Sopenharmony_ci written to the `GL_KHR_vulkan_glsl` GLSL extension specification 127e5c31af7Sopenharmony_ciendif::VK_NV_glsl_shader[] 128e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01089]] 129e5c31af7Sopenharmony_ci pname:pCode must: declare the code:Shader capability for SPIR-V code 130e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01090]] 131e5c31af7Sopenharmony_ci pname:pCode must: not declare any capability that is not supported by 132e5c31af7Sopenharmony_ci the API, as described by the <<spirvenv-module-validation, 133e5c31af7Sopenharmony_ci Capabilities>> section of the <<spirvenv-capabilities,SPIR-V 134e5c31af7Sopenharmony_ci Environment>> appendix 135e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-01091]] 136e5c31af7Sopenharmony_ci If pname:pCode declares any of the capabilities listed in the 137e5c31af7Sopenharmony_ci <<spirvenv-capabilities-table,SPIR-V Environment>> appendix, one of the 138e5c31af7Sopenharmony_ci corresponding requirements must: be satisfied 139e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-04146]] 140e5c31af7Sopenharmony_ci pname:pCode must: not declare any SPIR-V extension that is not supported 141e5c31af7Sopenharmony_ci by the API, as described by the <<spirvenv-extensions, Extension>> 142e5c31af7Sopenharmony_ci section of the <<spirvenv-capabilities,SPIR-V Environment>> appendix 143e5c31af7Sopenharmony_ci * [[VUID-VkShaderModuleCreateInfo-pCode-04147]] 144e5c31af7Sopenharmony_ci If pname:pCode declares any of the SPIR-V extensions listed in the 145e5c31af7Sopenharmony_ci <<spirvenv-extensions-table,SPIR-V Environment>> appendix, one of the 146e5c31af7Sopenharmony_ci corresponding requirements must: be satisfied 147e5c31af7Sopenharmony_ci**** 148e5c31af7Sopenharmony_ci 149e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkShaderModuleCreateInfo.txt[] 150e5c31af7Sopenharmony_ci-- 151e5c31af7Sopenharmony_ci 152e5c31af7Sopenharmony_ci[open,refpage='VkShaderModuleCreateFlags',desc='Reserved for future use',type='flags'] 153e5c31af7Sopenharmony_ci-- 154e5c31af7Sopenharmony_ciinclude::{generated}/api/flags/VkShaderModuleCreateFlags.txt[] 155e5c31af7Sopenharmony_ci 156e5c31af7Sopenharmony_citname:VkShaderModuleCreateFlags is a bitmask type for setting a mask, but is 157e5c31af7Sopenharmony_cicurrently reserved for future use. 158e5c31af7Sopenharmony_ci-- 159e5c31af7Sopenharmony_ci 160e5c31af7Sopenharmony_ciifdef::VK_EXT_validation_cache[] 161e5c31af7Sopenharmony_ciinclude::{chapters}/VK_EXT_validation_cache/shader-module-validation-cache.txt[] 162e5c31af7Sopenharmony_ciendif::VK_EXT_validation_cache[] 163e5c31af7Sopenharmony_ci 164e5c31af7Sopenharmony_ci 165e5c31af7Sopenharmony_ci[open,refpage='vkDestroyShaderModule',desc='Destroy a shader module',type='protos'] 166e5c31af7Sopenharmony_ci-- 167e5c31af7Sopenharmony_ciTo destroy a shader module, call: 168e5c31af7Sopenharmony_ci 169e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkDestroyShaderModule.txt[] 170e5c31af7Sopenharmony_ci 171e5c31af7Sopenharmony_ci * pname:device is the logical device that destroys the shader module. 172e5c31af7Sopenharmony_ci * pname:shaderModule is the handle of the shader module to destroy. 173e5c31af7Sopenharmony_ci * pname:pAllocator controls host memory allocation as described in the 174e5c31af7Sopenharmony_ci <<memory-allocation, Memory Allocation>> chapter. 175e5c31af7Sopenharmony_ci 176e5c31af7Sopenharmony_ciA shader module can: be destroyed while pipelines created using its shaders 177e5c31af7Sopenharmony_ciare still in use. 178e5c31af7Sopenharmony_ci 179e5c31af7Sopenharmony_ci.Valid Usage 180e5c31af7Sopenharmony_ci**** 181e5c31af7Sopenharmony_ci * [[VUID-vkDestroyShaderModule-shaderModule-01092]] 182e5c31af7Sopenharmony_ci If sname:VkAllocationCallbacks were provided when pname:shaderModule was 183e5c31af7Sopenharmony_ci created, a compatible set of callbacks must: be provided here 184e5c31af7Sopenharmony_ci * [[VUID-vkDestroyShaderModule-shaderModule-01093]] 185e5c31af7Sopenharmony_ci If no sname:VkAllocationCallbacks were provided when pname:shaderModule 186e5c31af7Sopenharmony_ci was created, pname:pAllocator must: be `NULL` 187e5c31af7Sopenharmony_ci**** 188e5c31af7Sopenharmony_ci 189e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkDestroyShaderModule.txt[] 190e5c31af7Sopenharmony_ci-- 191e5c31af7Sopenharmony_ci 192e5c31af7Sopenharmony_ci 193e5c31af7Sopenharmony_ci[[shaders-execution]] 194e5c31af7Sopenharmony_ci== Shader Execution 195e5c31af7Sopenharmony_ci 196e5c31af7Sopenharmony_ciAt each stage of the pipeline, multiple invocations of a shader may: execute 197e5c31af7Sopenharmony_cisimultaneously. 198e5c31af7Sopenharmony_ciFurther, invocations of a single shader produced as the result of different 199e5c31af7Sopenharmony_cicommands may: execute simultaneously. 200e5c31af7Sopenharmony_ciThe relative execution order of invocations of the same shader type is 201e5c31af7Sopenharmony_ciundefined:. 202e5c31af7Sopenharmony_ciShader invocations may: complete in a different order than that in which the 203e5c31af7Sopenharmony_ciprimitives they originated from were drawn or dispatched by the application. 204e5c31af7Sopenharmony_ciHowever, fragment shader outputs are written to attachments in 205e5c31af7Sopenharmony_ci<<primsrast-order,rasterization order>>. 206e5c31af7Sopenharmony_ci 207e5c31af7Sopenharmony_ciThe relative execution order of invocations of different shader types is 208e5c31af7Sopenharmony_cilargely undefined:. 209e5c31af7Sopenharmony_ciHowever, when invoking a shader whose inputs are generated from a previous 210e5c31af7Sopenharmony_cipipeline stage, the shader invocations from the previous stage are 211e5c31af7Sopenharmony_ciguaranteed to have executed far enough to generate input values for all 212e5c31af7Sopenharmony_cirequired inputs. 213e5c31af7Sopenharmony_ci 214e5c31af7Sopenharmony_ci 215e5c31af7Sopenharmony_ci[[shaders-execution-memory-ordering]] 216e5c31af7Sopenharmony_ci== Shader Memory Access Ordering 217e5c31af7Sopenharmony_ci 218e5c31af7Sopenharmony_ciThe order in which image or buffer memory is read or written by shaders is 219e5c31af7Sopenharmony_cilargely undefined:. 220e5c31af7Sopenharmony_ciFor some shader types (vertex, tessellation evaluation, and in some cases, 221e5c31af7Sopenharmony_cifragment), even the number of shader invocations that may: perform loads and 222e5c31af7Sopenharmony_cistores is undefined:. 223e5c31af7Sopenharmony_ci 224e5c31af7Sopenharmony_ciIn particular, the following rules apply: 225e5c31af7Sopenharmony_ci 226e5c31af7Sopenharmony_ci * <<shaders-vertex-execution,Vertex>> and 227e5c31af7Sopenharmony_ci <<shaders-tessellation-evaluation-execution,tessellation evaluation>> 228e5c31af7Sopenharmony_ci shaders will be invoked at least once for each unique vertex, as defined 229e5c31af7Sopenharmony_ci in those sections. 230e5c31af7Sopenharmony_ci * <<fragops-shader,Fragment>> shaders will be invoked zero or more times, 231e5c31af7Sopenharmony_ci as defined in that section. 232e5c31af7Sopenharmony_ci * The relative execution order of invocations of the same shader type is 233e5c31af7Sopenharmony_ci undefined:. 234e5c31af7Sopenharmony_ci A store issued by a shader when working on primitive B might complete 235e5c31af7Sopenharmony_ci prior to a store for primitive A, even if primitive A is specified prior 236e5c31af7Sopenharmony_ci to primitive B. This applies even to fragment shaders; while fragment 237e5c31af7Sopenharmony_ci shader outputs are always written to the framebuffer in 238e5c31af7Sopenharmony_ci <<primsrast-order, rasterization order>>, stores executed by fragment 239e5c31af7Sopenharmony_ci shader invocations are not. 240e5c31af7Sopenharmony_ci * The relative execution order of invocations of different shader types is 241e5c31af7Sopenharmony_ci largely undefined:. 242e5c31af7Sopenharmony_ci 243e5c31af7Sopenharmony_ci[NOTE] 244e5c31af7Sopenharmony_ci.Note 245e5c31af7Sopenharmony_ci==== 246e5c31af7Sopenharmony_ciThe above limitations on shader invocation order make some forms of 247e5c31af7Sopenharmony_cisynchronization between shader invocations within a single set of primitives 248e5c31af7Sopenharmony_ciunimplementable. 249e5c31af7Sopenharmony_ciFor example, having one invocation poll memory written by another invocation 250e5c31af7Sopenharmony_ciassumes that the other invocation has been launched and will complete its 251e5c31af7Sopenharmony_ciwrites in finite time. 252e5c31af7Sopenharmony_ci==== 253e5c31af7Sopenharmony_ci 254e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 255e5c31af7Sopenharmony_ci 256e5c31af7Sopenharmony_ciThe <<memory-model,Memory Model>> appendix defines the terminology and rules 257e5c31af7Sopenharmony_cifor how to correctly communicate between shader invocations, such as when a 258e5c31af7Sopenharmony_ciwrite is <<memory-model-visible-to,Visible-To>> a read, and what constitutes 259e5c31af7Sopenharmony_cia <<memory-model-access-data-race,Data Race>>. 260e5c31af7Sopenharmony_ci 261e5c31af7Sopenharmony_ciApplications must: not cause a data race. 262e5c31af7Sopenharmony_ci 263e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 264e5c31af7Sopenharmony_ci 265e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 266e5c31af7Sopenharmony_ci 267e5c31af7Sopenharmony_ciStores issued to different memory locations within a single shader 268e5c31af7Sopenharmony_ciinvocation may: not be visible to other invocations, or may: not become 269e5c31af7Sopenharmony_civisible in the order they were performed. 270e5c31af7Sopenharmony_ci 271e5c31af7Sopenharmony_ciThe code:OpMemoryBarrier instruction can: be used to provide stronger 272e5c31af7Sopenharmony_ciordering of reads and writes performed by a single invocation. 273e5c31af7Sopenharmony_cicode:OpMemoryBarrier guarantees that any memory transactions issued by the 274e5c31af7Sopenharmony_cishader invocation prior to the instruction complete prior to the memory 275e5c31af7Sopenharmony_citransactions issued after the instruction. 276e5c31af7Sopenharmony_ciMemory barriers are needed for algorithms that require multiple invocations 277e5c31af7Sopenharmony_cito access the same memory and require the operations to be performed in a 278e5c31af7Sopenharmony_cipartially-defined relative order. 279e5c31af7Sopenharmony_ciFor example, if one shader invocation does a series of writes, followed by 280e5c31af7Sopenharmony_cian code:OpMemoryBarrier instruction, followed by another write, then the 281e5c31af7Sopenharmony_ciresults of the series of writes before the barrier become visible to other 282e5c31af7Sopenharmony_cishader invocations at a time earlier or equal to when the results of the 283e5c31af7Sopenharmony_cifinal write become visible to those invocations. 284e5c31af7Sopenharmony_ciIn practice it means that another invocation that sees the results of the 285e5c31af7Sopenharmony_cifinal write would also see the previous writes. 286e5c31af7Sopenharmony_ciWithout the memory barrier, the final write may: be visible before the 287e5c31af7Sopenharmony_ciprevious writes. 288e5c31af7Sopenharmony_ci 289e5c31af7Sopenharmony_ciWrites that are the result of shader stores through a variable decorated 290e5c31af7Sopenharmony_ciwith code:Coherent automatically have available writes to the same buffer, 291e5c31af7Sopenharmony_cibuffer view, or image view made visible to them, and are themselves 292e5c31af7Sopenharmony_ciautomatically made available to access by the same buffer, buffer view, or 293e5c31af7Sopenharmony_ciimage view. 294e5c31af7Sopenharmony_ciReads that are the result of shader loads through a variable decorated with 295e5c31af7Sopenharmony_cicode:Coherent automatically have available writes to the same buffer, buffer 296e5c31af7Sopenharmony_ciview, or image view made visible to them. 297e5c31af7Sopenharmony_ciThe order that coherent writes to different locations become available is 298e5c31af7Sopenharmony_ciundefined:, unless enforced by a memory barrier instruction or other memory 299e5c31af7Sopenharmony_cidependency. 300e5c31af7Sopenharmony_ci 301e5c31af7Sopenharmony_ci[NOTE] 302e5c31af7Sopenharmony_ci.Note 303e5c31af7Sopenharmony_ci==== 304e5c31af7Sopenharmony_ciExplicit memory dependencies must: still be used to guarantee availability 305e5c31af7Sopenharmony_ciand visibility for access via other buffers, buffer views, or image views. 306e5c31af7Sopenharmony_ci==== 307e5c31af7Sopenharmony_ci 308e5c31af7Sopenharmony_ciThe built-in atomic memory transaction instructions can: be used to read and 309e5c31af7Sopenharmony_ciwrite a given memory address atomically. 310e5c31af7Sopenharmony_ciWhile built-in atomic functions issued by multiple shader invocations are 311e5c31af7Sopenharmony_ciexecuted in undefined: order relative to each other, these functions perform 312e5c31af7Sopenharmony_ciboth a read and a write of a memory address and guarantee that no other 313e5c31af7Sopenharmony_cimemory transaction will write to the underlying memory between the read and 314e5c31af7Sopenharmony_ciwrite. 315e5c31af7Sopenharmony_ciAtomic operations ensure automatic availability and visibility for writes 316e5c31af7Sopenharmony_ciand reads in the same way as those to code:Coherent variables. 317e5c31af7Sopenharmony_ci 318e5c31af7Sopenharmony_ci[NOTE] 319e5c31af7Sopenharmony_ci.Note 320e5c31af7Sopenharmony_ci==== 321e5c31af7Sopenharmony_ciMemory accesses performed on different resource descriptors with the same 322e5c31af7Sopenharmony_cimemory backing may: not be well-defined even with the code:Coherent 323e5c31af7Sopenharmony_cidecoration or via atomics, due to things such as image layouts or ownership 324e5c31af7Sopenharmony_ciof the resource - as described in the <<synchronization, Synchronization and 325e5c31af7Sopenharmony_ciCache Control>> chapter. 326e5c31af7Sopenharmony_ci==== 327e5c31af7Sopenharmony_ci 328e5c31af7Sopenharmony_ci[NOTE] 329e5c31af7Sopenharmony_ci.Note 330e5c31af7Sopenharmony_ci==== 331e5c31af7Sopenharmony_ciAtomics allow shaders to use shared global addresses for mutual exclusion or 332e5c31af7Sopenharmony_cias counters, among other uses. 333e5c31af7Sopenharmony_ci==== 334e5c31af7Sopenharmony_ci 335e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 336e5c31af7Sopenharmony_ci 337e5c31af7Sopenharmony_ciThe SPIR-V *SubgroupMemory*, *CrossWorkgroupMemory*, and 338e5c31af7Sopenharmony_ci*AtomicCounterMemory* memory semantics are ignored. 339e5c31af7Sopenharmony_ciSequentially consistent atomics and barriers are not supported and 340e5c31af7Sopenharmony_ci*SequentiallyConsistent* is treated as *AcquireRelease*. 341e5c31af7Sopenharmony_ci*SequentiallyConsistent* should: not be used. 342e5c31af7Sopenharmony_ci 343e5c31af7Sopenharmony_ci 344e5c31af7Sopenharmony_ci[[shaders-inputs]] 345e5c31af7Sopenharmony_ci== Shader Inputs and Outputs 346e5c31af7Sopenharmony_ci 347e5c31af7Sopenharmony_ciData is passed into and out of shaders using variables with input or output 348e5c31af7Sopenharmony_cistorage class, respectively. 349e5c31af7Sopenharmony_ciUser-defined inputs and outputs are connected between stages by matching 350e5c31af7Sopenharmony_citheir code:Location decorations. 351e5c31af7Sopenharmony_ciAdditionally, data can: be provided by or communicated to special functions 352e5c31af7Sopenharmony_ciprovided by the execution environment using code:BuiltIn decorations. 353e5c31af7Sopenharmony_ci 354e5c31af7Sopenharmony_ciIn many cases, the same code:BuiltIn decoration can: be used in multiple 355e5c31af7Sopenharmony_cishader stages with similar meaning. 356e5c31af7Sopenharmony_ciThe specific behavior of variables decorated as code:BuiltIn is documented 357e5c31af7Sopenharmony_ciin the following sections. 358e5c31af7Sopenharmony_ci 359e5c31af7Sopenharmony_ci 360e5c31af7Sopenharmony_ciifdef::VK_NV_mesh_shader[] 361e5c31af7Sopenharmony_ci[[shaders-task]] 362e5c31af7Sopenharmony_ci== Task Shaders 363e5c31af7Sopenharmony_ci 364e5c31af7Sopenharmony_ciTask shaders operate in conjunction with the mesh shaders to produce a 365e5c31af7Sopenharmony_cicollection of primitives that will be processed by subsequent stages of the 366e5c31af7Sopenharmony_cigraphics pipeline. 367e5c31af7Sopenharmony_ciIts primary purpose is to create a variable amount of subsequent mesh shader 368e5c31af7Sopenharmony_ciinvocations. 369e5c31af7Sopenharmony_ci 370e5c31af7Sopenharmony_ciTask shaders are invoked via the execution of the 371e5c31af7Sopenharmony_ci<<drawing-mesh-shading,programmable mesh shading>> pipeline. 372e5c31af7Sopenharmony_ci 373e5c31af7Sopenharmony_ciThe task shader has no fixed-function inputs other than variables 374e5c31af7Sopenharmony_ciidentifying the specific workgroup and invocation. 375e5c31af7Sopenharmony_ciThe only fixed output of the task shader is a task count, identifying the 376e5c31af7Sopenharmony_cinumber of mesh shader workgroups to create. 377e5c31af7Sopenharmony_ciThe task shader can write additional outputs to task memory, which can be 378e5c31af7Sopenharmony_ciread by all of the mesh shader workgroups it created. 379e5c31af7Sopenharmony_ci 380e5c31af7Sopenharmony_ci 381e5c31af7Sopenharmony_ci=== Task Shader Execution 382e5c31af7Sopenharmony_ci 383e5c31af7Sopenharmony_ciTask workloads are formed from groups of work items called workgroups and 384e5c31af7Sopenharmony_ciprocessed by the task shader in the current graphics pipeline. 385e5c31af7Sopenharmony_ciA workgroup is a collection of shader invocations that execute the same 386e5c31af7Sopenharmony_cishader, potentially in parallel. 387e5c31af7Sopenharmony_ciTask shaders execute in _global workgroups_ which are divided into a number 388e5c31af7Sopenharmony_ciof _local workgroups_ with a size that can: be set by assigning a value to 389e5c31af7Sopenharmony_cithe code:LocalSize 390e5c31af7Sopenharmony_ciifdef::VK_KHR_maintenance4[or code:LocalSizeId] 391e5c31af7Sopenharmony_ciexecution mode or via an object decorated by the code:WorkgroupSize 392e5c31af7Sopenharmony_cidecoration. 393e5c31af7Sopenharmony_ciAn invocation within a local workgroup can: share data with other members of 394e5c31af7Sopenharmony_cithe local workgroup through shared variables and issue memory and control 395e5c31af7Sopenharmony_ciflow barriers to synchronize with other members of the local workgroup. 396e5c31af7Sopenharmony_ci 397e5c31af7Sopenharmony_ci 398e5c31af7Sopenharmony_ci[[shaders-mesh]] 399e5c31af7Sopenharmony_ci== Mesh Shaders 400e5c31af7Sopenharmony_ci 401e5c31af7Sopenharmony_ciMesh shaders operate in workgroups to produce a collection of primitives 402e5c31af7Sopenharmony_cithat will be processed by subsequent stages of the graphics pipeline. 403e5c31af7Sopenharmony_ciEach workgroup emits zero or more output primitives and the group of 404e5c31af7Sopenharmony_civertices and their associated data required for each output primitive. 405e5c31af7Sopenharmony_ci 406e5c31af7Sopenharmony_ciMesh shaders are invoked via the execution of the 407e5c31af7Sopenharmony_ci<<drawing-mesh-shading,programmable mesh shading>> pipeline. 408e5c31af7Sopenharmony_ci 409e5c31af7Sopenharmony_ciThe only inputs available to the mesh shader are variables identifying the 410e5c31af7Sopenharmony_cispecific workgroup and invocation and, if applicable, any outputs written to 411e5c31af7Sopenharmony_citask memory by the task shader that spawned the mesh shader's workgroup. 412e5c31af7Sopenharmony_ciThe mesh shader can operate without a task shader as well. 413e5c31af7Sopenharmony_ci 414e5c31af7Sopenharmony_ciThe invocations of the mesh shader workgroup write an output mesh, 415e5c31af7Sopenharmony_cicomprising a set of primitives with per-primitive attributes, a set of 416e5c31af7Sopenharmony_civertices with per-vertex attributes, and an array of indices identifying the 417e5c31af7Sopenharmony_cimesh vertices that belong to each primitive. 418e5c31af7Sopenharmony_ciThe primitives of this mesh are then processed by subsequent graphics 419e5c31af7Sopenharmony_cipipeline stages, where the outputs of the mesh shader form an interface with 420e5c31af7Sopenharmony_cithe fragment shader. 421e5c31af7Sopenharmony_ci 422e5c31af7Sopenharmony_ci 423e5c31af7Sopenharmony_ci=== Mesh Shader Execution 424e5c31af7Sopenharmony_ci 425e5c31af7Sopenharmony_ciMesh workloads are formed from groups of work items called workgroups and 426e5c31af7Sopenharmony_ciprocessed by the mesh shader in the current graphics pipeline. 427e5c31af7Sopenharmony_ciA workgroup is a collection of shader invocations that execute the same 428e5c31af7Sopenharmony_cishader, potentially in parallel. 429e5c31af7Sopenharmony_ciMesh shaders execute in _global workgroups_ which are divided into a number 430e5c31af7Sopenharmony_ciof _local workgroups_ with a size that can: be set by assigning a value to 431e5c31af7Sopenharmony_cithe code:LocalSize 432e5c31af7Sopenharmony_ciifdef::VK_KHR_maintenance4[or code:LocalSizeId] 433e5c31af7Sopenharmony_ciexecution mode or via an object decorated by the code:WorkgroupSize 434e5c31af7Sopenharmony_cidecoration. 435e5c31af7Sopenharmony_ciAn invocation within a local workgroup can: share data with other members of 436e5c31af7Sopenharmony_cithe local workgroup through shared variables and issue memory and control 437e5c31af7Sopenharmony_ciflow barriers to synchronize with other members of the local workgroup. 438e5c31af7Sopenharmony_ci 439e5c31af7Sopenharmony_ciThe _global workgroups_ may be generated explcitly via the API, or 440e5c31af7Sopenharmony_ciimplicitly through the task shader's work creation mechanism. 441e5c31af7Sopenharmony_ciendif::VK_NV_mesh_shader[] 442e5c31af7Sopenharmony_ci 443e5c31af7Sopenharmony_ci 444e5c31af7Sopenharmony_ci[[shaders-vertex]] 445e5c31af7Sopenharmony_ci== Vertex Shaders 446e5c31af7Sopenharmony_ci 447e5c31af7Sopenharmony_ciEach vertex shader invocation operates on one vertex and its associated 448e5c31af7Sopenharmony_ci<<fxvertex-attrib,vertex attribute>> data, and outputs one vertex and 449e5c31af7Sopenharmony_ciassociated data. 450e5c31af7Sopenharmony_ciifndef::VK_NV_mesh_shader[] 451e5c31af7Sopenharmony_ciGraphics pipelines must: include a vertex shader, and the vertex shader 452e5c31af7Sopenharmony_cistage is always the first shader stage in the graphics pipeline. 453e5c31af7Sopenharmony_ciendif::VK_NV_mesh_shader[] 454e5c31af7Sopenharmony_ciifdef::VK_NV_mesh_shader[] 455e5c31af7Sopenharmony_ciGraphics pipelines using primitive shading must: include a vertex shader, 456e5c31af7Sopenharmony_ciand the vertex shader stage is always the first shader stage in the graphics 457e5c31af7Sopenharmony_cipipeline. 458e5c31af7Sopenharmony_ciendif::VK_NV_mesh_shader[] 459e5c31af7Sopenharmony_ci 460e5c31af7Sopenharmony_ci 461e5c31af7Sopenharmony_ci[[shaders-vertex-execution]] 462e5c31af7Sopenharmony_ci=== Vertex Shader Execution 463e5c31af7Sopenharmony_ci 464e5c31af7Sopenharmony_ciA vertex shader must: be executed at least once for each vertex specified by 465e5c31af7Sopenharmony_cia drawing command. 466e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_multiview[] 467e5c31af7Sopenharmony_ciIf the subpass includes multiple views in its view mask, the shader may: be 468e5c31af7Sopenharmony_ciinvoked separately for each view. 469e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_multiview[] 470e5c31af7Sopenharmony_ciDuring execution, the shader is presented with the index of the vertex and 471e5c31af7Sopenharmony_ciinstance for which it has been invoked. 472e5c31af7Sopenharmony_ciInput variables declared in the vertex shader are filled by the 473e5c31af7Sopenharmony_ciimplementation with the values of vertex attributes associated with the 474e5c31af7Sopenharmony_ciinvocation being executed. 475e5c31af7Sopenharmony_ci 476e5c31af7Sopenharmony_ciIf the same vertex is specified multiple times in a drawing command (e.g. by 477e5c31af7Sopenharmony_ciincluding the same index value multiple times in an index buffer) the 478e5c31af7Sopenharmony_ciimplementation may: reuse the results of vertex shading if it can statically 479e5c31af7Sopenharmony_cidetermine that the vertex shader invocations will produce identical results. 480e5c31af7Sopenharmony_ci 481e5c31af7Sopenharmony_ci[NOTE] 482e5c31af7Sopenharmony_ci.Note 483e5c31af7Sopenharmony_ci==== 484e5c31af7Sopenharmony_ciIt is implementation-dependent when and if results of vertex shading are 485e5c31af7Sopenharmony_cireused, and thus how many times the vertex shader will be executed. 486e5c31af7Sopenharmony_ciThis is true also if the vertex shader contains stores or atomic operations 487e5c31af7Sopenharmony_ci(see <<features-vertexPipelineStoresAndAtomics, 488e5c31af7Sopenharmony_cipname:vertexPipelineStoresAndAtomics>>). 489e5c31af7Sopenharmony_ci==== 490e5c31af7Sopenharmony_ci 491e5c31af7Sopenharmony_ci 492e5c31af7Sopenharmony_ci[[shaders-tessellation-control]] 493e5c31af7Sopenharmony_ci== Tessellation Control Shaders 494e5c31af7Sopenharmony_ci 495e5c31af7Sopenharmony_ciThe tessellation control shader is used to read an input patch provided by 496e5c31af7Sopenharmony_cithe application and to produce an output patch. 497e5c31af7Sopenharmony_ciEach tessellation control shader invocation operates on an input patch 498e5c31af7Sopenharmony_ci(after all control points in the patch are processed by a vertex shader) and 499e5c31af7Sopenharmony_ciits associated data, and outputs a single control point of the output patch 500e5c31af7Sopenharmony_ciand its associated data, and can: also output additional per-patch data. 501e5c31af7Sopenharmony_ciThe input patch is sized according to the pname:patchControlPoints member of 502e5c31af7Sopenharmony_cislink:VkPipelineTessellationStateCreateInfo, as part of input assembly. 503e5c31af7Sopenharmony_ci 504e5c31af7Sopenharmony_ciifdef::VK_EXT_extended_dynamic_state2[] 505e5c31af7Sopenharmony_ciThe input patch can also be dynamically sized with pname:patchControlPoints 506e5c31af7Sopenharmony_ciparameter of flink:vkCmdSetPatchControlPointsEXT. 507e5c31af7Sopenharmony_ci 508e5c31af7Sopenharmony_ci[open,refpage='vkCmdSetPatchControlPointsEXT',desc='Specify the number of control points per patch dynamically for a command buffer',type='protos'] 509e5c31af7Sopenharmony_ci-- 510e5c31af7Sopenharmony_ciTo <<pipelines-dynamic-state, dynamically set>> the number of control points 511e5c31af7Sopenharmony_ciper patch, call: 512e5c31af7Sopenharmony_ci 513e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkCmdSetPatchControlPointsEXT.txt[] 514e5c31af7Sopenharmony_ci 515e5c31af7Sopenharmony_ci * pname:commandBuffer is the command buffer into which the command will be 516e5c31af7Sopenharmony_ci recorded. 517e5c31af7Sopenharmony_ci * pname:patchControlPoints specifies the number of control points per 518e5c31af7Sopenharmony_ci patch. 519e5c31af7Sopenharmony_ci 520e5c31af7Sopenharmony_ciThis command sets the number of control points per patch for subsequent 521e5c31af7Sopenharmony_cidrawing commands when the graphics pipeline is created with 522e5c31af7Sopenharmony_ciename:VK_DYNAMIC_STATE_PATCH_CONTROL_POINTS_EXT set in 523e5c31af7Sopenharmony_cislink:VkPipelineDynamicStateCreateInfo::pname:pDynamicStates. 524e5c31af7Sopenharmony_ciOtherwise, this state is specified by the 525e5c31af7Sopenharmony_cislink:VkPipelineTessellationStateCreateInfo::pname:patchControlPoints value 526e5c31af7Sopenharmony_ciused to create the currently active pipeline. 527e5c31af7Sopenharmony_ci 528e5c31af7Sopenharmony_ci.Valid Usage 529e5c31af7Sopenharmony_ci**** 530e5c31af7Sopenharmony_ci * [[VUID-vkCmdSetPatchControlPointsEXT-None-04873]] 531e5c31af7Sopenharmony_ci The <<features-extendedDynamicState2PatchControlPoints, 532e5c31af7Sopenharmony_ci extendedDynamicState2PatchControlPoints>> feature must: be enabled 533e5c31af7Sopenharmony_ci * [[VUID-vkCmdSetPatchControlPointsEXT-patchControlPoints-04874]] 534e5c31af7Sopenharmony_ci pname:patchControlPoints must: be greater than zero and less than or 535e5c31af7Sopenharmony_ci equal to sname:VkPhysicalDeviceLimits::pname:maxTessellationPatchSize 536e5c31af7Sopenharmony_ci**** 537e5c31af7Sopenharmony_ci 538e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkCmdSetPatchControlPointsEXT.txt[] 539e5c31af7Sopenharmony_ci-- 540e5c31af7Sopenharmony_ciendif::VK_EXT_extended_dynamic_state2[] 541e5c31af7Sopenharmony_ci 542e5c31af7Sopenharmony_ciThe size of the output patch is controlled by the code:OpExecutionMode 543e5c31af7Sopenharmony_cicode:OutputVertices specified in the tessellation control or tessellation 544e5c31af7Sopenharmony_cievaluation shaders, which must: be specified in at least one of the shaders. 545e5c31af7Sopenharmony_ciThe size of the input and output patches must: each be greater than zero and 546e5c31af7Sopenharmony_ciless than or equal to 547e5c31af7Sopenharmony_cisname:VkPhysicalDeviceLimits::pname:maxTessellationPatchSize. 548e5c31af7Sopenharmony_ci 549e5c31af7Sopenharmony_ci 550e5c31af7Sopenharmony_ci[[shaders-tessellation-control-execution]] 551e5c31af7Sopenharmony_ci=== Tessellation Control Shader Execution 552e5c31af7Sopenharmony_ci 553e5c31af7Sopenharmony_ciA tessellation control shader is invoked at least once for each _output_ 554e5c31af7Sopenharmony_civertex in a patch. 555e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_multiview[] 556e5c31af7Sopenharmony_ciIf the subpass includes multiple views in its view mask, the shader may: be 557e5c31af7Sopenharmony_ciinvoked separately for each view. 558e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_multiview[] 559e5c31af7Sopenharmony_ci 560e5c31af7Sopenharmony_ciInputs to the tessellation control shader are generated by the vertex 561e5c31af7Sopenharmony_cishader. 562e5c31af7Sopenharmony_ciEach invocation of the tessellation control shader can: read the attributes 563e5c31af7Sopenharmony_ciof any incoming vertices and their associated data. 564e5c31af7Sopenharmony_ciThe invocations corresponding to a given patch execute logically in 565e5c31af7Sopenharmony_ciparallel, with undefined: relative execution order. 566e5c31af7Sopenharmony_ciHowever, the code:OpControlBarrier instruction can: be used to provide 567e5c31af7Sopenharmony_cilimited control of the execution order by synchronizing invocations within a 568e5c31af7Sopenharmony_cipatch, effectively dividing tessellation control shader execution into a set 569e5c31af7Sopenharmony_ciof phases. 570e5c31af7Sopenharmony_ciTessellation control shaders will read undefined: values if one invocation 571e5c31af7Sopenharmony_cireads a per-vertex or per-patch output written by another invocation at any 572e5c31af7Sopenharmony_cipoint during the same phase, or if two invocations attempt to write 573e5c31af7Sopenharmony_cidifferent values to the same per-patch output in a single phase. 574e5c31af7Sopenharmony_ci 575e5c31af7Sopenharmony_ci 576e5c31af7Sopenharmony_ci[[shaders-tessellation-evaluation]] 577e5c31af7Sopenharmony_ci== Tessellation Evaluation Shaders 578e5c31af7Sopenharmony_ci 579e5c31af7Sopenharmony_ciThe Tessellation Evaluation Shader operates on an input patch of control 580e5c31af7Sopenharmony_cipoints and their associated data, and a single input barycentric coordinate 581e5c31af7Sopenharmony_ciindicating the invocation's relative position within the subdivided patch, 582e5c31af7Sopenharmony_ciand outputs a single vertex and its associated data. 583e5c31af7Sopenharmony_ci 584e5c31af7Sopenharmony_ci 585e5c31af7Sopenharmony_ci[[shaders-tessellation-evaluation-execution]] 586e5c31af7Sopenharmony_ci=== Tessellation Evaluation Shader Execution 587e5c31af7Sopenharmony_ci 588e5c31af7Sopenharmony_ciA tessellation evaluation shader is invoked at least once for each unique 589e5c31af7Sopenharmony_civertex generated by the tessellator. 590e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_multiview[] 591e5c31af7Sopenharmony_ciIf the subpass includes multiple views in its view mask, the shader may: be 592e5c31af7Sopenharmony_ciinvoked separately for each view. 593e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_multiview[] 594e5c31af7Sopenharmony_ci 595e5c31af7Sopenharmony_ci 596e5c31af7Sopenharmony_ci[[shaders-geometry]] 597e5c31af7Sopenharmony_ci== Geometry Shaders 598e5c31af7Sopenharmony_ci 599e5c31af7Sopenharmony_ciThe geometry shader operates on a group of vertices and their associated 600e5c31af7Sopenharmony_cidata assembled from a single input primitive, and emits zero or more output 601e5c31af7Sopenharmony_ciprimitives and the group of vertices and their associated data required for 602e5c31af7Sopenharmony_cieach output primitive. 603e5c31af7Sopenharmony_ci 604e5c31af7Sopenharmony_ci 605e5c31af7Sopenharmony_ci[[shaders-geometry-execution]] 606e5c31af7Sopenharmony_ci=== Geometry Shader Execution 607e5c31af7Sopenharmony_ci 608e5c31af7Sopenharmony_ciA geometry shader is invoked at least once for each primitive produced by 609e5c31af7Sopenharmony_cithe tessellation stages, or at least once for each primitive generated by 610e5c31af7Sopenharmony_ci<<drawing,primitive assembly>> when tessellation is not in use. 611e5c31af7Sopenharmony_ciA shader can request that the geometry shader runs multiple 612e5c31af7Sopenharmony_ci<<geometry-invocations, instances>>. 613e5c31af7Sopenharmony_ciA geometry shader is invoked at least once for each instance. 614e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_multiview[] 615e5c31af7Sopenharmony_ciIf the subpass includes multiple views in its view mask, the shader may: be 616e5c31af7Sopenharmony_ciinvoked separately for each view. 617e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_multiview[] 618e5c31af7Sopenharmony_ci 619e5c31af7Sopenharmony_ci 620e5c31af7Sopenharmony_ci[[shaders-fragment]] 621e5c31af7Sopenharmony_ci== Fragment Shaders 622e5c31af7Sopenharmony_ci 623e5c31af7Sopenharmony_ciFragment shaders are invoked as a <<fragops-shader, fragment operation>> in 624e5c31af7Sopenharmony_cia graphics pipeline. 625e5c31af7Sopenharmony_ciEach fragment shader invocation operates on a single fragment and its 626e5c31af7Sopenharmony_ciassociated data. 627e5c31af7Sopenharmony_ciWith few exceptions, fragment shaders do not have access to any data 628e5c31af7Sopenharmony_ciassociated with other fragments and are considered to execute in isolation 629e5c31af7Sopenharmony_ciof fragment shader invocations associated with other fragments. 630e5c31af7Sopenharmony_ci 631e5c31af7Sopenharmony_ci 632e5c31af7Sopenharmony_ci[[shaders-compute]] 633e5c31af7Sopenharmony_ci== Compute Shaders 634e5c31af7Sopenharmony_ci 635e5c31af7Sopenharmony_ciCompute shaders are invoked via flink:vkCmdDispatch and 636e5c31af7Sopenharmony_ciflink:vkCmdDispatchIndirect commands. 637e5c31af7Sopenharmony_ciIn general, they have access to similar resources as shader stages executing 638e5c31af7Sopenharmony_cias part of a graphics pipeline. 639e5c31af7Sopenharmony_ci 640e5c31af7Sopenharmony_ciCompute workloads are formed from groups of work items called workgroups and 641e5c31af7Sopenharmony_ciprocessed by the compute shader in the current compute pipeline. 642e5c31af7Sopenharmony_ciA workgroup is a collection of shader invocations that execute the same 643e5c31af7Sopenharmony_cishader, potentially in parallel. 644e5c31af7Sopenharmony_ciCompute shaders execute in _global workgroups_ which are divided into a 645e5c31af7Sopenharmony_cinumber of _local workgroups_ with a size that can: be set by assigning a 646e5c31af7Sopenharmony_civalue to the code:LocalSize 647e5c31af7Sopenharmony_ciifdef::VK_KHR_maintenance4[or code:LocalSizeId] 648e5c31af7Sopenharmony_ciexecution mode or via an object decorated by the code:WorkgroupSize 649e5c31af7Sopenharmony_cidecoration. 650e5c31af7Sopenharmony_ciAn invocation within a local workgroup can: share data with other members of 651e5c31af7Sopenharmony_cithe local workgroup through shared variables and issue memory and control 652e5c31af7Sopenharmony_ciflow barriers to synchronize with other members of the local workgroup. 653e5c31af7Sopenharmony_ci 654e5c31af7Sopenharmony_ci 655e5c31af7Sopenharmony_ciifdef::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[] 656e5c31af7Sopenharmony_ci[[shaders-raytracing-shaders]] 657e5c31af7Sopenharmony_ci[[shaders-ray-generation]] 658e5c31af7Sopenharmony_ci== Ray Generation Shaders 659e5c31af7Sopenharmony_ci 660e5c31af7Sopenharmony_ciA ray generation shader is similar to a compute shader. 661e5c31af7Sopenharmony_ciIts main purpose is to execute ray tracing queries using code:OpTraceRayKHR 662e5c31af7Sopenharmony_ciinstructions and process the results. 663e5c31af7Sopenharmony_ci 664e5c31af7Sopenharmony_ci 665e5c31af7Sopenharmony_ci[[shaders-ray-generation-execution]] 666e5c31af7Sopenharmony_ci=== Ray Generation Shader Execution 667e5c31af7Sopenharmony_ci 668e5c31af7Sopenharmony_ciOne ray generation shader is executed per ray tracing dispatch. 669e5c31af7Sopenharmony_ciIts location in the shader binding table (see <<shader-binding-table,Shader 670e5c31af7Sopenharmony_ciBinding Table>> for details) is passed directly into fname:vkCmdTraceRaysKHR 671e5c31af7Sopenharmony_ciusing the pname:raygenShaderBindingTableBuffer and 672e5c31af7Sopenharmony_cipname:raygenShaderBindingOffset parameters. 673e5c31af7Sopenharmony_ci 674e5c31af7Sopenharmony_ci 675e5c31af7Sopenharmony_ci[[shaders-intersection]] 676e5c31af7Sopenharmony_ci== Intersection Shaders 677e5c31af7Sopenharmony_ci 678e5c31af7Sopenharmony_ciIntersection shaders enable the implementation of arbitrary, application 679e5c31af7Sopenharmony_cidefined geometric primitives. 680e5c31af7Sopenharmony_ciAn intersection shader for a primitive is executed whenever its axis-aligned 681e5c31af7Sopenharmony_cibounding box is hit by a ray. 682e5c31af7Sopenharmony_ci 683e5c31af7Sopenharmony_ciLike other ray tracing shader domains, an intersection shader operates on a 684e5c31af7Sopenharmony_cisingle ray at a time. 685e5c31af7Sopenharmony_ciIt also operates on a single primitive at a time. 686e5c31af7Sopenharmony_ciIt is therefore the purpose of an intersection shader to compute the 687e5c31af7Sopenharmony_ciray-primitive intersections and report them. 688e5c31af7Sopenharmony_ciTo report an intersection, the shader calls the code:OpReportIntersectionKHR 689e5c31af7Sopenharmony_ciinstruction. 690e5c31af7Sopenharmony_ci 691e5c31af7Sopenharmony_ciAn intersection shader communicates with any-hit and closest shaders by 692e5c31af7Sopenharmony_cigenerating attribute values that they can: read. 693e5c31af7Sopenharmony_ciIntersection shaders cannot: read or modify the ray payload. 694e5c31af7Sopenharmony_ci 695e5c31af7Sopenharmony_ci 696e5c31af7Sopenharmony_ci[[shaders-intersection-execution]] 697e5c31af7Sopenharmony_ci=== Intersection Shader Execution 698e5c31af7Sopenharmony_ciThe order in which intersections are found along a ray, and therefore the 699e5c31af7Sopenharmony_ciorder in which intersection shaders are executed, is unspecified. 700e5c31af7Sopenharmony_ci 701e5c31af7Sopenharmony_ciThe intersection shader of the closest AABB which intersects the ray is 702e5c31af7Sopenharmony_ciguaranteed to be executed at some point during traversal, unless the ray is 703e5c31af7Sopenharmony_ciforcibly terminated. 704e5c31af7Sopenharmony_ci 705e5c31af7Sopenharmony_ci 706e5c31af7Sopenharmony_ci[[shaders-any-hit]] 707e5c31af7Sopenharmony_ci== Any-Hit Shaders 708e5c31af7Sopenharmony_ci 709e5c31af7Sopenharmony_ciThe any-hit shader is executed after the intersection shader reports an 710e5c31af7Sopenharmony_ciintersection that lies within the current [eq]#[t~min~,t~max~]# of the ray. 711e5c31af7Sopenharmony_ciThe main use of any-hit shaders is to programmatically decide whether or not 712e5c31af7Sopenharmony_cian intersection will be accepted. 713e5c31af7Sopenharmony_ciThe intersection will be accepted unless the shader calls the 714e5c31af7Sopenharmony_cicode:OpIgnoreIntersectionKHR instruction. 715e5c31af7Sopenharmony_ciAny-hit shaders have read-only access to the attributes generated by the 716e5c31af7Sopenharmony_cicorresponding intersection shader, and can: read or modify the ray payload. 717e5c31af7Sopenharmony_ci 718e5c31af7Sopenharmony_ci 719e5c31af7Sopenharmony_ci[[shaders-any-hit-execution]] 720e5c31af7Sopenharmony_ci=== Any-Hit Shader Execution 721e5c31af7Sopenharmony_ci 722e5c31af7Sopenharmony_ciThe order in which intersections are found along a ray, and therefore the 723e5c31af7Sopenharmony_ciorder in which any-hit shaders are executed, is unspecified. 724e5c31af7Sopenharmony_ci 725e5c31af7Sopenharmony_ciThe any-hit shader of the closest hit is guaranteed to be executed at some 726e5c31af7Sopenharmony_cipoint during traversal, unless the ray is forcibly terminated. 727e5c31af7Sopenharmony_ci 728e5c31af7Sopenharmony_ci 729e5c31af7Sopenharmony_ci[[shaders-closest-hit]] 730e5c31af7Sopenharmony_ci== Closest Hit Shaders 731e5c31af7Sopenharmony_ci 732e5c31af7Sopenharmony_ciClosest hit shaders have read-only access to the attributes generated by the 733e5c31af7Sopenharmony_cicorresponding intersection shader, and can: read or modify the ray payload. 734e5c31af7Sopenharmony_ciThey also have access to a number of system-generated values. 735e5c31af7Sopenharmony_ciClosest hit shaders can: call code:OpTraceRayKHR to recursively trace rays. 736e5c31af7Sopenharmony_ci 737e5c31af7Sopenharmony_ci 738e5c31af7Sopenharmony_ci[[shaders-closest-hit-execution]] 739e5c31af7Sopenharmony_ci=== Closest Hit Shader Execution 740e5c31af7Sopenharmony_ci 741e5c31af7Sopenharmony_ciExactly one closest hit shader is executed when traversal is finished and an 742e5c31af7Sopenharmony_ciintersection has been found and accepted. 743e5c31af7Sopenharmony_ci 744e5c31af7Sopenharmony_ci 745e5c31af7Sopenharmony_ci[[shaders-miss]] 746e5c31af7Sopenharmony_ci== Miss Shaders 747e5c31af7Sopenharmony_ci 748e5c31af7Sopenharmony_ciMiss shaders can: access the ray payload and can: trace new rays through the 749e5c31af7Sopenharmony_cicode:OpTraceRayKHR instruction, but cannot: access attributes since they are 750e5c31af7Sopenharmony_cinot associated with an intersection. 751e5c31af7Sopenharmony_ci 752e5c31af7Sopenharmony_ci 753e5c31af7Sopenharmony_ci[[shaders-miss-execution]] 754e5c31af7Sopenharmony_ci=== Miss Shader Execution 755e5c31af7Sopenharmony_ci 756e5c31af7Sopenharmony_ciA miss shader is executed instead of a closest hit shader if no intersection 757e5c31af7Sopenharmony_ciwas found during traversal. 758e5c31af7Sopenharmony_ci 759e5c31af7Sopenharmony_ci 760e5c31af7Sopenharmony_ci[[shaders-callable]] 761e5c31af7Sopenharmony_ci== Callable Shaders 762e5c31af7Sopenharmony_ci 763e5c31af7Sopenharmony_ciCallable shaders can: access a callable payload that works similarly to ray 764e5c31af7Sopenharmony_cipayloads to do subroutine work. 765e5c31af7Sopenharmony_ci 766e5c31af7Sopenharmony_ci 767e5c31af7Sopenharmony_ci[[shaders-callable-execution]] 768e5c31af7Sopenharmony_ci=== Callable Shader Execution 769e5c31af7Sopenharmony_ci 770e5c31af7Sopenharmony_ciA callable shader is executed by calling code:OpExecuteCallableKHR from an 771e5c31af7Sopenharmony_ciallowed shader stage. 772e5c31af7Sopenharmony_ci 773e5c31af7Sopenharmony_ciendif::VK_NV_ray_tracing,VK_KHR_ray_tracing_pipeline[] 774e5c31af7Sopenharmony_ci 775e5c31af7Sopenharmony_ci 776e5c31af7Sopenharmony_ci[[shaders-interpolation-decorations]] 777e5c31af7Sopenharmony_ci== Interpolation Decorations 778e5c31af7Sopenharmony_ci 779e5c31af7Sopenharmony_ciInterpolation decorations control the behavior of attribute interpolation in 780e5c31af7Sopenharmony_cithe fragment shader stage. 781e5c31af7Sopenharmony_ciInterpolation decorations can: be applied to code:Input storage class 782e5c31af7Sopenharmony_civariables in the fragment shader stage's interface, and control the 783e5c31af7Sopenharmony_ciinterpolation behavior of those variables. 784e5c31af7Sopenharmony_ci 785e5c31af7Sopenharmony_ciInputs that could be interpolated can: be decorated by at most one of the 786e5c31af7Sopenharmony_cifollowing decorations: 787e5c31af7Sopenharmony_ci 788e5c31af7Sopenharmony_ci * code:Flat: no interpolation 789e5c31af7Sopenharmony_ci * code:NoPerspective: linear interpolation (for 790e5c31af7Sopenharmony_ci <<line_linear_interpolation,lines>> and 791e5c31af7Sopenharmony_ci <<triangle_linear_interpolation,polygons>>) 792e5c31af7Sopenharmony_ciifdef::VK_NV_fragment_shader_barycentric[] 793e5c31af7Sopenharmony_ci * code:PerVertexNV: values fetched from shader-specified primitive vertex 794e5c31af7Sopenharmony_ciendif::VK_NV_fragment_shader_barycentric[] 795e5c31af7Sopenharmony_ci 796e5c31af7Sopenharmony_ciFragment input variables decorated with neither code:Flat nor 797e5c31af7Sopenharmony_cicode:NoPerspective use perspective-correct interpolation (for 798e5c31af7Sopenharmony_ci<<line_perspective_interpolation,lines>> and 799e5c31af7Sopenharmony_ci<<triangle_perspective_interpolation,polygons>>). 800e5c31af7Sopenharmony_ci 801e5c31af7Sopenharmony_ciThe presence of and type of interpolation is controlled by the above 802e5c31af7Sopenharmony_ciinterpolation decorations as well as the auxiliary decorations code:Centroid 803e5c31af7Sopenharmony_ciand code:Sample. 804e5c31af7Sopenharmony_ci 805e5c31af7Sopenharmony_ciA variable decorated with code:Flat will not be interpolated. 806e5c31af7Sopenharmony_ciInstead, it will have the same value for every fragment within a triangle. 807e5c31af7Sopenharmony_ciThis value will come from a single <<vertexpostproc-flatshading,provoking 808e5c31af7Sopenharmony_civertex>>. 809e5c31af7Sopenharmony_ciA variable decorated with code:Flat can: also be decorated with 810e5c31af7Sopenharmony_cicode:Centroid or code:Sample, which will mean the same thing as decorating 811e5c31af7Sopenharmony_ciit only as code:Flat. 812e5c31af7Sopenharmony_ci 813e5c31af7Sopenharmony_ciFor fragment shader input variables decorated with neither code:Centroid nor 814e5c31af7Sopenharmony_cicode:Sample, the assigned variable may: be interpolated anywhere within the 815e5c31af7Sopenharmony_cifragment and a single value may: be assigned to each sample within the 816e5c31af7Sopenharmony_cifragment. 817e5c31af7Sopenharmony_ci 818e5c31af7Sopenharmony_ciIf a fragment shader input is decorated with code:Centroid, a single value 819e5c31af7Sopenharmony_cimay: be assigned to that variable for all samples in the fragment, but that 820e5c31af7Sopenharmony_civalue must: be interpolated to a location that lies in both the fragment and 821e5c31af7Sopenharmony_ciin the primitive being rendered, including any of the fragment's samples 822e5c31af7Sopenharmony_cicovered by the primitive. 823e5c31af7Sopenharmony_ciBecause the location at which the variable is interpolated may: be different 824e5c31af7Sopenharmony_ciin neighboring fragments, and derivatives may: be computed by computing 825e5c31af7Sopenharmony_cidifferences between neighboring fragments, derivatives of centroid-sampled 826e5c31af7Sopenharmony_ciinputs may: be less accurate than those for non-centroid interpolated 827e5c31af7Sopenharmony_civariables. 828e5c31af7Sopenharmony_ciifdef::VK_EXT_post_depth_coverage[] 829e5c31af7Sopenharmony_ciThe code:PostDepthCoverage execution mode does not affect the determination 830e5c31af7Sopenharmony_ciof the centroid location. 831e5c31af7Sopenharmony_ciendif::VK_EXT_post_depth_coverage[] 832e5c31af7Sopenharmony_ci 833e5c31af7Sopenharmony_ciIf a fragment shader input is decorated with code:Sample, a separate value 834e5c31af7Sopenharmony_cimust: be assigned to that variable for each covered sample in the fragment, 835e5c31af7Sopenharmony_ciand that value must: be sampled at the location of the individual sample. 836e5c31af7Sopenharmony_ciWhen pname:rasterizationSamples is ename:VK_SAMPLE_COUNT_1_BIT, the fragment 837e5c31af7Sopenharmony_cicenter must: be used for code:Centroid, code:Sample, and undecorated 838e5c31af7Sopenharmony_ciattribute interpolation. 839e5c31af7Sopenharmony_ci 840e5c31af7Sopenharmony_ciFragment shader inputs that are signed or unsigned integers, integer 841e5c31af7Sopenharmony_civectors, or any double-precision floating-point type must: be decorated with 842e5c31af7Sopenharmony_cicode:Flat. 843e5c31af7Sopenharmony_ci 844e5c31af7Sopenharmony_ciifdef::VK_AMD_shader_explicit_vertex_parameter[] 845e5c31af7Sopenharmony_ciWhen the `apiext:VK_AMD_shader_explicit_vertex_parameter` device extension 846e5c31af7Sopenharmony_ciis enabled inputs can: be also decorated with the code:CustomInterpAMD 847e5c31af7Sopenharmony_ciinterpolation decoration, including fragment shader inputs that are signed 848e5c31af7Sopenharmony_cior unsigned integers, integer vectors, or any double-precision 849e5c31af7Sopenharmony_cifloating-point type. 850e5c31af7Sopenharmony_ciInputs decorated with code:CustomInterpAMD can: only be accessed by the 851e5c31af7Sopenharmony_ciextended instruction code:InterpolateAtVertexAMD and allows accessing the 852e5c31af7Sopenharmony_civalue of the input for individual vertices of the primitive. 853e5c31af7Sopenharmony_ciendif::VK_AMD_shader_explicit_vertex_parameter[] 854e5c31af7Sopenharmony_ci 855e5c31af7Sopenharmony_ciifdef::VK_NV_fragment_shader_barycentric[] 856e5c31af7Sopenharmony_ci[[shaders-interpolation-decorations-pervertexnv]] 857e5c31af7Sopenharmony_ciWhen the pname:fragmentShaderBarycentric feature is enabled, inputs can: be 858e5c31af7Sopenharmony_cialso decorated with the code:PerVertexNV interpolation decoration, including 859e5c31af7Sopenharmony_cifragment shader inputs that are signed or unsigned integers, integer 860e5c31af7Sopenharmony_civectors, or any double-precision floating-point type. 861e5c31af7Sopenharmony_ciInputs decorated with code:PerVertexNV can: only be accessed using an extra 862e5c31af7Sopenharmony_ciarray dimension, where the extra index identifies one of the vertices of the 863e5c31af7Sopenharmony_ciprimitive that produced the fragment. 864e5c31af7Sopenharmony_ciendif::VK_NV_fragment_shader_barycentric[] 865e5c31af7Sopenharmony_ci 866e5c31af7Sopenharmony_ci 867e5c31af7Sopenharmony_ci[[shaders-staticuse]] 868e5c31af7Sopenharmony_ci== Static Use 869e5c31af7Sopenharmony_ci 870e5c31af7Sopenharmony_ciA SPIR-V module declares a global object in memory using the code:OpVariable 871e5c31af7Sopenharmony_ciinstruction, which results in a pointer code:x to that object. 872e5c31af7Sopenharmony_ciA specific entry point in a SPIR-V module is said to _statically use_ that 873e5c31af7Sopenharmony_ciobject if that entry point's call tree contains a function containing a 874e5c31af7Sopenharmony_cimemory instruction or image instruction with code:x as an code:id operand. 875e5c31af7Sopenharmony_ciSee the "`Memory Instructions`" and "`Image Instructions`" subsections of 876e5c31af7Sopenharmony_cisection 3 "`Binary Form`" of the SPIR-V specification for the complete list 877e5c31af7Sopenharmony_ciof SPIR-V memory instructions. 878e5c31af7Sopenharmony_ci 879e5c31af7Sopenharmony_ciStatic use is not used to control the behavior of variables with code:Input 880e5c31af7Sopenharmony_ciand code:Output storage. 881e5c31af7Sopenharmony_ciThe effects of those variables are applied based only on whether they are 882e5c31af7Sopenharmony_cipresent in a shader entry point's interface. 883e5c31af7Sopenharmony_ci 884e5c31af7Sopenharmony_ci 885e5c31af7Sopenharmony_ci[[shaders-scope]] 886e5c31af7Sopenharmony_ci== Scope 887e5c31af7Sopenharmony_ci 888e5c31af7Sopenharmony_ciA _scope_ describes a set of shader invocations, where each such set is a 889e5c31af7Sopenharmony_ci_scope instance_. 890e5c31af7Sopenharmony_ciEach invocation belongs to one or more scope instances, but belongs to no 891e5c31af7Sopenharmony_cimore than one scope instance for each scope. 892e5c31af7Sopenharmony_ci 893e5c31af7Sopenharmony_ciThe operations available between invocations in a given scope instance vary, 894e5c31af7Sopenharmony_ciwith smaller scopes generally able to perform more operations, and with 895e5c31af7Sopenharmony_cigreater efficiency. 896e5c31af7Sopenharmony_ci 897e5c31af7Sopenharmony_ci 898e5c31af7Sopenharmony_ci[[shaders-scope-cross-device]] 899e5c31af7Sopenharmony_ci=== Cross Device 900e5c31af7Sopenharmony_ci 901e5c31af7Sopenharmony_ciAll invocations executed in a Vulkan instance fall into a single _cross 902e5c31af7Sopenharmony_cidevice scope instance_. 903e5c31af7Sopenharmony_ci 904e5c31af7Sopenharmony_ciWhilst the code:CrossDevice scope is defined in SPIR-V, it is disallowed in 905e5c31af7Sopenharmony_ciVulkan. 906e5c31af7Sopenharmony_ciAPI <<synchronization, synchronization>> commands can: be used to 907e5c31af7Sopenharmony_cicommunicate between devices. 908e5c31af7Sopenharmony_ci 909e5c31af7Sopenharmony_ci 910e5c31af7Sopenharmony_ci[[shaders-scope-device]] 911e5c31af7Sopenharmony_ci=== Device 912e5c31af7Sopenharmony_ci 913e5c31af7Sopenharmony_ciAll invocations executed on a single device form a _device scope instance_. 914e5c31af7Sopenharmony_ci 915e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 916e5c31af7Sopenharmony_ciIf the <<features-vulkanMemoryModel,pname:vulkanMemoryModel>> and 917e5c31af7Sopenharmony_ci<<features-vulkanMemoryModelDeviceScope, 918e5c31af7Sopenharmony_cipname:vulkanMemoryModelDeviceScope>> features are enabled, this scope is 919e5c31af7Sopenharmony_cirepresented in SPIR-V by the code:Device code:Scope, which can: be used as a 920e5c31af7Sopenharmony_cicode:Memory code:Scope for barrier and atomic operations. 921e5c31af7Sopenharmony_ci 922e5c31af7Sopenharmony_ciifdef::VK_KHR_shader_clock[] 923e5c31af7Sopenharmony_ciIf both the <<features-shaderDeviceClock, pname:shaderDeviceClock>> and 924e5c31af7Sopenharmony_ci<<features-vulkanMemoryModelDeviceScope, 925e5c31af7Sopenharmony_cipname:vulkanMemoryModelDeviceScope>> features are enabled, using the 926e5c31af7Sopenharmony_cicode:Device code:Scope with the code:OpReadClockKHR instruction will read 927e5c31af7Sopenharmony_cifrom a clock that is consistent across invocations in the same device scope 928e5c31af7Sopenharmony_ciinstance. 929e5c31af7Sopenharmony_ciendif::VK_KHR_shader_clock[] 930e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 931e5c31af7Sopenharmony_ci 932e5c31af7Sopenharmony_ciThere is no method to synchronize the execution of these invocations within 933e5c31af7Sopenharmony_ciSPIR-V, and this can: only be done with API synchronization primitives. 934e5c31af7Sopenharmony_ci 935e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_device_group[] 936e5c31af7Sopenharmony_ciInvocations executing on different devices in a device group operate in 937e5c31af7Sopenharmony_ciseparate device scope instances. 938e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_device_group[] 939e5c31af7Sopenharmony_ci 940e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 941e5c31af7Sopenharmony_ciThe scope only extends to the queue family, not the whole device. 942e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 943e5c31af7Sopenharmony_ci 944e5c31af7Sopenharmony_ci 945e5c31af7Sopenharmony_ci[[shaders-scope-queue-family]] 946e5c31af7Sopenharmony_ci=== Queue Family 947e5c31af7Sopenharmony_ci 948e5c31af7Sopenharmony_ciInvocations executed by queues in a given queue family form a _queue family 949e5c31af7Sopenharmony_ciscope instance_. 950e5c31af7Sopenharmony_ci 951e5c31af7Sopenharmony_ciThis scope is identified in SPIR-V as the 952e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 953e5c31af7Sopenharmony_cicode:QueueFamily code:Scope if the 954e5c31af7Sopenharmony_ci<<features-vulkanMemoryModel,pname:vulkanMemoryModel>> feature is enabled, 955e5c31af7Sopenharmony_cior if not, the 956e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 957e5c31af7Sopenharmony_cicode:Device code:Scope, which can: be used as a code:Memory code:Scope for 958e5c31af7Sopenharmony_cibarrier and atomic operations. 959e5c31af7Sopenharmony_ci 960e5c31af7Sopenharmony_ciifdef::VK_KHR_shader_clock[] 961e5c31af7Sopenharmony_ciIf the <<features-shaderDeviceClock, pname:shaderDeviceClock>> feature is 962e5c31af7Sopenharmony_cienabled, 963e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 964e5c31af7Sopenharmony_cibut the <<features-vulkanMemoryModelDeviceScope, 965e5c31af7Sopenharmony_cipname:vulkanMemoryModelDeviceScope>> feature is not enabled, 966e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_vulkan_memory_model[] 967e5c31af7Sopenharmony_ciusing the code:Device code:Scope with the code:OpReadClockKHR instruction 968e5c31af7Sopenharmony_ciwill read from a clock that is consistent across invocations in the same 969e5c31af7Sopenharmony_ciqueue family scope instance. 970e5c31af7Sopenharmony_ciendif::VK_KHR_shader_clock[] 971e5c31af7Sopenharmony_ci 972e5c31af7Sopenharmony_ciThere is no method to synchronize the execution of these invocations within 973e5c31af7Sopenharmony_ciSPIR-V, and this can: only be done with API synchronization primitives. 974e5c31af7Sopenharmony_ci 975e5c31af7Sopenharmony_ciEach invocation in a queue family scope instance must: be in the same 976e5c31af7Sopenharmony_ci<<shaders-scope-device, device scope instance>>. 977e5c31af7Sopenharmony_ci 978e5c31af7Sopenharmony_ci 979e5c31af7Sopenharmony_ci[[shaders-scope-command]] 980e5c31af7Sopenharmony_ci=== Command 981e5c31af7Sopenharmony_ci 982e5c31af7Sopenharmony_ciAny shader invocations executed as the result of a single command such as 983e5c31af7Sopenharmony_ciflink:vkCmdDispatch or flink:vkCmdDraw form a _command scope instance_. 984e5c31af7Sopenharmony_ciFor indirect drawing commands with pname:drawCount greater than one, 985e5c31af7Sopenharmony_ciinvocations from separate draws are in separate command scope instances. 986e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline,VK_NV_ray_tracing[] 987e5c31af7Sopenharmony_ciFor ray tracing shaders, an invocation group is an implementation-dependent 988e5c31af7Sopenharmony_cisubset of the set of shader invocations of a given shader stage which are 989e5c31af7Sopenharmony_ciproduced by a single trace rays command. 990e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline,VK_NV_ray_tracing[] 991e5c31af7Sopenharmony_ci 992e5c31af7Sopenharmony_ciThere is no specific code:Scope for communication across invocations in a 993e5c31af7Sopenharmony_cicommand scope instance. 994e5c31af7Sopenharmony_ciAs this has a clear boundary at the API level, coordination here can: be 995e5c31af7Sopenharmony_ciperformed in the API, rather than in SPIR-V. 996e5c31af7Sopenharmony_ci 997e5c31af7Sopenharmony_ciEach invocation in a command scope instance must: be in the same 998e5c31af7Sopenharmony_ci<<shaders-scope-queue-family, queue-family scope instance>>. 999e5c31af7Sopenharmony_ci 1000e5c31af7Sopenharmony_ciFor shaders without defined <<shaders-scope-workgroup, workgroups>>, this 1001e5c31af7Sopenharmony_ciset of invocations forms an _invocation group_ as defined in the 1002e5c31af7Sopenharmony_ci<<spirv-spec,SPIR-V specification>>. 1003e5c31af7Sopenharmony_ci 1004e5c31af7Sopenharmony_ci 1005e5c31af7Sopenharmony_ci[[shaders-scope-primitive]] 1006e5c31af7Sopenharmony_ci=== Primitive 1007e5c31af7Sopenharmony_ci 1008e5c31af7Sopenharmony_ciAny fragment shader invocations executed as the result of rasterization of a 1009e5c31af7Sopenharmony_cisingle primitive form a _primitive scope instance_. 1010e5c31af7Sopenharmony_ci 1011e5c31af7Sopenharmony_ciThere is no specific code:Scope for communication across invocations in a 1012e5c31af7Sopenharmony_ciprimitive scope instance. 1013e5c31af7Sopenharmony_ci 1014e5c31af7Sopenharmony_ciAny generated <<shaders-helper-invocations, helper invocations>> are 1015e5c31af7Sopenharmony_ciincluded in this scope instance. 1016e5c31af7Sopenharmony_ci 1017e5c31af7Sopenharmony_ciEach invocation in a primitive scope instance must: be in the same 1018e5c31af7Sopenharmony_ci<<shaders-scope-command, command scope instance>>. 1019e5c31af7Sopenharmony_ci 1020e5c31af7Sopenharmony_ciAny input variables decorated with code:Flat are uniform within a primitive 1021e5c31af7Sopenharmony_ciscope instance. 1022e5c31af7Sopenharmony_ci 1023e5c31af7Sopenharmony_ci 1024e5c31af7Sopenharmony_ci// intentionally no VK_NV_ray_tracing here since this scope does not exist there 1025e5c31af7Sopenharmony_ciifdef::VK_KHR_ray_tracing_pipeline[] 1026e5c31af7Sopenharmony_ci[[shaders-scope-shadercall]] 1027e5c31af7Sopenharmony_ci=== Shader Call 1028e5c31af7Sopenharmony_ci 1029e5c31af7Sopenharmony_ciAny <<shader-call-related,shader-call-related>> invocations that are 1030e5c31af7Sopenharmony_ciexecuted in one or more ray tracing execution models form a _shader call 1031e5c31af7Sopenharmony_ciscope instance_. 1032e5c31af7Sopenharmony_ci 1033e5c31af7Sopenharmony_ciThe code:ShaderCallKHR code:Scope can be used as code:Memory code:Scope for 1034e5c31af7Sopenharmony_cibarrier and atomic operations. 1035e5c31af7Sopenharmony_ci 1036e5c31af7Sopenharmony_ciEach invocation in a shader call scope instance must: be in the same 1037e5c31af7Sopenharmony_ci<<shaders-scope-queue-family, queue family scope instance>>. 1038e5c31af7Sopenharmony_ciendif::VK_KHR_ray_tracing_pipeline[] 1039e5c31af7Sopenharmony_ci 1040e5c31af7Sopenharmony_ci 1041e5c31af7Sopenharmony_ci[[shaders-scope-workgroup]] 1042e5c31af7Sopenharmony_ci=== Workgroup 1043e5c31af7Sopenharmony_ci 1044e5c31af7Sopenharmony_ciA _local workgroup_ is a set of invocations that can synchronize and share 1045e5c31af7Sopenharmony_cidata with each other using memory in the code:Workgroup storage class. 1046e5c31af7Sopenharmony_ci 1047e5c31af7Sopenharmony_ciThe code:Workgroup code:Scope can be used as both an code:Execution 1048e5c31af7Sopenharmony_cicode:Scope and code:Memory code:Scope for barrier and atomic operations. 1049e5c31af7Sopenharmony_ci 1050e5c31af7Sopenharmony_ciEach invocation in a local workgroup must: be in the same 1051e5c31af7Sopenharmony_ci<<shaders-scope-command, command scope instance>>. 1052e5c31af7Sopenharmony_ci 1053e5c31af7Sopenharmony_ciOnly 1054e5c31af7Sopenharmony_ciifdef::VK_NV_mesh_shader[] 1055e5c31af7Sopenharmony_citask, mesh, and 1056e5c31af7Sopenharmony_ciendif::VK_NV_mesh_shader[] 1057e5c31af7Sopenharmony_cicompute shaders have defined workgroups - other shader types cannot: use 1058e5c31af7Sopenharmony_ciworkgroup functionality. 1059e5c31af7Sopenharmony_ciFor shaders that have defined workgroups, this set of invocations forms an 1060e5c31af7Sopenharmony_ci_invocation group_ as defined in the <<spirv-spec,SPIR-V specification>>. 1061e5c31af7Sopenharmony_ci 1062e5c31af7Sopenharmony_ci 1063e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 1064e5c31af7Sopenharmony_ci[[shaders-scope-subgroup]] 1065e5c31af7Sopenharmony_ci=== Subgroup 1066e5c31af7Sopenharmony_ci 1067e5c31af7Sopenharmony_ciA _subgroup_ (see the subsection "`Control Flow`" of section 2 of the SPIR-V 1068e5c31af7Sopenharmony_ci1.3 Revision 1 specification) is a set of invocations that can synchronize 1069e5c31af7Sopenharmony_ciand share data with each other efficiently. 1070e5c31af7Sopenharmony_ci 1071e5c31af7Sopenharmony_ciThe code:Subgroup code:Scope can be used as both an code:Execution 1072e5c31af7Sopenharmony_cicode:Scope and code:Memory code:Scope for barrier and atomic operations. 1073e5c31af7Sopenharmony_ciOther <<VkSubgroupFeatureFlagBits, subgroup features>> allow the use of 1074e5c31af7Sopenharmony_ci<<shaders-group-operations, group operations>> with subgroup scope. 1075e5c31af7Sopenharmony_ci 1076e5c31af7Sopenharmony_ciifdef::VK_KHR_shader_clock[] 1077e5c31af7Sopenharmony_ciIf the <<features-shaderSubgroupClock, pname:shaderSubgroupClock>> feature 1078e5c31af7Sopenharmony_ciis enabled, using the code:Subgroup code:Scope with the code:OpReadClockKHR 1079e5c31af7Sopenharmony_ciinstruction will read from a clock that is consistent across invocations in 1080e5c31af7Sopenharmony_cithe same subgroup. 1081e5c31af7Sopenharmony_ciendif::VK_KHR_shader_clock[] 1082e5c31af7Sopenharmony_ci 1083e5c31af7Sopenharmony_ciFor <<shaders-scope-workgroup, shaders that have defined workgroups>>, each 1084e5c31af7Sopenharmony_ciinvocation in a subgroup must: be in the same <<shaders-scope-workgroup, 1085e5c31af7Sopenharmony_cilocal workgroup>>. 1086e5c31af7Sopenharmony_ci 1087e5c31af7Sopenharmony_ciIn other shader stages, each invocation in a subgroup must: be in the same 1088e5c31af7Sopenharmony_ci<<shaders-scope-device, device scope instance>>. 1089e5c31af7Sopenharmony_ci 1090e5c31af7Sopenharmony_ciOnly <<limits-subgroup-supportedStages, shader stages that support subgroup 1091e5c31af7Sopenharmony_cioperations>> have defined subgroups. 1092e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1093e5c31af7Sopenharmony_ci 1094e5c31af7Sopenharmony_ci 1095e5c31af7Sopenharmony_ci[[shaders-scope-quad]] 1096e5c31af7Sopenharmony_ci=== Quad 1097e5c31af7Sopenharmony_ci 1098e5c31af7Sopenharmony_ciA _quad scope instance_ is formed of four shader invocations. 1099e5c31af7Sopenharmony_ci 1100e5c31af7Sopenharmony_ciIn a fragment shader, each invocation in a quad scope instance is formed of 1101e5c31af7Sopenharmony_ciinvocations in neighboring framebuffer locations [eq]#(x~i~, y~i~)#, where: 1102e5c31af7Sopenharmony_ci 1103e5c31af7Sopenharmony_ci * [eq]#i# is the index of the invocation within the scope instance. 1104e5c31af7Sopenharmony_ci * [eq]#w# and [eq]#h# are the number of pixels the fragment covers in the 1105e5c31af7Sopenharmony_ci [eq]#x# and [eq]#y# axes. 1106e5c31af7Sopenharmony_ci * [eq]#w# and [eq]#h# are identical for all participating invocations. 1107e5c31af7Sopenharmony_ci * [eq]#(x~0~) = (x~1~ - w) = (x~2~) = (x~3~ - w)# 1108e5c31af7Sopenharmony_ci * [eq]#(y~0~) = (y~1~) = (y~2~ - h) = (y~3~ - h)# 1109e5c31af7Sopenharmony_ci * Each invocation has the same layer and sample indices. 1110e5c31af7Sopenharmony_ci 1111e5c31af7Sopenharmony_ciifdef::VK_NV_compute_shader_derivatives[] 1112e5c31af7Sopenharmony_ciIn a compute shader, if the code:DerivativeGroupQuadsNV execution mode is 1113e5c31af7Sopenharmony_cispecified, each invocation in a quad scope instance is formed of invocations 1114e5c31af7Sopenharmony_ciwith adjacent local invocation IDs [eq]#(x~i~, y~i~)#, where: 1115e5c31af7Sopenharmony_ci 1116e5c31af7Sopenharmony_ci * [eq]#i# is the index of the invocation within the quad scope instance. 1117e5c31af7Sopenharmony_ci * [eq]#(x~0~) = (x~1~ - 1) = (x~2~) = (x~3~ - 1)# 1118e5c31af7Sopenharmony_ci * [eq]#(y~0~) = (y~1~) = (y~2~ - 1) = (y~3~ - 1)# 1119e5c31af7Sopenharmony_ci * [eq]#x~0~# and [eq]#y~0~# are integer multiples of 2. 1120e5c31af7Sopenharmony_ci * Each invocation has the same [eq]#z# coordinate. 1121e5c31af7Sopenharmony_ci 1122e5c31af7Sopenharmony_ciIn a compute shader, if the code:DerivativeGroupLinearNV execution mode is 1123e5c31af7Sopenharmony_cispecified, each invocation in a quad scope instance is formed of invocations 1124e5c31af7Sopenharmony_ciwith adjacent local invocation indices [eq]#(l~i~)#, where: 1125e5c31af7Sopenharmony_ci 1126e5c31af7Sopenharmony_ci * [eq]#i# is the index of the invocation within the quad scope instance. 1127e5c31af7Sopenharmony_ci * [eq]#(l~0~) = (l~1~ - 1) = (l~2~ - 2) = (l~3~ - 3)# 1128e5c31af7Sopenharmony_ci * [eq]#l~0~# is an integer multiple of 4. 1129e5c31af7Sopenharmony_ci 1130e5c31af7Sopenharmony_ciendif::VK_NV_compute_shader_derivatives[] 1131e5c31af7Sopenharmony_ci 1132e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 1133e5c31af7Sopenharmony_ciIn all shaders, each invocation in a quad scope instance is formed of 1134e5c31af7Sopenharmony_ciinvocations in adjacent subgroup invocation indices [eq]#(s~i~)#, where: 1135e5c31af7Sopenharmony_ci 1136e5c31af7Sopenharmony_ci * [eq]#i# is the index of the invocation within the quad scope instance. 1137e5c31af7Sopenharmony_ci * [eq]#(s~0~) = (s~1~ - 1) = (s~2~ - 2) = (s~3~ - 3)# 1138e5c31af7Sopenharmony_ci * [eq]#s~0~# is an integer multiple of 4. 1139e5c31af7Sopenharmony_ci 1140e5c31af7Sopenharmony_ciEach invocation in a quad scope instance must: be in the same 1141e5c31af7Sopenharmony_ci<<shaders-scope-subgroup, subgroup>>. 1142e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1143e5c31af7Sopenharmony_ci 1144e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_1[] 1145e5c31af7Sopenharmony_ciThe specific set of invocations that make up a quad scope instance in other 1146e5c31af7Sopenharmony_cishader stages is undefined:. 1147e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1148e5c31af7Sopenharmony_ci 1149e5c31af7Sopenharmony_ciIn a fragment shader, each invocation in a quad scope instance must: be in 1150e5c31af7Sopenharmony_cithe same <<shaders-scope-primitive, primitive scope instance>>. 1151e5c31af7Sopenharmony_ci 1152e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_1[] 1153e5c31af7Sopenharmony_ciFor <<shaders-scope-workgroup, shaders that have defined workgroups>>, each 1154e5c31af7Sopenharmony_ciinvocation in a quad scope instance must: be in the same 1155e5c31af7Sopenharmony_ci<<shaders-scope-workgroup, local workgroup>>. 1156e5c31af7Sopenharmony_ci 1157e5c31af7Sopenharmony_ciIn other shader stages, each invocation in a quad scope instance must: be in 1158e5c31af7Sopenharmony_cithe same <<shaders-scope-device, device scope instance>>. 1159e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1160e5c31af7Sopenharmony_ci 1161e5c31af7Sopenharmony_ciFragment 1162e5c31af7Sopenharmony_ciifdef::VK_NV_compute_shader_derivatives,VK_VERSION_1_1[] 1163e5c31af7Sopenharmony_ciand compute 1164e5c31af7Sopenharmony_ciendif::VK_NV_compute_shader_derivatives,VK_VERSION_1_1[] 1165e5c31af7Sopenharmony_cishaders have defined quad scope instances. 1166e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 1167e5c31af7Sopenharmony_ciIf the <<limits-subgroup-quadOperationsInAllStages, 1168e5c31af7Sopenharmony_cipname:quadOperationsInAllStages>> limit is supported, any 1169e5c31af7Sopenharmony_ci<<limits-subgroup-supportedStages, shader stages that support subgroup 1170e5c31af7Sopenharmony_cioperations>> also have defined quad scope instances. 1171e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1172e5c31af7Sopenharmony_ci 1173e5c31af7Sopenharmony_ci 1174e5c31af7Sopenharmony_ciifdef::VK_EXT_fragment_shader_interlock[] 1175e5c31af7Sopenharmony_ci[[shaders-scope-fragment-interlock]] 1176e5c31af7Sopenharmony_ci=== Fragment Interlock 1177e5c31af7Sopenharmony_ci 1178e5c31af7Sopenharmony_ciA _fragment interlock scope instance_ is formed of fragment shader 1179e5c31af7Sopenharmony_ciinvocations based on their framebuffer locations [eq]#(x,y,layer,sample)#, 1180e5c31af7Sopenharmony_ciexecuted by commands inside a single <<renderpass,subpass>>. 1181e5c31af7Sopenharmony_ci 1182e5c31af7Sopenharmony_ciThe specific set of invocations included varies based on the execution mode 1183e5c31af7Sopenharmony_cias follows: 1184e5c31af7Sopenharmony_ci 1185e5c31af7Sopenharmony_ci * If the code:SampleInterlockOrderedEXT or 1186e5c31af7Sopenharmony_ci code:SampleInterlockUnorderedEXT execution modes are used, only 1187e5c31af7Sopenharmony_ci invocations with identical framebuffer locations 1188e5c31af7Sopenharmony_ci [eq]#(x,y,layer,sample)# are included. 1189e5c31af7Sopenharmony_ci * If the code:PixelInterlockOrderedEXT or code:PixelInterlockUnorderedEXT 1190e5c31af7Sopenharmony_ci execution modes are used, fragments with different sample ids are also 1191e5c31af7Sopenharmony_ci included. 1192e5c31af7Sopenharmony_ciifdef::VK_NV_shading_rate_image,VK_KHR_fragment_shading_rate[] 1193e5c31af7Sopenharmony_ci * If the code:ShadingRateInterlockOrderedEXT or 1194e5c31af7Sopenharmony_ci code:ShadingRateInterlockUnorderedEXT execution modes are used, 1195e5c31af7Sopenharmony_ci fragments from neighbouring framebuffer locations are also included, as 1196e5c31af7Sopenharmony_ci <<primsrast-shading-rate-image,determined by the shading rate>>. 1197e5c31af7Sopenharmony_ciendif::VK_NV_shading_rate_image,VK_KHR_fragment_shading_rate[] 1198e5c31af7Sopenharmony_ci 1199e5c31af7Sopenharmony_ciOnly fragment shaders with one of the above execution modes have defined 1200e5c31af7Sopenharmony_cifragment interlock scope instances. 1201e5c31af7Sopenharmony_ci 1202e5c31af7Sopenharmony_ciThere is no specific code:Scope value for communication across invocations 1203e5c31af7Sopenharmony_ciin a fragment interlock scope instance. 1204e5c31af7Sopenharmony_ciHowever, this is implicitly used as a memory scope by 1205e5c31af7Sopenharmony_cicode:OpBeginInvocationInterlockEXT and code:OpEndInvocationInterlockEXT. 1206e5c31af7Sopenharmony_ci 1207e5c31af7Sopenharmony_ciEach invocation in a fragment interlock scope instance must: be in the same 1208e5c31af7Sopenharmony_ci<<shaders-scope-queue-family, queue family scope instance>>. 1209e5c31af7Sopenharmony_ciendif::VK_EXT_fragment_shader_interlock[] 1210e5c31af7Sopenharmony_ci 1211e5c31af7Sopenharmony_ci 1212e5c31af7Sopenharmony_ci[[shaders-scope-invocation]] 1213e5c31af7Sopenharmony_ci=== Invocation 1214e5c31af7Sopenharmony_ci 1215e5c31af7Sopenharmony_ciThe smallest _scope_ is a single invocation; this is represented by the 1216e5c31af7Sopenharmony_cicode:Invocation code:Scope in SPIR-V. 1217e5c31af7Sopenharmony_ci 1218e5c31af7Sopenharmony_ciFragment shader invocations must: be in a <<shaders-scope-primitive, 1219e5c31af7Sopenharmony_ciprimitive scope instance>>. 1220e5c31af7Sopenharmony_ci 1221e5c31af7Sopenharmony_ciifdef::VK_EXT_fragment_shader_interlock[] 1222e5c31af7Sopenharmony_ciInvocations in <<shaders-scope-fragment-interlock, fragment shaders that 1223e5c31af7Sopenharmony_cihave a defined fragment interlock scope>> must: be in a 1224e5c31af7Sopenharmony_ci<<shaders-scope-fragment-interlock, fragment interlock scope instance>>. 1225e5c31af7Sopenharmony_ciendif::VK_EXT_fragment_shader_interlock[] 1226e5c31af7Sopenharmony_ci 1227e5c31af7Sopenharmony_ciInvocations in <<shaders-scope-workgroup, shaders that have defined 1228e5c31af7Sopenharmony_ciworkgroups>> must: be in a <<shaders-scope-workgroup, local workgroup>>. 1229e5c31af7Sopenharmony_ci 1230e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 1231e5c31af7Sopenharmony_ciInvocations in <<shaders-scope-subgroup, shaders that have a defined 1232e5c31af7Sopenharmony_cisubgroup scope>> must: be in a <<shaders-scope-subgroup, subgroup>>. 1233e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1234e5c31af7Sopenharmony_ci 1235e5c31af7Sopenharmony_ciInvocations in <<shaders-scope-quad, shaders that have a defined quad 1236e5c31af7Sopenharmony_ciscope>> must: be in a <<shaders-scope-quad, quad scope instance>>. 1237e5c31af7Sopenharmony_ci 1238e5c31af7Sopenharmony_ciAll invocations in all stages must: be in a <<shaders-scope-command,command 1239e5c31af7Sopenharmony_ciscope instance>>. 1240e5c31af7Sopenharmony_ci 1241e5c31af7Sopenharmony_ci 1242e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 1243e5c31af7Sopenharmony_ci[[shaders-group-operations]] 1244e5c31af7Sopenharmony_ci== Group Operations 1245e5c31af7Sopenharmony_ci 1246e5c31af7Sopenharmony_ci_Group operations_ are executed by multiple invocations within a 1247e5c31af7Sopenharmony_ci<<shaders-scope, scope instance>>; with each invocation involved in 1248e5c31af7Sopenharmony_cicalculating the result. 1249e5c31af7Sopenharmony_ciThis provides a mechanism for efficient communication between invocations in 1250e5c31af7Sopenharmony_cia particular scope instance. 1251e5c31af7Sopenharmony_ci 1252e5c31af7Sopenharmony_ciGroup operations all take a code:Scope defining the desired 1253e5c31af7Sopenharmony_ci<<shaders-scope,scope instance>> to operate within. 1254e5c31af7Sopenharmony_ciOnly the code:Subgroup scope can: be used for these operations; the 1255e5c31af7Sopenharmony_ci<<limits-subgroupSupportedOperations, pname:subgroupSupportedOperations>> 1256e5c31af7Sopenharmony_cilimit defines which types of operation can: be used. 1257e5c31af7Sopenharmony_ci 1258e5c31af7Sopenharmony_ci 1259e5c31af7Sopenharmony_ci[[shaders-group-operations-basic]] 1260e5c31af7Sopenharmony_ci=== Basic Group Operations 1261e5c31af7Sopenharmony_ci 1262e5c31af7Sopenharmony_ciBasic group operations include the use of code:OpGroupNonUniformElect, 1263e5c31af7Sopenharmony_cicode:OpControlBarrier, code:OpMemoryBarrier, and atomic operations. 1264e5c31af7Sopenharmony_ci 1265e5c31af7Sopenharmony_cicode:OpGroupNonUniformElect can: be used to choose a single invocation to 1266e5c31af7Sopenharmony_ciperform a task for the whole group. 1267e5c31af7Sopenharmony_ciOnly the invocation with the lowest id in the group will return code:true. 1268e5c31af7Sopenharmony_ci 1269e5c31af7Sopenharmony_ciThe <<memory-model,Memory Model>> appendix defines the operation of barriers 1270e5c31af7Sopenharmony_ciand atomics. 1271e5c31af7Sopenharmony_ci 1272e5c31af7Sopenharmony_ci 1273e5c31af7Sopenharmony_ci[[shaders-group-operations-vote]] 1274e5c31af7Sopenharmony_ci=== Vote Group Operations 1275e5c31af7Sopenharmony_ci 1276e5c31af7Sopenharmony_ciThe vote group operations allow invocations within a group to compare values 1277e5c31af7Sopenharmony_ciacross a group. 1278e5c31af7Sopenharmony_ciThe types of votes enabled are: 1279e5c31af7Sopenharmony_ci 1280e5c31af7Sopenharmony_ci * Do all active group invocations agree that an expression is true? 1281e5c31af7Sopenharmony_ci * Do any active group invocations evaluate an expression to true? 1282e5c31af7Sopenharmony_ci * Do all active group invocations have the same value of an expression? 1283e5c31af7Sopenharmony_ci 1284e5c31af7Sopenharmony_ci[NOTE] 1285e5c31af7Sopenharmony_ci.Note 1286e5c31af7Sopenharmony_ci==== 1287e5c31af7Sopenharmony_ciThese operations are useful in combination with control flow in that they 1288e5c31af7Sopenharmony_ciallow for developers to check whether conditions match across the group and 1289e5c31af7Sopenharmony_cichoose potentially faster code-paths in these cases. 1290e5c31af7Sopenharmony_ci==== 1291e5c31af7Sopenharmony_ci 1292e5c31af7Sopenharmony_ci 1293e5c31af7Sopenharmony_ci[[shaders-group-operations-arithmetic]] 1294e5c31af7Sopenharmony_ci=== Arithmetic Group Operations 1295e5c31af7Sopenharmony_ci 1296e5c31af7Sopenharmony_ciThe arithmetic group operations allow invocations to perform scans and 1297e5c31af7Sopenharmony_cireductions across a group. 1298e5c31af7Sopenharmony_ciThe operators supported are add, mul, min, max, and, or, xor. 1299e5c31af7Sopenharmony_ci 1300e5c31af7Sopenharmony_ciFor reductions, every invocation in a group will obtain the cumulative 1301e5c31af7Sopenharmony_ciresult of these operators applied to all values in the group. 1302e5c31af7Sopenharmony_ciFor exclusive scans, each invocation in a group will obtain the cumulative 1303e5c31af7Sopenharmony_ciresult of these operators applied to all values in invocations with a lower 1304e5c31af7Sopenharmony_ciindex in the group. 1305e5c31af7Sopenharmony_ciInclusive scans are identical to exclusive scans, except the cumulative 1306e5c31af7Sopenharmony_ciresult includes the operator applied to the value in the current invocation. 1307e5c31af7Sopenharmony_ci 1308e5c31af7Sopenharmony_ciThe order in which these operators are applied is implementation-dependent. 1309e5c31af7Sopenharmony_ci 1310e5c31af7Sopenharmony_ci 1311e5c31af7Sopenharmony_ci[[shaders-group-operations-ballot]] 1312e5c31af7Sopenharmony_ci=== Ballot Group Operations 1313e5c31af7Sopenharmony_ci 1314e5c31af7Sopenharmony_ciThe ballot group operations allow invocations to perform more complex votes 1315e5c31af7Sopenharmony_ciacross the group. 1316e5c31af7Sopenharmony_ciThe ballot functionality allows all invocations within a group to provide a 1317e5c31af7Sopenharmony_ciboolean value and get as a result what each invocation provided as their 1318e5c31af7Sopenharmony_ciboolean value. 1319e5c31af7Sopenharmony_ciThe broadcast functionality allows values to be broadcast from an invocation 1320e5c31af7Sopenharmony_cito all other invocations within the group. 1321e5c31af7Sopenharmony_ci 1322e5c31af7Sopenharmony_ci 1323e5c31af7Sopenharmony_ci[[shaders-group-operations-shuffle]] 1324e5c31af7Sopenharmony_ci=== Shuffle Group Operations 1325e5c31af7Sopenharmony_ci 1326e5c31af7Sopenharmony_ciThe shuffle group operations allow invocations to read values from other 1327e5c31af7Sopenharmony_ciinvocations within a group. 1328e5c31af7Sopenharmony_ci 1329e5c31af7Sopenharmony_ci 1330e5c31af7Sopenharmony_ci[[shaders-group-operations-shuffle-relative]] 1331e5c31af7Sopenharmony_ci=== Shuffle Relative Group Operations 1332e5c31af7Sopenharmony_ci 1333e5c31af7Sopenharmony_ciThe shuffle relative group operations allow invocations to read values from 1334e5c31af7Sopenharmony_ciother invocations within the group relative to the current invocation in the 1335e5c31af7Sopenharmony_cigroup. 1336e5c31af7Sopenharmony_ciThe relative operations supported allow data to be shifted up and down 1337e5c31af7Sopenharmony_cithrough the invocations within a group. 1338e5c31af7Sopenharmony_ci 1339e5c31af7Sopenharmony_ci 1340e5c31af7Sopenharmony_ci[[shaders-group-operations-clustered]] 1341e5c31af7Sopenharmony_ci=== Clustered Group Operations 1342e5c31af7Sopenharmony_ci 1343e5c31af7Sopenharmony_ciThe clustered group operations allow invocations to perform an operation 1344e5c31af7Sopenharmony_ciamong partitions of a group, such that the operation is only performed 1345e5c31af7Sopenharmony_ciwithin the group invocations within a partition. 1346e5c31af7Sopenharmony_ciThe partitions for clustered group operations are consecutive power-of-two 1347e5c31af7Sopenharmony_cisize groups of invocations and the cluster size must: be known at pipeline 1348e5c31af7Sopenharmony_cicreation time. 1349e5c31af7Sopenharmony_ciThe operations supported are add, mul, min, max, and, or, xor. 1350e5c31af7Sopenharmony_ci 1351e5c31af7Sopenharmony_ci 1352e5c31af7Sopenharmony_ci[[shaders-quad-operations]] 1353e5c31af7Sopenharmony_ci== Quad Group Operations 1354e5c31af7Sopenharmony_ci 1355e5c31af7Sopenharmony_ciQuad group operations (code:OpGroupNonUniformQuad*) are a specialized type 1356e5c31af7Sopenharmony_ciof <<shaders-group-operations, group operations>> that only operate on 1357e5c31af7Sopenharmony_ci<<shaders-scope-quad, quad scope instances>>. 1358e5c31af7Sopenharmony_ciWhilst these instructions do include a code:Scope parameter, this scope is 1359e5c31af7Sopenharmony_cialways overridden; only the <<shaders-scope-quad, quad scope instance>> is 1360e5c31af7Sopenharmony_ciincluded in its execution scope. 1361e5c31af7Sopenharmony_ci 1362e5c31af7Sopenharmony_ciFragment shaders that statically execute quad group operations must: launch 1363e5c31af7Sopenharmony_cisufficient invocations to ensure their correct operation; additional 1364e5c31af7Sopenharmony_ci<<shaders-helper-invocations, helper invocations>> are launched for 1365e5c31af7Sopenharmony_ciframebuffer locations not covered by rasterized fragments if necessary. 1366e5c31af7Sopenharmony_ci 1367e5c31af7Sopenharmony_ciThe index used to select participating invocations is [eq]#i#, as described 1368e5c31af7Sopenharmony_cifor a <<shaders-scope-quad, quad scope instance>>, defined as the _quad 1369e5c31af7Sopenharmony_ciindex_ in the <<spirv-spec,SPIR-V specification>>. 1370e5c31af7Sopenharmony_ci 1371e5c31af7Sopenharmony_ciFor code:OpGroupNonUniformQuadBroadcast this value is equal to code:Index. 1372e5c31af7Sopenharmony_ciFor code:OpGroupNonUniformQuadSwap, it is equal to the implicit code:Index 1373e5c31af7Sopenharmony_ciused by each participating invocation. 1374e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1375e5c31af7Sopenharmony_ci 1376e5c31af7Sopenharmony_ci 1377e5c31af7Sopenharmony_ci[[shaders-derivative-operations]] 1378e5c31af7Sopenharmony_ci== Derivative Operations 1379e5c31af7Sopenharmony_ci 1380e5c31af7Sopenharmony_ciDerivative operations calculate the partial derivative for an expression 1381e5c31af7Sopenharmony_ci[eq]#P# as a function of an invocation's [eq]#x# and [eq]#y# coordinates. 1382e5c31af7Sopenharmony_ci 1383e5c31af7Sopenharmony_ciDerivative operations operate on a set of invocations known as a _derivative 1384e5c31af7Sopenharmony_cigroup_ as defined in the <<spirv-spec,SPIR-V specification>>. 1385e5c31af7Sopenharmony_ciA derivative group is equivalent to 1386e5c31af7Sopenharmony_ciifdef::VK_NV_compute_shader_derivatives[] 1387e5c31af7Sopenharmony_cithe <<shaders-scope-quad, quad scope instance>> for a compute shader 1388e5c31af7Sopenharmony_ciinvocation, or 1389e5c31af7Sopenharmony_ciendif::VK_NV_compute_shader_derivatives[] 1390e5c31af7Sopenharmony_cithe <<shaders-scope-primitive, primitive scope instance>> for a fragment 1391e5c31af7Sopenharmony_cishader invocation. 1392e5c31af7Sopenharmony_ci 1393e5c31af7Sopenharmony_ciDerivatives are calculated assuming that [eq]#P# is piecewise linear and 1394e5c31af7Sopenharmony_cicontinuous within the derivative group. 1395e5c31af7Sopenharmony_ciAll dynamic instances of explicit derivative instructions (code:OpDPdx*, 1396e5c31af7Sopenharmony_cicode:OpDPdy*, and code:OpFwidth*) must: be executed in control flow that is 1397e5c31af7Sopenharmony_ciuniform within a derivative group. 1398e5c31af7Sopenharmony_ciFor other derivative operations, results are undefined: if a dynamic 1399e5c31af7Sopenharmony_ciinstance is executed in control flow that is not uniform within the 1400e5c31af7Sopenharmony_ciderivative group. 1401e5c31af7Sopenharmony_ci 1402e5c31af7Sopenharmony_ciFragment shaders that statically execute derivative operations must: launch 1403e5c31af7Sopenharmony_cisufficient invocations to ensure their correct operation; additional 1404e5c31af7Sopenharmony_ci<<shaders-helper-invocations, helper invocations>> are launched for 1405e5c31af7Sopenharmony_ciframebuffer locations not covered by rasterized fragments if necessary. 1406e5c31af7Sopenharmony_ci 1407e5c31af7Sopenharmony_ciifdef::VK_NV_compute_shader_derivatives[] 1408e5c31af7Sopenharmony_ci[NOTE] 1409e5c31af7Sopenharmony_ci.Note 1410e5c31af7Sopenharmony_ci==== 1411e5c31af7Sopenharmony_ciIn a compute shader, it is the application's responsibility to ensure that 1412e5c31af7Sopenharmony_cisufficient invocations are launched. 1413e5c31af7Sopenharmony_ci==== 1414e5c31af7Sopenharmony_ciendif::VK_NV_compute_shader_derivatives[] 1415e5c31af7Sopenharmony_ci 1416e5c31af7Sopenharmony_ciDerivative operations calculate their results as the difference between the 1417e5c31af7Sopenharmony_ciresult of [eq]#P# across invocations in the quad. 1418e5c31af7Sopenharmony_ciFor fine derivative operations (code:OpDPdxFine and code:OpDPdyFine), the 1419e5c31af7Sopenharmony_civalues of [eq]#DPdx(P~i~)# are calculated as 1420e5c31af7Sopenharmony_ci 1421e5c31af7Sopenharmony_ci {empty}:: [eq]#DPdx(P~0~) = DPdx(P~1~) = P~1~ - P~0~# 1422e5c31af7Sopenharmony_ci {empty}:: [eq]#DPdx(P~2~) = DPdx(P~3~) = P~3~ - P~2~# 1423e5c31af7Sopenharmony_ci 1424e5c31af7Sopenharmony_ciand the values of [eq]#DPdy(P~i~)# are calculated as 1425e5c31af7Sopenharmony_ci 1426e5c31af7Sopenharmony_ci {empty}:: [eq]#DPdy(P~0~) = DPdy(P~2~) = P~2~ - P~0~# 1427e5c31af7Sopenharmony_ci {empty}:: [eq]#DPdy(P~1~) = DPdy(P~3~) = P~3~ - P~1~# 1428e5c31af7Sopenharmony_ci 1429e5c31af7Sopenharmony_ciwhere [eq]#i# is the index of each invocation as described in 1430e5c31af7Sopenharmony_ci<<shaders-scope-quad>>. 1431e5c31af7Sopenharmony_ci 1432e5c31af7Sopenharmony_ciCoarse derivative operations (code:OpDPdxCoarse and code:OpDPdyCoarse), 1433e5c31af7Sopenharmony_cicalculate their results in roughly the same manner, but may: only calculate 1434e5c31af7Sopenharmony_citwo values instead of four (one for each of [eq]#DPdx# and [eq]#DPdy#), 1435e5c31af7Sopenharmony_cireusing the same result no matter the originating invocation. 1436e5c31af7Sopenharmony_ciIf an implementation does this, it should: use the fine derivative 1437e5c31af7Sopenharmony_cicalculations described for [eq]#P~0~#. 1438e5c31af7Sopenharmony_ci 1439e5c31af7Sopenharmony_ci[NOTE] 1440e5c31af7Sopenharmony_ci.Note 1441e5c31af7Sopenharmony_ci==== 1442e5c31af7Sopenharmony_ciDerivative values are calculated between fragments rather than pixels. 1443e5c31af7Sopenharmony_ciIf the fragment shader invocations involved in the calculation cover 1444e5c31af7Sopenharmony_cimultiple pixels, these operations cover a wider area, resulting in larger 1445e5c31af7Sopenharmony_ciderivative values. 1446e5c31af7Sopenharmony_ciThis in turn will result in a coarser level of detail being selected for 1447e5c31af7Sopenharmony_ciimage sampling operations using derivatives. 1448e5c31af7Sopenharmony_ci 1449e5c31af7Sopenharmony_ciApplications may want to account for this when using multi-pixel fragments; 1450e5c31af7Sopenharmony_ciif pixel derivatives are desired, applications should use explicit 1451e5c31af7Sopenharmony_ciderivative operations and divide the results by the size of the fragment in 1452e5c31af7Sopenharmony_cieach dimension as follows: 1453e5c31af7Sopenharmony_ci 1454e5c31af7Sopenharmony_ci {empty}:: [eq]#DPdx(P~n~)' = DPdx(P~n~) / w# 1455e5c31af7Sopenharmony_ci {empty}:: [eq]#DPdy(P~n~)' = DPdy(P~n~) / h# 1456e5c31af7Sopenharmony_ci 1457e5c31af7Sopenharmony_ciwhere [eq]#w# and [eq]#h# are the size of the fragments in the quad, and 1458e5c31af7Sopenharmony_ci[eq]#DPdx(P~n~)'# and [eq]#DPdy(P~n~)'# are the pixel derivatives. 1459e5c31af7Sopenharmony_ci==== 1460e5c31af7Sopenharmony_ci 1461e5c31af7Sopenharmony_ciThe results for code:OpDPdx and code:OpDPdy may: be calculated as either 1462e5c31af7Sopenharmony_cifine or coarse derivatives, with implementations favouring the most 1463e5c31af7Sopenharmony_ciefficient approach. 1464e5c31af7Sopenharmony_ciImplementations must: choose coarse or fine consistently between the two. 1465e5c31af7Sopenharmony_ci 1466e5c31af7Sopenharmony_ciExecuting code:OpFwidthFine, code:OpFwidthCoarse, or code:OpFwidth is 1467e5c31af7Sopenharmony_ciequivalent to executing the corresponding code:OpDPdx* and code:OpDPdy* 1468e5c31af7Sopenharmony_ciinstructions, taking the absolute value of the results, and summing them. 1469e5c31af7Sopenharmony_ci 1470e5c31af7Sopenharmony_ciExecuting an code:OpImage*Sample*ImplicitLod instruction is equivalent to 1471e5c31af7Sopenharmony_ciexecuting code:OpDPdx(code:Coordinate) and code:OpDPdy(code:Coordinate), and 1472e5c31af7Sopenharmony_cipassing the results as the code:Grad operands code:dx and code:dy. 1473e5c31af7Sopenharmony_ci 1474e5c31af7Sopenharmony_ci[NOTE] 1475e5c31af7Sopenharmony_ci.Note 1476e5c31af7Sopenharmony_ci==== 1477e5c31af7Sopenharmony_ciIt is expected that using the code:ImplicitLod variants of sampling 1478e5c31af7Sopenharmony_cifunctions will be substantially more efficient than using the 1479e5c31af7Sopenharmony_cicode:ExplicitLod variants with explicitly generated derivatives. 1480e5c31af7Sopenharmony_ci==== 1481e5c31af7Sopenharmony_ci 1482e5c31af7Sopenharmony_ci 1483e5c31af7Sopenharmony_ci[[shaders-helper-invocations]] 1484e5c31af7Sopenharmony_ci== Helper Invocations 1485e5c31af7Sopenharmony_ci 1486e5c31af7Sopenharmony_ciWhen performing <<shaders-derivative-operations, derivative>> 1487e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 1488e5c31af7Sopenharmony_cior <<shaders-quad-operations, quad group>> 1489e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1490e5c31af7Sopenharmony_cioperations in a fragment shader, additional invocations may: be spawned in 1491e5c31af7Sopenharmony_ciorder to ensure correct results. 1492e5c31af7Sopenharmony_ciThese additional invocations are known as _helper invocations_ and can: be 1493e5c31af7Sopenharmony_ciidentified by a non-zero value in the code:HelperInvocation built-in. 1494e5c31af7Sopenharmony_ciStores and atomics performed by helper invocations must: not have any effect 1495e5c31af7Sopenharmony_cion memory, and values returned by atomic instructions in helper invocations 1496e5c31af7Sopenharmony_ciare undefined:. 1497e5c31af7Sopenharmony_ci 1498e5c31af7Sopenharmony_ciFor <<shaders-group-operations, group operations>> other than 1499e5c31af7Sopenharmony_ci<<shaders-derivative-operations, derivative>> 1500e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[] 1501e5c31af7Sopenharmony_ciand <<shaders-quad-operations, quad group>> 1502e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[] 1503e5c31af7Sopenharmony_cioperations, helper invocations may: be treated as inactive even if they 1504e5c31af7Sopenharmony_ciwould be considered otherwise active. 1505e5c31af7Sopenharmony_ci 1506e5c31af7Sopenharmony_ciifdef::VK_EXT_shader_demote_to_helper_invocation[] 1507e5c31af7Sopenharmony_ciHelper invocations may: become permanently inactive if all invocations in a 1508e5c31af7Sopenharmony_ciquad scope instance become helper invocations. 1509e5c31af7Sopenharmony_ciendif::VK_EXT_shader_demote_to_helper_invocation[] 1510e5c31af7Sopenharmony_ci 1511e5c31af7Sopenharmony_ci 1512e5c31af7Sopenharmony_ciifdef::VK_NV_cooperative_matrix[] 1513e5c31af7Sopenharmony_ci== Cooperative Matrices 1514e5c31af7Sopenharmony_ci 1515e5c31af7Sopenharmony_ciA _cooperative matrix_ type is a SPIR-V type where the storage for and 1516e5c31af7Sopenharmony_cicomputations performed on the matrix are spread across the invocations in a 1517e5c31af7Sopenharmony_ciscope instance. 1518e5c31af7Sopenharmony_ciThese types give the implementation freedom in how to optimize matrix 1519e5c31af7Sopenharmony_cimultiplies. 1520e5c31af7Sopenharmony_ci 1521e5c31af7Sopenharmony_ciSPIR-V defines the types and instructions, but does not specify rules about 1522e5c31af7Sopenharmony_ciwhat sizes/combinations are valid, and it is expected that different 1523e5c31af7Sopenharmony_ciimplementations may: support different sizes. 1524e5c31af7Sopenharmony_ci 1525e5c31af7Sopenharmony_ci[open,refpage='vkGetPhysicalDeviceCooperativeMatrixPropertiesNV',desc='Returns properties describing what cooperative matrix types are supported',type='protos'] 1526e5c31af7Sopenharmony_ci-- 1527e5c31af7Sopenharmony_ciTo enumerate the supported cooperative matrix types and operations, call: 1528e5c31af7Sopenharmony_ci 1529e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetPhysicalDeviceCooperativeMatrixPropertiesNV.txt[] 1530e5c31af7Sopenharmony_ci 1531e5c31af7Sopenharmony_ci * pname:physicalDevice is the physical device. 1532e5c31af7Sopenharmony_ci * pname:pPropertyCount is a pointer to an integer related to the number of 1533e5c31af7Sopenharmony_ci cooperative matrix properties available or queried. 1534e5c31af7Sopenharmony_ci * pname:pProperties is either `NULL` or a pointer to an array of 1535e5c31af7Sopenharmony_ci slink:VkCooperativeMatrixPropertiesNV structures. 1536e5c31af7Sopenharmony_ci 1537e5c31af7Sopenharmony_ciIf pname:pProperties is `NULL`, then the number of cooperative matrix 1538e5c31af7Sopenharmony_ciproperties available is returned in pname:pPropertyCount. 1539e5c31af7Sopenharmony_ciOtherwise, pname:pPropertyCount must: point to a variable set by the user to 1540e5c31af7Sopenharmony_cithe number of elements in the pname:pProperties array, and on return the 1541e5c31af7Sopenharmony_civariable is overwritten with the number of structures actually written to 1542e5c31af7Sopenharmony_cipname:pProperties. 1543e5c31af7Sopenharmony_ciIf pname:pPropertyCount is less than the number of cooperative matrix 1544e5c31af7Sopenharmony_ciproperties available, at most pname:pPropertyCount structures will be 1545e5c31af7Sopenharmony_ciwritten, and ename:VK_INCOMPLETE will be returned instead of 1546e5c31af7Sopenharmony_ciename:VK_SUCCESS, to indicate that not all the available cooperative matrix 1547e5c31af7Sopenharmony_ciproperties were returned. 1548e5c31af7Sopenharmony_ci 1549e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkGetPhysicalDeviceCooperativeMatrixPropertiesNV.txt[] 1550e5c31af7Sopenharmony_ci-- 1551e5c31af7Sopenharmony_ci 1552e5c31af7Sopenharmony_ci[open,refpage='VkCooperativeMatrixPropertiesNV',desc='Structure specifying cooperative matrix properties',type='structs'] 1553e5c31af7Sopenharmony_ci-- 1554e5c31af7Sopenharmony_ciEach sname:VkCooperativeMatrixPropertiesNV structure describes a single 1555e5c31af7Sopenharmony_cisupported combination of types for a matrix multiply/add operation 1556e5c31af7Sopenharmony_ci(code:OpCooperativeMatrixMulAddNV). 1557e5c31af7Sopenharmony_ciThe multiply can: be described in terms of the following variables and types 1558e5c31af7Sopenharmony_ci(in SPIR-V pseudocode): 1559e5c31af7Sopenharmony_ci 1560e5c31af7Sopenharmony_ci[source,c] 1561e5c31af7Sopenharmony_ci~~~~ 1562e5c31af7Sopenharmony_ci %A is of type OpTypeCooperativeMatrixNV %AType %scope %MSize %KSize 1563e5c31af7Sopenharmony_ci %B is of type OpTypeCooperativeMatrixNV %BType %scope %KSize %NSize 1564e5c31af7Sopenharmony_ci %C is of type OpTypeCooperativeMatrixNV %CType %scope %MSize %NSize 1565e5c31af7Sopenharmony_ci %D is of type OpTypeCooperativeMatrixNV %DType %scope %MSize %NSize 1566e5c31af7Sopenharmony_ci 1567e5c31af7Sopenharmony_ci %D = %A * %B + %C // using OpCooperativeMatrixMulAddNV 1568e5c31af7Sopenharmony_ci~~~~ 1569e5c31af7Sopenharmony_ci 1570e5c31af7Sopenharmony_ciA matrix multiply with these dimensions is known as an _MxNxK_ matrix 1571e5c31af7Sopenharmony_cimultiply. 1572e5c31af7Sopenharmony_ci 1573e5c31af7Sopenharmony_ciThe sname:VkCooperativeMatrixPropertiesNV structure is defined as: 1574e5c31af7Sopenharmony_ci 1575e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkCooperativeMatrixPropertiesNV.txt[] 1576e5c31af7Sopenharmony_ci 1577e5c31af7Sopenharmony_ci * pname:sType is the type of this structure. 1578e5c31af7Sopenharmony_ci * pname:pNext is `NULL` or a pointer to a structure extending this 1579e5c31af7Sopenharmony_ci structure. 1580e5c31af7Sopenharmony_ci * pname:MSize is the number of rows in matrices A, C, and D. 1581e5c31af7Sopenharmony_ci * pname:KSize is the number of columns in matrix A and rows in matrix B. 1582e5c31af7Sopenharmony_ci * pname:NSize is the number of columns in matrices B, C, D. 1583e5c31af7Sopenharmony_ci * pname:AType is the component type of matrix A, of type 1584e5c31af7Sopenharmony_ci elink:VkComponentTypeNV. 1585e5c31af7Sopenharmony_ci * pname:BType is the component type of matrix B, of type 1586e5c31af7Sopenharmony_ci elink:VkComponentTypeNV. 1587e5c31af7Sopenharmony_ci * pname:CType is the component type of matrix C, of type 1588e5c31af7Sopenharmony_ci elink:VkComponentTypeNV. 1589e5c31af7Sopenharmony_ci * pname:DType is the component type of matrix D, of type 1590e5c31af7Sopenharmony_ci elink:VkComponentTypeNV. 1591e5c31af7Sopenharmony_ci * pname:scope is the scope of all the matrix types, of type 1592e5c31af7Sopenharmony_ci elink:VkScopeNV. 1593e5c31af7Sopenharmony_ci 1594e5c31af7Sopenharmony_ciIf some types are preferred over other types (e.g. for performance), they 1595e5c31af7Sopenharmony_cishould: appear earlier in the list enumerated by 1596e5c31af7Sopenharmony_ciflink:vkGetPhysicalDeviceCooperativeMatrixPropertiesNV. 1597e5c31af7Sopenharmony_ci 1598e5c31af7Sopenharmony_ciAt least one entry in the list must: have power of two values for all of 1599e5c31af7Sopenharmony_cipname:MSize, pname:KSize, and pname:NSize. 1600e5c31af7Sopenharmony_ci 1601e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkCooperativeMatrixPropertiesNV.txt[] 1602e5c31af7Sopenharmony_ci-- 1603e5c31af7Sopenharmony_ci 1604e5c31af7Sopenharmony_ci[open,refpage='VkScopeNV',desc='Specify SPIR-V scope',type='enums'] 1605e5c31af7Sopenharmony_ci-- 1606e5c31af7Sopenharmony_ciPossible values for elink:VkScopeNV include: 1607e5c31af7Sopenharmony_ci 1608e5c31af7Sopenharmony_ciinclude::{generated}/api/enums/VkScopeNV.txt[] 1609e5c31af7Sopenharmony_ci 1610e5c31af7Sopenharmony_ci * ename:VK_SCOPE_DEVICE_NV corresponds to SPIR-V code:Device scope. 1611e5c31af7Sopenharmony_ci * ename:VK_SCOPE_WORKGROUP_NV corresponds to SPIR-V code:Workgroup scope. 1612e5c31af7Sopenharmony_ci * ename:VK_SCOPE_SUBGROUP_NV corresponds to SPIR-V code:Subgroup scope. 1613e5c31af7Sopenharmony_ci * ename:VK_SCOPE_QUEUE_FAMILY_NV corresponds to SPIR-V code:QueueFamily 1614e5c31af7Sopenharmony_ci scope. 1615e5c31af7Sopenharmony_ci 1616e5c31af7Sopenharmony_ciAll enum values match the corresponding SPIR-V value. 1617e5c31af7Sopenharmony_ci-- 1618e5c31af7Sopenharmony_ci 1619e5c31af7Sopenharmony_ci[open,refpage='VkComponentTypeNV',desc='Specify SPIR-V cooperative matrix component type',type='enums'] 1620e5c31af7Sopenharmony_ci-- 1621e5c31af7Sopenharmony_ciPossible values for elink:VkComponentTypeNV include: 1622e5c31af7Sopenharmony_ci 1623e5c31af7Sopenharmony_ciinclude::{generated}/api/enums/VkComponentTypeNV.txt[] 1624e5c31af7Sopenharmony_ci 1625e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_FLOAT16_NV corresponds to SPIR-V 1626e5c31af7Sopenharmony_ci code:OpTypeFloat 16. 1627e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_FLOAT32_NV corresponds to SPIR-V 1628e5c31af7Sopenharmony_ci code:OpTypeFloat 32. 1629e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_FLOAT64_NV corresponds to SPIR-V 1630e5c31af7Sopenharmony_ci code:OpTypeFloat 64. 1631e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_SINT8_NV corresponds to SPIR-V code:OpTypeInt 8 1. 1632e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_SINT16_NV corresponds to SPIR-V code:OpTypeInt 1633e5c31af7Sopenharmony_ci 16 1. 1634e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_SINT32_NV corresponds to SPIR-V code:OpTypeInt 1635e5c31af7Sopenharmony_ci 32 1. 1636e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_SINT64_NV corresponds to SPIR-V code:OpTypeInt 1637e5c31af7Sopenharmony_ci 64 1. 1638e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_UINT8_NV corresponds to SPIR-V code:OpTypeInt 8 0. 1639e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_UINT16_NV corresponds to SPIR-V code:OpTypeInt 1640e5c31af7Sopenharmony_ci 16 0. 1641e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_UINT32_NV corresponds to SPIR-V code:OpTypeInt 1642e5c31af7Sopenharmony_ci 32 0. 1643e5c31af7Sopenharmony_ci * ename:VK_COMPONENT_TYPE_UINT64_NV corresponds to SPIR-V code:OpTypeInt 1644e5c31af7Sopenharmony_ci 64 0. 1645e5c31af7Sopenharmony_ci-- 1646e5c31af7Sopenharmony_ciendif::VK_NV_cooperative_matrix[] 1647e5c31af7Sopenharmony_ci 1648e5c31af7Sopenharmony_ci 1649e5c31af7Sopenharmony_ciifdef::VK_EXT_validation_cache[] 1650e5c31af7Sopenharmony_ci[[shaders-validation-cache]] 1651e5c31af7Sopenharmony_ci== Validation Cache 1652e5c31af7Sopenharmony_ci 1653e5c31af7Sopenharmony_ci[open,refpage='VkValidationCacheEXT',desc='Opaque handle to a validation cache object',type='handles'] 1654e5c31af7Sopenharmony_ci-- 1655e5c31af7Sopenharmony_ciValidation cache objects allow the result of internal validation to be 1656e5c31af7Sopenharmony_cireused, both within a single application run and between multiple runs. 1657e5c31af7Sopenharmony_ciReuse within a single run is achieved by passing the same validation cache 1658e5c31af7Sopenharmony_ciobject when creating supported Vulkan objects. 1659e5c31af7Sopenharmony_ciReuse across runs of an application is achieved by retrieving validation 1660e5c31af7Sopenharmony_cicache contents in one run of an application, saving the contents, and using 1661e5c31af7Sopenharmony_cithem to preinitialize a validation cache on a subsequent run. 1662e5c31af7Sopenharmony_ciThe contents of the validation cache objects are managed by the validation 1663e5c31af7Sopenharmony_cilayers. 1664e5c31af7Sopenharmony_ciApplications can: manage the host memory consumed by a validation cache 1665e5c31af7Sopenharmony_ciobject and control the amount of data retrieved from a validation cache 1666e5c31af7Sopenharmony_ciobject. 1667e5c31af7Sopenharmony_ci 1668e5c31af7Sopenharmony_ciValidation cache objects are represented by sname:VkValidationCacheEXT 1669e5c31af7Sopenharmony_cihandles: 1670e5c31af7Sopenharmony_ci 1671e5c31af7Sopenharmony_ciinclude::{generated}/api/handles/VkValidationCacheEXT.txt[] 1672e5c31af7Sopenharmony_ci-- 1673e5c31af7Sopenharmony_ci 1674e5c31af7Sopenharmony_ci[open,refpage='vkCreateValidationCacheEXT',desc='Creates a new validation cache',type='protos'] 1675e5c31af7Sopenharmony_ci-- 1676e5c31af7Sopenharmony_ciTo create validation cache objects, call: 1677e5c31af7Sopenharmony_ci 1678e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkCreateValidationCacheEXT.txt[] 1679e5c31af7Sopenharmony_ci 1680e5c31af7Sopenharmony_ci * pname:device is the logical device that creates the validation cache 1681e5c31af7Sopenharmony_ci object. 1682e5c31af7Sopenharmony_ci * pname:pCreateInfo is a pointer to a slink:VkValidationCacheCreateInfoEXT 1683e5c31af7Sopenharmony_ci structure containing the initial parameters for the validation cache 1684e5c31af7Sopenharmony_ci object. 1685e5c31af7Sopenharmony_ci * pname:pAllocator controls host memory allocation as described in the 1686e5c31af7Sopenharmony_ci <<memory-allocation, Memory Allocation>> chapter. 1687e5c31af7Sopenharmony_ci * pname:pValidationCache is a pointer to a slink:VkValidationCacheEXT 1688e5c31af7Sopenharmony_ci handle in which the resulting validation cache object is returned. 1689e5c31af7Sopenharmony_ci 1690e5c31af7Sopenharmony_ci[NOTE] 1691e5c31af7Sopenharmony_ci.Note 1692e5c31af7Sopenharmony_ci==== 1693e5c31af7Sopenharmony_ciApplications can: track and manage the total host memory size of a 1694e5c31af7Sopenharmony_civalidation cache object using the pname:pAllocator. 1695e5c31af7Sopenharmony_ciApplications can: limit the amount of data retrieved from a validation cache 1696e5c31af7Sopenharmony_ciobject in fname:vkGetValidationCacheDataEXT. 1697e5c31af7Sopenharmony_ciImplementations should: not internally limit the total number of entries 1698e5c31af7Sopenharmony_ciadded to a validation cache object or the total host memory consumed. 1699e5c31af7Sopenharmony_ci==== 1700e5c31af7Sopenharmony_ci 1701e5c31af7Sopenharmony_ciOnce created, a validation cache can: be passed to the 1702e5c31af7Sopenharmony_cifname:vkCreateShaderModule command by adding this object to the 1703e5c31af7Sopenharmony_cislink:VkShaderModuleCreateInfo structure's pname:pNext chain. 1704e5c31af7Sopenharmony_ciIf a slink:VkShaderModuleValidationCacheCreateInfoEXT object is included in 1705e5c31af7Sopenharmony_cithe slink:VkShaderModuleCreateInfo::pname:pNext chain, and its 1706e5c31af7Sopenharmony_cipname:validationCache field is not dlink:VK_NULL_HANDLE, the implementation 1707e5c31af7Sopenharmony_ciwill query it for possible reuse opportunities and update it with new 1708e5c31af7Sopenharmony_cicontent. 1709e5c31af7Sopenharmony_ciThe use of the validation cache object in these commands is internally 1710e5c31af7Sopenharmony_cisynchronized, and the same validation cache object can: be used in multiple 1711e5c31af7Sopenharmony_cithreads simultaneously. 1712e5c31af7Sopenharmony_ci 1713e5c31af7Sopenharmony_ci[NOTE] 1714e5c31af7Sopenharmony_ci.Note 1715e5c31af7Sopenharmony_ci==== 1716e5c31af7Sopenharmony_ciImplementations should: make every effort to limit any critical sections to 1717e5c31af7Sopenharmony_cithe actual accesses to the cache, which is expected to be significantly 1718e5c31af7Sopenharmony_cishorter than the duration of the fname:vkCreateShaderModule command. 1719e5c31af7Sopenharmony_ci==== 1720e5c31af7Sopenharmony_ci 1721e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkCreateValidationCacheEXT.txt[] 1722e5c31af7Sopenharmony_ci-- 1723e5c31af7Sopenharmony_ci 1724e5c31af7Sopenharmony_ci[open,refpage='VkValidationCacheCreateInfoEXT',desc='Structure specifying parameters of a newly created validation cache',type='structs'] 1725e5c31af7Sopenharmony_ci-- 1726e5c31af7Sopenharmony_ciThe sname:VkValidationCacheCreateInfoEXT structure is defined as: 1727e5c31af7Sopenharmony_ci 1728e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkValidationCacheCreateInfoEXT.txt[] 1729e5c31af7Sopenharmony_ci 1730e5c31af7Sopenharmony_ci * pname:sType is the type of this structure. 1731e5c31af7Sopenharmony_ci * pname:pNext is `NULL` or a pointer to a structure extending this 1732e5c31af7Sopenharmony_ci structure. 1733e5c31af7Sopenharmony_ci * pname:flags is reserved for future use. 1734e5c31af7Sopenharmony_ci * pname:initialDataSize is the number of bytes in pname:pInitialData. 1735e5c31af7Sopenharmony_ci If pname:initialDataSize is zero, the validation cache will initially be 1736e5c31af7Sopenharmony_ci empty. 1737e5c31af7Sopenharmony_ci * pname:pInitialData is a pointer to previously retrieved validation cache 1738e5c31af7Sopenharmony_ci data. 1739e5c31af7Sopenharmony_ci If the validation cache data is incompatible (as defined below) with the 1740e5c31af7Sopenharmony_ci device, the validation cache will be initially empty. 1741e5c31af7Sopenharmony_ci If pname:initialDataSize is zero, pname:pInitialData is ignored. 1742e5c31af7Sopenharmony_ci 1743e5c31af7Sopenharmony_ci.Valid Usage 1744e5c31af7Sopenharmony_ci**** 1745e5c31af7Sopenharmony_ci * [[VUID-VkValidationCacheCreateInfoEXT-initialDataSize-01534]] 1746e5c31af7Sopenharmony_ci If pname:initialDataSize is not `0`, it must: be equal to the size of 1747e5c31af7Sopenharmony_ci pname:pInitialData, as returned by fname:vkGetValidationCacheDataEXT 1748e5c31af7Sopenharmony_ci when pname:pInitialData was originally retrieved 1749e5c31af7Sopenharmony_ci * [[VUID-VkValidationCacheCreateInfoEXT-initialDataSize-01535]] 1750e5c31af7Sopenharmony_ci If pname:initialDataSize is not `0`, pname:pInitialData must: have been 1751e5c31af7Sopenharmony_ci retrieved from a previous call to fname:vkGetValidationCacheDataEXT 1752e5c31af7Sopenharmony_ci**** 1753e5c31af7Sopenharmony_ci 1754e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkValidationCacheCreateInfoEXT.txt[] 1755e5c31af7Sopenharmony_ci-- 1756e5c31af7Sopenharmony_ci 1757e5c31af7Sopenharmony_ci[open,refpage='VkValidationCacheCreateFlagsEXT',desc='Reserved for future use',type='flags'] 1758e5c31af7Sopenharmony_ci-- 1759e5c31af7Sopenharmony_ciinclude::{generated}/api/flags/VkValidationCacheCreateFlagsEXT.txt[] 1760e5c31af7Sopenharmony_ci 1761e5c31af7Sopenharmony_citname:VkValidationCacheCreateFlagsEXT is a bitmask type for setting a mask, 1762e5c31af7Sopenharmony_cibut is currently reserved for future use. 1763e5c31af7Sopenharmony_ci-- 1764e5c31af7Sopenharmony_ci 1765e5c31af7Sopenharmony_ci[open,refpage='vkMergeValidationCachesEXT',desc='Combine the data stores of validation caches',type='protos'] 1766e5c31af7Sopenharmony_ci-- 1767e5c31af7Sopenharmony_ciValidation cache objects can: be merged using the command: 1768e5c31af7Sopenharmony_ci 1769e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkMergeValidationCachesEXT.txt[] 1770e5c31af7Sopenharmony_ci 1771e5c31af7Sopenharmony_ci * pname:device is the logical device that owns the validation cache 1772e5c31af7Sopenharmony_ci objects. 1773e5c31af7Sopenharmony_ci * pname:dstCache is the handle of the validation cache to merge results 1774e5c31af7Sopenharmony_ci into. 1775e5c31af7Sopenharmony_ci * pname:srcCacheCount is the length of the pname:pSrcCaches array. 1776e5c31af7Sopenharmony_ci * pname:pSrcCaches is a pointer to an array of validation cache handles, 1777e5c31af7Sopenharmony_ci which will be merged into pname:dstCache. 1778e5c31af7Sopenharmony_ci The previous contents of pname:dstCache are included after the merge. 1779e5c31af7Sopenharmony_ci 1780e5c31af7Sopenharmony_ci[NOTE] 1781e5c31af7Sopenharmony_ci.Note 1782e5c31af7Sopenharmony_ci==== 1783e5c31af7Sopenharmony_ciThe details of the merge operation are implementation-dependent, but 1784e5c31af7Sopenharmony_ciimplementations should: merge the contents of the specified validation 1785e5c31af7Sopenharmony_cicaches and prune duplicate entries. 1786e5c31af7Sopenharmony_ci==== 1787e5c31af7Sopenharmony_ci 1788e5c31af7Sopenharmony_ci.Valid Usage 1789e5c31af7Sopenharmony_ci**** 1790e5c31af7Sopenharmony_ci * [[VUID-vkMergeValidationCachesEXT-dstCache-01536]] 1791e5c31af7Sopenharmony_ci pname:dstCache must: not appear in the list of source caches 1792e5c31af7Sopenharmony_ci**** 1793e5c31af7Sopenharmony_ci 1794e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkMergeValidationCachesEXT.txt[] 1795e5c31af7Sopenharmony_ci-- 1796e5c31af7Sopenharmony_ci 1797e5c31af7Sopenharmony_ci[open,refpage='vkGetValidationCacheDataEXT',desc='Get the data store from a validation cache',type='protos'] 1798e5c31af7Sopenharmony_ci-- 1799e5c31af7Sopenharmony_ciData can: be retrieved from a validation cache object using the command: 1800e5c31af7Sopenharmony_ci 1801e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetValidationCacheDataEXT.txt[] 1802e5c31af7Sopenharmony_ci 1803e5c31af7Sopenharmony_ci * pname:device is the logical device that owns the validation cache. 1804e5c31af7Sopenharmony_ci * pname:validationCache is the validation cache to retrieve data from. 1805e5c31af7Sopenharmony_ci * pname:pDataSize is a pointer to a value related to the amount of data in 1806e5c31af7Sopenharmony_ci the validation cache, as described below. 1807e5c31af7Sopenharmony_ci * pname:pData is either `NULL` or a pointer to a buffer. 1808e5c31af7Sopenharmony_ci 1809e5c31af7Sopenharmony_ciIf pname:pData is `NULL`, then the maximum size of the data that can: be 1810e5c31af7Sopenharmony_ciretrieved from the validation cache, in bytes, is returned in 1811e5c31af7Sopenharmony_cipname:pDataSize. 1812e5c31af7Sopenharmony_ciOtherwise, pname:pDataSize must: point to a variable set by the user to the 1813e5c31af7Sopenharmony_cisize of the buffer, in bytes, pointed to by pname:pData, and on return the 1814e5c31af7Sopenharmony_civariable is overwritten with the amount of data actually written to 1815e5c31af7Sopenharmony_cipname:pData. 1816e5c31af7Sopenharmony_ciIf pname:pDataSize is less than the maximum size that can: be retrieved by 1817e5c31af7Sopenharmony_cithe validation cache, at most pname:pDataSize bytes will be written to 1818e5c31af7Sopenharmony_cipname:pData, and fname:vkGetValidationCacheDataEXT will return 1819e5c31af7Sopenharmony_ciename:VK_INCOMPLETE instead of ename:VK_SUCCESS, to indicate that not all of 1820e5c31af7Sopenharmony_cithe validation cache was returned. 1821e5c31af7Sopenharmony_ci 1822e5c31af7Sopenharmony_ciAny data written to pname:pData is valid and can: be provided as the 1823e5c31af7Sopenharmony_cipname:pInitialData member of the slink:VkValidationCacheCreateInfoEXT 1824e5c31af7Sopenharmony_cistructure passed to fname:vkCreateValidationCacheEXT. 1825e5c31af7Sopenharmony_ci 1826e5c31af7Sopenharmony_ciTwo calls to fname:vkGetValidationCacheDataEXT with the same parameters 1827e5c31af7Sopenharmony_cimust: retrieve the same data unless a command that modifies the contents of 1828e5c31af7Sopenharmony_cithe cache is called between them. 1829e5c31af7Sopenharmony_ci 1830e5c31af7Sopenharmony_ci[[validation-cache-header]] 1831e5c31af7Sopenharmony_ciApplications can: store the data retrieved from the validation cache, and 1832e5c31af7Sopenharmony_ciuse these data, possibly in a future run of the application, to populate new 1833e5c31af7Sopenharmony_civalidation cache objects. 1834e5c31af7Sopenharmony_ciThe results of validation, however, may: depend on the vendor ID, device ID, 1835e5c31af7Sopenharmony_cidriver version, and other details of the device. 1836e5c31af7Sopenharmony_ciTo enable applications to detect when previously retrieved data is 1837e5c31af7Sopenharmony_ciincompatible with the device, the initial bytes written to pname:pData must: 1838e5c31af7Sopenharmony_cibe a header consisting of the following members: 1839e5c31af7Sopenharmony_ci 1840e5c31af7Sopenharmony_ci.Layout for validation cache header version ename:VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT 1841e5c31af7Sopenharmony_ci[width="85%",cols="8%,21%,71%",options="header"] 1842e5c31af7Sopenharmony_ci|==== 1843e5c31af7Sopenharmony_ci| Offset | Size | Meaning 1844e5c31af7Sopenharmony_ci| 0 | 4 | length in bytes of the entire validation cache header 1845e5c31af7Sopenharmony_ci written as a stream of bytes, with the least 1846e5c31af7Sopenharmony_ci significant byte first 1847e5c31af7Sopenharmony_ci| 4 | 4 | a elink:VkValidationCacheHeaderVersionEXT value 1848e5c31af7Sopenharmony_ci written as a stream of bytes, with the least 1849e5c31af7Sopenharmony_ci significant byte first 1850e5c31af7Sopenharmony_ci| 8 | ename:VK_UUID_SIZE | a layer commit ID expressed as a UUID, which uniquely 1851e5c31af7Sopenharmony_ci identifies the version of the validation layers used 1852e5c31af7Sopenharmony_ci to generate these validation results 1853e5c31af7Sopenharmony_ci|==== 1854e5c31af7Sopenharmony_ci 1855e5c31af7Sopenharmony_ciThe first four bytes encode the length of the entire validation cache 1856e5c31af7Sopenharmony_ciheader, in bytes. 1857e5c31af7Sopenharmony_ciThis value includes all fields in the header including the validation cache 1858e5c31af7Sopenharmony_civersion field and the size of the length field. 1859e5c31af7Sopenharmony_ci 1860e5c31af7Sopenharmony_ciThe next four bytes encode the validation cache version, as described for 1861e5c31af7Sopenharmony_cielink:VkValidationCacheHeaderVersionEXT. 1862e5c31af7Sopenharmony_ciA consumer of the validation cache should: use the cache version to 1863e5c31af7Sopenharmony_ciinterpret the remainder of the cache header. 1864e5c31af7Sopenharmony_ci 1865e5c31af7Sopenharmony_ciIf pname:pDataSize is less than what is necessary to store this header, 1866e5c31af7Sopenharmony_cinothing will be written to pname:pData and zero will be written to 1867e5c31af7Sopenharmony_cipname:pDataSize. 1868e5c31af7Sopenharmony_ci 1869e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkGetValidationCacheDataEXT.txt[] 1870e5c31af7Sopenharmony_ci-- 1871e5c31af7Sopenharmony_ci 1872e5c31af7Sopenharmony_ci[open,refpage='VkValidationCacheHeaderVersionEXT',desc='Encode validation cache version',type='enums',xrefs='vkCreateValidationCacheEXT vkGetValidationCacheDataEXT'] 1873e5c31af7Sopenharmony_ci-- 1874e5c31af7Sopenharmony_ciPossible values of the second group of four bytes in the header returned by 1875e5c31af7Sopenharmony_ciflink:vkGetValidationCacheDataEXT, encoding the validation cache version, 1876e5c31af7Sopenharmony_ciare: 1877e5c31af7Sopenharmony_ci 1878e5c31af7Sopenharmony_ciinclude::{generated}/api/enums/VkValidationCacheHeaderVersionEXT.txt[] 1879e5c31af7Sopenharmony_ci 1880e5c31af7Sopenharmony_ci * ename:VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT specifies version one 1881e5c31af7Sopenharmony_ci of the validation cache. 1882e5c31af7Sopenharmony_ci-- 1883e5c31af7Sopenharmony_ci 1884e5c31af7Sopenharmony_ci[open,refpage='vkDestroyValidationCacheEXT',desc='Destroy a validation cache object',type='protos'] 1885e5c31af7Sopenharmony_ci-- 1886e5c31af7Sopenharmony_ciTo destroy a validation cache, call: 1887e5c31af7Sopenharmony_ci 1888e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkDestroyValidationCacheEXT.txt[] 1889e5c31af7Sopenharmony_ci 1890e5c31af7Sopenharmony_ci * pname:device is the logical device that destroys the validation cache 1891e5c31af7Sopenharmony_ci object. 1892e5c31af7Sopenharmony_ci * pname:validationCache is the handle of the validation cache to destroy. 1893e5c31af7Sopenharmony_ci * pname:pAllocator controls host memory allocation as described in the 1894e5c31af7Sopenharmony_ci <<memory-allocation, Memory Allocation>> chapter. 1895e5c31af7Sopenharmony_ci 1896e5c31af7Sopenharmony_ci.Valid Usage 1897e5c31af7Sopenharmony_ci**** 1898e5c31af7Sopenharmony_ci * [[VUID-vkDestroyValidationCacheEXT-validationCache-01537]] 1899e5c31af7Sopenharmony_ci If sname:VkAllocationCallbacks were provided when pname:validationCache 1900e5c31af7Sopenharmony_ci was created, a compatible set of callbacks must: be provided here 1901e5c31af7Sopenharmony_ci * [[VUID-vkDestroyValidationCacheEXT-validationCache-01538]] 1902e5c31af7Sopenharmony_ci If no sname:VkAllocationCallbacks were provided when 1903e5c31af7Sopenharmony_ci pname:validationCache was created, pname:pAllocator must: be `NULL` 1904e5c31af7Sopenharmony_ci**** 1905e5c31af7Sopenharmony_ci 1906e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkDestroyValidationCacheEXT.txt[] 1907e5c31af7Sopenharmony_ci-- 1908e5c31af7Sopenharmony_ciendif::VK_EXT_validation_cache[] 1909