Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion drivers/gpu/drm/asahi/g17/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -793,7 +795,13 @@ impl Manager {
) -> Result<Self> {
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);
}
Expand Down Expand Up @@ -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::<fw::Graph>(0, |view| view.init(&graph_args))?;
Expand Down
72 changes: 68 additions & 4 deletions drivers/gpu/drm/asahi/g17/buffer/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ 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];
/// 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.
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -116,15 +133,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(META1_MIN_SIZE),
]
} 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) {
Expand Down Expand Up @@ -476,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]);
}
}
6 changes: 5 additions & 1 deletion drivers/gpu/drm/asahi/g17/fw/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub(crate) const SIZE: usize = 0x48000;
pub(crate) const METRICS_STRIDE: usize = SCENES * size_of::<u32>();
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,
Expand Down Expand Up @@ -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<u32> {
Expand Down Expand Up @@ -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(())
}
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/g17/fw/freelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
115 changes: 94 additions & 21 deletions drivers/gpu/drm/asahi/g17/fw/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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)?);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1848,6 +1888,7 @@ mod ta_mode_tests {
fragment: stage,
programs: RegisterPrograms::V25G83,
ta_mode_1: false,
clusters: 2,
deflake: Deflake::FOUR_CLUSTERS,
}
}
Expand Down Expand Up @@ -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();
Expand Down
Loading
Loading