Skip to content

pvr/g5p: reuse command stream blocks and job syncs, cache imported dma-buf mappings - #47

Merged
henrikklee merged 5 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-desk-overhead
Dec 4, 2026
Merged

henrikklee merged 5 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-desk-overhead

Conversation

@brkosebay

Copy link
Copy Markdown
Contributor

Cuts the CPU and kernel work around each A9 submission. The GPU work stays the same.

  • Winsys stamps, batched syncobj resets, a kept null-job merge syncobj: the optional winsys ops that the reuse below needs. A job can signal a point of a per-queue timeline syncobj within its own SUBMIT_JOBS ioctl, so there is no extra kernel call.
  • Command stream block reuse and pooled job syncs (G5P): every submission used to create, CPU-map and GPU-map a 4 KiB BO per command stream block, then unmap and close it at reset. That was 7 kernel calls per block, and every GPU unmap on the A9 also drops the translations of every loaded VM slot. Blocks now return to a pool once the queue's timeline shows their jobs complete, never at the application's reset, as IOGPU does on iOS. Job syncs are pooled and reset 32 at a time.
  • FloatControls2: accept the SPIR-V capability that Zink declares, which removes the warning spirv_to_nir printed for every such shader.
  • Query-only physical-device winsys (A9 and A10): physical-device enumeration no longer creates a VM.
  • Imported dma-buf mapping cache (all chips): an import of the same dma-buf (Zink, VA-API surface pools) reuses one GPU VM mapping per GEM handle instead of a VM_MAP/VM_UNMAP per bind. A bounded LRU keeps 32 entries / 64 MiB, and the cache is flushed on VA exhaustion and at teardown.

Tested on the iPad 5 (j71t), installed since 2026-12-02 (offscreen glmark2 1536×2048, build/texture/terrain 20 s each, two runs per arm):

score build / texture / terrain fps BO create/s VM map/s GPU ms per fragment job
stock 209, 207 318 / 296 / 17 364 364 2.13
this, PVR_G5P_REUSE=0 209, 209 318 / 296 / 17 366 367 2.13
this 224, 222 342 / 312 / 18 12 12.6 2.13

That is −97 % BO creates and maps per second and +6.7 % glmark2 at the same GPU time per job: the gain is CPU and kernel overhead. The desktop (Labwc, Firefox, the shell) has run on it since then. Offline (Dolphin FIFO replays), steady-state ioctls per frame went from 140 to 44 (Mario Kart Wii) and from 583 to 100.

Built on this head (Vulkan imagination with asserts on, and the Zink GL build); the G5P meson host tests pass, 9/9.

How to test

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

glmark2-es2-wayland --off-screen -b build:duration=20 -b texture:duration=20 -b terrain:duration=20
PVR_G5P_REUSE=0 glmark2-es2-wayland --off-screen -b build:duration=20 -b texture:duration=20 -b terrain:duration=20   # A/B: reuse off
PVR_G5P_REUSE_STATS=1 vkcube --c 600     # prints the reuse counts at device destruction
PVR_IMPORT_CACHE=0 mpv --hwdec=vaapi <video>   # A/B for the import cache

Expected on the iPad 5: about +7 % glmark2 with reuse on, the same score with PVR_G5P_REUSE=0, and a few BO creates per second instead of hundreds. A10: block reuse is off on G9P (A10) and its behaviour is unchanged. The query-only physical device and the import cache are enabled there too, untested on our side.

…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>
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