Repository navigation
pvr/g5p: barrier precision: geometry waits on fragments only on a hazard (on #47) - #53
Merged
henrikklee merged 8 commits intoDec 4, 2026
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>
This was referenced Dec 3, 2026
henrikklee
added a commit
that referenced
this pull request
Dec 4, 2026
pvr/g5p: clear fold: skip clear-only renders a later render overwrites (on #53)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #47 (command stream block reuse and the pooled job syncs). This branch is #47's five commits plus three new ones. Please review only the last three:
pvr: PVR_DEBUG=pass_log, per-render, per-submit and per-pipeline recordsadds diagnostics only. They are off unlessPVR_DEBUG=pass_logis set.pvr: pass_log: per-render vertex count and sampled-image layout censusalso adds diagnostics only, under the same flag.pvr/g5p: barrier precision: geometry waits on fragments only on a hazardis the fix.The fix extends the pass_log records with its own counters, so it sits on the two diagnostics commits.
What
On the A9, almost every render's geometry (TA) job waited for the previous render's fragment (3D) job. TA → handoff → 3D → handoff → TA ran strictly in series.
Our Vulkan → PVR stage mapping is spec-exact. The wide waits come from two places:
vkCmdPipelineBarrier2ORs every barrier's source with every barrier's destination.PVR_GEOM_PRECISEsets the behaviour on G5P (A8 and A9) only:Result (iPad 5, A9)
Firefox scrolling a YouTube page by finger, labwc presented fps, 10 s per run, same kernel:
PVR_GEOM_PRECISEThese runs used our integration Mesa, which carries these commits together with other G5P work that is not upstream yet. The three 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
The A10 is untouched.
pvr_geom_precise_level()returns 0 for anything other than G5P, and for the A7's G3 path, so G9P and Rogue keep the old waits. The pass_log diagnostics are shared code but do nothing unlessPVR_DEBUG=pass_logis set.How to test
On an A9 (or A8) desktop with Firefox:
PVR_GEOM_PRECISE=2is the default.PVR_GEOM_PRECISE=0and scroll again to see the old behaviour.PVR_DEBUG=pass_log PVR_PASS_LOG=/var/tmp/pl. TheGlines in/var/tmp/pl.<pid>show each deferred wait being kept, dropped or completed.Expected A9 result: a higher frame rate with the default, and no rendering differences. On the A10, both settings should behave the same.
🤖 Generated with Claude Code