Repository navigation
pvr/g5p: clear fold: skip clear-only renders a later render overwrites (on #53) - #54
Conversation
…rge syncobj The powervr winsys gains what G5P submit reuse (next commit) needs, all optional winsys ops: - struct pvr_winsys_stamp on the render and compute submit infos: a job that carries one also signals that point of a timeline syncobj, as one more sync op of the same SUBMIT_JOBS ioctl (no extra kernel call). A render puts it on its last job (fragment, else partial render, else geometry). stamp_create/stamp_destroy/stamp_query make and read such a timeline (drmSyncobjQuery: the point up to which it has signalled). - syncs_reset: returns job syncs of the device's type to the state vk_sync_create(..., 0) leaves them in (no fence, no job tag), in one DRM_IOCTL_SYNCOBJ_RESET for all of them. - A null job with waits merged them through a syncobj created and destroyed per job. On G5P it now keeps those: reset four or more together, then reused (pvr_drm_tmp_syncobj_get/put). PVR_G5P_REUSE=0 turns the kept merge syncobj off (pvr_g5p_reuse_option(), read at winsys creation). Other GPUs and pvrsrvkm: unchanged. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…pool job syncs Each vkQueueSubmit on the A9 created, CPU-mapped and GPU-mapped a 4 KiB BO per command stream block while recording, and unmapped and closed it at the command buffer's reset: 7 kernel calls per block, about 14 blocks per frame in Dolphin's Mario Kart Wii and 58 in fifolog_missing_bridge. Each GPU unmap on the A9 also moves the MMU tag of every loaded VM slot, so the next job of every client starts with its translations dropped. Every job also created and destroyed its syncobjs. Apple (iOS 16 IOGPU.framework) takes command buffer storage from a device-wide pool (IOGPUMetalCommandBufferStoragePoolCreateStorage) and returns it from the completion handler (-[IOGPUMetalCommandBuffer didCompleteWithStartTime:endTime:error:] -> IOGPUMetalCommandBufferStorageDealloc -> StorageReset + StoragePoolReturnStorage): reuse follows GPU completion, never the application's reset. pvr_g5p_reuse.c does the same: - Stamps: each queue owns a timeline syncobj; every render, compute and query job signals its next point within its own submission. A command buffer records, per queue, the last point issued when it was submitted. - Command stream blocks: a primary command buffer's blocks, at its reset or free, go pending with those points; they become free only once one query of the queues' timelines shows every point reached (blocks of a never-submitted buffer are free at once). A recording takes a free block, zeroed so the GPU sees what a new BO holds, or allocates a new one: reuse never waits. Free + pending is capped at 512 blocks; pending ones are kept whatever the count. Secondary command buffers keep the plain free. - Syncs: the queue's job, wait and barrier syncs go to a pool when they were destroyed before and are reset 32 at a time (one ioctl). Event syncs, owned by VkEvent, are unchanged. So a block is never rewritten while a job may read it, even when an application resets a pending command buffer. PVR_G5P_REUSE=0 turns all of it off for a same-boot A/B; PVR_G5P_REUSE_STATS=1 prints the counts at device destruction. Other GPUs (G9P/A10, Rogue): reuse is off, behaviour unchanged. Offline (fakepvr, Dolphin FIFO replays, steady state per frame): Mario Kart Wii 140 -> 44 ioctls, fifolog_missing_bridge 583 -> 100; BO create, map, unmap and close go from 14 and 57.5 per frame to 0. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Zink passes SPIR-V that declares FloatControls2, and spirv_to_nir warned about the unsupported capability for every such shader. spirv_to_nir already translates its execution modes, so accept it. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Physical-device initialization on the A9 and A10 needs only DRM device queries, the fd, the page size and the sync type, but it created a full winsys with its own VM. Make that winsys query-only. The logical device still creates the VM and uses its own winsys for heaps and static memory. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Each dma-buf import through Zink (e.g. hardware video frames from a fixed VA-API surface pool) creates a VkDeviceMemory via DRM_IOCTL_PRIME_FD_TO_HANDLE and binds it via pvr_bind_memory(). Even though the kernel returns the same GEM handle for the same dma-buf within one DRM file, pvr_bind_memory() always allocated a new GPU VA range and issued DRM_IOCTL_PVR_VM_MAP on bind and DRM_IOCTL_PVR_VM_UNMAP on unbind, invalidating GPU address translations on every frame. Cache one whole-BO GPU VM mapping per imported GEM handle in the powervr DRM winsys (general for all chips): - Add an optional winsys op vma_map_imported() used by pvr_bind_memory() when mem->vk.import_handle_type != 0. - Key the cached whole-BO mapping by GEM handle via drm_bo->import_vma. Each binding gets its own view VMA covering its (offset, size) slice so different offsets/sizes (such as multi-plane NV12) share one mapping without extra VM_MAP ioctls, while keeping distinct VMA pointers for g9p_vmas tracking. - Reference-count active bindings; when the last binding unmaps, keep the mapping (and its BO reference, so the kernel retains the GEM handle) in a bounded LRU (32 entries / 64 MiB) so rotating surface pools hit the cache. - Flush LRU entries on general_heap VA exhaustion, VM_MAP failure, and winsys/device teardown; evicting an entry unmaps its GPU VA, frees its VA space, and releases the BO reference (closing the GEM handle once unused). - Add PVR_IMPORT_CACHE=0 (read at winsys creation) to disable the cache for A/B testing. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
One line per recorded render (targets with format, extent, samples, layout, level/layer, load/store ops, resolve; depth/stencil ops and the effective ZLS; draw and clear counts; the drawn area as the union of the draws' scissors and the clear rectangles; draws with an imported or multi-planar image bound; the distinct fragment programs; YCbCr draws; a split-pass flag; the chip's effective background, partial-area and empty-tile choices), one line per job-submit ioctl with CLOCK_MONOTONIC before and after and the render it carries, one per vkQueueSubmit, one per refused render, one per view of an imported or multi-planar image and one per new graphics pipeline. Written to $PVR_PASS_LOG.<pid> (else stderr), one write() per line, none dropped or sampled, so the lines join with the kernel's drm_sched ftrace taken with trace_clock mono. The same records on every chip. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Extend PVR_DEBUG=pass_log with: - per-render vertex count (direct draws) and distinct bound descriptor set sampled-image layout census (tex, lin, lin_pot, lin_big) in P lines; - per-binding masks on pvr_descriptor_set propagated across writes and vkUpdateDescriptorSets copies; - deduplicated T lines logging each sampled image's format, extent, levels, layers, layout, usage and external flag on first descriptor write; - B lines in pvr_process_event_cmd_barrier() logging src/dst stage masks and active wait counts. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
On the A9 almost every render's geometry (TA) job waited for the previous
render's fragment (3D) job: TA -> handoff -> 3D -> handoff -> TA in strict
series. The Vulkan->PVR stage mapping (pvr_stage_mask()) is faithful; the
wide destination comes from the clients' masks (a fragment-written image
sampled next in the fragment shader arrives with VERTEX_SHADER, and wgpu-style
COMPUTE_SHADER, in dstStageMask), plus vkCmdPipelineBarrier2 OR-ing every
barrier's source with every barrier's destination.
PVR_GEOM_PRECISE (G5P: A8/A9; not the A7's tri path, G9P or Rogue):
- 1: per-barrier pairing. The geometry stage waits only for the sources of
barriers whose destination includes it; barriers_needed[GEOM] clears only
those bits.
- 2 (default): also defer an application barrier's FRAG -> GEOM wait to the
queue (pvr_queue::geom_defer). Before each render's geometry job the
deferred wait is taken when the render's geometry stage can observe a
covered fragment job's writes, else carried to the next render; it is
released only when taken or seen signalled. Per resource, by device-address
range, like Metal's hazard tracking:
* a fragment job writes its pass's attachments, or is opaque (fragment
stores/atomics, a non-optimal attachment a buffer may alias, overflow);
* a geometry stage reads the images its vertex program uploads (the G5P
vertex upload list names each set/binding/element; descriptor sets keep
the images of their pre-raster image descriptors), or is opaque (vertex
stores, transform feedback, push or update-after-bind descriptors,
overflow). Buffers need no list: only an opaque fragment job writes one.
Internal barriers (VDM split, stencil store/load, queries, events) keep
their full waits. Secondary command buffers merge their records.
- 0: the old behaviour.
PVR_DEBUG=pass_log: B lines gain gsrc/gdefer/gpending and running
defer/drop/keep/done counters (with keep reasons); new G lines log each
resolution (act=keep|drop|done, why=hit|vs|fs).
On an iPad 5 (A9), Firefox scrolling a YouTube page presents
22.1-23.7 frames per second with the default (three runs) against
17.7-20.9 with PVR_GEOM_PRECISE=0 (two runs).
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
A render that draws nothing (no draw, no vkCmdClearAttachments) is not submitted when a later render in the same vkQueueSubmit batch re-initialises (load op CLEAR or DONT_CARE) every attachment it stores, on the same image, level and layers and over at least its render area, and nothing in between can read what it stored. Each render job costs a firmware round trip (~0.6-1 ms on the A9) even when it only clears; Firefox WebGPU's Carbon records one 1024x656 colour + D32S8 clear-only pass per game frame whose target the next pass clears again. Why the skipped contents cannot be observed: the render has no other side effect (no query, resolve, suspend/resume or split); it leaves its stored attachments in attachment-only layouts, so any shader, transfer or present access first needs an image barrier naming the image (a "taint") or a render pass naming it, either of which stops the fold; images are compared by device-address range (aliases); linear-tiling and external images are never folded; events and secondaries stop it. The decision is made per batch at submit from a per-command-buffer event record, never stored in the command buffer. A folded render is skipped like a refused one: no job, no syncs; earlier barriers keep their waits for the next job. PVR_CLEAR_FOLD=0 turns it off. PVR_DEBUG=pass_log prints a K line per clear-only render (fold=1 by=<pass> or fold=0 why=<reason>), and P lines gain crect= (vkCmdClearAttachments rectangles apart from bbox) and cfirst= (the clear preceded every draw). Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
A barrier's source is the queue's last signal of that stage, so a skipped render must still signal what its jobs would have: Vulkan chains X -> FRAG, FRAG -> Y through the stage even when the render in between does nothing. When barriers left waits for the next geometry or fragment job, null jobs (g5p_merge_syncs(), syncobj transfers, no CPU wait) now stand in for the folded render's jobs: geometry after its waits and the previous geometry job, fragment after that, its waits and the previous fragment job. Without pending waits nothing is submitted. The K line of a fold is printed where it is skipped, with syncs=. A candidate must render exactly one layer (framebuffer layers or layerCount), and an overwriter at least one, so a render over fewer layers can no longer cover it. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
|
A follow-up on the no-op render path this touched. It's on main now, so I'm raising it here before sending anything that edits your lines. The bug: a no-op render ( Where it showed up: on an iPhone 6s, Vulkan
A fix, rebased on main: jeroentrappers/orchard-mesa
Tested on the 6s:
Shall I open it as a PR, or would you rather fold it into your next series (and drop |
Depends on #53 (barrier precision, which itself sits on #47). This branch is #53's eight commits plus two new ones. Please review only the last two:
pvr/g5p: clear fold: skip clear-only renders a later render overwritespvr/g5p: clear fold: keep a folded render's syncs, require one layerThe fold uses #53's pass_log records (its
Klines and the newcrect=/cfirst=fields) and #47's null-job merge syncs and pooled job syncs. It also touches the same submit code as the barrier change, so it is stacked on #53.What
On G5P, every render job costs one firmware round trip (about 0.6–1 ms on the A9), even when the render only clears. Firefox WebGPU games record a clear-only pass every frame: a 1024×656 colour + D32S8 pass with load op CLEAR and no draws. In the same
vkQueueSubmitbatch, the next pass clears that target again.With this change, a render that draws nothing (no draw and no
vkCmdClearAttachments) is not submitted when all of the following hold:Why the skipped contents can't be observed:
The decision is made per batch at submit time from a per-command-buffer event record. Nothing about it is stored in the command buffer, so re-submitting a command buffer stays correct.
When earlier barriers left waits pending, a folded render still signals what its jobs would have signalled. It does this with null jobs (
g5p_merge_syncs(), syncobj transfers, no CPU wait), because a Vulkan barrier chains through the stage even when the render in between does nothing. Without pending waits nothing is submitted.PVR_CLEAR_FOLD=0turns the fold off (it is on by default).PVR_DEBUG=pass_logprints aKline for every clear-only render:K pass=<serial> fold=1 by=<serial> syncs=<n>, orK pass=<serial> fold=0 why=<reason>.Result (iPad 5, A9)
Firefox WebGPU racing game in its garage scene, same kernel and same boot, Firefox relaunched for each arm, 10 s per run. Presents/s is the game's frame rate. 3D ms per present is the fragment firmware busy time divided by presents.
PVR_CLEAR_FOLD=0That is +7 % presents and −5.8 ms of 3D time per present. The game uses automatic render-scale adjustment, which can move between launches, so part of the difference may be noise. The direction matches what the clear-job count predicted.
Workloads without clear-only renders are unchanged by design. In WebRender's YouTube scroll, the 2048² renders all draw (blur and render-task ping-pong), so nothing is folded there.
These runs used our integration Mesa, which carries these commits together with other G5P work that is not upstream yet. The two commits here have the same patch contents as the flown ones (same
git patch-id). This branch builds as an aarch64 package (makepkg in podman).A10
Not enabled. The fold is G5P only (A8 and A9). The A7's G3 path, G9P and Rogue keep submitting every render. G9P merges renders instead, so it doesn't need the fold. The pass_log fields are shared code but do nothing unless
PVR_DEBUG=pass_logis set.How to test
On an A9 (or A8) desktop:
PVR_CLEAR_FOLD=0and compare.PVR_DEBUG=pass_log PVR_PASS_LOG=/var/tmp/pl.grep 'K pass=' /var/tmp/pl.<pid>shows each clear-only render, withfold=1 by=…orfold=0 why=….Expected A9 result: fewer renders per second with the default, a slightly higher frame rate, and identical frame content. On the A10 nothing changes.
🤖 Generated with Claude Code