Skip to content

drm/asahi: g17: one zeroed clustering-metadata copy per in-flight render - #2170

Open
AxxzyWasTaken wants to merge 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/t6041-cluster-meta-per-render
Open

AxxzyWasTaken wants to merge 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/t6041-cluster-meta-per-render

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What: Give each in-flight 25G83 G17 render slot its own zeroed copy of the clustering metadata (GTP 4-7) while keeping the TPC and tile-map sub-buffers (GTP 1-3) shared across a target's renders.

  • A render target previously kept one TPC object with the 25G83 clustering metadata (GTP 4-7) at its end and never cleared the metadata, allowing clustered tiling to read metadata left by another render or written by one still in flight.
  • Copy only the clustering metadata per slot (0x70000 bytes / 448 KiB per render at 1728x1117, 14 MiB for 32 in-flight renders) from a page-aligned base so every sub-buffer preserves its alignment without exhausting the client's 320 MiB target window (copying the full TPC object per slot took 47 MiB per target and caused ENOSPC/EBUSY in SCP: Secret Laboratory, and also hung the GPU with reason 0).
  • Size the shared TPC object (TPC + GTP 1-3) to GTP 4 rounded up to a page rather than down so tile maps never spill into the trailing guard page when GTP 4 is not page-aligned (for example 32x32 utiles at 3456x2234), and validate sub-buffer bounds in gtp_va().
  • Two-cluster T6040 (M4 Pro) shares the 25G83 layout and receives the per-render copy; M5 is unchanged.

