Skip to content
Closed
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
Loading
Loading