1e5c31af7Sopenharmony_ci// Copyright 2015-2021 The Khronos Group, Inc. 2e5c31af7Sopenharmony_ci// 3e5c31af7Sopenharmony_ci// SPDX-License-Identifier: CC-BY-4.0 4e5c31af7Sopenharmony_ci 5e5c31af7Sopenharmony_ci[[geometry]] 6e5c31af7Sopenharmony_ci= Geometry Shading 7e5c31af7Sopenharmony_ci 8e5c31af7Sopenharmony_ciThe geometry shader operates on a group of vertices and their associated 9e5c31af7Sopenharmony_cidata assembled from a single input primitive, and emits zero or more output 10e5c31af7Sopenharmony_ciprimitives and the group of vertices and their associated data required for 11e5c31af7Sopenharmony_cieach output primitive. 12e5c31af7Sopenharmony_ciGeometry shading is enabled when a geometry shader is included in the 13e5c31af7Sopenharmony_cipipeline. 14e5c31af7Sopenharmony_ci 15e5c31af7Sopenharmony_ci 16e5c31af7Sopenharmony_ci[[geometry-input]] 17e5c31af7Sopenharmony_ci== Geometry Shader Input Primitives 18e5c31af7Sopenharmony_ci 19e5c31af7Sopenharmony_ciEach geometry shader invocation has access to all vertices in the primitive 20e5c31af7Sopenharmony_ci(and their associated data), which are presented to the shader as an array 21e5c31af7Sopenharmony_ciof inputs. 22e5c31af7Sopenharmony_ci 23e5c31af7Sopenharmony_ciThe input primitive type expected by the geometry shader is specified with 24e5c31af7Sopenharmony_cian code:OpExecutionMode instruction in the geometry shader, and must: match 25e5c31af7Sopenharmony_cithe incoming primitive type specified by either the pipeline's 26e5c31af7Sopenharmony_ci<<drawing-primitive-topologies, primitive topology>> if tessellation is 27e5c31af7Sopenharmony_ciinactive, or the <<tessellation, tessellation mode>> if tessellation is 28e5c31af7Sopenharmony_ciactive, as follows: 29e5c31af7Sopenharmony_ci 30e5c31af7Sopenharmony_ci * An input primitive type of code:InputPoints must: only be used with a 31e5c31af7Sopenharmony_ci pipeline topology of ename:VK_PRIMITIVE_TOPOLOGY_POINT_LIST, or with a 32e5c31af7Sopenharmony_ci tessellation shader specifying code:PointMode. 33e5c31af7Sopenharmony_ci The input arrays always contain one element, as described by the 34e5c31af7Sopenharmony_ci <<drawing-point-lists, point list topology>> or 35e5c31af7Sopenharmony_ci <<tessellation-point-mode, tessellation in point mode>>. 36e5c31af7Sopenharmony_ci * An input primitive type of code:InputLines must: only be used with a 37e5c31af7Sopenharmony_ci pipeline topology of ename:VK_PRIMITIVE_TOPOLOGY_LINE_LIST or 38e5c31af7Sopenharmony_ci ename:VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, or with a tessellation shader 39e5c31af7Sopenharmony_ci specifying code:IsoLines that does not specify code:PointMode. 40e5c31af7Sopenharmony_ci The input arrays always contain two elements, as described by the 41e5c31af7Sopenharmony_ci <<drawing-line-lists, line list topology>> or <<drawing-line-strips, 42e5c31af7Sopenharmony_ci line strip topology>>, or by <<tessellation-isoline-tessellation, 43e5c31af7Sopenharmony_ci isoline tessellation>>. 44e5c31af7Sopenharmony_ci * An input primitive type of code:InputLinesAdjacency must: only be used 45e5c31af7Sopenharmony_ci when tessellation is inactive, with a pipeline topology of 46e5c31af7Sopenharmony_ci ename:VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY or 47e5c31af7Sopenharmony_ci ename:VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY. 48e5c31af7Sopenharmony_ci The input arrays always contain four elements, as described by the 49e5c31af7Sopenharmony_ci <<drawing-line-lists-with-adjacency, line list with adjacency topology>> 50e5c31af7Sopenharmony_ci or <<drawing-line-strips-with-adjacency, line strip with adjacency 51e5c31af7Sopenharmony_ci topology>>. 52e5c31af7Sopenharmony_ci * An input primitive type of code:Triangles must: only be used with a 53e5c31af7Sopenharmony_ci pipeline topology of ename:VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 54e5c31af7Sopenharmony_ci ename:VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, or 55e5c31af7Sopenharmony_ci ename:VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN; or with a tessellation shader 56e5c31af7Sopenharmony_ci specifying code:Quads or code:Triangles that does not specify 57e5c31af7Sopenharmony_ci code:PointMode. 58e5c31af7Sopenharmony_ci The input arrays always contain three elements, as described by the 59e5c31af7Sopenharmony_ci <<drawing-triangle-lists, triangle list topology>>, 60e5c31af7Sopenharmony_ci <<drawing-triangle-strips, triangle strip topology>>, or 61e5c31af7Sopenharmony_ci <<drawing-triangle-fans, triangle fan topology>>, or by 62e5c31af7Sopenharmony_ci <<tessellation-triangle-tessellation, triangle>> or 63e5c31af7Sopenharmony_ci <<tessellation-quad-tessellation, quad tessellation>>. 64e5c31af7Sopenharmony_ci Vertices may: be in a different absolute order than specified by the 65e5c31af7Sopenharmony_ci topology, but must: adhere to the specified winding order. 66e5c31af7Sopenharmony_ci * An input primitive type of code:InputTrianglesAdjacency must: only be 67e5c31af7Sopenharmony_ci used when tessellation is inactive, with a pipeline topology of 68e5c31af7Sopenharmony_ci ename:VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY or 69e5c31af7Sopenharmony_ci ename:VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY. 70e5c31af7Sopenharmony_ci The input arrays always contain six elements, as described by the 71e5c31af7Sopenharmony_ci <<drawing-triangle-lists-with-adjacency, triangle list with adjacency 72e5c31af7Sopenharmony_ci topology>> or <<drawing-triangle-strips-with-adjacency, triangle strip 73e5c31af7Sopenharmony_ci with adjacency topology>>. 74e5c31af7Sopenharmony_ci Vertices may: be in a different absolute order than specified by the 75e5c31af7Sopenharmony_ci topology, but must: adhere to the specified winding order, and the 76e5c31af7Sopenharmony_ci vertices making up the main primitive must: still occur at the first, 77e5c31af7Sopenharmony_ci third, and fifth index. 78e5c31af7Sopenharmony_ci 79e5c31af7Sopenharmony_ci[[geometry-output]] 80e5c31af7Sopenharmony_ci== Geometry Shader Output Primitives 81e5c31af7Sopenharmony_ci 82e5c31af7Sopenharmony_ciA geometry shader generates primitives in one of three output modes: points, 83e5c31af7Sopenharmony_ciline strips, or triangle strips. 84e5c31af7Sopenharmony_ciThe primitive mode is specified in the shader using an code:OpExecutionMode 85e5c31af7Sopenharmony_ciinstruction with the code:OutputPoints, code:OutputLineStrip or 86e5c31af7Sopenharmony_cicode:OutputTriangleStrip modes, respectively. 87e5c31af7Sopenharmony_ciEach geometry shader must: include exactly one output primitive mode. 88e5c31af7Sopenharmony_ci 89e5c31af7Sopenharmony_ciThe vertices output by the geometry shader are assembled into points, lines, 90e5c31af7Sopenharmony_cior triangles based on the output primitive type and the resulting primitives 91e5c31af7Sopenharmony_ciare then further processed as described in <<primsrast>>. 92e5c31af7Sopenharmony_ciIf the number of vertices emitted by the geometry shader is not sufficient 93e5c31af7Sopenharmony_cito produce a single primitive, vertices corresponding to incomplete 94e5c31af7Sopenharmony_ciprimitives are not processed by subsequent pipeline stages. 95e5c31af7Sopenharmony_ciThe number of vertices output by the geometry shader is limited to a maximum 96e5c31af7Sopenharmony_cicount specified in the shader. 97e5c31af7Sopenharmony_ci 98e5c31af7Sopenharmony_ciThe maximum output vertex count is specified in the shader using an 99e5c31af7Sopenharmony_cicode:OpExecutionMode instruction with the mode set to code:OutputVertices 100e5c31af7Sopenharmony_ciand the maximum number of vertices that will be produced by the geometry 101e5c31af7Sopenharmony_cishader specified as a literal. 102e5c31af7Sopenharmony_ciEach geometry shader must: specify a maximum output vertex count. 103e5c31af7Sopenharmony_ci 104e5c31af7Sopenharmony_ci 105e5c31af7Sopenharmony_ci[[geometry-invocations]] 106e5c31af7Sopenharmony_ci== Multiple Invocations of Geometry Shaders 107e5c31af7Sopenharmony_ci 108e5c31af7Sopenharmony_ciGeometry shaders can: be invoked more than one time for each input 109e5c31af7Sopenharmony_ciprimitive. 110e5c31af7Sopenharmony_ciThis is known as _geometry shader instancing_ and is requested by including 111e5c31af7Sopenharmony_cian code:OpExecutionMode instruction with code:mode specified as 112e5c31af7Sopenharmony_cicode:Invocations and the number of invocations specified as an integer 113e5c31af7Sopenharmony_ciliteral. 114e5c31af7Sopenharmony_ci 115e5c31af7Sopenharmony_ciIn this mode, the geometry shader will execute at least [eq]#n# times for 116e5c31af7Sopenharmony_cieach input primitive, where [eq]#n# is the number of invocations specified 117e5c31af7Sopenharmony_ciin the code:OpExecutionMode instruction. 118e5c31af7Sopenharmony_ciThe instance number is available to each invocation as a built-in input 119e5c31af7Sopenharmony_ciusing code:InvocationId. 120e5c31af7Sopenharmony_ci 121e5c31af7Sopenharmony_ci 122e5c31af7Sopenharmony_ci[[geometry-ordering]] 123e5c31af7Sopenharmony_ci== Geometry Shader Primitive Ordering 124e5c31af7Sopenharmony_ci 125e5c31af7Sopenharmony_ciLimited guarantees are provided for the relative ordering of primitives 126e5c31af7Sopenharmony_ciproduced by a geometry shader, as they pertain to <<drawing-primitive-order, 127e5c31af7Sopenharmony_ciprimitive order>>. 128e5c31af7Sopenharmony_ci 129e5c31af7Sopenharmony_ci * For instanced geometry shaders, the output primitives generated from 130e5c31af7Sopenharmony_ci each input primitive are passed to subsequent pipeline stages using the 131e5c31af7Sopenharmony_ci invocation number to order the primitives, from least to greatest. 132e5c31af7Sopenharmony_ci * All output primitives generated from a given input primitive are passed 133e5c31af7Sopenharmony_ci to subsequent pipeline stages before any output primitives generated 134e5c31af7Sopenharmony_ci from subsequent input primitives. 135e5c31af7Sopenharmony_ci 136e5c31af7Sopenharmony_ci 137e5c31af7Sopenharmony_ciifdef::VK_NV_geometry_shader_passthrough[] 138e5c31af7Sopenharmony_ci[[geometry-passthrough]] 139e5c31af7Sopenharmony_ci== Geometry Shader Passthrough 140e5c31af7Sopenharmony_ci 141e5c31af7Sopenharmony_ciA geometry shader that uses the code:PassthroughNV decoration on a variable 142e5c31af7Sopenharmony_ciin its input interface is considered a _passthrough geometry shader_. 143e5c31af7Sopenharmony_ciOutput primitives in a passthrough geometry shader must: have the same 144e5c31af7Sopenharmony_citopology as the input primitive and are not produced by emitting vertices. 145e5c31af7Sopenharmony_ciThe vertices of the output primitive have two different types of attributes, 146e5c31af7Sopenharmony_ciper-vertex and per-primitive. 147e5c31af7Sopenharmony_ciGeometry shader input variables with code:PassthroughNV decoration are 148e5c31af7Sopenharmony_ciconsidered to produce per-vertex outputs, where values for each output 149e5c31af7Sopenharmony_civertex are copied from the corresponding input vertex. 150e5c31af7Sopenharmony_ciAny built-in or user-defined geometry shader outputs are considered 151e5c31af7Sopenharmony_ciper-primitive in a passthrough geometry shader, where a single output value 152e5c31af7Sopenharmony_ciis copied to all output vertices. 153e5c31af7Sopenharmony_ci 154e5c31af7Sopenharmony_ciThe remainder of this section details the usage of the code:PassthroughNV 155e5c31af7Sopenharmony_cidecoration and modifications to the interface matching rules when using 156e5c31af7Sopenharmony_cipassthrough geometry shaders. 157e5c31af7Sopenharmony_ci 158e5c31af7Sopenharmony_ci 159e5c31af7Sopenharmony_ci[[geometry-passthrough-passthrough]] 160e5c31af7Sopenharmony_ci=== code:PassthroughNV Decoration 161e5c31af7Sopenharmony_ci 162e5c31af7Sopenharmony_ciDecorating a geometry shader input variable with the code:PassthroughNV 163e5c31af7Sopenharmony_cidecoration indicates that values of this input are copied through to the 164e5c31af7Sopenharmony_cicorresponding vertex of the output primitive. 165e5c31af7Sopenharmony_ciInput variables and block members which do not have the code:PassthroughNV 166e5c31af7Sopenharmony_cidecoration are consumed by the geometry shader without being passed through 167e5c31af7Sopenharmony_cito subsequent stages. 168e5c31af7Sopenharmony_ci 169e5c31af7Sopenharmony_ciThe code:PassthroughNV decoration must: only be used within a geometry 170e5c31af7Sopenharmony_cishader. 171e5c31af7Sopenharmony_ci 172e5c31af7Sopenharmony_ciAny variable decorated with code:PassthroughNV must: be declared using the 173e5c31af7Sopenharmony_cicode:Input storage class. 174e5c31af7Sopenharmony_ci 175e5c31af7Sopenharmony_ciThe code:PassthroughNV decoration must: not be used with any of: 176e5c31af7Sopenharmony_ci 177e5c31af7Sopenharmony_ci * an input primitive type other than code:InputPoints, code:InputLines, or 178e5c31af7Sopenharmony_ci code:Triangles, as specified by the mode for code:OpExecutionMode. 179e5c31af7Sopenharmony_ci * an invocation count other than one, as specified by the code:Invocations 180e5c31af7Sopenharmony_ci mode for code:OpExecutionMode. 181e5c31af7Sopenharmony_ci * an code:OpEntryPoint which statically uses the code:OpEmitVertex or 182e5c31af7Sopenharmony_ci code:OpEndPrimitive instructions. 183e5c31af7Sopenharmony_ci * a variable decorated with the code:InvocationId built-in decoration. 184e5c31af7Sopenharmony_ci * a variable decorated with the code:PrimitiveId built-in decoration that 185e5c31af7Sopenharmony_ci is declared using the code:Input storage class. 186e5c31af7Sopenharmony_ci 187e5c31af7Sopenharmony_ci 188e5c31af7Sopenharmony_ci[[geometry-passthrough-interface]] 189e5c31af7Sopenharmony_ci=== Passthrough Interface Matching 190e5c31af7Sopenharmony_ci 191e5c31af7Sopenharmony_ciWhen a passthrough geometry shader is in use, the 192e5c31af7Sopenharmony_ci<<interfaces-iointerfaces-matching,Interface Matching>> rules involving the 193e5c31af7Sopenharmony_cigeometry shader input and output interfaces operate as described in this 194e5c31af7Sopenharmony_cisection. 195e5c31af7Sopenharmony_ci 196e5c31af7Sopenharmony_ciFor the purposes of matching passthrough geometry shader inputs with outputs 197e5c31af7Sopenharmony_ciof the previous pipeline stages, the code:PassthroughNV decoration is 198e5c31af7Sopenharmony_ciignored. 199e5c31af7Sopenharmony_ci 200e5c31af7Sopenharmony_ciFor the purposes of matching the outputs of the geometry shader with 201e5c31af7Sopenharmony_cisubsequent pipeline stages, each input variable with the code:PassthroughNV 202e5c31af7Sopenharmony_cidecoration is considered to add an equivalent output variable with the same 203e5c31af7Sopenharmony_citype, decoration (other than code:PassthroughNV), number, and declaration 204e5c31af7Sopenharmony_ciorder on the output interface. 205e5c31af7Sopenharmony_ciThe output variable declaration corresponding to an input variable decorated 206e5c31af7Sopenharmony_ciwith code:PassthroughNV will be identical to the input declaration, except 207e5c31af7Sopenharmony_cithat the outermost array dimension of such variables is removed. 208e5c31af7Sopenharmony_ciThe output block declaration corresponding to an input block decorated with 209e5c31af7Sopenharmony_cicode:PassthroughNV or having members decorated with code:PassthroughNV will 210e5c31af7Sopenharmony_cibe identical to the input declaration, except that the outermost array 211e5c31af7Sopenharmony_cidimension of such declaration is removed. 212e5c31af7Sopenharmony_ci 213e5c31af7Sopenharmony_ciIf an input block is decorated with code:PassthroughNV, the equivalent 214e5c31af7Sopenharmony_cioutput block contains all the members of the input block. 215e5c31af7Sopenharmony_ciOtherwise, the equivalent output block contains only those input block 216e5c31af7Sopenharmony_cimembers decorated with code:PassthroughNV. 217e5c31af7Sopenharmony_ciAll members of the corresponding output block are assigned code:Location and 218e5c31af7Sopenharmony_cicode:Component decorations identical to those assigned to the corresponding 219e5c31af7Sopenharmony_ciinput block members. 220e5c31af7Sopenharmony_ci 221e5c31af7Sopenharmony_ciOutput variables and blocks generated from inputs decorated with 222e5c31af7Sopenharmony_cicode:PassthroughNV will only exist for the purposes of interface matching; 223e5c31af7Sopenharmony_cithese declarations are not available to geometry shader code or listed in 224e5c31af7Sopenharmony_cithe module interface. 225e5c31af7Sopenharmony_ci 226e5c31af7Sopenharmony_ciFor the purposes of component counting, passthrough geometry shaders count 227e5c31af7Sopenharmony_ciall statically used input variable components declared with the 228e5c31af7Sopenharmony_cicode:PassthroughNV decoration as output components as well, since their 229e5c31af7Sopenharmony_civalues will be copied to the output primitive produced by the geometry 230e5c31af7Sopenharmony_cishader. 231e5c31af7Sopenharmony_ci 232e5c31af7Sopenharmony_ciendif::VK_NV_geometry_shader_passthrough[] 233e5c31af7Sopenharmony_ci 234e5c31af7Sopenharmony_ci 235