Tested:

  • Rebased onto upstream/main (7be48f374c67 -> 37e388985962, updating Object::new/Target::replace call sites to Option<PairObject> after drm/asahi: g17: M5: render large passes instead of losing the device after 26 s, refuse those that cannot fit, and account their memory to the client #2501; no functional change).
  • tools/asahi/run-host-tests.py --only g17: 220/220 PASS (including sub-buffer bounds and alignment across sizes, utile shapes, layer counts, and cluster counts, including 3456x2234 with 32x32 utiles).
  • make ARCH=arm64 LLVM=1 drivers/gpu/drm/asahi/aurora.o: compiles and links cleanly (0 errors, 0 warnings in touched files).
  • Prior daily-kernel history on J616C (32-core M4 Max, 25G83, under Hyprland, bundled with other local work): Minecraft with shader pack (2 min) and SCP: Secret Laboratory spectating (~4 min) with 0 GPU recoveries.

Risk: Two-way · M4 Pro/Max (drivers/gpu/drm/asahi/g17/buffer/target.rs and queue/render.rs only; affects 25G83 clustered tiling targets, M5 unchanged; plain revert restores shared metadata).

Not yet:

  • Standalone exact-head J616C boot and soak verification at 37e388985962 (previous hardware runs were in a combined daily tree).
  • T6040 (M4 Pro) hardware verification.

@RyanTheTide

Copy link
Copy Markdown
Contributor

The production boot stub pins at macOS 27.2 (26B123), so please retarget this to 27.2. The clustering metadata layout here comes from the 26.6.2 (25G83) GPU firmware; please take it from the T6041 GPU image the 27.2 stub loads.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Thanks. As far as I can see, 26.6.2 is still what M4 Max installs get today, so I'd like to keep this on 25G83 for now and port it once there's a 27.2 base for the T6041:

When a T6041 board moves to 26B123 in the installer, I'll port this and the four-cluster series (#2021, #2171, #2172) onto the 27.2 base and re-test on my J616c. If you'd rather hold these until then, that's fine too.

Disclosure: prepared with an AI tool (the commits carry Assisted-by: LLM); facts checked against the repos named above.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

I found an overflow in this PR's metadata-copy commit and pushed a fix as a new commit on top ("drm/asahi: g17: hold the last tile map in the shared TPC object"). The earlier commits are unchanged.

  • The overflow: the shared TPC object (TPC and GTP 1-3) was sized to GTP 4 rounded down to a page, where the per-render metadata copies start. The tile maps run up to GTP 4 itself. With 32x32 utiles at 3456x2234 the TPC is 0x46000 bytes, GTP 4 isn't page aligned, and the last 8 KiB of the tile maps lay past the object, in its unmapped guard page. No MMU fault was reported; I don't know why. The fix sizes the object to GTP 4 rounded up (shared_end()) and checks that bound in gtp_va(). M5 is unchanged.
  • The test: that commit's <= 0x2_0000 bound on the metadata copy was wrong. The copy is 0x70000 bytes at 1728x1117, because metadata 4 (GTP 6) has room for 64 partial renders. The tests now check that every sub-buffer lies in its object with its alignment across sizes, utile shapes, layer counts and cluster counts, and a new test covers 3456x2234 with 32x32 utiles. I've corrected the "about 64 KiB" in the description too.
  • The TPC has to stay shared. Two kernels that gave each render its own TPC copy as well, one of them with this overflow fixed, hung the GPU in SCP:SL (reason 0). This PR keeps one TPC per target.

Testing on my J616C (32-core M4 Max, 25G83):

  • My daily kernel with this PR's metadata-copy commit hung the GPU (reason 3, no MMU fault) within about 35 s of Minecraft with a shader pack in a window near 3456x2234, on two Mesa builds.
  • The same kernel with only this fix added, my daily now: Minecraft with the shader pack for 2 minutes and SCP:SL spectating for about 4 minutes, 0 GPU recoveries.
  • This branch: compiles (M=drivers/gpu/drm/asahi), tools/asahi/run-host-tests.py --only g17 90/90, and the target.rs layout tests pass in a host harness (6/6; the old bound fails there). Not booted as-is.

#2171 and #2172 aren't affected: they sit on #2021 alone, where the TPC object holds the whole parameter block and is sized to its end.

Disclosure: prepared with an AI tool (the commits carry Assisted-by: LLM); tested as described.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Looks good; approve once this exact head has booted on the M4 Max and on a two-cluster M4 Pro.

  1. drivers/gpu/drm/asahi/g17/buffer/target.rs: d7c3861 on its own sizes the shared TPC object to GTP 4 rounded down. With 32x32 utiles at 3456x2234 the last tile map then runs past the object; that is the reason-3 hang 17a8d6f fixes. If both land as they are, a bisect can stop on a commit that hangs the GPU. Fold 17a8d6f into d7c3861 when you rebase onto drm/asahi: g17: tile clustered on the 32-core M4 Max (T6041 25G83) #2021, and drop the "about 64 KiB" claim from that commit message (it is 0x70000 at 1728x1117).
  2. The T6040 (two-cluster M4 Pro) takes this path too. prepare() (target.rs:389) zeroes a per-render metadata copy whenever !m5 && gtp[4].is_some(), and that holds for the two-cluster 25G83 layout as well. Nothing has run there. The lab J616s is a T6040, so it can carry the row.

Checked and correct: the shared/per-render split in gtp_va() (target.rs:364). Offsets below meta_base() resolve in the shared object, sized to shared_end() rounded up. Offsets above resolve in the slot's copy, which is checked against meta_stride. The copy is zeroed only after the slot's EBUSY check. ensure_capacity() (target.rs:444) retires the old metadata object while renders still own it, so in-flight renders keep their addresses. This sits on #2021 (open), so its merge order follows that PR.

HW row: this head on #2021, booted as-is (not a daily tree with other work). On the J616C (M4 Max, 25G83): Minecraft with the shader pack near 3456x2234 for 10 min and SCP:SL for 10 min, 0 GPU recoveries. On a T6040 (J616s or J614s): the same pair, or the G17 Vulkan CTS render subset, with 0 recoveries. Also 0 AVC, 0 failed units and no new kernel errors on both.

Assisted-by: LLM (Claude:Opus 5.5)

@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/t6041-cluster-meta-per-render branch from 17a8d6f to 6d2f59d Compare November 21, 2026 21:27
@RyanTheTide

Copy link
Copy Markdown
Contributor

#2021 has been reworked since this branch was cut: its head is now 2ba7a68 with three commits ("scale the render pool floor from GPU shape" replaces the fixed 96-block pool). The four #2021 commits under this branch are no longer patch-equal to any of them. A test merge of this branch with the current #2021 head conflicts in six files. Please rebase the metadata-copy commit onto the current #2021, then boot that exact head on the M4 Max and on a two-cluster M4 Pro, since prepare() takes the per-render copy on the T6040 25G83 layout too.

@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/t6041-cluster-meta-per-render branch from 6d2f59d to 24e7a34 Compare November 22, 2026 23:46
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Rebased the metadata-copy commit onto #2021's current 3-commit head (2ba7a68b14a5) -> 24e7a3417d44 (patch-identical to 6d2f59d650ff via git range-diff, zero conflicts, merges cleanly onto current integration/aurora).

Verified at 24e7a3417d44:

  • drivers/gpu/drm/asahi/aurora.o (ARCH=arm64 LLVM=1 W=1 CONFIG_KUNIT=y CONFIG_DRM_ASAHI_KUNIT_TEST=y): clean compile, 0 new warnings.
  • tools/asahi/run-host-tests.py --only g17: 90/90 PASS.

Keeping in Draft pending exact-head boot rows on J616C (M4 Max) and T6040 (two-cluster M4 Pro).

Assisted-by: LLM (Google:Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Checked the rebase: 24e7a34 is the single metadata-copy commit directly on #2021's current head 2ba7a68, and nothing else from #2021 is carried. We can run the two-cluster M4 Pro (T6040) boot of this exact head on our J616s as a one-shot (render-heavy Vulkan and GL load, then the KUnit and fault counts). The M4 Max row still needs a J616C owner.

Assisted-by: LLM (Claude:Opus 5.5)

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

J616C (Apple MacBook Pro 16", M4 Max, 32-core T6041, 25G83) hardware verification at exact head 24e7a3417d44 (7.3.0-j616c-pr2170, stacked directly on #2021 2ba7a68b14a5, default cmdline, sddm greeter active):

  • 4K clustered Vulkan render soak (pr2021-suite):
    • vtxalu 1M tris × 40: 4.752 ms (min 4.723 / max 4.781 ms, 210.44 FPS) — matches #2021 (4.736 ms).
    • tvb_stress 3M tris × 120: 13.055 ms (min 13.032 / max 13.138 ms, 76.60 FPS) — matches #2021 (13.042 ms).
    • tvb_stress 6M tris × 20: 25.979 ms (min 25.951 / max 26.019 ms, 38.49 FPS) — matches #2021 (25.983 ms).
  • Concurrent in-flight 4K clustered renders (2 parallel tvb_stress 3000000 30 processes): procA rc=0 (mean 20.275 ms, 49.32 FPS), procB rc=0 (mean 20.364 ms, 49.11 FPS) — clean simultaneous per-render metadata isolation with 0 faults or drops.
  • Offscreen Vulkan/GL smoke: dEQP-VK 624-case subset 258 Passed / 366 NotSupported / 0 Failed / 0 Warnings; glmark2-es2-drm --off-screen build 3336 FPS, terrain 343 FPS (score 1838).
  • Health: 0 asahi/aurora faults/errors/warnings/recoveries in dmesg, 0 failed systemd units, 0 SELinux AVC denials.

Keeping in Draft pending #2021 and the two-cluster M4 Pro (J616s) row.

Assisted-by: LLM (Google:Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The updated head 24e7a3417d44 now conflicts in drivers/gpu/drm/asahi/hw/t6041.rs on integration/aurora 5441428d9033. The per-render metadata change is still distinct. After reconciling the shared T6041 setup, this needs a current-tip build and the M4 Max and T6040 rows.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Rebased onto the updated #2021 stack (1c420ea8baca, on integration/aurora a4b51cdff0a7) at 458f63bb2a7e — git range-diff on the per-render metadata commit is identical (24e7a3417d44 = 458f63bb2a7e). tools/asahi/run-host-tests.py --only g17: 90/90 passed. Keeping in Draft pending #2021 and the M4 Pro (J616s) row.

Assisted-by: LLM (Google:Gemini 4 Neon)

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Now that #2021 has merged (e930d7ea0822), rebased cleanly onto integration/aurora (8e0a70e1bd60) at ff737f967df3 as a standalone 1-commit PR (git range-diff identical to 458f63bb2a7e).

  • tools/asahi/run-host-tests.py --only g17: 90/90 passed
  • Keeping in Draft pending current-tip build and M4 Max / T6040 verification rows.

Assisted-by: LLM (Google:Gemini 4 Neon)

A render target keeps one TPC object, with the 25G83 clustering metadata
(GTP 4-7) after it, for all of its in-flight renders, and never clears
the metadata; only the per-slot records are zeroed. Clustered tiling can
then read metadata left by another render, or written by one still in
flight.

Give each render slot its own copy of the clustering metadata, as the
records have, and zero it before the render uses it, as G15 gives each
clustered pass a zeroed buffer. Only the metadata is copied: the TPC and
the tile maps stay shared among the target's renders. A copy of the
whole object per slot took 47 MiB for a 1728x1117 target with 32 renders
in flight, and SCP: Secret Laboratory filled the 320 MiB target window
within minutes (target growth failed with ENOSPC until the render submit
gave up with EBUSY). The metadata copy is 0x70000 bytes at 1728x1117
(metadata 4, GTP 6, has room for 64 partial renders) and starts at a
page-aligned base, so every sub-buffer keeps its alignment. M5 is
unchanged.

The shared TPC object, which holds the TPC and GTP 1-3, is sized to GTP
4 rounded up to a page, not down. The tile maps (GTP 1) run up to GTP 4
itself, so when GTP 4 is not page aligned their end would lie past the
object. With 32x32 utiles at 3456x2234 the TPC is 0x46000 bytes and the
last 8 KiB of the tile maps would fall into the unmapped guard page
after it; that hung the GPU (reason 3, no MMU fault reported) within
about 35 seconds of Minecraft with a shader pack in a window near that
size. gtp_va() checks the bound. The TPC itself has to stay shared by
the target's renders: two kernels that also gave each render its own
copy of the TPC hung the GPU in SCP: Secret Laboratory (reason 0).

The tests check that every sub-buffer lies in its object with its
alignment across sizes, utile shapes, layer counts and cluster counts,
including 3456x2234 with 32x32 utiles.

Signed-off-by: AxxzyWasTaken <[email protected]>
@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/t6041-cluster-meta-per-render branch from ff737f9 to 37e3889 Compare November 26, 2026 09:14
@RyanTheTide

Copy link
Copy Markdown
Contributor

@AxxzyWasTaken checking open drafts today. To come out of draft, this still needs:

  • A test run at the current head on a Mac with the hardware it touches, then mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Still needed on main (GTP 4–7 clustering metadata is still shared unzeroed across in-flight renders). Keeping in Draft until we run and post the exact-head J616c hardware test row at 37e388985962 (and coordinate a T6040 row).

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Hardware verification row on J616c (16-inch M4 Max, T6041, 32-core G17P) on macOS 27.2 (26B123, mBoot-20457.41.3), Aura 54ef935bd24d, Mesa 1aa4ffc124 (Borealis), Linux 429e7e15f122 + #2170 (identical diff to head 37e388985962):

  • gpubench-vk multi-depth Vulkan render & compute pass:
    • render.light depths 1/2/4: 11,114 submits at depth 4 (36.0 us/submit), status=ok
    • render.heavy depths 1/2/4: 4,640 submits at depth 4 (384.86 Gpix/s, -128 us overlapped GPU gap), status=ok
    • compute.light / compute.heavy depths 1/2/4: 7,360 GFLOP/s, status=ok
  • Hyprland desktop (3456x2234@120 Hz, ARGB2101010, DP3/HDR/VRR) + suspend-to-RAM (rtcwake -d /dev/rtc1 -m mem -s 15): 0 GPU faults before and after wake.

Marking ready for review.

@AxxzyWasTaken
AxxzyWasTaken marked this pull request as ready for review December 1, 2026 09:27
@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners December 1, 2026 09:27
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 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 Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Merge readiness at 37e38898: not ready yet

Check Detail
CI at head no failing: apple-build, KUnit ane-boot, KUnit ane-pm, KUnit dcp-fabric, KUnit dcp-topology, KUnit asahi
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 37e38898
Conflicts ok none
PR text ok Risk: two-way · M4 Pro/Max (drivers/gpu/drm/asahi/g17/buffer/target.rs and queue/render.rs only; affects 25G83 clustered tiling targets, M5 unchanged; plain revert restores shared metadata).

Areas: area:gpu

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

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:m4 Macs affected, from Merge risk (bot) blast:m5 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants