From 480d4b59d5dde17e1cc1d6e51aed2e1d0957972f Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 27 Nov 2026 21:39:40 -0500 Subject: [PATCH 1/3] drm/asahi: g16: leave the same-VM TA order to the TA ring g16 posts a barrier on TA(N-1)'s stamp ahead of every pipelined TA whose plan does not already wait on the previous FS. Every render's TA work goes on the one firmware TA queue, whose works the firmware runs in ring order: macOS posts no barriers on that ring at all, and in our J773g captures of Metal running the postfx and bindless-UBO tests each pass's tiling still starts after the previous pass's tiling has ended. For a predecessor of the same VM, which shares the render's parameter buffer and UMA slot only through that order, the barrier re-checks a stamp the ring implies, and the firmware can hold the new record on it until a later event. Post it only when the ring's order does not cover it: behind another VM's render, and whenever this render or a live flight carries InitBM. Folded members always belong to the first member's VM, so only the first member can follow another VM's render. The stats file counts the barriers posted and the ones left to ring order. The publication selftest covers the decision, and checks that it is taken after every InitBM producer is known. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/engine.rs | 35 +++++++++++++++---- drivers/gpu/drm/asahi/g16/poll.rs | 5 +++ .../drivers/gpu/asahi-m4/test-publication.py | 22 +++++++++++- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index fc08739e9e671..911e45047388a 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -287,6 +287,19 @@ fn plan_render_barriers( } } +/// Whether the TA ring's own order already holds TA(N) behind TA(N-1), so that the TA->TA +/// `prev_barrier` of [`plan_render_barriers`] would only re-check a stamp the ring implies. +/// +/// Every render's TA work goes on the one firmware TA queue, whose works the firmware runs in +/// ring order: on Metal's TA ring, which carries no barriers, each pass's tiling starts after +/// the previous pass's tiling has ended. A same-VM predecessor shares this render's parameter +/// buffer and UMA slot only through that order. A predecessor of another VM +/// (`cross_vm_prev`, its own UMA slot and the conflict of [`msaa_render_conflict`]) and any +/// InitBM producer or consumer (`producer_initbm`) keep the barrier. +fn ta_ring_orders_prev(cross_vm_prev: bool, producer_initbm: bool) -> bool { + !cross_vm_prev && !producer_initbm +} + /// Engine of the previous member. #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub(crate) enum Prev { @@ -523,6 +536,9 @@ pub(crate) struct Stats { pub(crate) job_cmds: u64, pub(crate) job_max: u64, pub(crate) early: u64, + /// TA->TA barriers posted, and those the TA ring's order made unnecessary. + pub(crate) ta_prev: u64, + pub(crate) ta_order: u64, /// Type-0 FS->compute / compute->TA waits. pub(crate) fs2c0: u64, pub(crate) c2ta0: u64, @@ -4118,12 +4134,18 @@ impl Firmware { || fs_wait_render.is_some_and(|w| w.initbm) || ta_wait_fs.is_some_and(|w| w.initbm); let render_bar = cross_engine_barrier_type(producer_initbm, init_buffer); - // Pipelined renders share TA/FS pipes across same-VM and cross-VM flights, so keep - // the TA(N-1)->TA(N) `prev_barrier` (matching G15) whenever `plan.ta_fs_wait` does not - // already serialize behind `prev_fs`. Emit `ta_fs_barrier` only when `plan.ta_fs_wait` - // names an in-flight FS stamp, and `fs_dep` when `plan.fs_render_wait` names an - // in-flight FS dependency (or cross-VM `prev_fs`) not already dominated by TA. - if plan.ta_prev_wait { + // Pipelined renders share TA/FS pipes across same-VM and cross-VM flights. The plan + // asks for the TA(N-1)->TA(N) `prev_barrier` (matching G15) whenever `plan.ta_fs_wait` + // does not already serialize behind `prev_fs`; it is posted unless the TA ring's own + // order already holds TA(N) behind TA(N-1) (`ta_ring_orders_prev`). Emit + // `ta_fs_barrier` only when `plan.ta_fs_wait` names an in-flight FS stamp, and `fs_dep` + // when `plan.fs_render_wait` names an in-flight FS dependency (or cross-VM `prev_fs`) + // not already dominated by TA. + let ta_ordered = ta_ring_orders_prev(cross_vm_prev, producer_initbm); + if plan.ta_prev_wait && ta_ordered { + self.engine.stats.ta_order += 1; + } + if plan.ta_prev_wait && !ta_ordered { let prev = encode::barrier( r.fw_stamp[0].va, prev_ta, @@ -4135,6 +4157,7 @@ impl Firmware { p.prev_barrier.write(0, &prev)?; r.ring[0].w64(8 * pf.ta_head as usize, p.prev_barrier.va)?; pf.ta_head = (pf.ta_head + 1) % cap; + self.engine.stats.ta_prev += 1; } if let Some(wait_fs) = plan.ta_fs_wait { let ta_fs = encode::barrier( diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index c767737ed560e..506bc755e4f98 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -2281,6 +2281,11 @@ impl Firmware { self.slots.tilemap_clear_bytes_total() )?; writeln!(f, "type0: fs2c {} c2ta {}", s.fs2c0, s.c2ta0)?; + writeln!( + f, + "ta_prev: barriers {} ring_ordered {}", + s.ta_prev, s.ta_order + )?; write!(f, "horizon:")?; for n in s.hz.iter() { write!(f, " {}", n)?; diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 373b2285d4669..7c14f144c79c3 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -53,6 +53,15 @@ def item(declaration): ), 'render_bar must be hoisted ahead of barrier emission' assert prefix_render_fn.count('render_bar,') == 5, prefix_render_fn assert 'p.prev_barrier.write(0, &prev)?;' in prefix_render_fn +# The TA->TA barrier is posted exactly when the plan asks for it and the TA ring's order +# does not already imply it, decided after every InitBM producer is known. +assert 'if plan.ta_prev_wait && !ta_ordered {' in prefix_render_fn +assert ( + prefix_render_fn.index('let producer_initbm = pf.initbm') + < prefix_render_fn.index('let ta_ordered = ta_ring_orders_prev(cross_vm_prev, producer_initbm);') + < prefix_render_fn.index('if plan.ta_prev_wait && !ta_ordered {') + < prefix_render_fn.index('p.prev_barrier.write(0, &prev)?;') +), 'prev_barrier must follow the ring-order decision' # The VM mark waits for visibility: an unpublished prefix never marks its VM. assert 'note_msaa_render' not in prefix_render_fn assert 'f.msaa |= cmd.is_multisampled();' in prefix_render_fn @@ -921,6 +930,7 @@ def item(declaration): #[derive(Copy, Clone, Debug, PartialEq, Eq)] __RENDER_BARRIER_PLAN__ __PLAN_RENDER_BARRIERS__ + __TA_RING_ORDERS_PREV__ __SCS_COMPUTE_CONFLICT__ __MSAA_RENDER_CONFLICT__ impl QueueBehindHost { @@ -1920,6 +1930,15 @@ def item(declaration): } ); } + #[test]fn ta_ring_order_replaces_only_the_same_vm_ta_barrier(){ + // A same-VM predecessor with no InitBM on either side: the plan's TA->TA wait is + // left to the TA ring's order (case 2 above still plans it). + assert!(ta_ring_orders_prev(false, false)); + // Another VM's predecessor, or an InitBM producer or consumer, keeps prev_barrier. + assert!(!ta_ring_orders_prev(true, false)); + assert!(!ta_ring_orders_prev(false, true)); + assert!(!ta_ring_orders_prev(true, true)); + } #[test]fn two_pipe_concurrent_compute_dispatch_and_fw_timestamp_safety(){ let vm1=Arc::new(Vm{id:1,status:Status(AtomicU32::new(0)),slot:1,msaa:AtomicBool::new(false)}); let vm2=Arc::new(Vm{id:2,status:Status(AtomicU32::new(0)),slot:2,msaa:AtomicBool::new(false)}); @@ -3385,6 +3404,7 @@ def item(declaration): '__CROSS_ENGINE_BARRIER_TYPE__': 'const fn cross_engine_barrier_type(', '__RENDER_BARRIER_PLAN__': 'struct RenderBarrierPlan {', '__PLAN_RENDER_BARRIERS__': 'fn plan_render_barriers(', + '__TA_RING_ORDERS_PREV__': 'fn ta_ring_orders_prev(', }.items(): harness = harness.replace(token, item(declaration).replace("super::command::", "crate::command::").replace("super::recovery::", "crate::recovery::").replace("super::hw::", "crate::hw::").replace("super::resources::", "crate::resources::").replace("super::queue::QueueState", "crate::Queue").replace("super::vm::VmState", "crate::Vm").replace("super::fence::", "crate::fence::")) unit = output / 'publication.rs' @@ -3399,7 +3419,7 @@ def item(declaration): if result.returncode: raise SystemExit(result.returncode) (output/'publication.json').write_text(json.dumps({ - 'passed': True, 'tests': 70, 'cpu_only': True, 'hardware_execution': False, + 'passed': True, 'tests': 71, 'cpu_only': True, 'hardware_execution': False, 'scope': 'Verbatim production publication wrapper, selection, error isolation and descriptor-error containment branch; wire encoder, descriptor failure injection and transport replaced by CPU recorders.', 'source_sha256': sha(production), }, indent=2)+'\n') From af6c6e4423f5b772e172f1153adcebb317641359 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 27 Nov 2026 22:39:30 -0500 Subject: [PATCH 2/3] drm/asahi: g16: lower the compute fan-out threshold to 140 us Barrier-free compute of one queue stays on its pipe, where the horizon fold can merge it, until the queue counts as heavy and fans out across two pipes. A queue is heavy when its retired CDM time EWMA reaches COMPUTE_HEAVY_EMA_US (200 us), or when a sole single-command flight of it has run for COMPUTE_HEAVY_INFLIGHT_NS (180 us). A stream of ~185 us dispatches sits between the two limits. The in-flight probe promotes it while one of its flights runs alone on a pipe, but stops applying once a second flight shares that pipe, and the EWMA stays under 200 us, so the queue drops back to one pipe and serializes. Whether such a stream fans out depends on submit timing. Use one crossover for both decisions and put it at 140 us. Dispatches of that size clear it with room to get faster, while light dispatches, a few tens of microseconds each, still stay on one pipe and fold. The publication selftest now takes both limits from hw.rs and checks the probe and EWMA boundaries at 140 us. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/hw.rs | 8 +++++-- .../drivers/gpu/asahi-m4/test-publication.py | 23 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/hw.rs b/drivers/gpu/drm/asahi/g16/hw.rs index 2ea74d873e127..66ff094897d83 100644 --- a/drivers/gpu/drm/asahi/g16/hw.rs +++ b/drivers/gpu/drm/asahi/g16/hw.rs @@ -1295,10 +1295,14 @@ pub(crate) mod sizes { pub(crate) const COALESCE_WINDOW_NS: u64 = (COALESCE_WINDOW_US as u64) * 1000; /// Per-queue retired CDM execution EWMA threshold (microseconds) at or above which /// barrier-free compute fans out across both CDM pipes instead of staying 1-pipe affine. - pub(crate) const COMPUTE_HEAVY_EMA_US: u32 = 200; + /// Light dispatches, a few tens of microseconds each, stay well below it and keep folding + /// on one pipe; heavy dispatches of about 185 us clear it with room to get faster. + pub(crate) const COMPUTE_HEAVY_EMA_US: u32 = 140; /// Elapsed wall-clock time (nanoseconds) on a sole active single-command compute flight /// that immediately classifies the queue as heavy before its first retirement updates EWMA. - pub(crate) const COMPUTE_HEAVY_INFLIGHT_NS: u64 = 180_000; + /// It is the same crossover as [`COMPUTE_HEAVY_EMA_US`], so a queue the probe promotes + /// stays heavy once its retired dispatches feed the EWMA. + pub(crate) const COMPUTE_HEAVY_INFLIGHT_NS: u64 = COMPUTE_HEAVY_EMA_US as u64 * 1000; /// Jobs admitted to the engine per logical queue: enough to keep deep queues (`d=64`) /// queued back to back without scheduler backpressure stalls; exact prior-command /// dependencies still gate each one. diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 7c14f144c79c3..6bed120f89cb1 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -41,6 +41,8 @@ def item(declaration): assert 'DRM_ASAHI_FEATURE_INDEPENDENT_QUEUES' in gpu_src max_queues_line = next(line for line in hw_src.splitlines() if 'const MAX_QUEUES:' in line) flights_line = next(line for line in hw_src.splitlines() if 'const FLIGHTS:' in line) +heavy_limits = [line.strip() for line in hw_src.splitlines() if 'const COMPUTE_HEAVY_' in line] +assert len(heavy_limits) == 2, heavy_limits assert 'const COMPUTE_SLOTS: usize = COMPUTE_UNITS;' in hw_src assert 'const HORIZON_JOBS: u32 = COMPUTE_UNITS as u32;' in hw_src prefix_render_fn = item('fn prefix_render(') @@ -214,7 +216,7 @@ def item(declaration): // containment branch below decides whether the unit becomes claimable again. pub fn validate_compute_descriptor(refs:&ComputeRefs,_old:&[u8;160],_before:u64)->Result<(),()>{if refs.invalid{Err(())}else{Ok(())}} } -mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const TA_WAVE_PASSES:usize=4; pub const TA_WAVE_PASSES_LIGHT:usize=8; pub const TA_LIGHT_TILEMAP_BYTES:u64=64*1024; pub const TA_WAVE_REFILL_HEADROOM:usize=2; pub const COMPUTE_PIPES:usize=8; pub const MAX_VM_COMPUTE_PIPES:usize=2; pub const COMPUTE_UNITS:usize=24; pub const PIPE1_COMPUTE_START:usize=6; pub const COMPUTE_SLOTS:usize=24; pub const RENDER_SLOTS:usize=48; pub const COALESCE_MAX_CMDS:usize=6; pub const COALESCE_WINDOW_US:u32=18; pub const COALESCE_WINDOW_NS:u64=18_000; pub const COMPUTE_HEAVY_EMA_US:u32=200; pub const COMPUTE_HEAVY_INFLIGHT_NS:u64=180_000; } } +mod hw { pub mod sizes { pub const FLIGHTS:usize=32; pub const TA_WAVE_PASSES:usize=4; pub const TA_WAVE_PASSES_LIGHT:usize=8; pub const TA_LIGHT_TILEMAP_BYTES:u64=64*1024; pub const TA_WAVE_REFILL_HEADROOM:usize=2; pub const COMPUTE_PIPES:usize=8; pub const MAX_VM_COMPUTE_PIPES:usize=2; pub const COMPUTE_UNITS:usize=24; pub const PIPE1_COMPUTE_START:usize=6; pub const COMPUTE_SLOTS:usize=24; pub const RENDER_SLOTS:usize=48; pub const COALESCE_MAX_CMDS:usize=6; pub const COALESCE_WINDOW_US:u32=18; pub const COALESCE_WINDOW_NS:u64=18_000; __HEAVY_LIMITS__ } } mod command {pub const RENDER:usize=0;pub const COMPUTE:usize=1;} thread_local!{static CLOCK:std::cell::Cell=const{std::cell::Cell::new(0)};} fn now_ns()->u64{CLOCK.with(|clock|clock.get())} @@ -1969,17 +1971,23 @@ def item(declaration): cstamp:[0x100;16],r_ta_stamp:[0;16],r_fs_stamp:[0;16],fs_target:0,initbm:false, has_timestamps:false,doomed:false,recovery_suspect:false, }); - // Cold-start heavy probe: sole single-command compute flight becomes heavy at >= 180 us. - assert!(!host.compute_queue_is_heavy(&q1, 1_179_999)); - assert!(host.compute_queue_is_heavy(&q1, 1_180_000)); + // Cold-start heavy probe: sole single-command compute flight becomes heavy at >= 140 us. + assert!(!host.compute_queue_is_heavy(&q1, 1_139_999)); + assert!(host.compute_queue_is_heavy(&q1, 1_140_000)); // Folded multi-command light flight does not trigger the cold-start probe. host.engine.flights[0].computes = 3; assert!(!host.compute_queue_is_heavy(&q1, 2_000_000)); host.engine.flights[0].computes = 1; - // Per-queue retired hardware CDM EWMA transitions cleanly at 200 us. + // The retired EWMA crosses over at the probe's 140 us, after the probe has expired. + q1.note_compute_us(139); + assert!(!host.compute_queue_is_heavy(&q1, 1_050_000)); + q1.note_compute_us(141); + assert!(host.compute_queue_is_heavy(&q1, 1_050_000)); + q1.compute_ewma_us.store(0, Ordering::Relaxed); + // The EWMA follows subsequent changes in the stream. q1.note_compute_us(30); assert!(!host.compute_queue_is_heavy(&q1, 1_050_000)); - q1.note_compute_us(500); + q1.note_compute_us(300); assert!(host.compute_queue_is_heavy(&q1, 1_050_000)); q1.note_compute_us(20); assert!(!host.compute_queue_is_heavy(&q1, 1_050_000)); @@ -3050,7 +3058,7 @@ def item(declaration): h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, Some(2)])]; assert_eq!(h.defer_busy_coalesce(400_000), None); - // Heavy compute queue (EWMA >= 200 us) bypasses busy coalescing so 2-pipe fanout runs immediately. + // Heavy compute queue (EWMA >= 140 us) bypasses busy coalescing so 2-pipe fanout runs immediately. h.engine.pending = vec![mk_job(&vm1, &q1, false, 3, [None, None])]; q1.note_compute_us(500); assert_eq!(h.defer_busy_coalesce(420_000), None); @@ -3324,6 +3332,7 @@ def item(declaration): harness = harness.replace('__USAGE__', str(production.parent.parent / 'usage.rs')) harness = harness.replace('__FLIGHTS_LINE__', flights_line.strip()) harness = harness.replace('__MAX_QUEUES_LINE__', max_queues_line.strip()) +harness = harness.replace('__HEAVY_LIMITS__', ' '.join(heavy_limits)) harness = harness.replace('__QUEUE_LIMITS_FN__', item_in(params_src, 'pub(crate) fn queue_limits()')) harness = harness.replace('__GPU_QUEUE_LIMITS_FN__', gpu_limits_fn) harness = harness.replace('__QUEUE_CREDIT_STRUCT__', item_in(queue_src, 'struct QueueCredit {')) From 766141ca428d55cd83c4f1a341a3c6d6116d0729 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sat, 28 Nov 2026 00:05:51 -0500 Subject: [PATCH 3/3] drm/asahi: g16: commit TA ring-order counters on TA producer publication Stage `ta_prev` and `ta_order` counts on `Prefix` during `prefix_render` and commit them to `self.engine.stats` only after `publish_producer` publishes the TA producer index, so an unpublished prefix rejected by `recovery_pending()` (-EAGAIN) or an earlier publication error never advances the barrier counters. Also update `test-publication.py` to cover the -EAGAIN and TA-publication failure paths and record the actual passed test count in `publication.json`. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/engine.rs | 8 +- .../drivers/gpu/asahi-m4/test-publication.py | 81 +++++++++++++++++-- 2 files changed, 79 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index 911e45047388a..011544737b19f 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -451,6 +451,8 @@ struct Prefix { last_ct: u32, last_ta: u32, last_fs: u32, + ta_prev: u64, + ta_order: u64, } /// Error provenance must remain independent of errno: EIO can be an ordinary failed VM @@ -3532,6 +3534,8 @@ impl Firmware { prefix.ta_head, &mut self.engine.stats.publications[1], )?; + self.engine.stats.ta_prev += prefix.ta_prev; + self.engine.stats.ta_order += prefix.ta_order; self.graph.render.qstate[1].w32(qstate::WRITE, prefix.fs_head)?; } else { publish_producer( @@ -4143,7 +4147,7 @@ impl Firmware { // not already dominated by TA. let ta_ordered = ta_ring_orders_prev(cross_vm_prev, producer_initbm); if plan.ta_prev_wait && ta_ordered { - self.engine.stats.ta_order += 1; + pf.ta_order += 1; } if plan.ta_prev_wait && !ta_ordered { let prev = encode::barrier( @@ -4157,7 +4161,7 @@ impl Firmware { p.prev_barrier.write(0, &prev)?; r.ring[0].w64(8 * pf.ta_head as usize, p.prev_barrier.va)?; pf.ta_head = (pf.ta_head + 1) % cap; - self.engine.stats.ta_prev += 1; + pf.ta_prev += 1; } if let Some(wait_fs) = plan.ta_fs_wait { let ta_fs = encode::barrier( diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 6bed120f89cb1..4c2e4a622df8d 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -3,6 +3,7 @@ """Execute production M4 publication/error isolation with a CPU-only transport recorder.""" from common import kernel_root, output_dir, rustc, sha import json +import re import subprocess production = kernel_root() / 'drivers/gpu/drm/asahi/g16/engine.rs' @@ -64,6 +65,9 @@ def item(declaration): < prefix_render_fn.index('if plan.ta_prev_wait && !ta_ordered {') < prefix_render_fn.index('p.prev_barrier.write(0, &prev)?;') ), 'prev_barrier must follow the ring-order decision' +# Barrier stats are staged on `Prefix` and committed only on TA producer publication. +assert 'stats.ta_prev' not in prefix_render_fn and 'stats.ta_order' not in prefix_render_fn +assert 'pf.ta_order += 1;' in prefix_render_fn and 'pf.ta_prev += 1;' in prefix_render_fn # The VM mark waits for visibility: an unpublished prefix never marks its VM. assert 'note_msaa_render' not in prefix_render_fn assert 'f.msaa |= cmd.is_multisampled();' in prefix_render_fn @@ -3163,7 +3167,7 @@ def item(declaration): group: Group(vec![]), msaa: false, pb: Some(Pb), pb_slot: 0 } } __MSAA_RENDER_CONFLICT__ - struct Prefix { draw: u64, ta_head: u32, fs_head: u32, renders: u32 } + struct Prefix { draw: u64, ta_head: u32, fs_head: u32, renders: u32, ta_prev: u64, ta_order: u64 } struct Cfg { num_clusters: u32, gpu_generation: u32 } struct Slots { pass_busy: u64, publish_fails: bool } impl Slots { @@ -3174,11 +3178,27 @@ def item(declaration): fn publish(&mut self, _c: &mut Claims) -> Result { if self.publish_fails { Err(EIO) } else { Ok(()) } } } struct Pools; impl Pools { fn hold_alloc(&mut self, _k: usize, _vm: &Arc, _a: u32, _l: u32) -> Result { Ok(()) } } - struct Engine { flights: Vec, pending: Vec> } - struct Host { cfg: Cfg, slots: Slots, pools: Pools, engine: Engine, prefixed: Vec<(u32, u32)> } + mod qstate { pub const WRITE: usize = 0; } + struct QState { fail: bool } + impl QState { + fn w32(&self, _off: usize, _v: u32) -> Result { + if self.fail { Err(EIO) } else { Ok(()) } + } + } + struct RenderGraph { qstate: [QState; 2] } + struct Graph { render: RenderGraph } + #[derive(Default)] + struct RenderStats { publications: [u64; 2], ta_prev: u64, ta_order: u64 } + fn publish_producer(q: &QState, head: u32, count: &mut u64) -> Result { + q.w32(qstate::WRITE, head)?; + *count += 1; + Ok(()) + } + struct Engine { flights: Vec, pending: Vec>, stats: RenderStats } + struct Host { cfg: Cfg, slots: Slots, pools: Pools, graph: Graph, engine: Engine, prefixed: Vec<(u32, u32)>, recovery: bool } impl Host { __MSAA_MEMBER_ALLOWED__ - fn recovery_pending(&self) -> Result { Ok(false) } + fn recovery_pending(&self) -> Result { Ok(self.recovery) } fn wait_compute_stamps_for(&self, _j: &Arc, _t: Option) -> Result { Ok(()) } fn wait_stamp_for_with(&self, _j: &Arc, _c: usize, _t: Option, _f: Option<&Flight>) -> Result { Ok(()) } #[allow(clippy::too_many_arguments)] @@ -3195,7 +3215,7 @@ def item(declaration): fn fold(&mut self, job: &Arc, f: &mut Flight, more: usize) -> Result { let index = 0u32; let mut end = 1u32; - let mut prefix = Prefix { draw: 1, ta_head: 0, fs_head: 0, renders: 1 }; + let mut prefix = Prefix { draw: 1, ta_head: 0, fs_head: 0, renders: 1, ta_prev: 0, ta_order: 0 }; let (ta_read, fs_read) = (0u32, 0u32); let (behind, class_behind) = (true, true); let stage_prefix = kernel::uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_STAGE_PREFIXES; @@ -3214,10 +3234,23 @@ def item(declaration): if fail_after { return Err(EIO); } Ok(()) } + fn publish_render_producers(&mut self, job: &Arc, f: &mut Flight, prefix: &Prefix, visible: &mut bool) -> Result { + let render = true; + __PUBLICATION_PROLOGUE__ + __RENDER_PRODUCER_PUBLICATION__ + Ok(()) + } } fn host(flights: Vec, pending: Vec>) -> Host { - Host { cfg: Cfg { num_clusters: 1, gpu_generation: 16 }, slots: Slots { pass_busy: 1, publish_fails: false }, pools: Pools, - engine: Engine { flights, pending }, prefixed: vec![] } + Host { + cfg: Cfg { num_clusters: 1, gpu_generation: 16 }, + slots: Slots { pass_busy: 1, publish_fails: false }, + pools: Pools, + graph: Graph { render: RenderGraph { qstate: [QState { fail: false }, QState { fail: false }] } }, + engine: Engine { flights, pending, stats: RenderStats::default() }, + prefixed: vec![], + recovery: false, + } } #[test] fn same_submit_fold_splits_before_a_multisampled_member_beside_another_vm() { let (vm1, vm2, q1, q2) = (vm(1), vm(2), Arc::new(Queue), Arc::new(Queue)); @@ -3298,6 +3331,30 @@ def item(declaration): assert!(visible && !v3.renders_msaa()); let _ = (EAGAIN, EINVAL); } + #[test] fn ta_prev_barrier_stats_commit_only_on_ta_producer_publication() { + let q = Arc::new(Queue); + let v = vm(1); + let j = job(1, &v, &q, 1, &[LIGHT]); + let prefix = Prefix { draw: 1, ta_head: 4, fs_head: 5, renders: 1, ta_prev: 2, ta_order: 3 }; + // Rejected by recovery_pending (-EAGAIN) before visibility: staged counts are discarded. + let mut h = host(vec![], vec![]); + h.recovery = true; + let (mut f, mut visible) = (flight(&j, 1), false); + assert_eq!(h.publish_render_producers(&j, &mut f, &prefix, &mut visible), Err(EAGAIN)); + assert!(!visible && h.engine.stats.ta_prev == 0 && h.engine.stats.ta_order == 0); + // TA producer publication fails: counts do not advance. + let mut h = host(vec![], vec![]); + h.graph.render.qstate[0].fail = true; + let (mut f, mut visible) = (flight(&j, 1), false); + assert_eq!(h.publish_render_producers(&j, &mut f, &prefix, &mut visible), Err(EIO)); + assert!(visible && h.engine.stats.ta_prev == 0 && h.engine.stats.ta_order == 0); + // TA producer publishes cleanly: staged counts commit alongside publications[1]. + let mut h = host(vec![], vec![]); + let (mut f, mut visible) = (flight(&j, 1), false); + assert_eq!(h.publish_render_producers(&j, &mut f, &prefix, &mut visible), Ok(())); + assert!(visible && h.engine.stats.publications[1] == 1); + assert_eq!((h.engine.stats.ta_prev, h.engine.stats.ta_order), (2, 3)); + } } ''' @@ -3311,12 +3368,18 @@ def item(declaration): _prologue_end = source.index(' let publication = (|| -> Result {', _prologue_start) _prologue = source[_prologue_start:_prologue_end] assert '*visible = true;' in _prologue and 'job.vm.note_msaa_render();' in _prologue +_ta_pub_start = source.index(' publish_producer(\n &self.graph.render.qstate[0],', _prologue_end) +_ta_pub_end = source.index(' } else {', _ta_pub_start) +_ta_pub = source[_ta_pub_start:_ta_pub_end] +assert 'self.engine.stats.ta_prev += prefix.ta_prev;' in _ta_pub +assert 'self.engine.stats.ta_order += prefix.ta_order;' in _ta_pub _scope_start = harness.index('mod msaa_fold_scope {') _scope = harness[_scope_start:] for token, text in { '__SAME_SUBMIT_FOLD__': _same_fold, '__HORIZON_FOLD__': _horizon_fold, '__PUBLICATION_PROLOGUE__': _prologue, + '__RENDER_PRODUCER_PUBLICATION__': _ta_pub, '__IS_MULTISAMPLED__': item_in(command_src, 'pub(crate) fn is_multisampled('), '__RENDERS_MSAA__': item_in(vm_src, 'pub(crate) fn renders_msaa('), '__NOTE_MSAA_RENDER__': item_in(vm_src, 'pub(crate) fn note_msaa_render('), @@ -3427,8 +3490,10 @@ def item(declaration): (output/'publication.log').write_text(log) if result.returncode: raise SystemExit(result.returncode) +passed_match = re.search(r'test result: ok\. (\d+) passed; 0 failed;', log) +assert passed_match, f'could not parse test count from:\n{log}' (output/'publication.json').write_text(json.dumps({ - 'passed': True, 'tests': 71, 'cpu_only': True, 'hardware_execution': False, + 'passed': True, 'tests': int(passed_match.group(1)), 'cpu_only': True, 'hardware_execution': False, 'scope': 'Verbatim production publication wrapper, selection, error isolation and descriptor-error containment branch; wire encoder, descriptor failure injection and transport replaced by CPU recorders.', 'source_sha256': sha(production), }, indent=2)+'\n')