Skip to content

drm/asahi: g17: allow compute_direct() on mixed render/compute contexts - #3429

Open
DjDeveloperr wants to merge 3 commits into
mainfrom
perf/g17-direct-compute-render-prefix
Open

DjDeveloperr wants to merge 3 commits into
mainfrom
perf/g17-direct-compute-render-prefix

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What:
Let Backend::compute_direct() publish compute commands on mixed render/compute contexts without holding the device mutex across descriptor encoding, cache maintenance and the doorbell.

  • context.rs, queue/render.rs: Context::render_active (AtomicU32) counts live render entries. It goes up just before Pair::publish() pushes an Active entry and down in Drop for Active, which covers retirement, cancellation, quarantine and teardown.
  • Renders parked in Pair::replay after a GPU recovery keep the count up through a ParkedReplay guard built before Active is popped, so compute_direct() never sees zero and skips the replay_parked() / render_prefix() check once publication reopens.
  • runtime.rs: the unconditional render_seen() bailout is gone. check_firmware_producers() runs first. The device lock is skipped when wait_through[0] is empty or no render is active; otherwise it is held only to check lease.is_current(), no pending recovery and no parked replay, and to resolve render_prefix(), then dropped before target_cell is locked and the command published.
  • Host test tools/asahi/g17-direct-compute-render-prefix-tests.py (5 contract mutations, including dropping the count on park). Stack: Backend::compute_direct 3,408 B, render_prefix_at 768 B.

Tested:

  • J714s M5 Pro (G17S B1) at exact head 65830e5: candidate 7.3.0-m5-s10cand = main 9e38a27 + this branch (65830e5) + perf/g17-publication-direct-lazy (8442bb0), driver code carried unchanged (only the host-test list in tools/asahi/run-host-tests.py needed a merge), origin/main DTB, Mesa kit inst-A. VK CTS 674/681 passed, 7 not supported, 0 failed (occlusion_query copy 152/159, concurrent_queries 2/2, multiview queries 16/16, pipeline timestamp basic_graphics 80/80, synchronization smoke 12/12, synchronization2 *read_image_compute* 412/412); gpubench-vk compute.cull_mdi CRC 07f6c861 valid (d1 1041.7 us, d2 886.5 us per submit); chainbench_diag clean; GPU online, 0 crashed, 0 quarantined, no GPU faults or WARNs.
  • J700 MacBook Neo (G17P B1) at exact head 65830e5: VK CTS 31,611 passed, 6,275 not supported, 0 failed, 0 recoveries (row in the comments).
  • J714s M5 Pro (G17S B1), candidate 7.3.0-m5-pr67 that carries the first commit 0a72e57 unchanged (same patch-id), stacked with drm/asahi: g17: expand single-pair M5 render depth to 64 #3411 and drm/asahi: g17: batch report-ring drains and skip redundant render re-observe #3428, origin/main DTB: VK CTS 594/594 passed, 0 failed; gpubench-vk compute.cull_mdi CRC valid; GTA V Enhanced 3024x1964 Very High TAA: GPU busy 97.658% -> 97.765%, P4 57.92 -> 58.03 FPS; 0 GPU faults, WARNs or errors.
  • Host tests 244/244 g17-* passed; checkpatch.pl --strict 0 errors, 0 warnings, 0 checks.

Risk: two-way · G17 Macs (M5 Pro, Neo)

Not yet:

  • Nothing known.

Backend::compute_direct() currently bails out unconditionally whenever
self.context.render_seen() is true, forcing 100% of compute commands on
mixed render/compute contexts (such as games) onto the device-mutex slow
path where compute descriptor encoding, cache maintenance, and doorbell
rings hold self.shared.state.lock(). Under contention with periodic event
worker passes or concurrent render_direct() loans, compute submissions
serialize behind the device mutex.

Track an RAII atomic count of active (published and unretired) render
entries on Context (incremented when Pair::publish() pushes an Active
entry and decremented in Active::drop()). Remove the unconditional
render_seen() bailout from compute_direct() and resolve any active render
prefix as follows:
- When wait_through[0] is none or Context::render_active() is zero, skip
  self.shared.state.lock() completely.
- When renders are active, acquire self.shared.state.lock() only long
  enough to resolve firmware.queues.render_prefix() (checking
  lease.is_current(), !firmware.recovery.pending(), and
  !firmware.queues.render.replay_parked()), merge the resulting frontier
  into direct_frontier, and release the device mutex before locking the
  compute cell and publishing.

