Skip to content
Merged
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
35 changes: 24 additions & 11 deletions drivers/gpu/drm/asahi/m5/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,11 @@ fn validate_zls<A: GpuAddressSpace>(
}

/// Validate the complete single-layer M5 Z/S allocations before their unused
/// array strides are discarded. AIL stores samples in an expanded 2D surface:
/// 2x doubles Y, and 4x doubles both axes. The dimensions register stays in pixels.
/// array strides are discarded. AIL folds the sample count into the data
/// plane's element size, so 2x Z16 tiles as 4-byte elements over the pixel
/// dimensions; the compression metadata uses the expanded surface instead
/// (2x doubles Y, 4x doubles both axes). The dimensions register stays in
/// pixels either way.
pub(crate) fn validate_m5_reference_depth<A: GpuAddressSpace>(
command: &UapiRenderCommand,
address_space: &A,
Expand Down Expand Up @@ -796,20 +799,28 @@ pub(crate) fn validate_m5_reference_depth<A: GpuAddressSpace>(
}
expected_control |= command.zls_control & transfers;
if compressed { expected_control |= compression; }
// AIL tiles contain 16 KiB: 64x64 Z32, 128x64 Z16, 128x128 S8.
// AIL tiles contain 16 KiB and their shape follows the element size:
// 64x64 at four bytes, 128x64 at two, 128x128 at one, 64x32 at eight
// and 32x32 at sixteen. The sample count scales that element size,
// so the tile shape must be picked from bytes_per_sample * samples
// and the tiles counted over the pixel dimensions.
// A miptail smaller than either tile axis is power-of-two padded and
// cacheline aligned, rather than rounded to a whole 16-KiB page.
let (tile_width, tile_height) = match bytes_per_sample {
4 => (64u32, 64u32),
let bytes_per_element = bytes_per_sample * u64::from(command.samples);
let (tile_width, tile_height) = match bytes_per_element {
1 => (128u32, 128u32),
2 => (128, 64),
_ => (128, 128),
4 => (64, 64),
8 => (64, 32),
16 => (32, 32),
_ => return Err(UapiTranslateError::ZlsFields),
};
let data_bytes = if sample_width >= tile_width && sample_height >= tile_height {
u64::from(sample_width.div_ceil(tile_width))
* u64::from(sample_height.div_ceil(tile_height)) * 0x4000
let data_bytes = if width >= tile_width && height >= tile_height {
u64::from(width.div_ceil(tile_width))
* u64::from(height.div_ceil(tile_height)) * 0x4000
} else {
(u64::from(sample_width.next_power_of_two())
* u64::from(sample_height.next_power_of_two()) * bytes_per_sample)
(u64::from(width.next_power_of_two())
* u64::from(height.next_power_of_two()) * bytes_per_element)
.div_ceil(128) * 128
};
require_range(address_space, plane.base, data_bytes, GpuAccess::ReadWrite)?;
Expand Down Expand Up @@ -1005,6 +1016,8 @@ fn translate_render_command_with_capacity<A: GpuAddressSpace>(
parameters.height = command.height as u32;
parameters.encoder = command.vdm_base;
parameters.layers = command.layers;
parameters.samples = command.samples;
parameters.sample_size = command.sample_size;
parameters.utile_width = command.utile_width;
parameters.utile_height = command.utile_height;
parameters.utile_config = utile_config;
Expand Down
33 changes: 11 additions & 22 deletions drivers/gpu/drm/asahi/m5/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl queue::Queue for M5Queue {
parser.finish().map_err(|_| EINVAL)?;
if let command::ParsedHardwareCommand::Compute { payload, attachments, .. } = command {
let timestamps = [payload.timestamps.start, payload.timestamps.end];
if payload.flags != 0 || payload.sampler_heap != 0 || payload.sampler_count != 0
if payload.flags != 0
|| timestamps.iter().any(|t| t.handle != 0 || t.offset != 0) {
pr_err!("M5 compute admission rejected flags={:#x} sampler_heap={:#x} samplers={} timestamps={}\n",
payload.flags, payload.sampler_heap, payload.sampler_count,
Expand Down Expand Up @@ -332,14 +332,6 @@ impl queue::Queue for M5Queue {
translated.parameters.depth_aux_stride = 0;
translated.parameters.stencil_stride = 0;
translated.parameters.stencil_aux_stride = 0;
if payload.samples > 1 {
// 25G76 2x/4x captures: 10051 carries samples << 16,
// d491 enables multisampling, and PTC gains eight entries.
// The UAPI already supplies sample positions and utile size.
translated.parameters.tib_blocks = u64::from(payload.samples) << 16;
controls.fragment.resource_flags |= 1 << 32;
controls.fragment.ptc_max = 0xd6;
}
// Native 25G76 indexed draws use 15021=0x10c000. The reference
// triangle's low bit causes fragment recovery with larger
// indexed overdraw, even after the tiling stage completes.
Expand Down Expand Up @@ -369,27 +361,24 @@ impl queue::Queue for M5Queue {
}
}

/// Admit the captured M5 single-layer render-state envelope. This is an experimental first-job ABI
/// Admit the captured M5 single-layer render-state envelope. An occlusion
/// (visibility) buffer is admitted: translate range-checks it and it is
/// written to 0x15311 and the descriptor, and Apple's visibility renders move
/// only the ISP control and query-index words beside it
/// (gpu/g17g-witness/ppp/statedump.m occl=1/2). A sampler heap is admitted:
/// translate range-checks it and the descriptor carries it
/// (+0x87a/+0x882/+0x886 as on G17P). This is an experimental first-job ABI
/// path, not an assertion that arbitrary Vulkan programs are supported.
fn admit_reference_render(command: &command::UapiRenderCommand) -> Result {
// A single 32-bit color target has an eight-byte aligned sample stride
// in Mesa's tilebuffer layout; sample_size includes that padding.
let sample_layout = match command.samples {
1 => command.utile_width == 32 && command.utile_height == 32,
2 => command.utile_width == 32 && command.utile_height == 32
&& command.sample_size == 8 && command.multisample_control == 0x44cc,
4 => command.utile_width == 32 && command.utile_height == 16
&& command.sample_size == 8 && command.multisample_control == 0xeaa2_6e26,
_ => false,
};
let sample_layout = matches!((command.utile_width, command.utile_height,
command.samples),
(32, 32, 1) | (32, 32, 2) | (32, 16, 4));
let timestamps = [command.vertex_timestamps.start, command.vertex_timestamps.end,
command.fragment_timestamps.start, command.fragment_timestamps.end];
if !(1..=command::M5_MAX_RENDER_DIMENSION).contains(&u32::from(command.width))
|| !(1..=command::M5_MAX_RENDER_DIMENSION).contains(&u32::from(command.height))
|| command.layers != 1
|| !sample_layout
|| command.sampler_heap != 0 || command.sampler_count != 0
|| command.occlusion_query_base != 0
|| timestamps.iter().any(|timestamp| timestamp.handle != 0 || timestamp.offset != 0) {
return Err(ENOTSUPP);
}
Expand Down
47 changes: 44 additions & 3 deletions drivers/gpu/drm/asahi/m5/render_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ pub(crate) struct G17pRenderParameters {
pub(crate) merge_upper_x_bits: u32,
pub(crate) merge_upper_y_bits: u32,
pub(crate) layers: u16,
/// Sample count: 1, 2 or 4. Defaults to 1, so every existing parameter
/// vector keeps its exact register program.
pub(crate) samples: u8,
/// Imageblock bytes per sample, as the render UAPI carries it. Read only
/// at two and four samples (`isp_sample_control`).
pub(crate) sample_size: u8,
/// Utile dimensions in pixels, including the sample-layout adjustment.
pub(crate) utile_width: u8,
pub(crate) utile_height: u8,
Expand Down Expand Up @@ -280,6 +286,8 @@ impl G17pRenderParameters {
merge_upper_x_bits: 0x3cdd_b3d9,
merge_upper_y_bits: 0x3cdd_b3d9,
layers: 1,
samples: 1,
sample_size: 0,
utile_width: 32,
utile_height: 32,
utile_config: 0xa000,
Expand Down Expand Up @@ -328,6 +336,32 @@ struct Geometry {
macro_size: u64,
}

/// Register 0x10051 and fragment descriptor +0x1f38. A single-sample render
/// keeps the TIB block count its captures were matched against. At two and
/// four samples the field is the ISP sample allocation instead, in bits
/// 16..20, as the g17 M5 driver programs it for native-sized 4x renders
/// (ewb/j716c-daily isp_sample_control). The block count left it zero, and
/// a 4x render of more than 16 tiles failed the GPU.
fn isp_sample_control(p: &G17pRenderParameters) -> u64 {
if p.samples <= 1 {
return p.tib_blocks;
}
let sample_bytes = (p.sample_size.max(8) as u64 + 7) & !7;
let groups = sample_bytes.div_ceil(32);
let units = (p.utile_width as u64 >> 3) * (p.utile_height as u64 >> 2) * groups;
let value = match p.samples {
2 => units.max(8) >> 3,
4 => units >> 1,
_ => 0,
};
let value = if p.samples == 2 && p.utile_width == 16 && p.utile_height == 16 {
value
} else {
value >> 1
};
(value & 0x1f) << 16
}

const fn align(value: u64, alignment: u64) -> u64 {
(value + alignment - 1) & !(alignment - 1)
}
Expand Down Expand Up @@ -619,7 +653,7 @@ fn build_fragment_registers_for_work_key(
RegisterWrite::new(0x15021, p.aux_fb_flags),
RegisterWrite::new(0x15211, ((p.height as u64) << 32) | p.width as u64),
RegisterWrite::new(0x15049, p.aux_fb_page_count),
RegisterWrite::new(0x10051, p.tib_blocks),
RegisterWrite::new(0x10051, isp_sample_control(p)),
RegisterWrite::new(0x15321, p.depth_dimensions),
RegisterWrite::new(0x15301, p.depth_clear_value_bits as u64),
RegisterWrite::new(0x15309, (p.stencil_clear_value | 0x300) as u64),
Expand Down Expand Up @@ -1060,7 +1094,7 @@ pub(crate) fn build_fragment_descriptor_base(
put_u64(raw, 0x1ea8, parameters.partial_load_pipeline_bind);
put_u64(raw, 0x1eb0, parameters.partial_load_pipeline);
put_u32(raw, 0x1ec0, 0x0404_0404);
put_u64(raw, 0x1f38, parameters.tib_blocks);
put_u64(raw, 0x1f38, isp_sample_control(parameters));
put_u64(raw, 0x1f40, parameters.aux_fb_flags);
put_u32(raw, 0x1f48, parameters.width);
put_u32(raw, 0x1f4c, parameters.height);
Expand All @@ -1071,7 +1105,14 @@ pub(crate) fn build_fragment_descriptor_base(
put_u32(raw, 0x1f98, parameters.partial_store_pipeline_bind as u32);
put_u64(raw, 0x1f9c, parameters.partial_store_pipeline);
put_u32(raw, 0x1fa8, parameters.depth_clear_value_bits);
put_u64(raw, 0x1fac, (parameters.tib_blocks << 33) | 0x300);
// +0x1fb0 is the imageblock allocation per sample. Twice the block count
// is that at one sample with a 32x32 utile; a multisampled render names
// it directly, as native's 4x captures keep it (g17 M5 driver).
if parameters.samples > 1 {
put_u64(raw, 0x1fac, ((parameters.sample_size as u64) << 32) | 0x300);
} else {
put_u64(raw, 0x1fac, (parameters.tib_blocks << 33) | 0x300);
}
// Native copies isMemorylessRender through the UMD render record +0x240,
// parsed record +0x1b8, and host descriptor +0x8bf into this byte. It is
// not a TIB-size predicate: native's memoryless policy also selects the
Expand Down
11 changes: 8 additions & 3 deletions drivers/gpu/drm/asahi/m5/render_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub(crate) struct M5RenderTargetLayout {
pub(crate) heapmeta_bytes: usize,
pub(crate) target_bytes: usize,
pub(crate) tpc_bytes: usize,
/// The TPC geometry size before page rounding: the TA descriptor's
/// +0x788 (the g17 M5 driver's `tpc_size`).
pub(crate) tpc_geometry_bytes: usize,
}

fn align(value: usize, alignment: usize) -> Option<usize> {
Expand Down Expand Up @@ -39,10 +42,12 @@ impl M5RenderTargetLayout {
let heapmeta_offset = align(tilemap_bytes, 0x1000)?;
let heapmeta_bytes = if layers > 1 { 0x300 } else { 0x200 };
let target_bytes = align(heapmeta_offset.checked_add(heapmeta_bytes)?, PAGE_BYTES)?;
let tpc_bytes = align(8usize.checked_mul(per_mtile)?.checked_mul(utiles)?
let tpc_geometry_bytes = 8usize.checked_mul(per_mtile)?.checked_mul(utiles)?
.checked_mul(16)?.checked_mul(layers as usize)?
.checked_mul(clusters as usize)?, PAGE_BYTES)?;
Some(Self { tilemap_bytes, heapmeta_offset, heapmeta_bytes, target_bytes, tpc_bytes })
.checked_mul(clusters as usize)?;
let tpc_bytes = align(tpc_geometry_bytes, PAGE_BYTES)?;
Some(Self { tilemap_bytes, heapmeta_offset, heapmeta_bytes, target_bytes, tpc_bytes,
tpc_geometry_bytes })
}
}

Expand Down
8 changes: 8 additions & 0 deletions drivers/gpu/drm/asahi/m5/resources/target_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ impl M5TargetMemory {
p.tilemap = self.target.iova();
p.heapmeta = self.target.iova() + self.layout.heapmeta_offset as u64;
p.tpc = self.tpc.iova();
// The TA descriptor names the TPC geometry it may fill. The single-
// sample captures hold 0x800 (one 32x32 utile per tile); a 32x16
// four-sample utile doubles it, and a render past one 4x4 group of
// tiles failed the GPU with the fixed value (g17 M5 driver: tpc_size
// from the same layout). Single-sample renders keep their value.
if p.samples > 1 {
p.tpc_size = self.layout.tpc_geometry_bytes as u64;
}
p.deflake_3 = self.deflake.iova();
p.deflake_2 = self.deflake.iova() + 0x40;
p.deflake_1 = self.deflake.iova() + 0x340;
Expand Down
Loading