From 2fc7c2147b28341d03886267d3abb4cce054fdef Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 26 Nov 2026 21:23:14 -0500 Subject: [PATCH 1/2] drm/asahi: g16: accept 48 KiB tile buffers on the M4 macOS 26B123 runs MSAA4 render passes on the M4 (G16G) with 48 KiB tiles: 32x16 utiles of up to 24 bytes per sample. The g16 backend refused any tile buffer over 32 KiB, so Mesa has to fall back to 16x16 utiles for the same passes, which doubles the tile count of a 1080p MSAA4 pass. Keep the limit per chip in the g16 configuration: 48 KiB for T8132, 32 KiB for the M3 family (T6030, T8122) until each is shown to work there. Report the higher limit as DRM_ASAHI_FEATURE_TILE_BUFFER_48K, bit 46, so that userspace sizes tiles from what the kernel accepts. The g15, g17 and g18 backends do not report the bit. The 48 KiB value is the one macOS programs on this GPU; the hardware may accept more, but this backend does not claim it. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/file.rs | 3 ++ drivers/gpu/drm/asahi/g16/command.rs | 5 ++- drivers/gpu/drm/asahi/g16/hw.rs | 11 ++++++ drivers/gpu/drm/asahi/g16/params.rs | 5 +++ drivers/gpu/drm/asahi/g16/queue.rs | 1 + include/uapi/drm/asahi_drm.h | 8 ++++ .../gpu/asahi-m4/test-command-stream.py | 37 +++++++++++++++---- 7 files changed, 61 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/asahi/file.rs b/drivers/gpu/drm/asahi/file.rs index fc2d2dd6cedaf..bd4554611267d 100644 --- a/drivers/gpu/drm/asahi/file.rs +++ b/drivers/gpu/drm/asahi/file.rs @@ -94,6 +94,9 @@ pub(crate) const DRM_ASAHI_RENDER_SHADER_WRITES: u32 = /// (DRM_ASAHI_RENDER_STAGE_PREFIXES), as the complete struct drm_asahi_cmd_render_m5. pub(crate) const DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2: u64 = uapi::DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2 as u64; +/// Render commands accept tile buffers of up to 48 KiB. +pub(crate) const DRM_ASAHI_FEATURE_TILE_BUFFER_48K: u64 = + uapi::DRM_ASAHI_FEATURE_TILE_BUFFER_48K as u64; /// Compute commands may declare a stream that ends with a memory-scoped flush /// (DRM_ASAHI_COMPUTE_VISIBLE_COMPLETION). pub(crate) const DRM_ASAHI_FEATURE_COMPUTE_VISIBLE_COMPLETION: u64 = diff --git a/drivers/gpu/drm/asahi/g16/command.rs b/drivers/gpu/drm/asahi/g16/command.rs index 197d31e93fa0f..e499231e06084 100644 --- a/drivers/gpu/drm/asahi/g16/command.rs +++ b/drivers/gpu/drm/asahi/g16/command.rs @@ -74,7 +74,6 @@ const SET_COMPUTE_ATTACHMENTS: u32 = uapi::drm_asahi_cmd_type_DRM_ASAHI_SET_COMP const MAX_DIMENSION: u16 = 16384; const MAX_LAYERS: u16 = 2048; -const MAX_TILE_BUFFER: u32 = 32768; const ZLS_METADATA_STRIDE: u64 = 0x80; /// Size of a queue's USC window. pub(crate) const USC_WINDOW: u64 = 1 << 32; @@ -373,6 +372,8 @@ pub(crate) struct Context<'a> { pub(crate) active_cores: u32, /// The queue's reserved render scratch pages per stage (`render_scs_layout`). pub(crate) render_scs: [u16; 2], + /// Largest tile buffer render commands may use, in bytes (`Config::max_tile_buffer`). + pub(crate) max_tile_buffer: u32, } /// A stream whose timestamps and ordinals are resolved ([`ParsedStream::prepare`]), before its @@ -1277,7 +1278,7 @@ fn check_render_for( || !matches!(cmd.samples, 1 | 2 | 4) || !matches!(cmd.utile_width_px, 16 | 32) || !matches!(cmd.utile_height_px, 16 | 32) - || tile_buffer > MAX_TILE_BUFFER + || tile_buffer > context.max_tile_buffer || cmd.sampler_heap != 0 || cmd.sampler_count != 0 || cmd.ppp_ctrl & !0x203 != 0 diff --git a/drivers/gpu/drm/asahi/g16/hw.rs b/drivers/gpu/drm/asahi/g16/hw.rs index 4026072bde1ee..2ea74d873e127 100644 --- a/drivers/gpu/drm/asahi/g16/hw.rs +++ b/drivers/gpu/drm/asahi/g16/hw.rs @@ -92,6 +92,10 @@ pub(crate) struct Config { pub(crate) supports_render_scs: bool, /// Whether FS->compute cross-engine barriers require `BarrierType::Hold` (type 1), as on G15. pub(crate) cross_engine_hold: bool, + /// Largest tile buffer a render command may use, in bytes per tile (sample size times + /// utile width, utile height and samples). Reported as DRM_ASAHI_FEATURE_TILE_BUFFER_48K + /// when it reaches [`sizes::TILE_BUFFER_48K`]. + pub(crate) max_tile_buffer: u32, } impl Config { @@ -242,6 +246,8 @@ pub(crate) mod t8132 { deep_sleep: true, supports_render_scs: true, cross_engine_hold: false, + // macOS 26B123 programs 48 KiB tiles (MSAA4, 32x16 utiles) on this GPU. + max_tile_buffer: super::sizes::TILE_BUFFER_48K, }; /// What iBoot writes into the 25G83 build b000 TEXT it loads, in TEXT order: @@ -401,6 +407,7 @@ pub(crate) mod t6030 { deep_sleep: false, supports_render_scs: false, cross_engine_hold: true, + max_tile_buffer: super::sizes::TILE_BUFFER_32K, }; const LAYOUT: FwLayout = FwLayout { @@ -541,6 +548,7 @@ pub(crate) mod t8122 { deep_sleep: false, supports_render_scs: false, cross_engine_hold: true, + max_tile_buffer: super::sizes::TILE_BUFFER_32K, }; /// 26B123 G15G: __TEXT 0x64000 as on G16G, __DATA 0xb4000 and the 0x8000 __DATA_SHARED_RO @@ -1101,6 +1109,9 @@ pub(crate) mod client { /// Sizes and counts of the engine's objects. pub(crate) mod sizes { + /// Tile buffer limits of [`super::Config::max_tile_buffer`]. + pub(crate) const TILE_BUFFER_32K: u32 = 32 * 1024; + pub(crate) const TILE_BUFFER_48K: u32 = 48 * 1024; pub(crate) const POOLS: usize = 16; pub(crate) const POOL_SIZE: u64 = 0x200000; pub(crate) const FREELIST_SEED: u32 = 8192; diff --git a/drivers/gpu/drm/asahi/g16/params.rs b/drivers/gpu/drm/asahi/g16/params.rs index 869ab8bd1daa6..1aef70eae06d7 100644 --- a/drivers/gpu/drm/asahi/g16/params.rs +++ b/drivers/gpu/drm/asahi/g16/params.rs @@ -102,6 +102,11 @@ pub(crate) fn fill(gpu: &Gpu, params: &mut uapi::drm_asahi_params_global) -> Res } else { 0 } + | if gpu.cfg.max_tile_buffer >= hw::sizes::TILE_BUFFER_48K { + crate::file::DRM_ASAHI_FEATURE_TILE_BUFFER_48K + } else { + 0 + } | crate::g17::sync_output::FEATURE_CUMULATIVE_SIGNALS | crate::file::DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2; params.gpu_generation = gpu.cfg.gpu_generation; diff --git a/drivers/gpu/drm/asahi/g16/queue.rs b/drivers/gpu/drm/asahi/g16/queue.rs index 7fadc1a3af5d7..98381912f9eab 100644 --- a/drivers/gpu/drm/asahi/g16/queue.rs +++ b/drivers/gpu/drm/asahi/g16/queue.rs @@ -288,6 +288,7 @@ impl Queue { usc_base: self.state.usc_base, active_cores: self.active_cores, render_scs: self.render_scs, + max_tile_buffer: self.cfg.max_tile_buffer, }, &mut self.proof, )?; diff --git a/include/uapi/drm/asahi_drm.h b/include/uapi/drm/asahi_drm.h index dd79dfb569bdc..f1fee4537e2b9 100644 --- a/include/uapi/drm/asahi_drm.h +++ b/include/uapi/drm/asahi_drm.h @@ -605,6 +605,14 @@ enum drm_asahi_feature { */ #define DRM_ASAHI_FEATURE_ORDERED_PARTIAL_RENDERS ((1ULL) << 45) +/* + * DRM_ASAHI_FEATURE_TILE_BUFFER_48K: render commands accept tile buffers of + * up to 48 KiB (sample_size_B * utile_width_px * utile_height_px * samples + * <= 49152), instead of 32 KiB. A feature bit like those of enum + * drm_asahi_feature, defined here like bit 32. + */ +#define DRM_ASAHI_FEATURE_TILE_BUFFER_48K ((1ULL) << 46) + #define DRM_ASAHI_PARAM_GROUP_VM_STATUS 1 #define DRM_ASAHI_PARAM_GROUP_QUEUE_LIMITS 2 diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py index f1684b4122557..057ac60cd5097 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py @@ -633,7 +633,7 @@ mod render_admission_tests { use super::{ check_render_helpers, hw, uapi, Result, DBIAS_IS_INT, EINVAL, FEW_PRIMITIVES, - FRAGMENT_BARRIERS, MAX_DIMENSION, MAX_LAYERS, MAX_TILE_BUFFER, PROCESS_EMPTY_TILES, + FRAGMENT_BARRIERS, MAX_DIMENSION, MAX_LAYERS, PROCESS_EMPTY_TILES, RSRC_SPEC_HI, STAGE_PREFIXES, ZLS_METADATA_STRIDE, }; const ENOENT: i32 = -2; @@ -700,6 +700,7 @@ pub(crate) usc_base: u64, pub(crate) active_cores: u32, pub(crate) render_scs: [u16; 2], + pub(crate) max_tile_buffer: u32, } use super::MAX_COMMANDS; RENDER_ADMISSION @@ -749,7 +750,7 @@ #[test] fn compressed_zls_1x_layered_and_2x_accepted() { let vm = base_vm(); - let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0] }; + let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0], max_tile_buffer: 32 * 1024 }; // 1x compressed D32F depth + stencil. let mut cmd = base_cmd(); cmd.zls_ctrl = Z_COMP | S_COMP; @@ -779,10 +780,32 @@ assert_eq!(check_render_one(&ctx, &layered, &[], &[]), Ok(())); } + #[test] + fn tile_buffer_limit_follows_the_context() { + let vm = base_vm(); + let k32 = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0], max_tile_buffer: 32 * 1024 }; + let k48 = Context { max_tile_buffer: 48 * 1024, ..k32 }; + // 8 B x 32x32 x 4 samples = 32 KiB: accepted by both. + let mut k32_tile = base_cmd(); + k32_tile.samples = 4; + assert_eq!(check_render_one(&k32, &k32_tile, &[], &[]), Ok(())); + assert_eq!(check_render_one(&k48, &k32_tile, &[], &[]), Ok(())); + // 24 B x 32x16 x 4 samples = 48 KiB, the MSAA4 tile macOS programs on the M4. + let mut k48_tile = k32_tile; + k48_tile.utile_height_px = 16; + k48_tile.sample_size_B = 24; + assert_eq!(check_render_one(&k32, &k48_tile, &[], &[]), Err(EINVAL)); + assert_eq!(check_render_one(&k48, &k48_tile, &[], &[]), Ok(())); + // 28 B x 32x16 x 4 samples = 56 KiB: over both limits. + let mut over = k48_tile; + over.sample_size_B = 28; + assert_eq!(check_render_one(&k48, &over, &[], &[]), Err(EINVAL)); + } + #[test] fn compressed_zls_invalid_ctrl_alignment_and_vm_spans_rejected() { let vm = base_vm(); - let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0] }; + let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0], max_tile_buffer: 32 * 1024 }; let valid = || { let mut cmd = base_cmd(); cmd.zls_ctrl = Z_COMP | S_COMP; @@ -839,7 +862,7 @@ #[test] fn submit_wide_span_batch_dedups_and_flushes_once_across_passes() { let vm = base_vm(); - let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0] }; + let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0], max_tile_buffer: 32 * 1024 }; let mut batch = SpanBatch::new(); for pass in 0..4u64 { let mut cmd = base_cmd(); @@ -879,7 +902,7 @@ #[test] fn few_primitives_flag_admitted_in_parse_and_render_check() { let vm = base_vm(); - let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0] }; + let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0], max_tile_buffer: 32 * 1024 }; let mut r = super::render(); r.flags = FEW_PRIMITIVES; assert!(super::check_stream( @@ -916,7 +939,7 @@ // First flush populates the proof for epoch 1. let mut batch = SpanBatch::new(); - let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0] }; + let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0], max_tile_buffer: 32 * 1024 }; check_render(&mut batch, &ctx, &cmd, &[], &[]).unwrap(); assert_eq!(batch.flush_with_proof(&vm, &mut proof), Ok(())); assert_eq!(vm.batch_calls.get(), 1); @@ -962,7 +985,7 @@ vm.maps.remove(1); vm.epoch.set(Some(2)); let mut batch = SpanBatch::new(); - let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0] }; + let ctx = Context { vm: &vm, usc_base: 1 << 40, active_cores: 10, render_scs: [0, 0], max_tile_buffer: 32 * 1024 }; check_render(&mut batch, &ctx, &cmd, &[att], &[]).unwrap(); assert_eq!(batch.flush_with_proof(&vm, &mut proof), Err(ENOENT)); From f393918abe5ba6657171117d93aad0044cd34697 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 26 Nov 2026 23:06:17 -0500 Subject: [PATCH 2/2] drm/asahi: don't present 32 KiB as every GPU's tile-buffer limit The M5 path of g17 admits 64 KiB tile buffers without reporting DRM_ASAHI_FEATURE_TILE_BUFFER_48K, so "instead of 32 KiB" in the bit's comment is wrong there. Say that the bit is about the GPU that reports it, and that 32 KiB is the portable limit without it. Comment only. Signed-off-by: DjDeveloperr --- include/uapi/drm/asahi_drm.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/uapi/drm/asahi_drm.h b/include/uapi/drm/asahi_drm.h index f1fee4537e2b9..fb91658169745 100644 --- a/include/uapi/drm/asahi_drm.h +++ b/include/uapi/drm/asahi_drm.h @@ -606,10 +606,10 @@ enum drm_asahi_feature { #define DRM_ASAHI_FEATURE_ORDERED_PARTIAL_RENDERS ((1ULL) << 45) /* - * DRM_ASAHI_FEATURE_TILE_BUFFER_48K: render commands accept tile buffers of - * up to 48 KiB (sample_size_B * utile_width_px * utile_height_px * samples - * <= 49152), instead of 32 KiB. A feature bit like those of enum - * drm_asahi_feature, defined here like bit 32. + * DRM_ASAHI_FEATURE_TILE_BUFFER_48K: render commands on this GPU accept tile + * buffers of up to 48 KiB (sample_size_B * utile_width_px * utile_height_px * + * samples <= 49152). Without it, 32 KiB is the portable limit. A feature bit + * like those of enum drm_asahi_feature, defined here like bit 32. */ #define DRM_ASAHI_FEATURE_TILE_BUFFER_48K ((1ULL) << 46)