Add compiled host contract tests and mutations in
tools/asahi/g17-direct-compute-render-prefix-tests.py.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 19:03
Keep Context::render_active non-zero while renders are parked in Pair::replay after GPU recovery by wrapping parked packets in a ParkedReplay RAII guard constructed before popping Active. This prevents compute_direct() from observing render_active() == 0 and skipping the replay_parked()/render_prefix() check once publication reopens.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J700 (MacBook Neo, Apple A18 Pro T8140 / G17P B1, second generation) exact-head kernel verification row at 65830e55401635e91fb59eb4ad5e55bb6b60ffc5: PASS (no regression, 0 failures, 0 GPU faults/recoveries).

  • Tree & host tests (7.3.0-neo-pr3429, exact head 65830e55401635e91fb59eb4ad5e55bb6b60ffc5):
    • python3 tools/asahi/run-host-tests.py --only g17- passed 244/244 (10 s), including g17-direct-compute-render-prefix-tests and all 5 mutations (bail-on-render-seen, skip-render-prefix, ignore-replay-parked, drop-active-dec, drop-count-on-park, covering the ParkedReplay RAII guard).
  • Setup & identity:
    • Built from exact head 65830e55401635e91fb59eb4ad5e55bb6b60ffc5 with stock 7.3.0-41 config + LOCALVERSION=-neo-pr3429 (0 build errors, 2,002 modules).
    • Booted via one-shot grub2-reboot only with a 10-minute fallback timer; default entry remained 7.3.0-41.fc44.aurora.aarch64. System Mesa, stock kernel command line (0-byte diff vs stock).
    • Verified on boot (d7b19829): uname -r = 7.3.0-neo-pr3429, kernel build ID 1c98e185580acba0ab469101513dc37ae43b05f5 (MATCH), aurora.ko build ID fedc61f0d0d9faa76d1f1cb3f33a5f74fb155ebb (MATCH).
  • VK CTS (6 jobs, 37,886 cases in 183 s): 31,611 Pass, 6,275 NotSupported, 0 Fail, 0 recoveries (gate rc 0):
    • dEQP-VK.synchronization{,2}.* (basic, smoke, single-queue, timeline semaphore, implicit, none_set_reset, internally synchronized objects, plus all synchronization2.*_read_image_compute*): 31,242 Pass, 6,178 NotSupported, 0 Fail (of which synchronization2.*_read_image_compute* is 5,100 Pass, 5,806 NotSupported, 0 Fail).
    • dEQP-VK.compute.pipeline.basic.*: 79 Pass, 2 NotSupported, 0 Fail.
    • dEQP-VK.api.command_buffers.*: 65 Pass, 66 NotSupported, 0 Fail.
    • dEQP-VK.renderpass{,2}.suballocation.subpass_dependencies.*: 73 Pass, 22 NotSupported, 0 Fail.
    • dEQP-VK.query_pool.occlusion_query.copy_*: 152 Pass, 7 NotSupported, 0 Fail.
  • gpubench-vk (fdf4dd6, system Mesa, 21/21 rows ok, all CRCs matched same-slot stock 7.3.0-41 pre-boot baseline):
    • compute.cull_mdi d1/d2/d4: 57276de2 (match), us/sub 9677.4 / 1973.7 / 1935.5 µs, submit_cpu_us 62.8 / 8.2 / 9.1 µs (stock us/sub 5084.7 / 1986.8 / 2000.0 µs, submit_cpu_us 36.3 / 11.5 / 12.8 µs).
    • render.pass_chain (all_bar d1/d4): 93411763 (match), us/sub 550.5 / 370.4 µs, submit_cpu_us 169.9 / 51.7 µs (stock 518.1 / 453.9 µs).
    • render.pass_chain (oq_bar d1/d4): 93411763 (match), us/sub 849.9 / 1265.8 µs, submit_cpu_us 117.1 / 454.9 µs (stock 783.3 / 852.3 µs).
    • render.light d1/d8/d32: ok, us/sub 131.3 / 31.1 / 29.2 µs, submit_cpu_us 18.8 / 16.7 / 15.4 µs (stock 124.5 / 29.8 / 28.0 µs).
    • render.deferred (tile msaa=4 1080p d1/d2): 5e4130ce (match), GPU 11072.9 / 10604.1 µs (stock 10821.9 / 10743.5 µs).
    • render.postfx (msaa=4 1080p d1/d2): 668d6f0a (match), us/sub 779.2 / 602.4 µs (stock 781.2 / 612.2 µs).
    • render.mdi (draws=1024 bindless=1024 d1/d4): 3ba813b3 (match), us/sub 506.8 / 177.6 µs (stock 461.5 / 141.8 µs).
    • compute.heavy (alu d1/d4): ok, us/sub 1351.4 / 1181.1 µs, submit_cpu_us 28.1 / 26.5 µs (stock 1382.5 / 1195.2 µs, submit_cpu_us 42.1 / 43.0 µs).
    • compute.light d1/d8: ok, us/sub 108.1 / 16.9 µs, submit_cpu_us 13.2 / 9.7 µs (stock 104.0 / 16.0 µs, submit_cpu_us 12.1 / 8.1 µs).
    • sync.signal (compute.light d1): ok, latency p5/med/p95 134.9 / 150.6 / 164.2 µs (stock 140.3 / 145.2 / 151.8 µs).
    • Note: stock 7.3.0-41 predates the PR base (aa3351bc8e6f2), so this row serves as a second-generation correctness/CRC/stability verification rather than a merge-base perf A/B.
  • Kernel health & restore:
    • 0 GPU faults/recoveries, 0 MMU faults, 0 WARN/BUG/Oops/stack-overflow/KASAN/lockup/RCU-stall/timeout lines, 0 new kernel error lines, 0 AVC denials, 0 failed units, 0 core dumps.
    • Restored cleanly to stock 7.3.0-41.fc44.aurora.aarch64 (boot f6d8f546, PMU f701/f702 = 30 00); trial /boot, /lib/modules, BLS entry, and fallback timer removed, stock.sh POST vs PRE diff = 0 bytes.

