网格着色
任务着色器输出
任务着色器可以发出要生成的零个或多个网格工作组。使用 TaskNV
Execution
Model
的着色器可以使用内置变量 TaskCountNV
来执行此操作。此值必须小于或等于 VkPhysicalDeviceMeshShaderPropertiesNV
::maxTaskOutputCount
。使用 TaskEXT
Execution
Model
的着色器可以使用 OpEmitMeshTasksEXT
指令来执行此操作。传递给此指令的 groupCountX
、groupCountY
和 groupCountZ
参数必须小于或等于 VkPhysicalDeviceMeshShaderPropertiesEXT
::maxMeshWorkGroupCount
中的相应维度。这些参数的乘积必须小于或等于 VkPhysicalDeviceMeshShaderPropertiesEXT
::maxMeshWorkGroupTotalCount
。
任务着色器还可以将用户定义的数据传递给它创建的所有网格着色器调用。使用 TaskNV
Execution
Model
的着色器可以通过写入用 PerTaskNV
修饰的输出变量来执行此操作。它们在网格着色器中可用作输入。使用 TaskEXT
Execution
Model
的着色器可以通过写入带有传递给 OpEmitMeshTasksEXT
指令的 TaskPayloadWorkgroupEXT
存储类的有效负载变量来执行此操作。
网格着色器输入
网格着色器唯一可用的输入是标识特定工作组和调用的变量,如果适用,则是由任务着色器生成网格着色器工作组的作为 PerTaskNV
写入的任何输出或传递给 OpEmitMeshTasksEXT
指令的有效负载变量。网格着色器也可以在没有任务着色器的情况下运行。
网格着色器输出
网格着色器以三种输出模式之一生成图元:点、线或三角形。对于使用 MeshNV
Execution
Model
的着色器,图元模式在着色器中使用带有 OutputPoints
、OutputLinesNV
或 OutputTrianglesNV
模式的 OpExecutionMode
指令来指定。对于使用 MeshEXT
Execution
Model
的着色器,图元模式在着色器中使用带有 OutputPoints
、OutputLinesEXT
或 OutputTrianglesEXT
模式的 OpExecutionMode
指令来指定。每个网格着色器必须只包含一个输出图元模式。
对于使用 MeshNV
Execution
Model
的着色器,最大输出顶点数在着色器中使用模式设置为 OutputVertices
的 OpExecutionMode
指令指定为文字,并且必须小于或等于 VkPhysicalDeviceMeshShaderPropertiesNV
::maxMeshOutputVertices
。对于使用 MeshEXT
Execution
Model
的着色器,最大输出顶点数在着色器中使用模式设置为 OutputVertices
的 OpExecutionMode
指令指定为文字,并且必须小于或等于 VkPhysicalDeviceMeshShaderPropertiesEXT
::maxMeshOutputVertices
。
对于使用 MeshNV
Execution
Model
的着色器,最大输出图元数在着色器中使用模式设置为 OutputPrimitivesNV
的 OpExecutionMode
指令指定为文字,并且必须小于或等于 VkPhysicalDeviceMeshShaderPropertiesNV
::maxMeshOutputPrimitives
。对于使用 MeshEXT
Execution
Model
的着色器,最大输出图元数在着色器中使用模式设置为 OutputPrimitivesEXT
的 OpExecutionMode
指令指定为文字,并且必须小于或等于 VkPhysicalDeviceMeshShaderPropertiesEXT
::maxMeshOutputPrimitives
。
对于使用 MeshNV
Execution
Model
的着色器,网格着色器输出的图元数量通过写入内置变量 PrimitiveCountNV
提供,并且必须小于或等于着色器中指定的最大输出图元数量。使用 PrimitiveIndicesNV
修饰的变量是一个输出数组,其中包含顶点输出数组的局部索引值,这些索引值根据输出图元类型组装成图元。对于使用 MeshEXT
Execution
Model
的着色器,网格着色器输出的顶点和图元数量通过调用 OpSetMeshOutputsEXT
指令提供。vertexCount
参数必须小于或等于着色器中指定的最大输出顶点数量。primitiveCount
参数必须小于或等于着色器中指定的最大输出图元数量。
根据输出图元模式,使用适当修饰的变量是顶点输出数组的局部索引值输出数组,这些索引值根据输出图元类型组装成图元。
-
OutputPoints
使用PrimitivePointIndicesEXT
修饰符。 -
OutputLinesEXT
使用PrimitiveLineIndicesEXT
修饰符。 -
OutputTrianglesEXT
使用PrimitiveTriangleIndicesEXT
修饰符。
这些生成的图元将按照光栅化中所述进一步处理。
With the exception of primitive indices, all output built-ins and custom attributes count towards the total storage size occupied by output variables in mesh shaders. This size can be calculated as follows, taking into account the fact that the number of effective scalar attributes is 4 times the number of effective locations used according to the location assignment rules. Let be the number of views, be the number of effective scalar per-vertex attributes not dependent on ViewIndex
, be the number of effective scalar per-vertex attributes dependent on ViewIndex
, be the maximum number of vertices specified by the OutputVertices
Execution
Mode
, be meshOutputPerVertexGranularity
, be the number of effective scalar per-primitive attributes not dependent on ViewIndex
, be the number of effective scalar per-primitive attributes dependent on ViewIndex
, be the maximum number of primitives specified by the OutputPrimitivesEXT
Execution
Mode
and be meshOutputPerPrimitiveGranularity
网格着色器逐视图输出
使用 PositionPerViewNV
、ClipDistancePerViewNV
、CullDistancePerViewNV
、LayerPerViewNV
和 ViewportMaskPerViewNV
内置修饰符修饰的网格着色器输出是具有等效名称的单视图变量(即分别为 Position
、ClipDistance
、CullDistance
、Layer
和 ViewportMaskNV
)的逐视图版本。如果着色器静态地为逐视图数组的任何元素赋值,则必须不能静态地为等效的单视图变量赋值。
每个输出都被认为是数组化的,每个视图都有单独的值。视图编号用于索引这些数组的第一维。
ClipDistancePerViewNV
和 CullDistancePerViewNV
数组的第二维与 ClipDistance
和 CullDistance
数组具有相同的要求。
如果网格着色器输出是逐视图的,则相应的片段着色器输入取自逐视图输出数组中与片段着色器当前正在处理的视图相对应的元素。
这些逐视图输出仅在使用 MeshNV
Execution
Model
的着色器中可用。它们在使用 MeshEXT
Execution
Model
的着色器中不可用。
网格着色器图元排序
对于网格着色器生成的图元的相对顺序,以及它们与图元顺序的关系,提供以下保证。
-
当使用任务着色器时,从较低任务生成的网格工作组的顺序将优先于来自后续任务的那些工作组。
-
从给定网格工作组生成的所有输出图元都会传递到后续的管线阶段,然后再传递来自后续输入工作组的任何输出图元。
-
网格工作组内的所有输出图元将按照内置图元索引缓冲区的顺序(从低地址到高地址)生成。