Skip to content

Mali: the GPU-progress waiter thread on by default - #466

Merged
mamcjr merged 2 commits into
mamcjr:mainfrom
maxi000q:mali-waiter
Nov 27, 2026
Merged

mamcjr merged 2 commits into
mamcjr:mainfrom
maxi000q:mali-waiter

Conversation

@maxi000q

@maxi000q maxi000q commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Reading the timeline's value on ARM's Mali driver blocks in the kernel until the GPU has caught up with everything submitted - the same stall Turnip over KGSL had (the comment over seq_waiter, 2026-11-13): without the waiter thread, every read of vk_completed_seq (vk_collect_dead, the ring, the caches - once a submission or more) stopped the render thread until the GPU finished, so the render thread and the GPU never worked at the same time.

This turns the existing waiter thread on for Mali (device.c vk_driver_is_mali: VK_DRIVER_ID_ARM_PROPRIETARY, or the 0x13B5 vendor id - Xclipse reports Mesa's driverID, so the vendor id is what catches it). Nothing else: the per-submission fences, the "don't signal the timeline" path (LARECOMP_SEQ_NO_TIMELINE) and the low-RAM / Turnip defaults are exactly what main has.

Measurements

On the device this was tuned on - Helio G95, Mali-G76:

  • Without the waiter (main's behaviour on Mali): the render thread spent half of its on-CPU time blocked in vkGetSemaphoreCounterValue on the timeline - simpleperf --trace-offcpu, 2026-11-15. The world (BotW's overworld around the Great Plateau) ran at 14-15 fps.
  • With the waiter thread on fences (this PR): the render thread's block is a few percent, the render thread and the GPU overlap, and the same scenes run at 23-26 fps - ~1.7x.
  • For scale on the same code: the Turnip phones that made main's fence path (Galaxy Tab A9+) went 14.8 -> 19.7 fps with the same change, per the comment in exec.c.

LARECOMP_SEQ_THREAD=0 restores the stock behaviour; the log line ([vk] GPU progress: ...) says which one ran, so a report from any Mali phone says whether it applied.

Where it touches

  • runtime/nvn/vulkan/device.c - vk_driver_is_mali(), same shape as the Turnip/RADV ones beside it.
  • runtime/nvn/vulkan/exec.c - the default in seq_thread_on gains vk_driver_is_mali(); the comment block above it says what the Mali stall is and where the numbers come from.

Redone on current main as asked (PR #417's version was on the 0.4.1 fork: it rewrote that whole spot; main has since moved it to Turnip + per-submission fences, and Mali slots into that).

Reading the timeline's value on ARM's Mali driver blocks in the kernel until the
GPU has caught up with everything submitted, the same stall Turnip over KGSL had
(exec.c's comment there, 2026-11-13): without the waiter thread, every read of
vk_completed_seq (vk_collect_dead, the ring, the caches - once a submission or
more) stopped the render thread until the GPU finished.

On a Helio G95's Mali-G76 (Redmi Note 9 Pro, 8 GB) that was half the render
thread's time in the world (simpleperf --trace-offcpu, 2026-11-15). With the
waiter thread and its per-submission fences on: the render thread and the GPU
work at the same time, and nothing else reads the timeline, so it isn't
signalled either (LARECOMP_SEQ_NO_TIMELINE).

The default only gains Mali (device.c vk_driver_is_mali: driverID
VK_DRIVER_ID_ARM_PROPRIETARY, or the 0x13B5 vendor id - Xclipse reports Mesa's
driverID, so the vendor id is what catches it); Turnip and low RAM as before.
LARECOMP_SEQ_THREAD=0 restores the stock behavior.
@mamcjr

mamcjr commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks! Only the default changes, and Mali phones with 4 GB or less already run this path, so I'm fine with it. Could you add the [vk] GPU progress: log line from your G76, and if you can, a power comparison (LARECOMP_LOG_POWER=1, off the charger)? A second Mali on a newer driver would be great but isn't required. Small note: the vendor-id check catches PanVK (Mesa on Mali, vendor 0x13B5), not Xclipse.

@maxi000q

maxi000q commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Right you are, it's PanVK not Xclipse: the vendor id is ARM's, and Xclipse reports AMD's (0x1002, RADV's driverID), so the vendor-id catch was never about it. The PR text claimed it was; that sentence and the comment in device.c are corrected now (1eed901). The vendor id is the fallback for an old driver reporting a driverID of 0, it catching PanVK too is harmless (the waiter is only a thread, and Mesa's timeline is the emulated one the Turnip default already runs on), and Xclipse is neither and isn't meant to be caught.

@mamcjr

mamcjr commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks for fixing the note. The code is fine; I'll merge it once the [vk] GPU progress: line from your G76 and, if you can, the power comparison are here.

@maxi000q

maxi000q commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you. The PR text and the device.c comment were the whole of 1eed901, so the diff is just the waiter itself, as it was.

@mamcjr mamcjr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This merges cleanly as text but doesn't compile: main already has bool vk_driver_is_mali(void) (device.c, declared in vk.h), and this PR adds a second definition, so the merged device.c fails with a redefinition. Could you drop the device.c part and keep only the one line in exec.c (seq_thread_on)? Main's version is also the safer one: it only takes vendor 0x13B5 when driverID == 0, so PanVK isn't caught, and the PanVK comment can go.

Still missing from my last comment: the [vk] GPU progress: line from the G76 and the power numbers (LARECOMP_LOG_POWER=1). On Turnip nothing changes, since vk_driver_is_turnip() is already true there.

@mamcjr
mamcjr merged commit e0aeeca into mamcjr:main Nov 27, 2026
mamcjr added a commit that referenced this pull request Nov 27, 2026
main's own (8bb3c02) is kept: ARM's driver, or Mali's vendor id only when the
driver id is unset - so PanVK isn't counted as Mali. The waiter thread's default
(exec.c seq_thread_on) uses it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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