From 23cc0476c2ffbb1a5f6391bd1e0241207af768c3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 6 Nov 2026 22:16:26 +0100 Subject: [PATCH 1/4] drm/asahi: m5: admit sampler heaps A render or compute command with a sampler heap was refused, which drops every draw whose samplers go past the immediate range (GLES3 texture.units all_units, custom border colours). translate already range-checks the heap and the descriptor carries it at +0x87a/+0x882/ +0x886 as on G17P. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/asahi/m5/drm.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/asahi/m5/drm.rs b/drivers/gpu/drm/asahi/m5/drm.rs index 7252236924f91..add7668c446f6 100644 --- a/drivers/gpu/drm/asahi/m5/drm.rs +++ b/drivers/gpu/drm/asahi/m5/drm.rs @@ -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, @@ -369,7 +369,9 @@ 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. 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 @@ -388,7 +390,6 @@ fn admit_reference_render(command: &command::UapiRenderCommand) -> Result { || !(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); From 272899857e906ebe7215b5f163c531a5e67cd005 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 6 Nov 2026 22:16:32 +0100 Subject: [PATCH 2/4] drm/asahi: m5: admit occlusion queries Admit a render with an occlusion (visibility) buffer. translate already range-checks it and writes it to 0x15311 and the descriptor; Apple's visibility renders move only the ISP control and query-index words beside it (macOS 25G72, m5air gpu/g17g-witness/ppp/statedump.m occl=1/2), which userspace encodes. GLES3 occlusion_query passes with it. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/asahi/m5/drm.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/asahi/m5/drm.rs b/drivers/gpu/drm/asahi/m5/drm.rs index add7668c446f6..f06bc4c8b6624 100644 --- a/drivers/gpu/drm/asahi/m5/drm.rs +++ b/drivers/gpu/drm/asahi/m5/drm.rs @@ -369,8 +369,12 @@ impl queue::Queue for M5Queue { } } -/// Admit the captured M5 single-layer render-state envelope. A sampler heap -/// is admitted: translate range-checks it and the descriptor carries it +/// 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 { @@ -390,7 +394,6 @@ fn admit_reference_render(command: &command::UapiRenderCommand) -> Result { || !(1..=command::M5_MAX_RENDER_DIMENSION).contains(&u32::from(command.height)) || command.layers != 1 || !sample_layout - || command.occlusion_query_base != 0 || timestamps.iter().any(|timestamp| timestamp.handle != 0 || timestamp.offset != 0) { return Err(ENOTSUPP); } From d844b9dcbe1efdeaffb28900085d1bf062ab50a9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 6 Nov 2026 22:19:35 +0100 Subject: [PATCH 3/4] drm/asahi: m5: program the multisample ISP allocation from sample_size The render UAPI's samples and sample_size now reach the G17p parameters. The rendering descriptor derives the ISP sample control at +0x10051 and +0x1f38 from the sample stride instead of the fixed samples << 16 value, and +0x1fac carries the imageblock bytes per sample at two and four samples. The TA descriptor also names the unrounded TPC geometry size, which the 32x16 four-sample utile doubles; a render past one 4x4 group of tiles failed the GPU with the fixed size. The reference admission accepts the 32x32 two-sample and 32x16 four-sample layouts that Mesa's fbo.msaa rgba32f and depth16 cases submit. This is the programming the J813 bring-up measured on hardware. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/asahi/m5/command.rs | 2 + drivers/gpu/drm/asahi/m5/drm.rs | 21 ++------- drivers/gpu/drm/asahi/m5/render_desc.rs | 47 +++++++++++++++++-- drivers/gpu/drm/asahi/m5/render_target.rs | 11 +++-- .../drm/asahi/m5/resources/target_memory.rs | 8 ++++ 5 files changed, 65 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/asahi/m5/command.rs b/drivers/gpu/drm/asahi/m5/command.rs index 58e0ca0eb6670..5db5fa103cd9e 100644 --- a/drivers/gpu/drm/asahi/m5/command.rs +++ b/drivers/gpu/drm/asahi/m5/command.rs @@ -1005,6 +1005,8 @@ fn translate_render_command_with_capacity( 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; diff --git a/drivers/gpu/drm/asahi/m5/drm.rs b/drivers/gpu/drm/asahi/m5/drm.rs index f06bc4c8b6624..6ab2108d8813b 100644 --- a/drivers/gpu/drm/asahi/m5/drm.rs +++ b/drivers/gpu/drm/asahi/m5/drm.rs @@ -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. @@ -378,16 +370,9 @@ impl queue::Queue for M5Queue { /// (+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)) diff --git a/drivers/gpu/drm/asahi/m5/render_desc.rs b/drivers/gpu/drm/asahi/m5/render_desc.rs index 8e73ee27c5749..d81e1168e3bcc 100644 --- a/drivers/gpu/drm/asahi/m5/render_desc.rs +++ b/drivers/gpu/drm/asahi/m5/render_desc.rs @@ -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, @@ -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, @@ -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) } @@ -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), @@ -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); @@ -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 diff --git a/drivers/gpu/drm/asahi/m5/render_target.rs b/drivers/gpu/drm/asahi/m5/render_target.rs index a277377cb5851..1449fd43bde13 100644 --- a/drivers/gpu/drm/asahi/m5/render_target.rs +++ b/drivers/gpu/drm/asahi/m5/render_target.rs @@ -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 { @@ -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 }) } } diff --git a/drivers/gpu/drm/asahi/m5/resources/target_memory.rs b/drivers/gpu/drm/asahi/m5/resources/target_memory.rs index f0f2c5176018d..f182cf5ddf89a 100644 --- a/drivers/gpu/drm/asahi/m5/resources/target_memory.rs +++ b/drivers/gpu/drm/asahi/m5/resources/target_memory.rs @@ -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; From 0ad69a0ba33baf12aee75f98cdc8a80679cd54a4 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 6 Nov 2026 22:26:26 +0100 Subject: [PATCH 4/4] drm/asahi: m5: size the depth plane by AIL's sample-scaled element AIL folds the sample count into the data plane's element size and uses the expanded surface only for the compression metadata. The M5 depth admission expanded the dimensions for the data plane too, so the two-sample Depth16 surface of fbo.msaa.2_samples.depth_component16 (119x131, layer stride 0x18000) was validated as 0x20000 and rejected with ENOTSUPP even though the render itself was admitted. Count the 16-KiB tiles over the pixel dimensions with element size bytes_per_sample * samples, and pick the tile shape from that size: 64x64 at four bytes, 64x32 at eight, 128x64 at two. A one-sample surface computes exactly as before. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/asahi/m5/command.rs | 33 +++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/asahi/m5/command.rs b/drivers/gpu/drm/asahi/m5/command.rs index 5db5fa103cd9e..c07d1c1a5a9f8 100644 --- a/drivers/gpu/drm/asahi/m5/command.rs +++ b/drivers/gpu/drm/asahi/m5/command.rs @@ -755,8 +755,11 @@ fn validate_zls( } /// 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( command: &UapiRenderCommand, address_space: &A, @@ -796,20 +799,28 @@ pub(crate) fn validate_m5_reference_depth( } 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)?;