Skip to content

pvr/g5p: wait before a vertex realign copy only for GPU-written sources - #50

Merged
henrikklee merged 3 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-realign-drains
Dec 4, 2026
Merged

henrikklee merged 3 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-realign-drains

Conversation

@brkosebay

Copy link
Copy Markdown
Contributor

On the A9, a draw with an unaligned vertex binding gets a CPU realign copy at submission. Before the copy, the submission waited for the GPU queue to drain whenever the source buffer had storage, storage-texel or transform feedback usage. Zink creates every buffer with STORAGE_BUFFER usage, so every realigned binding under Zink counted as GPU-written, even CPU-filled vertex data. Firefox's WebRender on YouTube's home page drained the queue 17.7 times per frame, 35 ms of waiting per frame.

  • Mark every buffer the G5P GPU writes with g9p_gpu_written: transform feedback and counter buffers, vkCmdCopyQueryPoolResults destinations (a compute kernel on G5P), and the A7's compute-run transfers.
  • Wait only for GPU-written sources: test that flag alone, as G9P does. G9P_WAITLOG also logs each realigned binding and whether it waits.
  • Read the flag again at submission (G5P and G9P): a buffer first bound for GPU writes after the draw was recorded, in an earlier submitted command buffer, used to set the flag too late, and the copy could skip a needed wait. The realign record now keeps the source buffer and tests it in g9p_realign_needs_wait().

Tested on the iPad 5 (j71t) with this exact series, installed since 2026-12-03. Firefox scroll, before → after:

page fps drains per frame
YouTube home 14.3 → 19.7 17.7 → 0
Amazon 9.9 → 11.2 10.2 → 0
Wikipedia 58.4 → 59.1 2.6 → 0

The after column was measured on the newer kernel too, so part of the fps gain may come from it; the drain count is this series alone. Built on this head (Vulkan imagination with asserts on); the G5P meson host tests pass, 9/9.

How to test

On a stock Orchard install with Mesa built from this branch:

G9P_WAITLOG=1 firefox https://www.youtube.com/ 2>&1 | grep -c 'wait realign'   # scroll the page; ~0 waits
glmark2-es2-wayland -b build:duration=10        # unchanged

Expected on the iPad 5: no realign queue drains while scrolling, and higher scroll fps on heavy pages. A10: the submit-time re-read is in the shared G9P realign code, so it is enabled on the A10 and closes the same late-flag case there. Untested on our side.

… A7 transfers

g9p_gpu_written tells the realign copy of an unaligned vertex binding
(g5p_realign_binding()) whether it must wait for the jobs before it.
On G5P only the storage and texel buffer descriptors set it, so the
realign check also tested the buffer's usage flags to stay safe.

Set it on every other path where the GPU writes an app buffer on G5P:

 - transform feedback buffers and counter buffers, as the G9P bind does;
 - the destination of vkCmdCopyQueryPoolResults, which G5P runs as a
   compute kernel (pvr_arch_g5p_query.c), not on the CPU;
 - the destination of the A7's buffer copies, fills, updates and image
   to buffer copies, which run as compute jobs (pvr_arch_g3_compute.c).
   By default (PVR_G3_GFX=tri) the A7 draws through upstream's Rogue
   path; it reaches g5p_cmd_draw() and the realign copy when
   PVR_G3_GFX names another path (e.g. ta).

The A8/A9 transfers run on the CPU at submission, in queue order, after
waiting for every earlier job, so they need no flag.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
g5p_realign_binding() treated a source as GPU-written when its buffer
had storage, storage texel or transform feedback usage. Zink creates
every buffer with VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, so every realigned
binding under Zink counted as GPU-written, even CPU-filled vertex and
instance data. The submission of each such render then waited on the CPU
for the GPU queue to drain (pvr_arch_queue.c, "wait realign"). Firefox's
WebRender on YouTube's home page did this about 18 times per frame.

Every path where the G5P GPU writes an app buffer now sets
g9p_gpu_written, so test that flag alone, as G9P does.

Under G9P_WAITLOG, also log each realigned binding: why it is copied
(unaligned address or stride, or a fetch overread past the mapping), its
address, stride, size and whether the copy waits.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…ssion

The realign copy of an unaligned vertex binding runs on the CPU when its
job is submitted, and waits for the jobs before it only when the source
buffer may have been written by the GPU (g9p_gpu_written). The flag was
sampled when the draw was recorded. A buffer first bound for GPU writes
(storage descriptor, transform feedback, ...) after that, in a command
buffer submitted before the draw's, set the flag too late: the copy
skipped the wait and could read the buffer before the writer finished.
G5P's former usage-flag test covered this case; G9P never did.

Keep the source buffer in struct g9p_realign and test its flag again in
g9p_realign_needs_wait(), on G9P and G5P. The pointer is valid there:
destroying a buffer a command buffer uses makes that command buffer
invalid, an invalid command buffer cannot be submitted, and a pending
one keeps its buffers alive until it completes. The realign copy already
reads the buffer's memory at the same point.

Known limits, unchanged:
 - memory aliasing: another VkBuffer or a linear image bound to the
   same memory as a GPU-written buffer does not set this buffer's flag;
 - a secondary command buffer copies its realigned bindings when it is
   recorded, without waiting for any job.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants