tu: Fix and simplify execution dependency handling
authorConnor Abbott <cwabbott0@gmail.com>
Fri, 14 Jul 2023 15:48:12 +0000 (17:48 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 21 Jul 2023 16:02:50 +0000 (16:02 +0000)
commit847834461e9db39b7c82ff0b3b23082e7882a08f
treeeb911fb0057c73a55b34f6e85f0ec3f73fdadb29
parented020942350c6c7a7614c04d1d0f0a78b4f84aed
tu: Fix and simplify execution dependency handling

When I wrote this code, I was under the impression that at most one
context from each cluster could be executing at a time. This would mean
that we could treat clusters as pipeline stages and only insert a WFI if
there was a bubble where an earlier stage depends on the result of a
later stage.

This mental model was wrong, though. Experiments on a6xx show it's
possible for two contexts to be executing simultaneously, even though
there are only two contexts - register writing is just stalled until the
earliest-launched context finishes.

This means that the mental model is now much simpler. Any draw can, in
theory, execute in parallel with any previous draw, blit, flush, etc,
although it seems that flushes do wait for any earlier work to finish.
Clusters are mostly just an implementation detail that only matter in
some corner cases, like setting a non-context register (written in the
last cluster) that is used by an earlier cluster that can race ahead of
the write.

An example where this makes a difference is a fragment shader that
writes an image via stib followed by a blit from that same image.
Because both operations happen in the same cluster and use the same
cache, we wouldn't emit anything in the barrier, however actually we
still need to WFI.

This was getting worse on a7xx because later clusters now have 4
contexts, making it easier for draws to be executed in parallel. However
AFAICT it was already a problem on a6xx.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24162>
src/freedreno/vulkan/tu_cmd_buffer.cc
src/freedreno/vulkan/tu_cmd_buffer.h