satchlj
satchlj previously approved these changes Nov 27, 2026

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed 65830e554016 (both commits: 0a72e578d4e6 + 65830e554016).

Code audit:

  • Context::render_active uses Acquire/AcqRel, is incremented in Pair::publish() before pushing Active, decremented in Active::drop(), and preserved seamlessly across active -> replay -> republish/fail/drop via ParkedReplay::new() before self.active.pop() (so render_active() never dips to 0 while a parked replay exists).
  • In Backend::compute_direct(), when render_seen() && wait_through[0].is_some() && render_active() != 0, firmware.queues.render_prefix() runs under self.shared.state.lock(), covering both entry.pair and entry.borrowed_dependencies (from render_direct() loans) and calling note_firmware_consumer() on live render entries under the lock so replay_abandoned() cannot subsequently park them out from under the compute kick.
  • Because resolve_direct_sources() only resolves compute QIDs, merging render_frontier via direct_frontier.insert(0, *dep) cannot collide on QID with compute source dependencies.
  • Minor non-blocking note: under self.shared.state.lock() in compute_direct(), checking super::recovery::Memory::recovery_state(&firmware.init) alongside firmware.recovery.pending() (matching the fallback path in compute_packet()) would also catch a firmware recovery initiated between the earlier unlocked check and acquiring state.lock().

Tested on Apple M5 Max (J775c, G17C B1) at exact head 65830e554016:

  • python3 tools/asahi/run-host-tests.py --only g17-direct-compute-render-prefix-tests: 6/6 passed (base contract + all 5 mutations).

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo 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) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at de75de43: not ready yet

Check Detail
CI at head no failing: KUnit asahi, KUnit spi-hid-apple, KUnit avd, KUnit ave, KUnit isp, KUnit jpeg
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA de75de43, a Mac and a result in the PR body or a comment
Conflicts no merge conflicts with main: merge it in (no force push)
PR text ok Risk: two-way · G17 Macs (M5 Pro, Neo)

Areas: area:gpu

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

Resolve the Pair::publish() conflict in g17/queue/render.rs: keep both
the render_active increment from this branch and main's
packet.note_ordinal(published), which are independent.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

I merged current main into the branch at de75de43. The one conflict was in Pair::publish(): main added packet.note_ordinal(published) at the same spot. I kept both lines, with inc_render_active() directly before the Active push, which is what g17-direct-compute-render-prefix-tests.py checks. run-host-tests.py --only g17- passes 289/289 on the merged tree. The approval was dismissed by the push, so I've asked the review app for a verdict at this head. It merges on green after that.

@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.

The merge keeps publication ordinal accounting and acquires the render-active count immediately before the Active entry takes ownership. Active and ParkedReplay both release the count on drop. Please reconcile the PR description with the remaining render_seen predicate and keep hosted and integrated runtime evidence as merge gates.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@DjDeveloperr code-owner notice: the review app approved this forward-merged head. I'll merge it under the 6-point rule once CI is green at this head, no earlier than 1 h from now. Say hold here if you object.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) labels Nov 30, 2026
@github-actions github-actions Bot added needs-review No approving review from Core or Omarchy Mac yet (bot) ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) labels 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:m5 Macs affected, from Merge risk (bot) blast:neo 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) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (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.

3 participants