Skip to content

drm/asahi: g16: lease a TA/FS render queue pair to each rendering VM - #3355

Open
DjDeveloperr wants to merge 7 commits into
fix/g16-3349-compute-service-stampfrom
perf/g16-render-pairs-on-3201
Open

DjDeveloperr wants to merge 7 commits into
fix/g16-3349-compute-service-stampfrom
perf/g16-render-pairs-on-3201

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3370 (which is on #3353). The four implementation commits are followed by the merge of #3370 and two cleanup commits.

What: on the g16 backend, each VM that renders leases its own firmware TA/FS queue pair, the way compute already leases per-VM workqueues (62e450e). Renders of different VMs overlap again without sharing one queue.

  • Why:
  • macOS:
    • A hypervisor capture of Metal render.light procs with 2 and 4 processes, on macOS 26B123 on the J773g, shows every process with its own TA queue and FS queue, each with its own job-list entry.
    • All processes ring the same doorbell, and the firmware chooses among the queues.
    • This change gives each VM its own pair the same way, behind the same doorbells.

Design:

  1. Events through RenderRefs. A render's completion events travel in RenderRefs. Pair p uses TA 0x70 + 2p and FS 0x71 + 2p. Pair 0 keeps 0x70/0x71, so the render goldens don't change.
  2. Per-pair queue state, with one pair.
    • Graphs, stamps, targets, heads, registration, retirement, progress and recovery blame become per pair.
    • This commit sets RENDER_PAIRS = 1 and changes no behaviour.
  3. Displacement in publication order.
    • A PB slot or pass slot goes to another owner only after a render published after the owner's last render has retired.
    • This used to be "the last retirement observed", which only held while renders retired in order on one queue.
  4. Eight pairs, leased per VM.
    • Lease: a VM keeps its pair while any of its renders are in flight. Otherwise it takes its last pair if free, else the lowest free one.
    • Same-pair rule: two VMs' renders are never in flight on one pair at the same time. Admission and publication both check this; it's the linux#3201 rule.
    • Handoff: when every pair holds another VM's renders, the pair with the fewest passes in flight drains for the waiting VM while the others keep running.
    • Stage order: a render's first pass waits for the TA and FS of the newest render in flight on another pair. Renders reach the TA and FS engines in publication order across pairs, and one VM's TA still overlaps another VM's FS. The FINALIZE stamp orders each engine across pairs. Cross-VM data dependencies wait on host fences through producer retirement.
    • Unchanged: a render beside another VM's compute still drains, both ways, and so does any InitBM flight.
    • Firmware registration: pairs register with the firmware on their first record.
    • Stats: a render_pairs: line counts publications per pair and cross-pair overlaps.
  • With drm/asahi: g16: wait for the service stamp in cross-engine barriers #3370:
    • A compute's barrier on a render waits on the FS service stamp of the waited render's pair.
    • Retirement reads each pair's TA and FS service stamps through that pair's accessors.
    • Waits between processes never resolve in firmware: a fence from another VM, or one without a g16 origin, is waited on the host, and g16 job fences signal only at retirement on the service stamps.

Tested: J773g (M4 Mac mini, macOS 26B123 firmware), on a69f447171c8. Since that boot, a67f388a9ae4 clarifies stage order and cross-VM drains, removes an unused receipt helper, checks its two live components directly in the host fixture, and compiles a single-pipe convenience method only in tests. The executed driver paths are identical.

  • Cost against Metal: µs per submit, lower is better. Each kernel was measured on its own boot, median of 2 passes, with 0 GPU faults on every boot. Metal 4 values are native macOS 26B123.

    Row Base: drm/asahi: g16: keep renders of a multisampling VM apart from other VMs #3180 + drm/asahi: g16: drop the M4 TA wave window #3185 drm/asahi: g16: drain the engine before a render of another VM #3353 (+ drm/asahi: g16: wait for the service stamp in cross-engine barriers #3370) This PR Metal 4 Base / Metal drm/asahi: g16: drain the engine before a render of another VM #3353 / Metal This PR / Metal
    render.light procs d2 99.1 127.1 108.5 169.38 1.71× 1.33× 1.56×
    render.light procs d4 81.2 128.3 93.2 104.47 1.29× 0.81× 1.12×
    render.light procs d8 72.6 127.6 89.7 97.81 1.35× 0.77× 1.09×
    render.light procs d16 68.5 128.6 89.0 94.84 1.38× 0.74× 1.07×
    render.postfx 1080p msaa4 procs d1 766.3 757.6 766.6 no row
    render.postfx 1080p msaa4 procs d2 717.7 707.6 723.8 no row
    render.postfx 1080p msaa4 procs d4 1,967.2 1,941.8 735.7 no row
    render.light queue d4 (one process) 78.0 77.7 79.3 72.67 0.93× 0.94× 0.92×
    render.light queue d16 (one process) 58.3 57.2 58.4 48.29 0.83× 0.84× 0.83×
    • render.light procs is back above Metal at every depth.
    • postfx procs d4 is 2.6× faster than the base, because multisampled VMs no longer drain each other.
    • Single-process rows don't change.
    • All 8 pairs carried renders (publications 101,583 / 86,971 / 28,735 / 27,879 / 11,265 / 15,989 / 9,040 / 8,089), with 181,301 cross-pair overlaps and no cross-VM drain.
    • The base is faster than this PR from d4 on, but it is the shared-pair overlap that faults (linux#3201).
  • Correctness under CPU load, with 2 busy loops beside every list, one boot:

    List Workers Result
    dEQP-VK.synchronization*multi_queue* 3 8,538 pass, 0 fail
    dEQP-VK.synchronization*.cross_instance.* (two VMs, so cross-pair waits; 11,384 dma_buf cases) 2 20,008 pass, 0 fail
    api.copy_and_blit blit_image RGBA8/BGRA8 8 3,324 pass, 0 fail
    dEQP-VK.synchronization*.implicit.* 3 1,024 pass, 0 fail
    drm/asahi: g16: keep renders of a multisampling VM apart from other VMs #3180's MSAA hot list, 30 s 4 5,280 results, 0 non-pass

    0 GPU faults on the boot.

  • J516s (M3 Pro, G15S) on a69f447171c8, two passes with Mesa 69179743d9ae. Compared with drm/asahi: g16: wait for the service stamp in cross-engine barriers #3370, render.light procs d4 went from 119.9 to 66.7 µs and d16 from 126.5 to 61.5 µs. The 1440p MSAA1 postfx procs d4 row went from 2,547.8 to 1,290.3 µs. All eight render pairs carried work. The multi-queue, cross-instance and implicit synchronization lists recorded 29,484, 20,008 and 1,024 passes respectively, with zero failures.

  • Host: at a67f388a9ae4, all 26 asahi-m4 host selftest files passed. Strict checkpatch reported zero errors, warnings and checks on the complete diff against drm/asahi: g16: wait for the service stamp in cross-engine barriers #3370.

Risk: two-way · M4 and M3 Macs on the g16 backend.

  • Scope: render admission and publication on the g16 backend: M4, and the M3 parts on the 26B123 protocol.
  • Main unknowns:
    • Pairs 2–7 on the firmware. On the J773g they ran the rows above.
    • Cross-pair stage-order waits, which compute already does across pipes.

Not yet:

  • Long multi-process stress on the final J516s head.
  • A suspend/resume row on this head and a row on a second M4 chip.
  • The rest of the gap to the shared-pair overlap: 1.07–1.12× Metal against 1.29–1.38×.

The TA and FS work images, the scene's own-TA wait and the FS finalize
name the render queue's completion events. They were the literals 0x70
and 0x71 of the one TA/FS queue pair. Take them from RenderRefs::event
instead, filled from work::render_pair::events(pair), which gives pair p
the events 0x70 + 2p and 0x71 + 2p. The block 0x70..0x80 is bits 16..32
of type-1 event word 4, so it can name up to eight pairs.

Every render still uses pair 0, so the encoded images are byte-identical
and the render goldens are unchanged.

Signed-off-by: DjDeveloperr <[email protected]>
Give the render side the structure the compute pipes got in 62e450e,
so later renders can use more than one firmware TA/FS queue pair.
RENDER_PAIRS stays 1 here, and every render still uses pair 0.

- Graphs::render holds RENDER_PAIRS render graphs. Each pair has its
  own TA and FS qinfo, qstate, work ring, job list, stamps, notifier
  page and threshold. sched_ctx is shared, and the context still
  registers once, through pair 0's TA queue.
- Pair p completes with events 0x70 + 2p and 0x71 + 2p.
  Events::drain decodes them from word 4. The stage cells (event times
  and the recovery snapshot) keep pair 0 at 0/1 and put pairs 1.. after
  the compute pipes. RetiredStamps keeps a TA and an FS history per
  pair.
- Each pair numbers its stamps and thresholds with its own dense draw
  ordinal. The UMA counters and the work UUID keep the global one.
- The engine keeps TA/FS targets, heads and registered flags per pair.
  A flight records its pair, and an fs2c barrier waits on the waited
  render's pair.
- Retirement takes the oldest render flight of each pair. A later
  flight on the same pair makes the queue and stamp proof a "passed"
  one. Any other render flight or later record makes the proof on the
  shared TA/FS submit channels a "passed" one.
- Progress is sampled per pair and renews the one render deadline.
- Recovery maps a snapshot event to its pair and blames only that
  pair's flights, since dense per-pair stamps collide across pairs.

With one pair every value and image is as before; the host suite
covers the per-pair paths with two pairs in its mocks.

Signed-off-by: DjDeveloperr <[email protected]>
A PB/UMA allocator slot or render pass slot passes to another owner
only once it is displaced. After its last render retires, a slot stays
the TA and FS engines' current one until they run a render of another
slot. Both ledgers inferred that from the order in which retirements
were observed: the PB pool from the last cleanly retired slot, and the
pass ledger from a later publication retired on the same queue. That
holds while every render runs on one TA/FS queue pair, because the pair
retires in publication order.

Renders on different queue pairs are observed retiring out of
publication order, so the observed order says nothing about which
render the engines ran last. Decide by the publication sequence
instead:

- Pools::publish_flight returns the render's sequence, and
  retire_flight takes it back. A clean retirement displaces every other
  slot whose newest render was published before it.
- The render pass ledger has ordered pipes: a later publication that
  retired displaces an owner whatever pair it ran on. Each pair still
  retires its own owners in order, and pass slots are published on
  their flight's pair. The compute ledger keeps per-pipe displacement.

This relies on renders running on the TA and FS engines in publication
order. With the one pair in use, both rules decide exactly as before.

Signed-off-by: DjDeveloperr <[email protected]>
Every VM's renders shared one firmware TA/FS queue pair. While two VMs'
passes are published on one pair, the GPU faults in the one whose pass
runs (linux#3201), so a render of another VM drained the engine first
(8722b2e). That serialized multi-process rendering: gpubench
render.light with 2 to 16 processes took about 127 µs per frame against
Metal's 104 µs. macOS 26B123 gives every Metal process its own TA and FS
queue, each with its own job-list entry, all rung through one doorbell.

Lease one of RENDER_PAIRS = 8 pairs to each rendering VM instead. The
completion-event block 0x70..0x80 names eight pairs, so a compositor and
seven clients render without a handoff. Each pair costs fourteen 16 KiB
pages at probe. A pair registers with the firmware on its first record,
and a VM takes the lowest free pair, so unused pairs stay unregistered.

- Leasing. A VM keeps the pair of its renders in flight, so its render
  waits never leave one in-order pair. Otherwise it takes its last pair
  if free, else the lowest free pair. Two VMs' renders are never in
  flight on one pair (cross_vm_render_conflict).
- Handoff. When every pair holds another VM's renders, the pair with
  the fewest passes in flight drains for the waiting render, as
  compute_handoff_pipe drains a compute pipe, and the other pairs keep
  running. This replaces the full engine drain.
- Render vs another VM's compute still drains, in both directions, and
  so does any InitBM flight.
- Stage order. A prefix's first pass waits for the TA and FS of the
  newest render in flight when that render is on another pair. Renders
  so reach the TA and FS engines in publication order, as on one pair,
  which the PB and pass slot displacement proofs rely on. That render's
  completion implies every earlier one's, so these waits take the place
  of the pair's own prev_barrier and fs_dep, and a pass still takes at
  most MAX_RENDER_RING_ENTRIES entries per ring. One VM's TA still
  overlaps another VM's FS. Since a pair can wait on another, the pairs
  keep one render deadline.
- Shared submit channels. Like the compute pipes on Channel::Compute,
  TA/FS channel receipts are latched before another pair's records can
  lap a long flight, and no record is posted that would lap an unlatched
  one.
- aurora-g16/stats gains "render_pairs: publications <per pair>
  cross_pair <n>": the renders published on each pair, and those
  published while another VM's renders were in flight on another pair.

A prototype with two pairs and per-VM pairs ran on the J773g with no GPU
fault or recovery. render.light procs d2/d4/d8/d16 went from 126.9,
126.6, 127.4 and 128.8 µs to 105.6, 100.9, 102.4 and 102.7 µs; single-VM
rows were unchanged. The stage-order barriers and the eight pairs are
new here.

Signed-off-by: DjDeveloperr <[email protected]>
…r-pairs-on-3201

Stack this series on #3370 (linux#3349: cross-engine barriers wait on the
producer's service stamp, one accessor per service-stamp cell).

With per-VM render pairs every pair has its own render graph, so a
compute's barrier on a render waits on the FS service stamp of the
waited render's pair, and retirement reads each pair's TA and FS
service stamps through that pair's accessors.

Signed-off-by: DjDeveloperr <[email protected]>
The comment over the render barriers said G16 FINALIZE flushes producer
caches before fw_stamp advances. linux#3349 showed that it does not make
a producer's writes visible to another firmware queue, and the merged
service-stamp change makes every cross-engine wait use the service stamp.
The render->render waits that stay on fw_stamp only order the TA and FS
engines across pairs, which is what the displacement proofs need.

Comment only.

Signed-off-by: DjDeveloperr <[email protected]>
Document the visibility boundary of the stage-order waits and remove
the unused aggregate receipt check. The active retirement path checks
the rings and channels separately.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr changed the base branch from fix/g16-3201-cross-vm-render-drain to fix/g16-3349-compute-service-stamp November 27, 2026 19:55
@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 27, 2026 19:55
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 19:55
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro, G15S) at a69f447171c8ebd5fb00ee3ffd97f252265edb60. The PR advanced two commits to a67f388a9ae43066288a9e3022565f9c6739033a during stress testing. All hardware measurements below are from the earlier SHA.

Per-VM render pairs recovered most of the cross-process render cost on this Mac. The exact-head kernel booted with zero failed units. The two timing passes used the same native gpubench-vk binary and isolated Mesa 69179743d9ae as the earlier rows.

Median µs per submit across two passes, lower is faster.

Workload Before #3353 #3353 #3370 This head
render.light procs d4 63.5 119.0 119.9 66.7
render.light procs d16 45.2 136.5 126.5 61.5
postfx procs d4, 1440p MSAA1 1,286 2,564.1 2,547.8 1,290.3
render.light queue d4 51.8 51.4 51.5 51.3

On this head, 1080p MSAA4 postfx procs d1/2/4 measured 998.8 / 732.6 / 799.2 µs. The remaining render.light procs depths d2/8 measured 79.5 / 61.8 µs, queue d16 measured 38.3 µs, and compute.light procs d4/16 measured 30.6 / 27.8 µs. All eight render pairs carried work. Effective clocks reached S8 (1,380 MHz) in 1,766 of 1,913 busy samples. Earlier #3353 row · Earlier #3370 row

With one CTS worker and two busy CPU loops, all 238,015 case executions completed. Each of the three multi-queue runs had 29,484 pass and 7,089 unsupported. Each of the two cross-instance runs had 20,008 pass and 42,604 unsupported. All 1,024 implicit cases passed on each of three runs. Zero failures or missing results.

The concurrent render.light procs d16 and 1080p MSAA4 postfx procs d4 stress ran 603 seconds. Each completed 138 runs, all 276 returned valid results, and their under-load medians were 367.8 and 4,705.9 µs per submit. The candidate boot recorded zero GPU faults, SErrors, recoveries, or hang kills across timing, CTS, and stress.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at a67f388a: not ready yet

Check Detail
CI at head ok 3 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at a67f388a
Conflicts ok none
PR text ok Risk: two-way · M4 and M3 Macs on the g16 backend. - Scope: render admission and publication on the g16 backend: M4, and the M3 parts on the 26B123 protocol. - Main unknowns: - Pairs 2–7 on the firmware. On the J773g they ran the rows above. - Cross-pair stage-order waits, which compute already does across pipes.

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded 12-01: not a hold under the merge bar (no shown failure). Full diff review deferred; follow-ups: land #3370/#3353/#3185, retarget, main CI

Verdict: HOLD at a67f388a

Blockers:

  1. Targets open non-main base branch fix/g16-3349-compute-service-stamp (#3370, stacked on #3353 and #3185); full main CI has not run.

Checked:

  • Verified #3370, #3353, and #3185 are still OPEN.
  • Deferred full diff review until parent PRs land and this PR is retargeted onto main with green CI.
Evidence
  • Base ref: fix/g16-3349-compute-service-stamp (#3370 state: OPEN).

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant