| 1 |
Primitive Ordered Pixel Shading |
| 2 |
=============================== |
| 3 |
|
| 4 |
Primitive Ordered Pixel Shading (POPS) is the feature available starting from |
| 5 |
GFX9 that provides the Fragment Shader Interlock or Fragment Shader Ordering |
| 6 |
functionality. |
| 7 |
|
| 8 |
It allows a part of a fragment shader — an ordered section (or a critical |
| 9 |
section) — to be executed sequentially in rasterization order for different |
| 10 |
invocations covering the same pixel position. |
| 11 |
|
| 12 |
This article describes how POPS is set up in shader code and the registers. The |
| 13 |
information here is currently provided for architecture generations up to GFX11. |
| 14 |
|
| 15 |
Note that the information in this article is **not official** and may contain |
| 16 |
inaccuracies, as well as incomplete or incorrect assumptions. It is based on the |
| 17 |
shader code output of the Radeon GPU Analyzer for Rasterizer Ordered View usage |
| 18 |
in Direct3D shaders, AMD's Platform Abstraction Library (PAL), ISA references, |
| 19 |
and experimentation with the hardware. |
| 20 |
|
| 21 |
Shader code |
| 22 |
----------- |
| 23 |
|
| 24 |
With POPS, a wave can dynamically execute up to one ordered section. It is fine |
| 25 |
for a wave not to enter an ordered section at all if it doesn't need ordering on |
| 26 |
its execution path, however. |
| 27 |
|
| 28 |
The setup of the ordered section consists of three parts: |
| 29 |
|
| 30 |
1. Entering the ordered section in the current wave — awaiting the completion of |
| 31 |
ordered sections in overlapped waves. |
| 32 |
2. Resolving overlap within the current wave — intrawave collisions (optional |
| 33 |
and GFX9–10.3 only). |
| 34 |
3. Exiting the ordered section — resuming overlapping waves trying to enter |
| 35 |
their ordered sections. |
| 36 |
|
| 37 |
GFX9–10.3: Entering the ordered section in the wave |
| 38 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 39 |
|
| 40 |
Awaiting the completion of ordered sections in overlapped waves is performed by |
| 41 |
setting the POPS packer hardware register, and then polling the volatile |
| 42 |
``pops_exiting_wave_id`` ALU operand source until its value exceeds the newest |
| 43 |
overlapped wave ID for the current wave. |
| 44 |
|
| 45 |
The information needed for the wave to perform the waiting is provided to it via |
| 46 |
the SGPR argument ``COLLISION_WAVEID``. Its loading needs to be enabled in the |
| 47 |
``SPI_SHADER_PGM_RSRC2_PS`` and ``PA_SC_SHADER_CONTROL`` registers (note that |
| 48 |
the POPS arguments specifically need to be enabled not only in ``RSRC`` unlike |
| 49 |
various other arguments, but in ``PA_SC_SHADER_CONTROL`` as well). |
| 50 |
|
| 51 |
The collision wave ID argument contains the following unsigned values: |
| 52 |
|
| 53 |
* [31]: Whether overlap has occurred. |
| 54 |
* [29:28] (GFX10+) / [28] (GFX9): ID of the packer the wave should be associated |
| 55 |
with. |
| 56 |
* [25:16]: Newest overlapped wave ID. |
| 57 |
* [9:0]: Current wave ID. |
| 58 |
|
| 59 |
The 2020 RDNA and RDNA 2 ISA references contain incorrect offsets and widths of |
| 60 |
the fields, possibly from an early development iteration, but the meanings of |
| 61 |
them are accurate there. |
| 62 |
|
| 63 |
The wait must not be performed if the "did overlap" bit 31 is set to 0, |
| 64 |
otherwise it will result in a hang. Also, the bit being set to 0 indicates that |
| 65 |
there are *both* no wave overlap *and no intrawave collisions* for the current |
| 66 |
wave — so if the bit is 0, it's safe for the wave to skip all of the POPS logic |
| 67 |
completely and execute the contents of the ordered section simply as usual with |
| 68 |
unordered access as a potential additional optimization. The packer hardware |
| 69 |
register, however, may be set even without overlap safely — it's the wait loop |
| 70 |
itself that must not be executed if it was reported that there was no overlap. |
| 71 |
|
| 72 |
The packer ID needs to be passed to the packer hardware register using |
| 73 |
``s_setreg_b32`` so the wave can poll ``pops_exiting_wave_id`` on that packer. |
| 74 |
|
| 75 |
On GFX9, the ``MODE`` (1) hardware register has two bits specifying which packer |
| 76 |
the wave is associated with: |
| 77 |
|
| 78 |
* [25]: The wave is associated with packer 1. |
| 79 |
* [24]: The wave is associated with packer 0. |
| 80 |
|
| 81 |
Initially, both of these bits are set 0, meaning that POPS is disabled for the |
| 82 |
wave. If the wave needs to enter the ordered section, it must set bit 24 to 1 if |
| 83 |
the packer ID in ``COLLISION_WAVEID`` is 0, or set bit 25 to 1 if the packer ID |
| 84 |
is 1. |
| 85 |
|
| 86 |
Starting from GFX10, the ``POPS_PACKER`` (25) hardware register is used instead, |
| 87 |
containing the following fields: |
| 88 |
|
| 89 |
* [2:1]: Packer ID. |
| 90 |
* [0]: POPS enabled for the wave. |
| 91 |
|
| 92 |
Initially, POPS is disabled for a wave. To start entering the ordered section, |
| 93 |
bits 2:1 must be set to the packer ID from ``COLLISION_WAVEID``, and bit 0 needs |
| 94 |
to be set to 1. |
| 95 |
|
| 96 |
The wave IDs, both in ``COLLISION_WAVEID`` and ``pops_exiting_wave_id``, are |
| 97 |
10-bit values wrapping around on overflow — consecutive waves are numbered 1022, |
| 98 |
1023, 0, 1… This wraparound needs to be taken into account when comparing the |
| 99 |
exiting wave ID and the newest overlapped wave ID. |
| 100 |
|
| 101 |
Specifically, until the current wave exits the ordered section, its ID can't be |
| 102 |
smaller than the newest overlapped wave ID or the exiting wave ID. So |
| 103 |
``current_wave_id + 1`` can be subtracted from 10-bit wave IDs to remap them to |
| 104 |
monotonically increasing unsigned values. In this case, the largest value, |
| 105 |
0xFFFFFFFF, will correspond to the current wave, 10-bit values up to the current |
| 106 |
wave ID will be in a range near 0xFFFFFFFF growing towards it, and wave IDs from |
| 107 |
before the last wraparound will be near 0 increasing away from it. Subtracting |
| 108 |
``current_wave_id + 1`` is equivalent to adding ``~current_wave_id``. |
| 109 |
|
| 110 |
GFX9 has an off-by-one error in the newest overlapped wave ID: if the 10-bit |
| 111 |
newest overlapped wave ID is greater than the 10-bit current wave ID (meaning |
| 112 |
that it's behind the last wraparound point), 1 needs to be added to the newest |
| 113 |
overlapped wave ID before using it in the comparison. This was corrected in |
| 114 |
GFX10. |
| 115 |
|
| 116 |
The exiting wave ID (not to be confused with "exited" — the exiting wave ID is |
| 117 |
the wave that will exit the ordered section next) is queried via the |
| 118 |
``pops_exiting_wave_id`` ALU operand source, numbered 239. Normally, it will be |
| 119 |
one of the arguments of ``s_add_i32`` that remaps it from a wrapping 10-bit wave |
| 120 |
ID to monotonically increasing one. |
| 121 |
|
| 122 |
It's a volatile operand, and it needs to be read in a loop until its value |
| 123 |
becomes greater than the newest overlapped wave ID (after remapping both to |
| 124 |
monotonic). However, if it's too early for the current wave to enter the ordered |
| 125 |
section, it needs to yield execution to other waves that may potentially be |
| 126 |
overlapped — via ``s_sleep``. GFX9 requires a finite amount of delay to be |
| 127 |
specified, AMD uses 3. Starting from GFX10, exiting the ordered section wakes up |
| 128 |
the waiting waves, so the maximum delay of 0xFFFF can be used. |
| 129 |
|
| 130 |
In pseudocode, the entering logic would look like this:: |
| 131 |
|
| 132 |
bool did_overlap = collision_wave_id[31]; |
| 133 |
if (did_overlap) { |
| 134 |
if (gfx_level >= GFX10) { |
| 135 |
uint packer_id = collision_wave_id[29:28]; |
| 136 |
s_setreg_b32(HW_REG_POPS_PACKER[2:0], 1 | (packer_id << 1)); |
| 137 |
} else { |
| 138 |
uint packer_id = collision_wave_id[28]; |
| 139 |
s_setreg_b32(HW_REG_MODE[25:24], packer_id ? 0b10 : 0b01); |
| 140 |
} |
| 141 |
|
| 142 |
uint current_10bit_wave_id = collision_wave_id[9:0]; |
| 143 |
// Or -(current_10bit_wave_id + 1). |
| 144 |
uint wave_id_remap_offset = ~current_10bit_wave_id; |
| 145 |
|
| 146 |
uint newest_overlapped_10bit_wave_id = collision_wave_id[25:16]; |
| 147 |
if (gfx_level < GFX10 && |
| 148 |
newest_overlapped_10bit_wave_id > current_10bit_wave_id) { |
| 149 |
++newest_overlapped_10bit_wave_id; |
| 150 |
} |
| 151 |
uint newest_overlapped_wave_id = |
| 152 |
newest_overlapped_10bit_wave_id + wave_id_remap_offset; |
| 153 |
|
| 154 |
while (!(src_pops_exiting_wave_id + wave_id_remap_offset > |
| 155 |
newest_overlapped_wave_id)) { |
| 156 |
s_sleep(gfx_level >= GFX10 ? 0xFFFF : 3); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
The SPIR-V fragment shader interlock specification requires an invocation — an |
| 161 |
individual invocation, not the whole subgroup — to execute |
| 162 |
``OpBeginInvocationInterlockEXT`` exactly once. However, if there are multiple |
| 163 |
begin instructions, or even multiple begin/end pairs, under divergent |
| 164 |
conditions, a wave may end up waiting for the overlapped waves multiple times. |
| 165 |
Thankfully, it's safe to set the POPS packer hardware register to the same |
| 166 |
value, or to run the wait loop, multiple times during the wave's execution, as |
| 167 |
long as the ordered section isn't exited in between by the wave. |
| 168 |
|
| 169 |
GFX11: Entering the ordered section in the wave |
| 170 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 171 |
|
| 172 |
Instead of exposing wave IDs to shaders, GFX11 uses the "export ready" wave |
| 173 |
status flag to report that the wave may enter the ordered section. It's awaited |
| 174 |
by the ``s_wait_event`` instruction, with the bit 0 ("don't wait for |
| 175 |
``export_ready``") of the immediate operand set to 0. On GFX11 specifically, AMD |
| 176 |
passes 0 as the whole immediate operand. |
| 177 |
|
| 178 |
The "export ready" wait can be done multiple times safely. |
| 179 |
|
| 180 |
GFX9–10.3: Resolving intrawave collisions |
| 181 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 182 |
|
| 183 |
On GFX9–10.3, it's possible for overlapping fragment shader invocations to be |
| 184 |
placed not only in different waves, but also in the same wave, with the shader |
| 185 |
code making sure that the ordered section is executed for overlapping |
| 186 |
invocations in order. |
| 187 |
|
| 188 |
This functionality is optional — it can be activated by enabling loading of the |
| 189 |
``INTRAWAVE_COLLISION`` SGPR argument in ``SPI_SHADER_PGM_RSRC2_PS`` and |
| 190 |
``PA_SC_SHADER_CONTROL``. |
| 191 |
|
| 192 |
The lower 8 or 16 (depending on the wave size) bits of ``INTRAWAVE_COLLISION`` |
| 193 |
contain the mask of whether each quad in the wave starts a new layer of |
| 194 |
overlapping invocations, and thus the ordered section code for them needs to be |
| 195 |
executed after running it for all lanes with indices preceding that quad index |
| 196 |
multiplied by 4. The rest of the bits in the argument need to be ignored — AMD |
| 197 |
explicitly masks them out in shader code (although this is not necessary if the |
| 198 |
shader uses "find first 1" to obtain the start of the next set of overlapping |
| 199 |
quads or expands this quad mask into a lane mask). |
| 200 |
|
| 201 |
For example, if the intrawave collision mask is 0b0000001110000100, or |
| 202 |
``(1 << 2) | (1 << 7) | (1 << 8) | (1 << 9)``, the code of the ordered section |
| 203 |
needs to be executed first only for quads 1:0 (lanes 7:0), then only for quads |
| 204 |
6:2 (lanes 27:8), then for quad 7 (lanes 31:28), then for quad 8 (lanes 35:32), |
| 205 |
and then for the remaining quads 15:9 (lanes 63:36). |
| 206 |
|
| 207 |
This effectively causes the ordered section to be executed as smaller |
| 208 |
"sub-subgroups" within the original subgroup. |
| 209 |
|
| 210 |
However, this is not always compatible with the execution model of SPIR-V or |
| 211 |
GLSL fragment shaders, so enabling intrawave collisions and wrapping a part of |
| 212 |
the shader in a loop may be unsafe in some cases. One particular example is when |
| 213 |
the shader uses subgroup operations influenced by lanes outside the current |
| 214 |
quad. In this case, the code outside and inside the ordered section may be |
| 215 |
executed with different sets of active invocations, affecting the results of |
| 216 |
subgroup operations. But in SPIR-V and GLSL, fragment shader interlock is not |
| 217 |
supposed to modify the set of active invocations in any way. So the intrawave |
| 218 |
collision loop may break the results of subgroup operations in unpredictable |
| 219 |
ways, even outside the driver's compiler infrastructure. Even if the driver |
| 220 |
splits the subgroup exactly at ``OpBeginInvocationInterlockEXT`` and makes the |
| 221 |
lane subsets rejoin exactly at ``OpEndInvocationInterlockEXT``, the application |
| 222 |
and the compilers that created the source shader are still not aware of that |
| 223 |
happening — the input SPIR-V or GLSL shader might have already gone through |
| 224 |
various optimizations, such as common subexpression elimination which might |
| 225 |
have considered a subgroup operation before ``OpBeginInvocationInterlockEXT`` |
| 226 |
and one after it equivalent. |
| 227 |
|
| 228 |
The idea behind reporting intrawave collisions to shaders is to reduce the |
| 229 |
impact on the parallelism of the part of the shader that doesn't depend on the |
| 230 |
ordering, to avoid wasting lanes in the wave and to allow the code outside the |
| 231 |
ordered section in different invocations to run in parallel lanes as usual. This |
| 232 |
may be especially helpful if the ordered section is small compared to the rest |
| 233 |
of the shader — for instance, a custom blending equation in the end of the usual |
| 234 |
fragment shader for a surface in the world. |
| 235 |
|
| 236 |
However, whether handling intrawave collisions is preferred is not a question |
| 237 |
with one universal answer. Intrawave collisions are pretty uncommon without |
| 238 |
multisampling, or when using sample interlock with multisampling, although |
| 239 |
they're highly frequent with pixel interlock with multisampling, when adjacent |
| 240 |
primitives cover the same pixels along the shared edge (though that's an |
| 241 |
extremely expensive situation in general). But resolving intrawave collisions |
| 242 |
adds some overhead costs to the shader. If intrawave overlap is unlikely to |
| 243 |
happen often, or even more importantly, if the majority of the shader is inside |
| 244 |
the ordered section, handling it in the shader may cause more harm than good. |
| 245 |
|
| 246 |
GFX11 removes this concept entirely, instead overlapping invocations are always |
| 247 |
placed in different waves. |
| 248 |
|
| 249 |
GFX9–10.3: Exiting the ordered section in the wave |
| 250 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 251 |
|
| 252 |
To exit the ordered section and let overlapping waves resume execution and enter |
| 253 |
their ordered sections, the wave needs to send the ``ORDERED_PS_DONE`` message |
| 254 |
(7) using ``s_sendmsg``. |
| 255 |
|
| 256 |
If the wave has enabled POPS by setting the packer hardware register, it *must |
| 257 |
not* execute ``s_endpgm`` without having sent ``ORDERED_PS_DONE`` once, so the |
| 258 |
message must be sent on all execution paths after the packer register setup. |
| 259 |
However, if the wave exits before having configured the packer register, sending |
| 260 |
the message is not required, though it's still fine to send it regardless of |
| 261 |
that. |
| 262 |
|
| 263 |
Note that if the shader has multiple ``OpEndInvocationInterlockEXT`` |
| 264 |
instructions executed in the same wave (depending on a divergent condition, for |
| 265 |
example), it must still be ensured that ``ORDERED_PS_DONE`` is sent by the wave |
| 266 |
only once, and especially not before any awaiting of overlapped waves. |
| 267 |
|
| 268 |
Before the message is sent, all counters for memory accesses that need to be |
| 269 |
primitive-ordered, both writes and (in case something after the ordered section |
| 270 |
depends on the per-pixel data, for instance, the tail blending fallback in |
| 271 |
order-independent transparency) reads, must be awaited. Those may include |
| 272 |
``vm``, ``vs``, and in some cases ``lgkm`` (though normally primitive-ordered |
| 273 |
memory accesses will be done through VMEM with divergent addresses, not SMEM, as |
| 274 |
there's no synchronization between fragments at different pixel coordinates, but |
| 275 |
it's still technically possible for a shader, even though pointless and |
| 276 |
nonoptimal, to explicitly perform them in a waterfall loop, for instance, and |
| 277 |
that must work correctly too). Without that, a race condition will occur when |
| 278 |
the newly resumed waves start accessing the memory locations to which there |
| 279 |
still are outstanding accesses in the current wave. |
| 280 |
|
| 281 |
Another option for exiting is the ``s_endpgm_ordered_ps_done`` instruction, |
| 282 |
which combines waiting for all the counters, sending the ``ORDERED_PS_DONE`` |
| 283 |
message, and ending the program. Generally, however, it's desirable to resume |
| 284 |
overlapping waves as early as possible, including before the export, as it may |
| 285 |
stall the wave for some time too. |
| 286 |
|
| 287 |
GFX11: Exiting the ordered section in the wave |
| 288 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 289 |
|
| 290 |
The overlapping waves are resumed when the wave performs the last export (with |
| 291 |
the ``done`` flag). |
| 292 |
|
| 293 |
The same requirements for awaiting the memory access counters as on GFX9–10.3 |
| 294 |
still apply. |
| 295 |
|
| 296 |
Memory access requirements |
| 297 |
^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 298 |
|
| 299 |
The compiler needs to ensure that entering the ordered section implements |
| 300 |
acquire semantics, and exiting it implements release semantics, in the fragment |
| 301 |
interlock memory scope for ``UniformMemory`` and ``ImageMemory`` SPIR-V storage |
| 302 |
classes. |
| 303 |
|
| 304 |
A fragment interlock memory scope instance includes overlapping fragment shader |
| 305 |
invocations executed by commands inside a single subpass. It may be considered a |
| 306 |
subset of a queue family memory scope instance from the perspective of memory |
| 307 |
barriers. |
| 308 |
|
| 309 |
Fragment shader interlock doesn't perform implicit memory availability or |
| 310 |
visibility operations. Shaders must do them by themselves for accesses requiring |
| 311 |
primitive ordering, such as via ``coherent`` (``queuefamilycoherent``) in GLSL |
| 312 |
or ``MakeAvailable`` and ``MakeVisible`` in at least the ``QueueFamily`` scope |
| 313 |
in SPIR-V. |
| 314 |
|
| 315 |
On AMD hardware, this means that the accessed memory locations must be made |
| 316 |
available or visible between waves that may be executed on any compute unit — so |
| 317 |
accesses must go directly to the global L2 cache, bypassing L0$ via the GLC flag |
| 318 |
and L1$ via DLC. |
| 319 |
|
| 320 |
However, it should be noted that memory accesses in the ordered section may be |
| 321 |
expected by the application to be done in primitive order even if they don't |
| 322 |
have the GLC and DLC flags. Coherent access not only bypasses, but also |
| 323 |
invalidates the lower-level caches for the accessed memory locations. Thus, |
| 324 |
considering that normally per-pixel data is accessed exclusively by the |
| 325 |
invocation executing the ordered section, it's not necessary to make all reads |
| 326 |
or writes in the ordered section for one memory location to be GLC/DLC — just |
| 327 |
the first read and the last write: it doesn't matter if per-pixel data is cached |
| 328 |
in L0/L1 in the middle of a dependency chain in the ordered section, as long as |
| 329 |
it's invalidated in them in the beginning and flushed to L2 in the end. |
| 330 |
Therefore, optimizations in the compiler must not simply assume that only |
| 331 |
coherent accesses need primitive ordering — and moreover, the compiler must also |
| 332 |
take into account that the same data may be accessed through different bindings. |
| 333 |
|
| 334 |
Export requirements |
| 335 |
^^^^^^^^^^^^^^^^^^^ |
| 336 |
|
| 337 |
With POPS, on all hardware generations, the shader must have at least one |
| 338 |
export, though it can be a null or an ``off, off, off, off`` one. |
| 339 |
|
| 340 |
Also, even if the shader doesn't need to export any real data, the export |
| 341 |
skipping that was added in GFX10 must not be used, and some space must be |
| 342 |
allocated in the export buffer, such as by setting ``SPI_SHADER_COL_FORMAT`` for |
| 343 |
some color output to ``SPI_SHADER_32_R``. |
| 344 |
|
| 345 |
Without this, the shader will be executed without the needed synchronization on |
| 346 |
GFX10, and will hang on GFX11. |
| 347 |
|
| 348 |
Drawing context setup |
| 349 |
--------------------- |
| 350 |
|
| 351 |
Configuring POPS |
| 352 |
^^^^^^^^^^^^^^^^ |
| 353 |
|
| 354 |
Most of the configuration is performed via the ``DB_SHADER_CONTROL`` register. |
| 355 |
|
| 356 |
To enable POPS for the draw, |
| 357 |
``DB_SHADER_CONTROL.PRIMITIVE_ORDERED_PIXEL_SHADER`` should be set to 1. |
| 358 |
|
| 359 |
On GFX9–10.3, ``DB_SHADER_CONTROL.POPS_OVERLAP_NUM_SAMPLES`` controls which |
| 360 |
fragment shader invocations are considered overlapping: |
| 361 |
|
| 362 |
* For pixel interlock, it must be set to 0 (1 sample). |
| 363 |
* If sample interlock is sufficient (only synchronizing between invocations that |
| 364 |
have any common sample mask bits), it may be set to |
| 365 |
``PA_SC_AA_CONFIG.MSAA_EXPOSED_SAMPLES`` — the number of sample coverage mask |
| 366 |
bits passed to the shader which is expected to use the sample mask to |
| 367 |
determine whether it's allowed to access the data for each of the samples. As |
| 368 |
of April 2023, PAL for some reason doesn't use non-1x |
| 369 |
``POPS_OVERLAP_NUM_SAMPLES`` at all, even when using Direct3D Rasterizer |
| 370 |
Ordered Views or ``GL_INTEL_fragment_shader_ordering`` with sample shading |
| 371 |
(those APIs tie the interlock granularity to the shading frequency — Vulkan |
| 372 |
and OpenGL fragment shader interlock, however, allows specifying the interlock |
| 373 |
granularity independently of it, making it possible both to ask for finer |
| 374 |
synchronization guarantees and to require stronger ones than Direct3D ROVs can |
| 375 |
provide). However, with MSAA, on AMD hardware, pixel interlock generally |
| 376 |
performs *massively*, sometimes prohibitively, slower than sample interlock, |
| 377 |
because it causes fragment shader invocations along the common edge of |
| 378 |
adjacent primitives to be ordered as they cover the same pixels (even though |
| 379 |
they don't cover any common samples). So it's highly desirable for the driver |
| 380 |
to provide sample interlock, and to set ``POPS_OVERLAP_NUM_SAMPLES`` |
| 381 |
accordingly, if the shader declares that it's enough for it via the execution |
| 382 |
mode. |
| 383 |
|
| 384 |
On GFX11, when POPS is enabled, ``DB_SHADER_CONTROL.OVERRIDE_INTRINSIC_RATE`` is |
| 385 |
used in place of ``DB_SHADER_CONTROL.POPS_OVERLAP_NUM_SAMPLES`` from the earlier |
| 386 |
architecture generations (and has a different bit offset in the register), and |
| 387 |
``DB_SHADER_CONTROL.OVERRIDE_INTRINSIC_RATE_ENABLE`` must be set to 1. The GFX11 |
| 388 |
blending performance workaround overriding the intrinsic rate must not be |
| 389 |
applied if POPS is used in the draw — the intrinsic rate override must be used |
| 390 |
solely to control the interlock granularity in this case. |
| 391 |
|
| 392 |
No explicit flushes/synchronization are needed when changing the pipeline state |
| 393 |
variables that may be involved in POPS, such as the rasterization sample count. |
| 394 |
POPS automatically keeps synchronizing invocations even between draws with |
| 395 |
different sample counts (invocations with common coverage mask bits are |
| 396 |
considered overlapping by the hardware, regardless of what those samples |
| 397 |
actually are — only the indices are important). |
| 398 |
|
| 399 |
Also, on GFX11, POPS uses ``DB_Z_INFO.NUM_SAMPLES`` to determine the coverage |
| 400 |
sample count, and it must be equal to ``PA_SC_AA_CONFIG.MSAA_EXPOSED_SAMPLES`` |
| 401 |
even if there's no depth/stencil target. |
| 402 |
|
| 403 |
Hardware bug workarounds |
| 404 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 405 |
|
| 406 |
Early revisions of GFX9 — ``CHIP_VEGA10`` and ``CHIP_RAVEN`` — contain a |
| 407 |
hardware bug that may result in a hang, and need a workaround to be enabled. |
| 408 |
Specifically, if POPS is used with 8 or more rasterization samples, or with 8 or |
| 409 |
more depth/stencil target samples, ``DB_DFSM_CONTROL.POPS_DRAIN_PS_ON_OVERLAP`` |
| 410 |
must be set to 1 for draws that satisfy this condition. In PAL, this is the |
| 411 |
``waMiscPopsMissedOverlap`` workaround. It results in slightly lower performance |
| 412 |
in those cases, increasing the frame time by around 1.5 to 2 times in |
| 413 |
`nvpro-samples/vk_order_independent_transparency <https://github.com/nvpro-samples/vk_order_independent_transparency>`_ |
| 414 |
on the RX Vega 10, but it's required in a pretty rare case (8x+ MSAA) and is |
| 415 |
mandatory to ensure stability. |
| 416 |
|
| 417 |
Also, even though ``DB_DFSM_CONTROL.POPS_DRAIN_PS_ON_OVERLAP`` is not required |
| 418 |
on chips other than the ``CHIP_VEGA10`` and ``CHIP_RAVEN`` GFX9 revisions, if |
| 419 |
it's enabled for some reason on GFX10.1 (``CHIP_NAVI10``, ``CHIP_NAVI12``, |
| 420 |
``CHIP_NAVI14``), and the draw uses POPS, |
| 421 |
``DB_RENDER_OVERRIDE2.PARTIAL_SQUAD_LAUNCH_CONTROL`` must be set to |
| 422 |
``PSLC_ON_HANG_ONLY`` to avoid a hang (see ``waStalledPopsMode`` in PAL). |
| 423 |
|
| 424 |
Out-of-order rasterization interaction |
| 425 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 426 |
|
| 427 |
This is a largely unresearched topic currently. However, considering that POPS |
| 428 |
is primarily the functionality of the Depth Block, similarity to the behavior of |
| 429 |
out-of-order rasterization in depth/stencil testing may possibly be expected. |
| 430 |
|
| 431 |
If the shader specifies an ordered interlock execution mode, out-of-order |
| 432 |
rasterization likely must not be enabled implicitly. |
| 433 |
|
| 434 |
As of April 2023, PAL doesn't have any rules specifically for POPS in the logic |
| 435 |
determining whether out-of-order rasterization can be enabled automatically. |
| 436 |
Some of the POPS usage cases may possibly be covered by the rule that always |
| 437 |
disables out-of-order rasterization if the shader writes to Unordered Access |
| 438 |
Views (storage resources), though fragment shader interlock can be used for |
| 439 |
read-only purposes too (for ordering between draws that only read per-pixel data |
| 440 |
and draws that may write it), so that may be an oversight. |
| 441 |
|
| 442 |
Explicitly enabled relaxed rasterization order modifies the concept of |
| 443 |
rasterization order itself in Vulkan, so from the point of view of the |
| 444 |
specification of fragment shader interlock, relaxed rasterization order should |
| 445 |
still be applicable regardless of whether the shader requests ordered interlock. |
| 446 |
PAL also doesn't make any POPS-specific exceptions here as of April 2023. |
| 447 |
|
| 448 |
Variable-rate shading interaction |
| 449 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 450 |
|
| 451 |
On GFX10.3, enabling ``DB_SHADER_CONTROL.PRIMITIVE_ORDERED_PIXEL_SHADER`` forces |
| 452 |
the shading rate to be 1x1, thus the |
| 453 |
``fragmentShadingRateWithFragmentShaderInterlock`` Vulkan device property must |
| 454 |
be false. |
| 455 |
|
| 456 |
On GFX11, by default, POPS itself can work with non-1x1 shading rates, and the |
| 457 |
``fragmentShadingRateWithFragmentShaderInterlock`` property must be true. |
| 458 |
However, if ``PA_SC_VRS_SURFACE_CNTL_1.FORCE_SC_VRS_RATE_FINE_POPS`` is set, |
| 459 |
enabling POPS will force 1x1 shading rate. |
| 460 |
|
| 461 |
The widest interlock granularity available on GFX11 — with the lowest possible |
| 462 |
Depth Block intrinsic rate, 1x — is per-fine-pixel, however. There's no |
| 463 |
synchronization between coarse fragment shader invocations if they don't cover |
| 464 |
common fine pixels, so the ``fragmentShaderShadingRateInterlock`` Vulkan device |
| 465 |
feature is not available. |
| 466 |
|
| 467 |
Additional configuration |
| 468 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 469 |
|
| 470 |
These are some largely unresearched options found in the register declarations. |
| 471 |
PAL doesn't use them, so it's unknown if they make any significant difference. |
| 472 |
No effect was found in `nvpro-samples/vk_order_independent_transparency <https://github.com/nvpro-samples/vk_order_independent_transparency>`_ |
| 473 |
during testing on GFX9 ``CHIP_RAVEN`` and GFX11 ``CHIP_NAVI31``. |
| 474 |
|
| 475 |
* ``DB_SHADER_CONTROL.EXEC_IF_OVERLAPPED`` on GFX9–10.3. |
| 476 |
* ``PA_SC_BINNER_CNTL_0.BIN_MAPPING_MODE = BIN_MAP_MODE_POPS`` on GFX10+. |