1bf215546Sopenharmony_ciANV
2bf215546Sopenharmony_ci===
3bf215546Sopenharmony_ci
4bf215546Sopenharmony_ciDebugging
5bf215546Sopenharmony_ci---------
6bf215546Sopenharmony_ci
7bf215546Sopenharmony_ciHere are a few environment variable debug environment variables
8bf215546Sopenharmony_cispecific to Anv:
9bf215546Sopenharmony_ci
10bf215546Sopenharmony_ci:envvar:`ANV_ENABLE_PIPELINE_CACHE`
11bf215546Sopenharmony_ci   If defined to ``0`` or ``false``, this will disable pipeline
12bf215546Sopenharmony_ci   caching, forcing Anv to reparse and recompile any VkShaderModule
13bf215546Sopenharmony_ci   (SPIRV) it is given.
14bf215546Sopenharmony_ci:envvar:`ANV_DISABLE_SECONDARY_CMD_BUFFER_CALLS`
15bf215546Sopenharmony_ci   If defined to ``1`` or ``true``, this will prevent usage of self
16bf215546Sopenharmony_ci   modifying command buffers to implement ``vkCmdExecuteCommands``. As
17bf215546Sopenharmony_ci   a result of this, it will also disable ``VK_KHR_performance_query``.
18bf215546Sopenharmony_ci:envvar:`ANV_ALWAYS_BINDLESS`
19bf215546Sopenharmony_ci   If defined to ``1`` or ``true``, this forces all descriptor sets to
20bf215546Sopenharmony_ci   use the internal `Bindless model`_.
21bf215546Sopenharmony_ci:envvar:`ANV_QUEUE_THREAD_DISABLE`
22bf215546Sopenharmony_ci   If defined to ``1`` or ``true``, this disables support for timeline
23bf215546Sopenharmony_ci   semaphores.
24bf215546Sopenharmony_ci:envvar:`ANV_USERSPACE_RELOCS`
25bf215546Sopenharmony_ci   If defined to ``1`` or ``true``, this forces Anv to always do
26bf215546Sopenharmony_ci   kernel relocations in command buffers. This should only have an
27bf215546Sopenharmony_ci   effect on hardware that doesn't support soft-pinning (Ivybridge,
28bf215546Sopenharmony_ci   Haswell, Cherryview).
29bf215546Sopenharmony_ci:envvar:`ANV_PRIMITIVE_REPLICATION_MAX_VIEWS`
30bf215546Sopenharmony_ci   Specifies up to how many view shaders can be lowered to handle
31bf215546Sopenharmony_ci   VK_KHR_multiview. Beyond this number, multiview is implemented
32bf215546Sopenharmony_ci   using instanced rendering. If unspecified, the value default to
33bf215546Sopenharmony_ci   ``2``.
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ciExperimental features
37bf215546Sopenharmony_ci---------------------
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci:envvar:`ANV_EXPERIMENTAL_NV_MESH_SHADER`
40bf215546Sopenharmony_ci   If defined to ``1`` or ``true``, this advertise support for
41bf215546Sopenharmony_ci   VK_NV_mesh_shader extension for platforms that have hardware
42bf215546Sopenharmony_ci   support for it.
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci.. _`Bindless model`:
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ciBinding Model
48bf215546Sopenharmony_ci-------------
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ciHere is the Anv bindless binding model that was implemented for the
51bf215546Sopenharmony_cidescriptor indexing feature of Vulkan 1.2 :
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci.. graphviz::
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci  digraph G {
56bf215546Sopenharmony_ci    fontcolor="black";
57bf215546Sopenharmony_ci    compound=true;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci    subgraph cluster_1 {
60bf215546Sopenharmony_ci      label = "Binding Table (HW)";
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci      bgcolor="cornflowerblue";
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci      node [ style=filled,shape="record",fillcolor="white",
65bf215546Sopenharmony_ci             label="RT0"    ] n0;
66bf215546Sopenharmony_ci      node [ label="RT1"    ] n1;
67bf215546Sopenharmony_ci      node [ label="dynbuf0"] n2;
68bf215546Sopenharmony_ci      node [ label="set0"   ] n3;
69bf215546Sopenharmony_ci      node [ label="set1"   ] n4;
70bf215546Sopenharmony_ci      node [ label="set2"   ] n5;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci      n0 -> n1 -> n2 -> n3 -> n4 -> n5 [style=invis];
73bf215546Sopenharmony_ci    }
74bf215546Sopenharmony_ci    subgraph cluster_2 {
75bf215546Sopenharmony_ci      label = "Descriptor Set 0";
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci      bgcolor="burlywood3";
78bf215546Sopenharmony_ci      fixedsize = true;
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci      node [ style=filled,shape="record",fillcolor="white", fixedsize = true, width=4,
81bf215546Sopenharmony_ci             label="binding 0 - STORAGE_IMAGE\n anv_storage_image_descriptor"          ] n8;
82bf215546Sopenharmony_ci      node [ label="binding 1 - COMBINED_IMAGE_SAMPLER\n anv_sampled_image_descriptor" ] n9;
83bf215546Sopenharmony_ci      node [ label="binding 2 - UNIFORM_BUFFER\n anv_address_range_descriptor"         ] n10;
84bf215546Sopenharmony_ci      node [ label="binding 3 - UNIFORM_TEXEL_BUFFER\n anv_storage_image_descriptor"   ] n11;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci      n8 -> n9 -> n10 -> n11 [style=invis];
87bf215546Sopenharmony_ci    }
88bf215546Sopenharmony_ci    subgraph cluster_5 {
89bf215546Sopenharmony_ci      label = "Vulkan Objects"
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci      fontcolor="black";
92bf215546Sopenharmony_ci      bgcolor="darkolivegreen4";
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci      subgraph cluster_6 {
95bf215546Sopenharmony_ci        label = "VkImageView";
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci        bgcolor=darkolivegreen3;
98bf215546Sopenharmony_ci        node [ style=filled,shape="box",fillcolor="white", fixedsize = true, width=2,
99bf215546Sopenharmony_ci               label="surface_state" ] n12;
100bf215546Sopenharmony_ci      }
101bf215546Sopenharmony_ci      subgraph cluster_7 {
102bf215546Sopenharmony_ci        label = "VkSampler";
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci        bgcolor=darkolivegreen3;
105bf215546Sopenharmony_ci        node [ style=filled,shape="box",fillcolor="white", fixedsize = true, width=2,
106bf215546Sopenharmony_ci               label="sample_state" ] n13;
107bf215546Sopenharmony_ci      }
108bf215546Sopenharmony_ci      subgraph cluster_8 {
109bf215546Sopenharmony_ci        label = "VkImageView";
110bf215546Sopenharmony_ci        bgcolor="darkolivegreen3";
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci        node [ style=filled,shape="box",fillcolor="white", fixedsize = true, width=2,
113bf215546Sopenharmony_ci               label="surface_state" ] n14;
114bf215546Sopenharmony_ci      }
115bf215546Sopenharmony_ci      subgraph cluster_9 {
116bf215546Sopenharmony_ci        label = "VkBuffer";
117bf215546Sopenharmony_ci        bgcolor=darkolivegreen3;
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci        node [ style=filled,shape="box",fillcolor="white", fixedsize = true, width=2,
120bf215546Sopenharmony_ci               label="address" ] n15;
121bf215546Sopenharmony_ci      }
122bf215546Sopenharmony_ci      subgraph cluster_10 {
123bf215546Sopenharmony_ci        label = "VkBufferView";
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci        bgcolor=darkolivegreen3;
126bf215546Sopenharmony_ci        node [ style=filled,shape="box",fillcolor="white", fixedsize = true, width=2,
127bf215546Sopenharmony_ci               label="surface_state" ] n16;
128bf215546Sopenharmony_ci      }
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci      n12 -> n13 -> n14 -> n15 -> n16 [style=invis];
131bf215546Sopenharmony_ci    }
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci    subgraph cluster_11 {
134bf215546Sopenharmony_ci      subgraph cluster_12 {
135bf215546Sopenharmony_ci        label = "CommandBuffer state stream";
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ci        bgcolor="gold3";
138bf215546Sopenharmony_ci        node [ style=filled,shape="box",fillcolor="white", fixedsize = true, width=2,
139bf215546Sopenharmony_ci               label="surface_state" ] n17;
140bf215546Sopenharmony_ci        node [ label="surface_state" ] n18;
141bf215546Sopenharmony_ci        node [ label="surface_state" ] n19;
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci        n17 -> n18 -> n19 [style=invis];
144bf215546Sopenharmony_ci      }
145bf215546Sopenharmony_ci    }
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci    n3  -> n8 [lhead=cluster_2];
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci    n8  -> n12;
150bf215546Sopenharmony_ci    n9  -> n13;
151bf215546Sopenharmony_ci    n9  -> n14;
152bf215546Sopenharmony_ci    n10 -> n15;
153bf215546Sopenharmony_ci    n11 -> n16;
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci    n0 -> n17;
156bf215546Sopenharmony_ci    n1 -> n18;
157bf215546Sopenharmony_ci    n2 -> n19;
158bf215546Sopenharmony_ci  }
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ciThe HW binding table is generated when the draw or dispatch commands
163bf215546Sopenharmony_ciare emitted. Here are the types of entries one can find in the binding
164bf215546Sopenharmony_citable :
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_ci- The currently bound descriptor sets, one entry per descriptor set
167bf215546Sopenharmony_ci  (our limit is 8).
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ci- For dynamic buffers, one entry per dynamic buffer.
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci- For draw commands, render target entries if needed.
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ciThe entries of the HW binding table for descriptor sets are
174bf215546Sopenharmony_ciRENDER_SURFACE_STATE similar to what you would have for a normal
175bf215546Sopenharmony_ciuniform buffer. The shader will emit reads this buffer first to get
176bf215546Sopenharmony_cithe information it needs to access a surface/sampler/etc... and then
177bf215546Sopenharmony_ciemits the appropriate message using the information gathered from the
178bf215546Sopenharmony_cidescriptor set buffer.
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ciEach binding type entry gets an associated structure in memory
181bf215546Sopenharmony_ci(``anv_storage_image_descriptor``, ``anv_sampled_image_descriptor``,
182bf215546Sopenharmony_ci``anv_address_range_descriptor``, ``anv_storage_image_descriptor``).
183bf215546Sopenharmony_ciThis is the information read by the shader.
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_ci
186bf215546Sopenharmony_ci.. _`Descriptor Set Memory Layout`:
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ciDescriptor Set Memory Layout
189bf215546Sopenharmony_ci----------------------------
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_ciHere is a representation of how the descriptor set bindings, with each
192bf215546Sopenharmony_cielements in each binding is mapped to a the descriptor set memory :
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_ci.. graphviz::
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_ci  digraph structs {
197bf215546Sopenharmony_ci    node [shape=record];
198bf215546Sopenharmony_ci    rankdir=LR;
199bf215546Sopenharmony_ci
200bf215546Sopenharmony_ci    struct1 [label="Descriptor Set | \
201bf215546Sopenharmony_ci                    <b0> binding 0\n STORAGE_IMAGE \n (array_length=3) | \
202bf215546Sopenharmony_ci                    <b1> binding 1\n COMBINED_IMAGE_SAMPLER \n (array_length=2) | \
203bf215546Sopenharmony_ci                    <b2> binding 2\n UNIFORM_BUFFER \n (array_length=1) | \
204bf215546Sopenharmony_ci                    <b3> binding 3\n UNIFORM_TEXEL_BUFFER \n (array_length=1)"];
205bf215546Sopenharmony_ci    struct2 [label="Descriptor Set Memory | \
206bf215546Sopenharmony_ci                    <b0e0> anv_storage_image_descriptor|\
207bf215546Sopenharmony_ci                    <b0e1> anv_storage_image_descriptor|\
208bf215546Sopenharmony_ci                    <b0e2> anv_storage_image_descriptor|\
209bf215546Sopenharmony_ci                    <b1e0> anv_sampled_image_descriptor|\
210bf215546Sopenharmony_ci                    <b1e1> anv_sampled_image_descriptor|\
211bf215546Sopenharmony_ci                    <b2e0> anv_address_range_descriptor|\
212bf215546Sopenharmony_ci                    <b3e0> anv_storage_image_descriptor"];
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_ci    struct1:b0 -> struct2:b0e0;
215bf215546Sopenharmony_ci    struct1:b0 -> struct2:b0e1;
216bf215546Sopenharmony_ci    struct1:b0 -> struct2:b0e2;
217bf215546Sopenharmony_ci    struct1:b1 -> struct2:b1e0;
218bf215546Sopenharmony_ci    struct1:b1 -> struct2:b1e1;
219bf215546Sopenharmony_ci    struct1:b2 -> struct2:b2e0;
220bf215546Sopenharmony_ci    struct1:b3 -> struct2:b3e0;
221bf215546Sopenharmony_ci  }
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ciEach Binding in the descriptor set is allocated an array of
224bf215546Sopenharmony_ci``anv_*_descriptor`` data structure. The type of ``anv_*_descriptor``
225bf215546Sopenharmony_ciused for a binding is selected based on the ``VkDescriptorType`` of
226bf215546Sopenharmony_cithe bindings.
227bf215546Sopenharmony_ci
228bf215546Sopenharmony_ciThe value of ``anv_descriptor_set_binding_layout::descriptor_offset``
229bf215546Sopenharmony_ciis a byte offset from the descriptor set memory to the associated
230bf215546Sopenharmony_cibinding. ``anv_descriptor_set_binding_layout::array_size`` is the
231bf215546Sopenharmony_cinumber of ``anv_*_descriptor`` elements in the descriptor set memory
232bf215546Sopenharmony_cifrom that offset for the binding.
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ciPipeline state emission
236bf215546Sopenharmony_ci-----------------------
237bf215546Sopenharmony_ci
238bf215546Sopenharmony_ciVulkan initially started by baking as much state as possible in
239bf215546Sopenharmony_cipipelines. But extension after extension, more and more state has
240bf215546Sopenharmony_cibecome potentially dynamic.
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_ciAnv tries to limit the amount of time an instruction has to be packed
243bf215546Sopenharmony_cito reprogram part of the 3D pipeline state. The packing is happening
244bf215546Sopenharmony_ciin 2 places :
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_ci- ``genX_pipeline.c`` where the non dynamic state is emitted in the
247bf215546Sopenharmony_ci  pipeline batch. This batch is copied into the command buffer batch
248bf215546Sopenharmony_ci  when calling ``vkCmdBindPipeline()``
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ci- ``genX_cmd_buffer.c`` in the ``cmd_buffer_flush_state`` function
251bf215546Sopenharmony_ci  which ends up calling into ``gfx8_cmd_buffer.c`` &
252bf215546Sopenharmony_ci  ``gfx7_cmd_buffer.c``
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_ciThe rule to know where to emit an instruction programming the 3D
255bf215546Sopenharmony_cipipeline is as follow :
256bf215546Sopenharmony_ci
257bf215546Sopenharmony_ci- If any field of the instruction can be made dynamic, it should be
258bf215546Sopenharmony_ci  emitted in ``genX_cmd_buffer.c``, ``gfx8_cmd_buffer.c`` or
259bf215546Sopenharmony_ci  ``gfx7_cmd_buffer.c``
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci- Otherwise, the instruction can be emitted in ``genX_pipeline.c``
262bf215546Sopenharmony_ci
263bf215546Sopenharmony_ciWhen a piece of state programming is dynamic, it should have a
264bf215546Sopenharmony_cicorresponding field in ``anv_dynamic_state`` and the
265bf215546Sopenharmony_ci``anv_dynamic_state_copy()`` function should be updated to ensure we
266bf215546Sopenharmony_ciminimize the amount of time an instruction should be emitted. Each
267bf215546Sopenharmony_ciinstruction should have a associated ``ANV_CMD_DIRTY_*`` mask so that
268bf215546Sopenharmony_cithe dynamic emission code can tell when to re-emit an instruction.
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_ciAn instruction can also be re-emitted when a pipeline changes by
271bf215546Sopenharmony_cichecking for ``ANV_CMD_DIRTY_PIPELINE``. It should only do so if it
272bf215546Sopenharmony_cirequires to know some value that is coming from the
273bf215546Sopenharmony_ci``anv_graphics_pipeline`` object that is not available from
274bf215546Sopenharmony_ci``anv_dynamic_state``.
275