From ce99a909013862203b4d62bca6410190929db8fb Mon Sep 17 00:00:00 2001 From: AxxzyWasTaken Date: Mon, 16 Nov 2026 19:49:11 +0000 Subject: [PATCH 1/3] drm/asahi: g17: scale the render pool floor from GPU shape 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 --- drivers/gpu/drm/asahi/g17/fw/freelist.rs | 6 ++ drivers/gpu/drm/asahi/g17/fw/render_rt.rs | 91 ++++++++++++++++++-- drivers/gpu/drm/asahi/g17/runtime/backend.rs | 7 +- 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/fw/freelist.rs b/drivers/gpu/drm/asahi/g17/fw/freelist.rs index 56c1f2324e2a1..fe5981b439666 100644 --- a/drivers/gpu/drm/asahi/g17/fw/freelist.rs +++ b/drivers/gpu/drm/asahi/g17/fw/freelist.rs @@ -10,6 +10,12 @@ pub(crate) const RUN_LIST_SIZE: usize = 0x1_0000; pub(crate) const TABLE_SIZE: usize = PAGE_LIST_SIZE + RUN_LIST_SIZE; pub(crate) const CONTROL_SIZE: usize = 0x4000; pub(crate) const RENDER_BLOCKS: usize = 44; +/// Minimum render pool per active USC core (in 1 MiB blocks) on GPUs with more +/// than two clusters. With clustered tiling running vertex work across all +/// clusters concurrently with fragment work, 44 blocks run out under Vulkan +/// vertex load (reason-0 no-progress recoveries); three blocks per enabled core +/// yield 96 blocks on 32-core T6041 and scale linearly on larger parts. +pub(crate) const MULTI_CLUSTER_RENDER_BLOCKS_PER_CORE: usize = 3; pub(crate) const COMPUTE_BLOCKS: usize = 21; /// Render reserves eight run words per block; compute packs runs consecutively. diff --git a/drivers/gpu/drm/asahi/g17/fw/render_rt.rs b/drivers/gpu/drm/asahi/g17/fw/render_rt.rs index 666209690efde..74679c34d18ae 100644 --- a/drivers/gpu/drm/asahi/g17/fw/render_rt.rs +++ b/drivers/gpu/drm/asahi/g17/fw/render_rt.rs @@ -1,8 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -use super::{compute::{IntersectionTables, ScratchRequest}, compute_pool, - freelist::{PAGE_LIST_SIZE, RENDER_BLOCKS}, - initdata::{FREE_LIST_BLOCK_PAGES, FREE_LIST_BLOCK_SIZE}}; +use super::{ + compute::{IntersectionTables, ScratchRequest}, + compute_pool, + freelist::{MULTI_CLUSTER_RENDER_BLOCKS_PER_CORE, PAGE_LIST_SIZE, RENDER_BLOCKS}, + initdata::{FREE_LIST_BLOCK_PAGES, FREE_LIST_BLOCK_SIZE}, +}; use kernel::prelude::*; #[derive(Clone, Copy)] @@ -33,18 +36,92 @@ impl RayQueryStage { } } +/// Minimum render pool in 1 MiB blocks for a GPU's cluster and active-core shape. +/// +/// One- and two-cluster parts (A18 Pro, M4 Pro) keep [`RENDER_BLOCKS`] (44), +/// which fits the narrow shared pool window and has been validated there. Above +/// two clusters, clustered tiling runs vertex shaders across every cluster +/// concurrently with fragment work, so the base pool scales linearly with +/// enabled cores at [`MULTI_CLUSTER_RENDER_BLOCKS_PER_CORE`] (3) blocks per +/// core, floored at [`RENDER_BLOCKS`]. +pub(crate) fn base_blocks(active_cores: u32, clusters: u32) -> Result { + if active_cores == 0 || clusters == 0 { + return Err(EINVAL); + } + if clusters <= 2 { + return Ok(RENDER_BLOCKS); + } + let scaled = usize::try_from(active_cores) + .ok() + .and_then(|cores| cores.checked_mul(MULTI_CLUSTER_RENDER_BLOCKS_PER_CORE)) + .ok_or(EOVERFLOW)?; + Ok(scaled.max(RENDER_BLOCKS)) +} + /// The render pool of an owner is shared by its `pairs` render pairs, each with -/// its own compute-pool extras. -pub(crate) fn required_blocks(active_cores: u32, pages: [u16; 2], pairs: u8) -> Result { +/// its own compute-pool extras on top of the GPU-shape base pool. +pub(crate) fn required_blocks( + active_cores: u32, + clusters: u32, + pages: [u16; 2], + pairs: u8, +) -> Result { + let base = base_blocks(active_cores, clusters)?; let extra = compute_pool::extra_bytes(active_cores, pages[0])? .checked_add(compute_pool::extra_bytes(active_cores, pages[1])?) .and_then(|bytes| bytes.checked_mul(u64::from(pairs))) .ok_or(EOVERFLOW)?; - let bytes = extra.checked_add((RENDER_BLOCKS * FREE_LIST_BLOCK_SIZE) as u64) + let base_bytes = u64::try_from(base) + .ok() + .and_then(|blocks| blocks.checked_mul(FREE_LIST_BLOCK_SIZE as u64)) .ok_or(EOVERFLOW)?; + let bytes = extra.checked_add(base_bytes).ok_or(EOVERFLOW)?; let blocks = usize::try_from(bytes.div_ceil(FREE_LIST_BLOCK_SIZE as u64)) .map_err(|_| EOVERFLOW)?; let maximum = PAGE_LIST_SIZE / (FREE_LIST_BLOCK_PAGES as usize * 8); - if blocks > maximum { return Err(E2BIG); } + if blocks > maximum { + return Err(E2BIG); + } Ok(blocks) } + +#[kernel::macros::kunit_tests(asahi_g17_render_pool)] +mod tests { + use super::*; + + #[test] + fn one_and_two_cluster_parts_keep_default_floor() { + for (cores, clusters) in [(5, 1), (6, 1), (8, 1), (10, 1), (16, 2), (20, 2)] { + assert_eq!(base_blocks(cores, clusters), Ok(RENDER_BLOCKS)); + assert_eq!(required_blocks(cores, clusters, [0, 0], 1), Ok(RENDER_BLOCKS)); + } + } + + #[test] + fn multi_cluster_parts_scale_with_active_cores() { + // 32-core J616C (4 clusters): 96 blocks; 40-core J614C/J575C (4 clusters): 120 blocks. + assert_eq!(required_blocks(32, 4, [0, 0], 1), Ok(96)); + assert_eq!(required_blocks(40, 4, [0, 0], 1), Ok(120)); + // A small hypothetical >2-cluster part stays floored at RENDER_BLOCKS. + assert_eq!(required_blocks(8, 4, [0, 0], 1), Ok(RENDER_BLOCKS)); + // Eight-cluster M5 Ultra topologies (M5 allocates its own pools, but queue creation + // still checks required_blocks): 192 / 240 blocks, well within the table limit. + assert_eq!(required_blocks(64, 8, [0, 0], 2), Ok(192)); + assert_eq!(required_blocks(80, 8, [0, 0], 2), Ok(240)); + } + + #[test] + fn ray_query_scratch_adds_on_top_of_base_pool() { + // 64 pages per stage -> per_core = 64 + 1 + 8 = 73 pages = 299,008 bytes/core/stage. + assert_eq!(required_blocks(20, 2, [64, 64], 1), Ok(44 + 12)); + assert_eq!(required_blocks(32, 4, [64, 64], 1), Ok(96 + 19)); + assert_eq!(required_blocks(40, 4, [64, 64], 1), Ok(120 + 23)); + } + + #[test] + fn rejects_invalid_shape_and_oversized_pools() { + assert_eq!(required_blocks(0, 4, [0, 0], 1), Err(EINVAL)); + assert_eq!(required_blocks(32, 0, [0, 0], 1), Err(EINVAL)); + assert_eq!(required_blocks(400, 4, [0, 0], 1), Err(E2BIG)); + } +} diff --git a/drivers/gpu/drm/asahi/g17/runtime/backend.rs b/drivers/gpu/drm/asahi/g17/runtime/backend.rs index 278534899b570..7b27cc53fe915 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/backend.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/backend.rs @@ -225,7 +225,12 @@ impl job::Backend for Backend { } fn render_scs_blocks(&self, pages: [u16; 2]) -> Result { - crate::g17::fw::render_rt::required_blocks(self.shared.active_cores, pages, self.pairs) + crate::g17::fw::render_rt::required_blocks( + self.shared.active_cores, + self.shared.clusters, + pages, + self.pairs, + ) } fn ensure_compute(&self, command: &crate::g17::command::Validated) -> Result { From 0ffbc70ac5c66b622ce79f443d9771ac2fdec2eb Mon Sep 17 00:00:00 2001 From: AxxzyWasTaken Date: Mon, 16 Nov 2026 19:49:11 +0000 Subject: [PATCH 2/3] drm/asahi: g17: tile clustered on the 32-core M4 Max (T6041 25G83) 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 --- drivers/gpu/drm/asahi/g17/buffer.rs | 11 +- drivers/gpu/drm/asahi/g17/buffer/target.rs | 39 +++++- drivers/gpu/drm/asahi/g17/fw/buffer.rs | 6 +- drivers/gpu/drm/asahi/g17/fw/render.rs | 115 ++++++++++++++---- drivers/gpu/drm/asahi/g17/fw/variant.rs | 5 + drivers/gpu/drm/asahi/g17/queue/render.rs | 1 + .../gpu/drm/asahi/g17/queue/render/memory.rs | 1 + drivers/gpu/drm/asahi/hw/t6041.rs | 25 +++- drivers/gpu/drm/asahi/hw/t6041_25g83.rs | 2 +- 9 files changed, 172 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/buffer.rs b/drivers/gpu/drm/asahi/g17/buffer.rs index 2e2c79ae15123..fd0aace6a4262 100644 --- a/drivers/gpu/drm/asahi/g17/buffer.rs +++ b/drivers/gpu/drm/asahi/g17/buffer.rs @@ -704,6 +704,8 @@ pub(crate) struct ManagerArgs { pub(crate) buffer_id: u8, pub(crate) generation: u64, pub(crate) first_ordinal: u64, + /// The heap's normal maximum in blocks (`Variant::tvb_normal_blocks`); NEO heaps only. + pub(crate) normal_blocks: usize, } /// A retained parameter-buffer graph and all of its sparse backing. Client @@ -793,7 +795,13 @@ impl Manager { ) -> Result { let geometry = tvb.geometry; let neo = geometry == BlockGeometry::NEO; - let layout = if neo { layout::Layout::NEO } else { layout::Layout::m5(geometry)? }; + let mut layout = if neo { layout::Layout::NEO } else { layout::Layout::m5(geometry)? }; + if neo { + if args.normal_blocks == 0 || args.normal_blocks > geometry.max_blocks() { + return Err(EINVAL); + } + layout.normal_blocks = args.normal_blocks; + } if metrics.scene_stride != layout.metric_stride { return Err(EINVAL); } @@ -827,6 +835,7 @@ impl Manager { discard: args.discard, buffer_id: args.buffer_id.into(), generation: args.generation, + normal_blocks: layout.normal_blocks, }; if neo { graph.initialize::(0, |view| view.init(&graph_args))?; diff --git a/drivers/gpu/drm/asahi/g17/buffer/target.rs b/drivers/gpu/drm/asahi/g17/buffer/target.rs index 8b87ccde7d985..b8c2677cb6648 100644 --- a/drivers/gpu/drm/asahi/g17/buffer/target.rs +++ b/drivers/gpu/drm/asahi/g17/buffer/target.rs @@ -35,6 +35,14 @@ const GTP_FIXED_SIZES: [usize; 4] = [0xc00, 0xa00, GTP6_SIZE, 0x80]; const GTP_SLOTS: usize = 64; const GTP6_SIZE: usize = GTP_SLOTS * (((cfg::TVB_MAX_BLOCKS * cfg::TVB_BLOCK_SIZE).div_ceil(0x8000) + 0x17ff) / 24 * 8 + 8); +/// Clustering metadata 2-4 (0x1c948, 0x1c888, 0x16c41/0x1ca40) on GPUs with more than two +/// clusters, at the sizes the M2 Pro/Max path gives them (`hw/t602x.rs` clustering config). +/// Metadata 1 (0x1c920) is sized per target there: [`META1_BLOCK_SIZE`] per block of tiles. +/// +/// macOS 26.6.2 on the J616C spaces a clustered pass's metadata 2, 3 and 4 0x1180, 0x1400 +/// and 0x1600 apart: metadata 2 needs 0x1180, more than the M2 Pro/Max 0xc00. +const GTP_MULTI_CLUSTER_SIZES: [usize; 3] = [0x1180, 0x280 * 16, 0x10 * 128]; +const META1_BLOCK_SIZE: usize = 0x44; /// Per-command geometry, independent of the capacity already allocated. #[derive(Copy, Clone, Debug)] @@ -116,15 +124,38 @@ impl Layout { let mut gtp = [None; 8]; let mut tpc_end = tpc_size; if programs == RegisterPrograms::V25G83 { + // The fixed sizes are the two-cluster M4 Pro's. With four clusters (M4 Max) clustered + // tiling outgrows them: the firmware then never starts a heavy render and kills it as + // no-progress (reason 0). Size them as the M2 Pro/Max path does. + let [meta2, meta3, meta4, meta1] = if clusters > 2 { + let meta1_blocks = aligned(tiles_x, 2)? + .checked_mul(aligned(tiles_y, 4)?) + .and_then(|v| v.checked_mul(utiles)) + .ok_or(EOVERFLOW)? + .div_ceil(0x1980); + [ + GTP_MULTI_CLUSTER_SIZES[0], + GTP_MULTI_CLUSTER_SIZES[1], + // Partial renders need the larger size here too. + GTP_MULTI_CLUSTER_SIZES[2].max(GTP6_SIZE), + aligned( + meta1_blocks.checked_mul(META1_BLOCK_SIZE).ok_or(EOVERFLOW)?, + 0x80, + )? + .max(GTP_FIXED_SIZES[3]), + ] + } else { + GTP_FIXED_SIZES + }; let sizes = [ tpc_size, tilemap_size.checked_mul(64).ok_or(EOVERFLOW)?, if layers > 1 { 0x4000 } else { 0 }, 0, - GTP_FIXED_SIZES[0], - GTP_FIXED_SIZES[1], - GTP_FIXED_SIZES[2], - GTP_FIXED_SIZES[3], + meta2, + meta3, + meta4, + meta1, ]; let mut position = 0; for ((offset, size), alignment) in gtp.iter_mut().zip(sizes).zip(GTP_ALIGNMENTS) { diff --git a/drivers/gpu/drm/asahi/g17/fw/buffer.rs b/drivers/gpu/drm/asahi/g17/fw/buffer.rs index 9d430d50db365..c6f9ef0819f75 100644 --- a/drivers/gpu/drm/asahi/g17/fw/buffer.rs +++ b/drivers/gpu/drm/asahi/g17/fw/buffer.rs @@ -22,6 +22,8 @@ pub(crate) const SIZE: usize = 0x48000; pub(crate) const METRICS_STRIDE: usize = SCENES * size_of::(); pub(crate) const METRICS_SLOTS: usize = cfg::METRICS_SIZE as usize / METRICS_STRIDE; pub(crate) const NORMAL_MAX_BLOCKS: usize = 0x45e; +/// The normal maximum of a four-cluster G17P heap: every slot of the block table. +pub(crate) const NORMAL_MAX_BLOCKS_FOUR_CLUSTERS: usize = cfg::TVB_MAX_BLOCKS; pub(crate) const GROW_BLOCKS: usize = 10; /// Firmware's active parameter-buffer state. Pointers at +0x44, +0x4c, @@ -136,6 +138,8 @@ pub(crate) struct GraphArgs<'a> { pub(crate) discard: u64, pub(crate) buffer_id: u32, pub(crate) generation: u64, + /// The heap's normal maximum in blocks (`Variant::tvb_normal_blocks`). + pub(crate) normal_blocks: usize, } pub(crate) fn compact_page(address: u64) -> Result { @@ -197,7 +201,7 @@ impl Graph { self.state.block_size = cfg::TVB_BLOCK_SIZE as u32; self.state.counter = offset_va(args.fw_va, COUNTER as u64)?; self.state.maximum_size = (cfg::TVB_BLOCK_SLOTS * 4) as u32; - self.state.normal_maximum_size = (NORMAL_MAX_BLOCKS * 4) as u32; + self.state.normal_maximum_size = (args.normal_blocks * 4) as u32; self.state.discard = discard; Ok(()) } diff --git a/drivers/gpu/drm/asahi/g17/fw/render.rs b/drivers/gpu/drm/asahi/g17/fw/render.rs index 1482ac68f2beb..9120b4126e32b 100644 --- a/drivers/gpu/drm/asahi/g17/fw/render.rs +++ b/drivers/gpu/drm/asahi/g17/fw/render.rs @@ -398,6 +398,9 @@ pub(crate) struct RenderArgs<'a> { pub(crate) programs: RegisterPrograms, /// Device/build policy for registers 0x1c890 and 0x1c918 in V25G83-format arrays. pub(crate) ta_mode_1: bool, + /// Clusters of the GPU: above two, clustered tiling takes the segment words of + /// `fw::m5::target::cluster_control` instead of the two-cluster capture. + pub(crate) clusters: u32, /// Deflake-buffer layout of the GPU. pub(crate) deflake: Deflake, } @@ -697,6 +700,13 @@ const T6041_TA_MODE_1: u64 = 1; /// Pages the tiler keeps out of a partial render's segments: without them the pages a pass /// returns shrink to none and the tiler can't advance. Fifteen blocks, macOS's minimum heap. const MIN_FREE_TVB_PAGES: u64 = 0x3c; +/// Free parameter-buffer pages (`0x1c9a8`) of a clustered V25G83 pass: `28 + 16 x clusters` +/// (`0x3c` for two clusters on M4 Pro, `0x5c` for four clusters on M4 Max as macOS 26.6.2 +/// writes it, four pages less than M5's `32 + 16 x clusters`). +const fn v25g83_clustered_free_pages(clusters: u32) -> u64 { + 0x1c + 0x10 * clusters as u64 +} +const _: () = assert!(v25g83_clustered_free_pages(2) == MIN_FREE_TVB_PAGES); /// The 25G83 tiling array: the A18 Pro's without 0x1748 and 0x1740 (and 0x17d9 unless the stage /// has SCS), with the tiler parameter sub-buffer registers and 0x10131 = 0x88, in the order the @@ -748,10 +758,20 @@ fn ta_registers_25g83( push(find(0x1c880, 0)?); push(RegisterWrite::new(0x1c948, gtp(4)?)); push(RegisterWrite::new(0x1c888, gtp(5)?)); - let (segment_control, segment_index) = if args.ta_mode_1 { - (T6041_TA_MODE_1, 0) - } else { - (VDM_SEGMENT_CONTROL, VDM_SEGMENT_INDEX) + let multi = (!args.ta_mode_1 && args.clusters > 2) + .then(|| { + super::m5::target::cluster_control( + args.clusters, + v25g83_clustered_free_pages(args.clusters), + ) + }) + .flatten(); + let (segment_control, segment_index, free_pages) = match (args.ta_mode_1, multi) { + (true, _) => (T6041_TA_MODE_1, 0, MIN_FREE_TVB_PAGES), + // Above two clusters (four-cluster M4 Max: 0x280540 / 4 / 0x5c): segment words from + // cluster_control() with the V25G83 free-page count (28 + 16 x clusters). + (false, Some([control, index, pages])) => (control, index, pages), + (false, None) => (VDM_SEGMENT_CONTROL, VDM_SEGMENT_INDEX, MIN_FREE_TVB_PAGES), }; push(RegisterWrite::new(0x1c890, segment_control)); push(RegisterWrite::new(0x1c918, segment_index)); @@ -761,7 +781,7 @@ fn ta_registers_25g83( push(RegisterWrite::new(0x1c9e0, gtp2)); push(RegisterWrite::new(0x16c41, gtp6)); push(RegisterWrite::new(0x1ca40, gtp6)); - push(RegisterWrite::new(0x1c9a8, MIN_FREE_TVB_PAGES)); + push(RegisterWrite::new(0x1c9a8, free_pages)); push(RegisterWrite::new(0x1c920, gtp(7)?)); for reg in [0x10151, 0x1c199, 0x1c1a1, 0x1c1a9, 0x1c1b1, 0x1c1b9, 0x1c8f8, 0x1c0b1, 0x1c850] { push(find(reg, 0)?); @@ -1753,49 +1773,69 @@ mod ta_mode_tests { } } - /// The variants of the builds T6041 admits: 25F84, then 25G83 and 26B123, each of which the - /// 40- and the 32-core configurations run with the same rules. - fn t6041_variants() -> [&'static Variant; 3] { + /// The variants of the builds T6041 admits: 25F84, 40-core 25G83, 32-core 25G83, and 26B123. + fn t6041_variants() -> [&'static Variant; 4] { let Firmware::Identified(builds) = crate::hw::t6041::CONFIG.firmware else { panic!("T6041 must identify its loaded firmware"); }; assert_eq!(builds.len(), 5); for (full, cut) in [(1, 2), (3, 4)] { let (full, cut) = (builds[full].variant, builds[cut].variant); - assert_eq!(full.ta_mode_1, cut.ta_mode_1); assert_eq!(full.compute, cut.compute); assert_eq!(full.programs, cut.programs); } - [builds[0].variant, builds[1].variant, builds[3].variant] + assert_eq!(builds[3].variant.ta_mode_1, builds[4].variant.ta_mode_1); + [ + builds[0].variant, + builds[1].variant, + builds[2].variant, + builds[3].variant, + ] } - /// The TA mode of every admitted T6041 build. + /// The TA mode of the non-clustered T6041 builds (25F84, 40-core 25G83, and 26B123). fn t6041_ta_mode_1() -> bool { - let [f84, g83, b123] = t6041_variants(); - assert_eq!(f84.ta_mode_1, g83.ta_mode_1); + let [f84, g83_40, _, b123] = t6041_variants(); + assert_eq!(f84.ta_mode_1, g83_40.ta_mode_1); assert_eq!(f84.ta_mode_1, b123.ta_mode_1); f84.ta_mode_1 } #[test] fn policy_is_local_to_the_admitted_t6041_builds() { - let [f84, g83, b123] = t6041_variants(); + let [f84, g83_40, g83_32, b123] = t6041_variants(); let pro = selected(&crate::hw::t6040::CONFIG.firmware); assert_eq!(f84.compute, crate::g17::fw::compute::ComputeProgram::V25F84); assert!(f84.split_firmware_area); // 25G83 keeps the M4 Pro's queue and compute rules on the M4 Max. - assert_eq!(g83.compute, pro.compute); - assert_eq!(g83.split_firmware_area, pro.split_firmware_area); - assert_eq!(g83.opening_record, pro.opening_record); - assert_eq!(g83.qid_floor, pro.qid_floor); - assert_eq!(g83.registration, pro.registration); + for g83 in [g83_40, g83_32] { + assert_eq!(g83.compute, pro.compute); + assert_eq!(g83.split_firmware_area, pro.split_firmware_area); + assert_eq!(g83.opening_record, pro.opening_record); + assert_eq!(g83.qid_floor, pro.qid_floor); + assert_eq!(g83.registration, pro.registration); + } // 26B123 runs 25F84's compute program with one firmware area. assert_eq!(b123.compute, f84.compute); assert!(!b123.split_firmware_area); - for max in [f84, g83, b123] { + for max in [f84, g83_40, g83_32, b123] { assert_eq!(max.programs, RegisterPrograms::V25G83); - assert!(max.ta_mode_1); } + // 25F84 and 40-core 25G83 keep TA mode 1; 32-core 25G83 tiles clustered with a heap that + // may fill the block table. + assert!(f84.ta_mode_1); + assert!(g83_40.ta_mode_1); + assert!(!g83_32.ta_mode_1); + assert_eq!( + g83_32.tvb_normal_blocks, + crate::g17::fw::buffer::NORMAL_MAX_BLOCKS_FOUR_CLUSTERS, + ); + assert_eq!(g83_40.tvb_normal_blocks, crate::g17::fw::buffer::NORMAL_MAX_BLOCKS); + assert_eq!(f84.tvb_normal_blocks, crate::g17::fw::buffer::NORMAL_MAX_BLOCKS); + assert_eq!(pro.tvb_normal_blocks, crate::g17::fw::buffer::NORMAL_MAX_BLOCKS); + // 26B123 keeps 25F84's TA mode 1 and heap maximum. + assert!(b123.ta_mode_1); + assert_eq!(b123.tvb_normal_blocks, crate::g17::fw::buffer::NORMAL_MAX_BLOCKS); assert!(!pro.ta_mode_1); assert!(!V25F84.ta_mode_1); assert!(!V25G83.ta_mode_1); @@ -1848,6 +1888,7 @@ mod ta_mode_tests { fragment: stage, programs: RegisterPrograms::V25G83, ta_mode_1: false, + clusters: 2, deflake: Deflake::FOUR_CLUSTERS, } } @@ -1892,6 +1933,38 @@ mod ta_mode_tests { } } + #[test] + fn four_clusters_take_the_four_cluster_segment_words() { + let (pass, resources) = fixture(); + let geometry = Geometry::new(&pass).unwrap(); + let words = PassWords::new(&pass).unwrap(); + let find = |a: &[RegisterWrite], reg: u32| a.iter().find(|w| w.reg == reg).map(|w| w.value); + let mut args = args(&pass, &resources, false); + let (two, count) = ta_registers_25g83(&args, &geometry, &words).unwrap(); + assert_eq!(find(&two[..count], 0x1c890), Some(VDM_SEGMENT_CONTROL)); + assert_eq!(find(&two[..count], 0x1c918), Some(VDM_SEGMENT_INDEX)); + assert_eq!(find(&two[..count], 0x1c9a8), Some(MIN_FREE_TVB_PAGES)); + args.clusters = 4; + let (four, count4) = ta_registers_25g83(&args, &geometry, &words).unwrap(); + assert_eq!(count4, count); + assert_eq!(find(&four[..count4], 0x1c890), Some(0x28_0540)); + assert_eq!(find(&four[..count4], 0x1c918), Some(4)); + assert_eq!(find(&four[..count4], 0x1c9a8), Some(0x5c)); + args.clusters = 8; + let (eight, count8) = ta_registers_25g83(&args, &geometry, &words).unwrap(); + assert_eq!(count8, count); + assert_eq!(find(&eight[..count8], 0x1c890), Some(0x30_0640)); + assert_eq!(find(&eight[..count8], 0x1c918), Some(4)); + assert_eq!(find(&eight[..count8], 0x1c9a8), Some(0x9c)); + // TA mode 1 is unaffected by the cluster count. + args.clusters = 4; + args.ta_mode_1 = true; + let (mode1, count1) = ta_registers_25g83(&args, &geometry, &words).unwrap(); + assert_eq!(count1, count); + assert_eq!(find(&mode1[..count1], 0x1c890), Some(T6041_TA_MODE_1)); + assert_eq!(find(&mode1[..count1], 0x1c9a8), Some(MIN_FREE_TVB_PAGES)); + } + #[test] fn mode_does_not_change_fragment_or_g17p_arrays() { let (pass, resources) = fixture(); diff --git a/drivers/gpu/drm/asahi/g17/fw/variant.rs b/drivers/gpu/drm/asahi/g17/fw/variant.rs index 59e9a5382cf8c..0f1319f84ee71 100644 --- a/drivers/gpu/drm/asahi/g17/fw/variant.rs +++ b/drivers/gpu/drm/asahi/g17/fw/variant.rs @@ -84,6 +84,9 @@ pub(crate) struct Variant { pub(crate) programs: super::render::RegisterPrograms, /// Use 0x1c890 = 1, 0x1c918 = 0 in V25G83-format tiling arrays (device/build policy). pub(crate) ta_mode_1: bool, + /// The normal maximum of a G17P tiler heap in blocks, which bounds host growth and the + /// firmware's own (device/build policy). + pub(crate) tvb_normal_blocks: usize, pub(crate) compute: super::compute::ComputeProgram, pub(crate) opening_record: bool, pub(crate) split_firmware_area: bool, @@ -156,6 +159,7 @@ pub(crate) const V26A428: Variant = Variant { lead_commands: false, programs: super::render::RegisterPrograms::G17P, ta_mode_1: false, + tvb_normal_blocks: super::buffer::NORMAL_MAX_BLOCKS, compute: super::compute::ComputeProgram::G17P, opening_record: true, split_firmware_area: false, @@ -197,6 +201,7 @@ pub(crate) const V25G83: Variant = Variant { lead_commands: true, programs: super::render::RegisterPrograms::V25G83, ta_mode_1: false, + tvb_normal_blocks: super::buffer::NORMAL_MAX_BLOCKS, compute: super::compute::ComputeProgram::G17P, opening_record: true, split_firmware_area: false, diff --git a/drivers/gpu/drm/asahi/g17/queue/render.rs b/drivers/gpu/drm/asahi/g17/queue/render.rs index 64d3f50a5df9d..4257f421dafef 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render.rs @@ -612,6 +612,7 @@ impl Pair { }, programs: self.variant.programs, ta_mode_1: self.variant.ta_mode_1, + clusters: self.clusters, deflake: deflake_layout, }; self.memory.graph.claim(ordinal)?; diff --git a/drivers/gpu/drm/asahi/g17/queue/render/memory.rs b/drivers/gpu/drm/asahi/g17/queue/render/memory.rs index f7698a7e3b0b7..4cc04e2ac23e9 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render/memory.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render/memory.rs @@ -603,6 +603,7 @@ impl Memory { buffer_id: buffer_id.0, generation: pm_generation, first_ordinal: ordinal, + normal_blocks: variant.tvb_normal_blocks, }, )?; let predecessor = crate::g17::ids::OBJECTS.object()?; diff --git a/drivers/gpu/drm/asahi/hw/t6041.rs b/drivers/gpu/drm/asahi/hw/t6041.rs index 30370e792e169..92942c1c0aefd 100644 --- a/drivers/gpu/drm/asahi/hw/t6041.rs +++ b/drivers/gpu/drm/asahi/hw/t6041.rs @@ -79,9 +79,8 @@ const BUILDS: [fw::variant::Build; 5] = [ ..BUILD_25G83 }, fw::variant::Build { - name: "macOS 26.6.2 (25G83, iBoot mBoot-18000.161.10), 32 cores", config: Some(&super::t6041_25g83::CONFIG), - ..BUILD_25G83 + ..BUILD_25G83_32CORE }, fw::variant::Build { config: Some(&BASE), @@ -141,8 +140,8 @@ const BUILD_25F84: fw::variant::Build = fw::variant::Build { /// The macOS 26.6.2 boot firmware (iBoot mBoot-18000.161.10) loads the 25G83 build the M4 Pro /// runs. iBoot fills part of the loaded TEXT for each Mac, so each admitted image is a -/// measurement. Four are listed: the 32-core J616C's, which runs with -/// [`super::t6041_25g83::CONFIG`], and the 40-core J614C's and J575C's, which run with +/// measurement. Four are listed: the 32-core J616C's, which runs via [`BUILD_25G83_32CORE`] +/// with [`super::t6041_25g83::CONFIG`], and the 40-core J614C's and J575C's, which run with /// [`CONFIG_25G83`]. The J575C's is measured with its boot-filled ranges zeroed, as is the /// J614C's under system firmware 27.2, whose iBoot fills the same ranges. pub(super) const BUILD_25G83: fw::variant::Build = fw::variant::Build { @@ -203,7 +202,8 @@ pub(super) const BUILD_25G83: fw::variant::Build = fw::variant::Build { ], }, ], - // Four clusters: the tiler segment values of 25F84 on this machine. + // 40-core T6041 parts (J614C, J575C) stay on TA mode 1 until clustered tiling is tested on + // 40-core hardware; 32-core parts run [`BUILD_25G83_32CORE`] below. variant: &fw::variant::Variant { ta_mode_1: true, ..fw::variant::V25G83 @@ -211,6 +211,21 @@ pub(super) const BUILD_25G83: fw::variant::Build = fw::variant::Build { config: None, }; +/// 32-core T6041 (J616C) on 25G83: inherits the 25G83 image list (the 32- vs 40-core config +/// is chosen by probed core count) and tiles clustered with the four-cluster segment words +/// (`fw::m5::target::cluster_control`). A clustered RD32 Minecraft frame needs ~1600-2200 heap +/// blocks, past the 0x45e normal maximum, and at that maximum a four-cluster pass never starts +/// (reason 0 recoveries), so the heap may use every slot of the block table. +pub(super) const BUILD_25G83_32CORE: fw::variant::Build = fw::variant::Build { + name: "macOS 26.6.2 (25G83, iBoot mBoot-18000.161.10), 32 cores", + variant: &fw::variant::Variant { + ta_mode_1: false, + tvb_normal_blocks: crate::g17::fw::buffer::NORMAL_MAX_BLOCKS_FOUR_CLUSTERS, + ..fw::variant::V25G83 + }, + ..BUILD_25G83 +}; + /// The 40-core M4 Max on 25G83: the 25F84 configuration with the 25G83 register map and /// [`CHIP_25G83`]. const CONFIG_25G83: Config = Config { diff --git a/drivers/gpu/drm/asahi/hw/t6041_25g83.rs b/drivers/gpu/drm/asahi/hw/t6041_25g83.rs index 955e45e14d2c3..6ccd27f2ddc11 100644 --- a/drivers/gpu/drm/asahi/hw/t6041_25g83.rs +++ b/drivers/gpu/drm/asahi/hw/t6041_25g83.rs @@ -47,7 +47,7 @@ pub(super) const CONFIG: Config = Config { perf: Some(&PERF), region_c: Some(®ION_C), chip: Some(&CHIP), - firmware: fw::variant::Firmware::Identified(&[t6041::BUILD_25G83, t6041::BUILD_26B123]), + firmware: fw::variant::Firmware::Identified(&[t6041::BUILD_25G83_32CORE, t6041::BUILD_26B123]), core_layout: CoreLayout { cores: Some((4, 32)), alternate_core_masks: None, From 2ba7a68b14a5072cd77fa22736f9f09d89f4a7a6 Mon Sep 17 00:00:00 2001 From: AxxzyWasTaken Date: Tue, 17 Nov 2026 20:54:56 +0000 Subject: [PATCH 3/3] drm/asahi: g17: a 16 KiB floor for four-cluster metadata 1 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 --- drivers/gpu/drm/asahi/g17/buffer/target.rs | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/asahi/g17/buffer/target.rs b/drivers/gpu/drm/asahi/g17/buffer/target.rs index b8c2677cb6648..c17e6c3643f2e 100644 --- a/drivers/gpu/drm/asahi/g17/buffer/target.rs +++ b/drivers/gpu/drm/asahi/g17/buffer/target.rs @@ -42,6 +42,15 @@ const GTP6_SIZE: usize = GTP_SLOTS /// macOS 26.6.2 on the J616C spaces a clustered pass's metadata 2, 3 and 4 0x1180, 0x1400 /// and 0x1600 apart: metadata 2 needs 0x1180, more than the M2 Pro/Max 0xc00. const GTP_MULTI_CLUSTER_SIZES: [usize; 3] = [0x1180, 0x280 * 16, 0x10 * 128]; +/// Floor for four-cluster metadata 1 (`0x1c920`, `gtp[7]`). +/// +/// The M2 Pro/Max per-block formula yields 0x100 (32x32 utiles) or 0x180 (16x16) on a +/// 3456x2234 Retina frame (Minecraft RD32) and 0x1100 on 10240x10240 (`point_size_10000`, +/// 16x16 utiles). 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; keep a conservative 16 KiB floor until a capture or hardware +/// high-water measurement shows the true upper bound. +const META1_MIN_SIZE: usize = 0x4000; const META1_BLOCK_SIZE: usize = 0x44; /// Per-command geometry, independent of the capacity already allocated. @@ -142,7 +151,7 @@ impl Layout { meta1_blocks.checked_mul(META1_BLOCK_SIZE).ok_or(EOVERFLOW)?, 0x80, )? - .max(GTP_FIXED_SIZES[3]), + .max(META1_MIN_SIZE), ] } else { GTP_FIXED_SIZES @@ -507,4 +516,28 @@ mod tests { layout.tpc_end = layout.tpc_size; assert_eq!(layout.tpc_capacity(), Err(ERANGE)); } + + #[test] + fn four_cluster_v25g83_metadata_layout() { + let mut retina = pass(3456, 32); + retina.height = 2234; + for (target, utile) in [(retina, 32), (retina, 16), (pass(10240, 16), 16)] { + let mut p = target; + p.utile_width = utile; + p.utile_height = utile; + let layout = Layout::new(&p, 4, RegisterPrograms::V25G83).unwrap(); + let gtp4 = layout.gtp[4].unwrap(); + let gtp5 = layout.gtp[5].unwrap(); + let gtp6 = layout.gtp[6].unwrap(); + let gtp7 = layout.gtp[7].unwrap(); + assert_eq!(gtp5 - gtp4, GTP_MULTI_CLUSTER_SIZES[0]); + assert!(gtp6 - gtp5 >= GTP_MULTI_CLUSTER_SIZES[1]); + assert!(gtp7 - gtp6 >= GTP_MULTI_CLUSTER_SIZES[2].max(GTP6_SIZE)); + assert_eq!(layout.tpc_end - gtp7, META1_MIN_SIZE); + } + // Two-cluster V25G83 (M4 Pro) keeps its original fixed metadata sizes. + let two = Layout::new(&retina, 2, RegisterPrograms::V25G83).unwrap(); + assert_eq!(two.gtp[5].unwrap() - two.gtp[4].unwrap(), GTP_FIXED_SIZES[0]); + assert_eq!(two.tpc_end - two.gtp[7].unwrap(), GTP_FIXED_SIZES[3]); + } }