Skip to content

Commit afbf5b2

Browse files
Add Primitive Topology chapter (#318)
* Add Primitive Topology chapter * Apply Artems feedback * Apply Sascha rasterizerDiscardEnable feedback
1 parent c89e55c commit afbf5b2

File tree

13 files changed

+171
-0
lines changed

13 files changed

+171
-0
lines changed

README.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ The Vulkan Guide can be built as a single page using `asciidoctor guide.adoc`
178178

179179
* `VK_EXT_depth_range_unrestricted`, `VK_EXT_depth_clip_enable`, `VK_EXT_depth_clip_control`
180180

181+
== xref:{chapters}primitive_topology.adoc[Primitive Topology]
182+
183+
// include::{chapters}primitive_topology.adoc[]
184+
181185
== xref:{chapters}mapping_data_to_shaders.adoc[Mapping Data to Shaders]
182186

183187
// include::{chapters}mapping_data_to_shaders.adoc[]

antora/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
** xref:{chapters}pipeline_cache.adoc[]
4141
** xref:{chapters}threading.adoc[]
4242
** xref:{chapters}depth.adoc[]
43+
** xref:{chapters}primitive_topology.adoc[]
4344
** xref:{chapters}mapping_data_to_shaders.adoc[]
4445
*** xref:{chapters}vertex_input_data_processing.adoc[]
4546
*** xref:{chapters}descriptor_dynamic_offset.adoc[]

chapters/images/primitive_topology_example.svg

Lines changed: 4 additions & 0 deletions
Loading

chapters/images/primitive_topology_polygon_mode.svg

Lines changed: 4 additions & 0 deletions
Loading

chapters/images/primitive_topology_stages.svg

Lines changed: 4 additions & 0 deletions
Loading

chapters/primitive_topology.adoc

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright 2025 The Khronos Group, Inc.
2+
// SPDX-License-Identifier: CC-BY-4.0
3+
4+
ifndef::chapters[:chapters:]
5+
ifndef::images[:images: images/]
6+
7+
[[primitive-topology]]
8+
= Primitive Topology
9+
10+
When using a graphics pipeline there are 2 types of shaders, link:https://docs.vulkan.org/spec/latest/chapters/pipelines.html#pipelines-graphics-subsets-pre-rasterization[pre-rasterization shaders] and fragment shaders.
11+
12+
[[pre-rasterization-stages]]
13+
== Pre-Rasterization stages
14+
15+
The following are the various shader stages that can be used in pre-rasterization.
16+
17+
image::{images}primitive_topology_stages.svg[primitive_topology_stages.svg]
18+
19+
The main thing to take away here is the last pre-rasterization stage might be any of the following:
20+
21+
- VK_SHADER_STAGE_VERTEX_BIT
22+
- VK_SHADER_STAGE_MESH_BIT_EXT
23+
- VK_SHADER_STAGE_GEOMETRY_BIT
24+
- VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT (must always be with a tessellation control stage)
25+
26+
== Types of Primitive
27+
28+
One of the goals of pre-rasterization is to get all the `primitives` ready for rasterization. The `primitive` is the smallest organized unit of vertices forming a basic geometric shape that's processed by the rasterizer. The `topology` of these primitives can be defined with the values in link:https://docs.vulkan.org/spec/latest/chapters/drawing.html#VkPrimitiveTopology[VkPrimitiveTopology].
29+
30+
The following shows a basic example how 6 vertices can be connected in different `VkPrimitiveTopology`
31+
32+
image::{images}primitive_topology_example.svg[primitive_topology_example.svg]
33+
34+
== Various Effective Topology
35+
36+
It is possible for the multiple link:https://docs.vulkan.org/spec/latest/chapters/drawing.html#drawing-primitive-topology-class[Topology Class] to be used during the graphics pipeline. It is important to know where in the pipeline you are when discussing "topology".
37+
38+
=== Vertex Input Assembly
39+
40+
`VkPipelineInputAssemblyStateCreateInfo::topology` (or set dynamically with `vkCmdSetPrimitiveTopology`) is what is provided as an input for the vertex shader.
41+
42+
When using mesh shaders, this value is ignored.
43+
44+
[NOTE]
45+
====
46+
If you want to set `VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY` in your pipeline, make sure to be aware of the `dynamicPrimitiveTopologyUnrestricted` property. Some hardware can only let you dynamically adjust the input assembly primitive topology to be in the same link:https://docs.vulkan.org/spec/latest/chapters/drawing.html#drawing-primitive-topology-class[Topology Class]
47+
====
48+
49+
=== Shader Execution Mode
50+
51+
Some stages have `Execution Mode` (SPIR-V term) that are defined in the shader code itself. This allows shader authors to determine the topology the shader will output.
52+
53+
It is possible to have multiple stages such as tessellation and geometry together. In this case the effective topology is only the `Execution Mode` set by the last shader stage in the pipeline.
54+
55+
==== Mesh output Execution Mode
56+
57+
The mesh stage will set either `OutputPoints`, `OutputLinesEXT`, or `OutputTrianglesEXT`
58+
59+
link:https://godbolt.org/z/jhhsoTfnT[Try Online]
60+
61+
[source,glsl]
62+
----
63+
#extension GL_EXT_mesh_shader : require
64+
65+
// Only 1 of the 3 is allowed
66+
layout(points) out;
67+
layout(lines) out;
68+
layout(triangles) out;
69+
----
70+
71+
==== Tessellation output Execution Mode
72+
73+
The tessellation evaluation stage will set either `Triangles`, `Quads`, or `Isolines`
74+
75+
link:https://godbolt.org/z/PbPT4WWrr[Try Online]
76+
77+
[source,glsl]
78+
----
79+
// Only 1 of the 3 is allowed
80+
layout(quads) in;
81+
layout(isolines) in;
82+
layout(triangles) in;
83+
----
84+
85+
==== Geometry output Execution Mode
86+
87+
A geometry stage will set either `OutputPoints`, `OutputLineStrip`, or `OutputTriangleStrip`
88+
89+
link:https://godbolt.org/z/K9nn98oGv[Try Online]
90+
91+
[source,glsl]
92+
----
93+
// Only 1 of the 3 is allowed
94+
layout(points) out;
95+
layout(line_strip) out;
96+
layout(triangle_strip) out;
97+
----
98+
99+
=== Polygon Mode
100+
101+
Once you have your primitives created you can set the link:https://docs.vulkan.org/spec/latest/chapters/primsrast.html#VkPolygonMode[VkPolygonMode]. This allows you to "fill in" the primitive.
102+
103+
image::{images}primitive_topology_polygon_mode.svg[primitive_topology_polygon_mode.svg]
104+
105+
If you have a vertex shader that has `VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST` input and then during rasterization uses `VK_POLYGON_MODE_LINE`, the effective topology is the Line link:https://docs.vulkan.org/spec/latest/chapters/drawing.html#drawing-primitive-topology-class[Topology Class] at time. This means something like `lineWidth` would be applied when filling in the polygon with `VK_POLYGON_MODE_LINE`.
106+
107+
== rasterizerDiscardEnable
108+
109+
`VkPipelineRasterizationStateCreateInfo::rasterizerDiscardEnable` (or set dynamically with `vkCmdSetRasterizerDiscardEnable`) controls whether primitives are discarded immediately before the rasterization stage. This is important because when this is set to `VK_TRUE` the rasterization hardware is not executed. There are many Validation Usage errors that will not occur if this is set to `VK_TRUE` because some topology hardware is unused and can be ignored.
110+
111+
[NOTE]
112+
====
113+
Enabling this state is meant for very specific use cases. Prior to compute shaders, this was a common technique for writting geometry shader output to a buffer. It can be used to debug/profile non-rasterization bottle necks.
114+
====

guide.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ include::{chapters}threading.adoc[]
173173

174174
include::{chapters}depth.adoc[]
175175

176+
// == Primitive Topology
177+
178+
include::{chapters}primitive_topology.adoc[]
179+
176180
// == Mapping Data to Shaders
177181

178182
include::{chapters}mapping_data_to_shaders.adoc[]

lang/jp/README-jp.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ Vulkan Guide は、`asciidoctor guide.adoc` を使って1つのページとし
164164

165165
* `VK_EXT_depth_range_unrestricted`, `VK_EXT_depth_clip_enable`, `VK_EXT_depth_clip_control`
166166

167+
== xref:{chapters}primitive_topology.adoc[Primitive Topology]
168+
169+
// include::{chapters}primitive_topology.adoc[]
170+
167171
== xref:{chapters}mapping_data_to_shaders.adoc[シェーダへのデータマッピング]
168172

169173
// include::{chapters}mapping_data_to_shaders.adoc[]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2025 The Khronos Group, Inc.
2+
// SPDX-License-Identifier: CC-BY-4.0
3+
4+
ifndef::chapters[:chapters:]
5+
ifndef::images[:images: images/]
6+
7+
[[primitive-topology]]
8+
= Primitive Topology
9+
10+
すみません!まだまだ翻訳が必要!

lang/jp/guide.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ include::{chapters}threading.adoc[]
166166

167167
include::{chapters}depth.adoc[]
168168

169+
// == Primitive Topology
170+
171+
include::{chapters}primitive_topology.adoc[]
172+
169173
// == Mapping Data to Shaders
170174

171175
include::{chapters}mapping_data_to_shaders.adoc[]

0 commit comments

Comments
 (0)