Skip to content

drm/asahi: g17: scale the tiler heap's normal maximum with memory - #2186

Closed
jgoyvaerts wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/g17-tvb-normal-max
Closed

jgoyvaerts wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/g17-tvb-normal-max

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

On 25G83 only the host grows the tiler heap: the driver keeps the firmware from growing it mid-render. Before a render, the host grows it to 3x the last high-water, capped at the heap's normal maximum. That cap also goes to the firmware in BM+0x80. A scene bigger than the cap partial-renders on every frame.

The cap is 0x45e (1,118 blocks, 140 MiB) on every NEO-layout heap. That is macOS's value for an 8 GiB Mac. macOS 25G83 scales the limit with memory (halGetDefaultParameterBufferSizeMax):

  • Maximum: a twentieth of the memory, at least 192 MiB, rounded up to whole groups of 129 blocks.
  • Normal maximum: a third of that. It caps a queue's pre-render growth and is what goes in BM+0x80.
Memory Maximum Normal maximum Where we have these numbers
8 GiB 3,354 1,118 The A18 Pro's TVB_BLOCK_SLOTS and NORMAL_MAX_BLOCKS
48 GiB 19,737 6,579 BM+0x7c / BM+0x80 written by macOS 26.6.2 on a 48 GiB J616s (live read)

The closed form matches an emulation of the kext's integer arithmetic on 200,000 memory sizes.

This change derives the normal maximum from memory the same way, up to the block table's TVB_MAX_BLOCKS:

Tested on the J616s (M4 Pro, 48 GiB, 25G83)

The test is off-screen GLES: N screen-spanning triangles into a stored 3456x2234 RGBA8 + D24S8 target, waiting for each frame (glFinish). 0 GPU recoveries.

N Before After
10,000 32 ms (3.2 us/tri) 32 ms
15,000 146 ms (9.7 us/tri) 41 ms (2.8 us/tri)
20,000 193 ms 55 ms
30,000 281 ms 83 ms
40,000 395 ms 110-138 ms
45,000 not run 417 ms (9.3 us/tri: past 3,353 blocks)

"After" is our m4.166 test kernel. It also carries #1902 and #1986, which only change pairs that never go idle and so don't affect this test. KUnit asahi suites 698 of 699, one skipped (needs CONFIG_UCLAMP_TASK). tools/asahi/run-host-tests.py --only g17 90/90.

#1902 / #1986 on the M4 Pro

The same test with two frames in flight, so the pair never idles, measures #1902 + #1986:

N without (m4.164) off (m4.166, g17_busy_tvb_grow=0) on (m4.166)
3,000 31 ms not run 8 ms
10,000 109 ms 108 ms 27.5 ms

#1986 asks for a heavier scene to measure this on 25G83; this is one.

Not done

  • The heap's capacity is still 3,354 slots; macOS allows 19,737 here. Raising it needs a memory-sized NEO graph and VA layout. Only scenes above about 420 MB of tiler data would gain.
  • Not tested on the A18 Pro, which keeps its values, or on an M4 Max.

🤖 Generated with Claude Code

The tiler heap of a 25G83 render grows on the host only: the driver does
not let the firmware grow it mid-render, as macOS doesn't for a pass that
can partial-render. The host grows it before a render to three times the
last high-water, capped at the heap's normal maximum, which also goes to
the firmware in BM+0x80. A scene larger than that cap partial-renders on
every frame.

That cap is 0x45e (1,118 blocks, 140 MiB) on every NEO-layout heap. It is
macOS's value on an 8 GiB Mac: macOS 25G83 scales the limits with memory
(halGetDefaultParameterBufferSizeMax). The maximum is a twentieth of the
memory, at least 192 MiB, in whole groups of 129 blocks, and a queue's
pre-render growth and BM+0x80 are capped at a third of it. That gives
3,354 and 1,118 blocks with 8 GiB, the A18 Pro's TVB_BLOCK_SLOTS and
NORMAL_MAX_BLOCKS, and 19,737 and 6,579 with 48 GiB, the BM+0x7c and
BM+0x80 macOS writes on a 48 GiB M4 Pro (J616s).

