Skip to content

drm/asahi: g17: tile small passes unclustered the way macOS does on the M4 Max - #2172

Closed
AxxzyWasTaken wants to merge 4 commits into
aurora-silicon:integration/aurorafrom
AxxzyWasTaken:pr/t6041-small-passes-unclustered
Closed

AxxzyWasTaken wants to merge 4 commits into
aurora-silicon:integration/aurorafrom
AxxzyWasTaken:pr/t6041-small-passes-unclustered

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #2021. This branch sits on #2021's branch, so GitHub shows #2021's four commits first; only the last commit belongs to this PR. I'll rebase it once #2021 lands.

With #2021, every four-cluster T6041 pass tiles clustered. In my macOS 26.6.2 (25G83) capture on this J616C, taken under a hypervisor while macOS ran a game, macOS clusters only some passes. The others keep the four-cluster segment control with bit 0 set (0x1c890 = 0x280541) and get no clustering buffers: the cluster tile maps and the metadata 1-4 pointers are zero.

This does the same for passes under 256 tiles (32x32); larger passes stay clustered. The 256-tile threshold is my own choice: I don't know macOS's rule for which passes it clusters. Two-cluster GPUs are unchanged.

Testing

All on a J616C (32-core M4 Max), 25G83:

  • My daily module since 16 Nov, with drm/asahi: g17: tile clustered on the 32-core M4 Max (T6041 25G83) #2021 and other work that isn't in this PR. That build ran Roblox (Vulkan) for 11+ minutes with 0 GPU recoveries, Minecraft (Sodium, OpenGL) at ~450 fps at RD32, and, since today's fix for the metadata copies, SCP:SL.
  • Never A/B tested on its own: I haven't compared fps or stability with and without it.
  • This branch: built (M=drivers/gpu/drm/asahi), not booted as-is. tools/asahi/run-host-tests.py --only g17: 90/90. I couldn't run KUnit (no QEMU here).

It conflicts in one line of queue/render.rs (the gtp_va call) with the PR for per-render clustering metadata. Whichever lands second needs a one-line rebase.

