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..fb91658169745 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 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) + #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));