Derive the normal maximum from memory the same way, up to the block
table's TVB_MAX_BLOCKS. The memory is si_meminfo()'s, as for the M5 heap
(shared helper). It is below the installed amount macOS reads, so the
8 GiB value stays the floor and the A18 Pro keeps 1,118. A 24 GiB Mac
gets 3,311, 32 GiB or more 3,353, the value aurora-silicon#2021 sets for the M4 Max by
hand. The A18 Pro's mesh floor keeps 1,118.

On the J616s (M4 Pro, 48 GiB, 25G83), an off-screen GLES test draws N
screen-spanning triangles into a stored 3456x2234 RGBA8 + D24S8 target and
waits for each frame. Before, a triangle cost 3.0 us up to N = 14,500 and
9.7 us from N = 15,000, on every frame. With this change, 3.0 us holds up
to N = 40,000: N = 20,000 takes 55 ms a frame instead of 193 ms, N = 30,000
83 ms instead of 281 ms. Above 3,353 blocks it partial-renders as before.
macOS on the same Mac keeps its 2.9 us up to its 6,579-block cap.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor

The production boot stub pins at macOS 27.2 (26B123), so please retarget this to 27.2. The heap sizing is measured and tested on the 26.6.2 (25G83) GPU firmware; please run the same tiler test on the J616s under the 27.2 stub and show the BM+0x80 value it takes there.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 2.

  1. drivers/gpu/drm/asahi/g17/buffer/layout.rs:27-33,36-42,139: the sizing is described, and implemented, as a copy of a macOS driver function: its internal symbol names in the doc comment and in the test, the "twentieth / 192 MiB / 129-block group / one third" constants, and (in the commit message and description) an "emulation of the kext's integer arithmetic". Driver symbol names and constants taken from that driver's internals can't go into public code, commit text or PR text. Remove the symbol names and the kext-emulation claim. Then state the cap as this driver's own policy and justify it from our own measurements: the BM+0x7c/BM+0x80 values read live on the 48 GiB J616s, the 8 GiB heap, and the triangle-count sweep in this PR. For example, take a fixed fraction of si_meminfo() memory, bounded by fw::NORMAL_MAX_BLOCKS and cfg::TVB_MAX_BLOCKS. Drop the 129-block group rounding, which only serves to match the other driver bit for bit. Update the KUnit expectations (layout.rs:136-156) to match.
  2. Commit f090d65 carries an Assisted-by: LLM trailer. Commits should carry only the human Signed-off-by; the agent note belongs only on the last line of the PR description, as Assisted-by: LLM (<vendor>:<model>). The description currently ends with a "Generated with Claude Code" line and an emoji. Rewrite the commit message on a fresh branch (no force push) and fix the description's last line.

The rest of the change is sound:

  • GraphArgs::normal_blocks is range-checked against NORMAL_MAX_BLOCKS..=TVB_MAX_BLOCKS before it reaches BM+0x80 (fw/buffer.rs:161,203).
  • normal_blocks * TVB_PAGES_PER_BLOCK equals the old NORMAL_MAX_BLOCKS * 4 on the 8 GiB floor.
  • mesh_floor() (buffer.rs:874) is pinned to fw::NORMAL_MAX_BLOCKS, so the A18 Pro stays at 1,118.
  • memory_bytes() (buffer.rs:319) is the old M5 code moved unchanged.

HW row: the 27.2 tiler row already requested on the J616s. On the same head, run J700 (A18 Pro, 8 GiB) and check that BM+0x80 still holds 1,118 blocks and that the mesh-shading and GLES CTS subsets match the base, with 0 GPU recoveries, 0 AVC and 0 failed units.

Assisted-by: LLM (Claude:Opus 5.5)

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Superseded by #2724, rewritten as requested: the normal maximum is now a 64th of si_meminfo() memory clamped to NORMAL_MAX_BLOCKS..=TVB_MAX_BLOCKS, justified from our BM+0x80 reads and the sweep; commit carries only the Signed-off-by.

@jgoyvaerts jgoyvaerts closed this Nov 21, 2026
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