Assisted-by: LLM (Anthropic:Claude Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The production boot stub pins at macOS 27.2 (26B123), so please retarget this to 27.2. The pass clustering here is matched to the 26.6.2 (25G83) GPU firmware; please check it against the T6041 GPU image the 27.2 stub loads.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 2.

  1. drivers/gpu/drm/asahi/g17/queue/render.rs:551-553 and 573-582: cluster_pass depends only on self.clusters <= 2. The zeroing of gtp[1], [4], [5], [6] and [7] therefore runs on every four-cluster pass under 256 tiles, including passes on T6041 builds that run TA mode 1. In fw/render.rs:760 the four-cluster segment control, and so the control | 1 at :773, is chosen only for !args.ta_mode_1. But Layout::new (buffer/target.rs:128) allocates the gtp sub-buffers for every RegisterPrograms::V25G83 variant. V25F84 and V26B123 (fw/variant.rs:233-247) inherit V25G83's programs, and hw/t6041.rs:113 and :136 set ta_mode_1: true. So on 25F84, and on 26B123 (the 27.2 firmware), small passes now get 0x1c041/0x1c9d0, 0x1c948 and 0x1c888 written as 0 while the tiler still runs in mode 1 with segment control 1. Nothing on those builds has been tested with that, and it contradicts "every other build keeps its values". Derive cluster_pass from the same condition that selects cluster_control(): true unless !variant.ta_mode_1 && clusters > 2 && small. Better, decide it once in fw/render.rs and return it with the segment words. Add a ta_mode_tests case with ta_mode_1: true, clusters: 4 and a small pass that asserts the gtp registers are unchanged.
  2. queue/render.rs:686 CLUSTERED_MIN_TILES = 256 is a threshold the commit says is a guess ("which passes macOS clusters is not known"). The change has not been booted on its own and has no A/B. As it stands it changes the tiling mode for most small passes on the M4 Max with no measurement that this helps or is safe. Either show which property of the pass the 25G83 capture correlates with (for example, the passes that kept 0x280541 against their tile counts), or bring a same-machine A/B on this head: frame time and stability, plus GPU recoveries, with and without the commit.

HW row: J616C (M4 Max) on this head over #2021, booted on the firmware the production boot stub loads. Run the same Roblox/Minecraft/SCP:SL session and a vkmark/dEQP-VK subset with and without this commit. Pass: 0 GPU recoveries, dEQP unchanged, fps equal or better, 0 AVC denials, 0 failed units, no new kernel errors. Also run one smoke boot on a 25F84 or 26B123 T6041 build showing that small passes still render after fix 1.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

This branch sits on an earlier version of #2021. Its head is now 2ba7a68, and a test merge against it conflicts in seven files, so a rebase is needed before this can be tested as-is. After the rebase, cluster_pass in queue/render.rs should follow the same condition that selects the four-cluster segment control (not TA mode 1, more than two clusters). Otherwise small passes on the 25F84 and 26B123 T6041 builds get their gtp registers zeroed. The 256-tile threshold still needs either a property of the pass that the capture correlates with, or a same-machine A/B on this head.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Rebased onto #2021's current 3-commit head (2ba7a68b14a5) -> df9e2521396d and resolved Blocker 1:

Blocker 1 (resolved)

  • Derived (segment_control, segment_index, free_pages, cluster_pass) once inside v25g83_segment_words() in drivers/gpu/drm/asahi/g17/fw/render.rs under the exact same !ta_mode_1 && clusters > 2 branch that selects cluster_control().
  • ta_mode_1: true builds (25F84, 40-core 25G83, 26B123) and two-cluster layouts always keep cluster_pass == true and leave all gtp registers untouched; g17/queue/render.rs no longer needs any change (eliminating both the redundant RenderArgs::cluster_pass and the gtp_va conflict with #2170).
  • Extended ta_mode_tests KUnit (small_unclustered_passes_leave_ta_mode_1_and_two_clusters_alone) to assert v25g83_segment_words() at the 255/256 tile boundary and exercise ta_registers_25g83() across ta_mode_1=true 4-cluster small passes, 2-cluster small passes, and 4-cluster small vs large passes.
  • Verified at df9e2521396d: drivers/gpu/drm/asahi/aurora.o (ARCH=arm64 LLVM=1 W=1 CONFIG_KUNIT=y, 0 warnings in g17/fw/render.rs, KUnit wrapper present in aurora.o), scripts/checkpatch.pl --strict -g HEAD (0/0/0), tools/asahi/run-host-tests.py --only g17 (90/90 PASS).

Blocker 2 (holding in Draft)

Re-audited our macOS 26.6.2 (25G83) J616C hypervisor captures (317 TA arrays across two traces): identical dimensions/tile counts (1024x1024 at 1,024 tiles and 3091x1939 at 5,917 tiles, same utile/MSAA words) appear on both 0x280540 (clustered) and 0x280541 (unclustered), while 1546x970 (1,519 tiles) was all 0x280541 — confirming macOS picks clustering per pass from workload/geometry demand rather than a fixed tile-count cutoff.

Keeping this PR in Draft until #2021 lands and we can run the full same-machine J616C A/B benchmark + stability/recovery comparison (plus 25F84/26B123 smoke) on this head to decide whether the heuristic pulls its weight or should be dropped.

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

@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/t6041-small-passes-unclustered branch from 8231c04 to df9e252 Compare November 23, 2026 00:27
@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-checked at df9e252 (one commit on #2021's 2ba7a68). Blocker 1 is resolved: v25g83_segment_words() (g17/fw/render.rs) now decides cluster_pass inside the same !ta_mode_1 && clusters > 2 arm that picks cluster_control(), so TA-mode-1 builds and two-cluster layouts keep cluster_pass == true and their gtp registers. The KUnit case at the 255/256 boundary and the two-cluster/TA-mode-1 cases cover that.

On blocker 2, your re-audit answers the question, and the answer is against the threshold. The same 1024x1024 (1,024 tiles) and 3091x1939 (5,917 tiles) passes appear both clustered and unclustered, so CLUSTERED_MIN_TILES = 256 is not what macOS keys on. The 1546x970 pass (1,519 tiles) was always unclustered, which a 256-tile cutoff would cluster. As written, the cutoff is a constant that the captures don't support. Before this leaves draft it needs one of these:

  • the per-pass property the captures do correlate with (for example the TVB demand of the previous pass, a geometry count, or what the pass's own TA arrays carry), read from the pass rather than a tile count; or
  • a same-machine A/B on the 32-core M4 Max at this head showing that unclustered small passes are a measurable win and never a regression (frame time and the TVB-overflow/partial-render counters, base vs head), with the cutoff stated in the commit message as a measured performance choice and not as "the way macOS does".

Keeping it in draft until then is right.

Assisted-by: LLM (Claude:Opus 5.5)

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Same-machine J616C (Apple MacBook Pro 16", M4 Max, 32-core T6041, 25G83) A/B at exact head df9e2521396d (7.3.0-j616c-pr2172) vs exact parent #2021 (2ba7a68b14a5, 7.3.0-j616c-pr2021), measuring both < 256-tile passes (unclustered on #2172) and >= 256-tile controls (clustered on both) across low- and high-geometry Vulkan render passes (0 GPU faults/warnings/AVC/failed units on both boots; dEQP-VK 624-case subset 258/366/0 on both):

Render Target (32×32 tiles) Workload #2021 (2ba7a68b, clustered) #2172 (df9e2521, <256 unclustered) Delta
128×128 (16 tiles) 100 tris × 300 0.376 ms 0.385 ms +2.4%
128×128 (16 tiles) 100K tris × 60 0.686 ms 0.773 ms +12.7% slower
128×128 (16 tiles) 500K tris × 40 1.110 ms 1.586 ms +42.9% slower
128×128 (16 tiles) vtxalu 1M × 20 4.406 ms 15.835 ms 3.59× slower
256×256 (64 tiles) 100 tris × 300 0.402 ms 0.375 ms -6.7% (-27 µs)
256×256 (64 tiles) 100K tris × 60 0.637 ms 0.707 ms +11.0% slower
256×256 (64 tiles) 500K tris × 40 0.845 ms 1.197 ms +41.7% slower
256×256 (64 tiles) vtxalu 1M × 20 4.432 ms 15.839 ms 3.57× slower
480×480 (225 tiles) 100 tris × 300 0.426 ms 0.388 ms -8.9% (-38 µs)
480×480 (225 tiles) 100K tris × 60 0.638 ms 0.715 ms +12.1% slower
480×480 (225 tiles) 500K tris × 40 0.869 ms 1.219 ms +40.3% slower
480×480 (225 tiles) vtxalu 1M × 20 4.257 ms 15.850 ms 3.72× slower
512×512 (256 tiles, ctrl) 100 / 100K / 500K / vtxalu 1M 0.428 / 0.647 / 0.866 / 4.250 ms 0.417 / 0.645 / 0.862 / 4.251 ms parity
1024×1024 (1024 tiles, ctrl) 100 / 100K / 500K / vtxalu 1M 0.424 / 0.691 / 1.099 / 4.694 ms 0.411 / 0.693 / 1.101 / 4.498 ms parity
3840×2160 (4K, ctrl) vtxalu 1M / 500K / 1.5M / 3M / 6M 4.736 / 2.306 / 6.617 / 13.042 / 25.983 ms 4.747 / 2.316 / 6.622 / 13.046 / 26.008 ms parity (0.0–0.4%)

Verdict on Blocker 2

This settles Blocker 2 decisively against a tile-count threshold:

  • Unclustering passes under 256 tiles saves at most 27–38 µs on nearly empty (100-tri) passes while regressing geometry-heavy small targets (shadow maps, cubemaps, reflection passes) by +11–13% at 100K tris, +40–43% at 500K tris, and 3.57×–3.72× on vertex-ALU-bound passes (4.26–4.43 ms -> 15.84–15.85 ms) as bit 0 (0x280541) collapses vertex work back onto a single cluster.
  • That also explains why macOS captures show identical tile sizes both clustered and unclustered — macOS is clearly gating on geometry/vertex demand rather than tile count.

Keeping #2172 parked in Draft (will leave the drop/close decision to the author — definitely not landing a tile-count cutoff).

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

@RyanTheTide

Copy link
Copy Markdown
Contributor

The updated head df9e2521396d conflicts in drivers/gpu/drm/asahi/hw/t6041.rs on integration/aurora 5441428d9033. The earlier base predated the current T6041 changes. The tiling behavior still needs a current-tip compile and M4 Max validation once the stack is reconciled.

With four-cluster tiling the 32-core M4 Max runs vertex shaders on every
cluster at once beside fragment work. Roblox (Vulkan) then hangs the GPU
about once a minute: the firmware kills a small depth/stencil render as
no-progress (reason 0), with no MMU fault and a nearly empty tiler heap.
The same hang showed up on this Mac with the earlier driver until its
render pool had 96 blocks. G17 firmware has no grow-request event for
the USC render pool (unlike TVB growth) and a published render pool
cannot be resized in place, so the pool must be sized up front.

Rather than gating a fixed 96-block pool on T6041 and firmware build
25G83, derive the render pool minimum from GPU shape (active cores and
cluster count) inside g17::fw::render_rt::required_blocks(), before
adding ray-query scratch extras:

- One- and two-cluster GPUs keep the 44-block floor (RENDER_BLOCKS),
  preserving the A18 Pro shared pool window invariant and the M4 Pro's
  narrow pool window unchanged.
- Above two clusters, the base pool scales at 3 blocks (3 MiB) per
  enabled core, floored at RENDER_BLOCKS (44). Note that 3 blocks/core
  is an empirical fit from one 32-core J616C measurement (96 / 32), not
  a hardware-derived bound; the 40-core J614C value (120 blocks) has not
  been run on hardware yet. Because it keys on GPU shape, every
  >2-cluster G17 firmware build (including 25F84 and 26B123 on T6041)
  gets this floor, not only 25G83.
- Ray-query scratch is added on top of this base instead of competing
  with it.

Capacity cost in WIDE_LOWER (~3.19 GiB, shared with other lower-window
allocations): queue creation allocates no VA or backing; backing is
placed lazily on first render (~98 MiB span on J616C, ~122 MiB span on
J614C, vs ~46 MiB before), reducing the simultaneously resident pool
budget from 58 (MAX_EXECUTION_CONTEXTS) to roughly 33 on J616C and 26 on
J614C. When WIDE_LOWER fills, submit enters wait_render_capacity() ->
reclaim_render_capacity(), which evicts idle render pools via
FreeListRelease and transparently re-arms them on next use. Only when
more than ~33 (J616C) / ~26 (J614C) distinct contexts are simultaneously
active for longer than QUEUE_WAIT_NS does a new submission fail with
EBUSY, leaving existing contexts intact. J616C has run with 96 blocks
daily since 16 Nov without hitting the cap.

Resulting base render pool blocks (pages = [0, 0]):

  Part                     Clusters  Cores  Base blocks
  A18 / A18 Pro (T8140)           1   5/6            44  (unchanged)
  M4 (T8132, uses g16)            1  8/10            44  (if on g17)
  M4 Pro (T6040)                  2 16/20            44  (unchanged)
  M4 Max 32-core (J616C)          4    32            96  (measured fix)
  M4 Max 40-core (J614C)          4    40           120  (untested)
  M5 (T8142, M5 pool path)        1  8/10            44  (unchanged)
  M5 Pro (T6050, M5 pool)         2 16/20            44  (unchanged)
  M5 Max (T6050, M5 pool)         4 32/40        96/120  (M5 uses own)
  M5 Ultra (T6050, M5 pool)       8 64/80       192/240  (M5 uses own)

Add KUnit tests (asahi_g17_render_pool) covering these shapes, ray-query
scratch addition, and invalid/oversized rejections.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
T6041 ran its 25G83 tiling passes in TA mode 1 (0x1c890 = 1), which
tiles non-clustered: one of the four clusters runs the tiling and
vertex work of a pass. Vertex shaders reached a quarter of the ALU rate
of the GPU (2.95 vs 12.3 TFLOPS), and geometry-bound games were capped
by it.

Tile clustered instead on the 32-core T6041 (J616C) 25G83 build, while
keeping the untested 40-core T6041 parts (J614C, J575C) on TA mode 1
until they have a hardware row. Clustered four-cluster passes receive:

- Clustering metadata sized for more than two clusters, with metadata 2
  at 0x1180 as macOS 26.6.2 writes on the 32-core M4 Max (metadata 2 at
  the M2 Pro/Max 0xc00 size allowed the tiler to write past it into
  metadata 3; metadata 3 and 4 keep their larger sizes). Because 25F84,
  40-core 25G83, and 26B123 share RegisterPrograms::V25G83, four-cluster
  targets on those builds also receive the 0x1180 metadata 2 sizing
  while keeping TA mode 1 (non-clustered); that oversizing has not been
  booted on 25F84/26B123.
- The four-cluster segment words of cluster_control(): 0x1c890 =
  0x280540, 0x1c918 = 4, and v25g83_clustered_free_pages(clusters) =
  28 + 16 * clusters free parameter-buffer pages in 0x1c9a8 (0x3c for
  two clusters, 0x5c for four, matching the macOS 26.6.2 capture). Two
  clusters keep the M4 Pro capture.
- The full block table for Variant::tvb_normal_blocks on 32-core 25G83,
  because a clustered RD32 Minecraft frame needs about 1600-2200 blocks
  and never starts at the 0x45e default.

25F84, 40-core 25G83, and 26B123 keep TA mode 1 and the default heap
maximum. Every other chip and build keeps its values.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
Four-cluster passes size clustering metadata 1 as the M2 Pro/Max path
does, 0x44 bytes per block of tiles, with 0x80, the two-cluster M4 Pro
size, as the floor. On a 3456x2234 Retina frame (Minecraft RD32) that
formula yields 0x100 (32x32 utiles) or 0x180 (16x16), and on 10240x10240
(point_size_10000, 16x16 utiles) it yields 0x1100.

Because metadata 1 is the last sub-buffer in the TPC object, neither
macOS's allocation size nor the hardware's written high-water mark was
visible in the J616C 26.6.2 capture. Give it a conservative 16 KiB floor
until measured, document the formula sizes on those frames, and add a
KUnit test covering the four-cluster V25G83 metadata layout. (Because
this keys on RegisterPrograms::V25G83 && clusters > 2, 25F84 and 26B123
on T6041 also get this conservative floor.)

The per-block size stays the M2 Pro/Max formula; the floor is our own
choice, not a macOS value.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
…he M4 Max

macOS 26.6.2 on the 32-core M4 Max clusters only some passes. The others
keep the four-cluster segment control with bit 0 set (0x280541) and get
no clustering buffers: the cluster tile maps and metadata 1-4 pointers
are zero. Do the same for passes under 256 tiles; larger passes stay
clustered. The 256-tile threshold is our own choice: which passes macOS
clusters is not known.

Derive cluster_pass once alongside the V25G83 segment words inside
v25g83_segment_words() using the exact same condition that selects
multi-cluster segment control (!ta_mode_1 && clusters > 2), so TA-mode-1
builds (25F84, 40-core 25G83, 26B123) and two-cluster layouts always
keep cluster_pass == true and leave their segment and GTP registers
unchanged. Add KUnit coverage in ta_mode_tests for small and large
passes across TA mode 1, two-cluster, and four-cluster configurations.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/t6041-small-passes-unclustered branch from df9e252 to 4b26f80 Compare November 23, 2026 09:13
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Rebased onto the updated #2021 stack (1c420ea8baca, on integration/aurora a4b51cdff0a7) at 4b26f800ea2b — git range-diff on the small-pass commit is identical (df9e2521396d = 4b26f800ea2b). tools/asahi/run-host-tests.py --only g17: 90/90 passed. Still parked in Draft per the A/B regression data above.

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

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Closing: live J616C A/B testing showed unclustered small-pass tiling regressed render performance by 3.57-3.72x.

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

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