diff --git a/drivers/gpu/drm/asahi/g17/job.rs b/drivers/gpu/drm/asahi/g17/job.rs index f0a7c032b1c9a..ea8e02319177f 100644 --- a/drivers/gpu/drm/asahi/g17/job.rs +++ b/drivers/gpu/drm/asahi/g17/job.rs @@ -28,7 +28,7 @@ const COMPUTE_CREDITS: u32 = crate::hw::t8140::queues::COMPUTE_DEPTH as u32; /// behind a long frontier (about 120 of them under Astro Bot) made every submit /// quadratic, about 1 ms of CPU. Past this many, the scheduler waits on one /// merged fence instead: the same wait, while status checks keep each fence. -const MERGED_DEPENDENCIES: usize = 8; +pub(crate) const MERGED_DEPENDENCIES: usize = 8; #[derive(Clone, Copy, PartialEq, Eq)] pub(crate) enum Engine { @@ -132,6 +132,9 @@ pub(crate) struct Packet { /// Number of render passes in the submit ioctl that created this packet. pub(crate) batch_renders: u16, inputs: KVec, + /// The submission's own input fences ([`super::sync_input::Inputs`]), unless compute sources + /// take them over in firmware. + shared_inputs: Option, /// The other engine's producers this packet waits for in firmware, checked for failure /// through that engine's failure log instead of one fence each. producers: Option, @@ -167,6 +170,7 @@ impl Packet { completion: Arc, batch_renders: u16, inputs: KVec, + shared_inputs: Option, producers: Option, ) -> Result> { let footprint = match &command { @@ -187,6 +191,7 @@ impl Packet { footprint, batch_renders, inputs, + shared_inputs, producers, publication: AtomicU8::new(0), cancelled: AtomicBool::new(false), @@ -236,7 +241,7 @@ impl Packet { /// Replay holds the device mutex. Its original inputs were satisfied before /// first publication; never sleep on a fence that needs event service here. pub(crate) fn check_replay_dependencies(&self) -> Result { - for fence in &self.inputs { + for fence in self.inputs() { super::dependency::replay_status(fence_status(fence))?; } self.check_firmware_producers()?; @@ -249,7 +254,7 @@ impl Packet { pub(crate) fn check_dependencies(&self) -> Result { let polls = if self.command.long_job() { 5 } else { 1 }; let deadline = super::now_ns().saturating_add(u64::from(TIMEOUT_MS) * polls * 1_000_000); - for fence in &self.inputs { + for fence in self.inputs() { loop { if self.cancel_requested() || self.completion.status().get() != 0 { return Err(ECANCELED); @@ -292,13 +297,20 @@ impl Packet { /// Dependency-bearing packets remain on the scheduler publication path. pub(crate) fn has_dependencies(&self) -> bool { - !self.inputs.is_empty() || self.producers.is_some() + self.inputs().next().is_some() || self.producers.is_some() + } + + /// The fences checked on the host before publication: the command's own, then its + /// submission's inputs. + fn inputs(&self) -> impl Iterator { + let shared = self.shared_inputs.as_ref().map_or(&[][..], |inputs| inputs.fences()); + Iterator::chain(self.inputs.iter(), shared) } /// Host-waited inputs keep a packet on the scheduler publication path; /// already-published cross-engine firmware producers do not. pub(crate) fn has_host_dependencies(&self) -> bool { - !self.inputs.is_empty() + self.inputs().next().is_some() } pub(crate) fn begin_publication(&self) -> bool { diff --git a/drivers/gpu/drm/asahi/g17/queue/mod.rs b/drivers/gpu/drm/asahi/g17/queue/mod.rs index d19278eeaf0af..4b0ec643f559f 100644 --- a/drivers/gpu/drm/asahi/g17/queue/mod.rs +++ b/drivers/gpu/drm/asahi/g17/queue/mod.rs @@ -13,6 +13,7 @@ use super::{ dependency::{FailureLog, FailureRecord}, fence::{ChunkWork, Outputs}, job::{self, Backend, Engine, Fences, Order, Packet, Scheduler}, + sync_input::Inputs, validation::Proof, }; use crate::{ @@ -255,6 +256,7 @@ impl Queue { aggregate: &super::fence::Aggregate, work: Option>, inputs: &[file::SyncItem], + shared_inputs: Option<&Arc>, destinations: Destinations, batch_renders: u16, ) -> Result { @@ -396,9 +398,17 @@ impl Queue { }); } let failure_count = failures.iter().flatten().count(); + // Each command waits on every input its compute sources do not take over in firmware. + let command_inputs = super::sync_input::command_inputs( + shared_inputs, + inputs.iter().filter_map(|sync| sync.fence.as_ref()), + |fence| sources.as_ref().is_some_and(|sources| sources.contains_input(fence)), + )?; + let input_dependencies = + command_inputs.as_ref().map_or(&[][..], |inputs| inputs.dependencies()); let mut dependencies = KVec::with_capacity( // The firmware-ordered producers add one scheduled fence between them. - inputs.len() + input_dependencies.len() + ordering_host_waits.len() + usize::from(!ordering_firmware_waits.is_empty()) + failure_count, @@ -406,7 +416,7 @@ impl Queue { )?; // Host-waited producers are checked on the host instead of in firmware. let mut checked_inputs = KVec::with_capacity( - inputs.len() + ordering_host_waits.len() + failure_count, + ordering_host_waits.len() + failure_count, GFP_KERNEL, )?; for fence in failures.into_iter().flatten() { @@ -440,26 +450,10 @@ impl Queue { prefix, }); producer_waits.finish(|fence| Ok(dependencies.push(fence.clone(), GFP_KERNEL)?))?; - // Each command owns every input fence; independent engines may publish in - // either order and must each consume an input's error status before running. - for sync in inputs { - if let Some(fence) = &sync.fence { - if sources - .as_ref() - .is_some_and(|sources| sources.contains_input(fence)) - { - continue; - } - // An input that already signalled without error orders nothing and has no status - // left to consume (like a completed frontier producer above). Keeping it would - // send the render through the scheduler thread instead of inline publication: - // most compositor and client renders carry such already-signalled buffer fences. - if job::fence_status(fence) > 0 { - continue; - } - dependencies.push(fence.clone(), GFP_KERNEL)?; - checked_inputs.push(fence.clone(), GFP_KERNEL)?; - } + // Independent engines may publish in either order and must each consume an input's error + // status before running, so every command keeps the inputs. + for fence in input_dependencies { + dependencies.push(fence.clone(), GFP_KERNEL)?; } if let Some(sources) = &sources { for ready in sources.publication_waits() { @@ -479,6 +473,7 @@ impl Queue { completion, batch_renders, checked_inputs, + command_inputs, producers, )?; let scheduler = match engine { @@ -746,6 +741,8 @@ impl crate::queue::Queue for Queue { 0, Some(&output_fence), ); + let shared_inputs = + Inputs::new(outputs.inputs().iter().filter_map(|sync| sync.fence.as_ref()))?; let mut work_states = work_states.into_iter(); for (command, order, destinations) in pending.drain_all() { let guard = guards.next().ok_or(EIO)?; @@ -757,6 +754,7 @@ impl crate::queue::Queue for Queue { &aggregate, work_states.next(), outputs.inputs(), + shared_inputs.as_ref(), destinations, batch_renders, )?; diff --git a/drivers/gpu/drm/asahi/g17/sync_input.rs b/drivers/gpu/drm/asahi/g17/sync_input.rs index ae69d2fcf9ac8..a63d4267dad60 100644 --- a/drivers/gpu/drm/asahi/g17/sync_input.rs +++ b/drivers/gpu/drm/asahi/g17/sync_input.rs @@ -143,6 +143,145 @@ pub(crate) fn collect_coalesced(input: &Fence) -> Option { collect_with(input, asahi_g17_collect_fences_coalesced) } +/// A submission's input fences that had not signalled without error when it was accepted, as base +/// fences, each kept once ([`dedup`]). Every +/// command of the submission waits on all of them and consumes their status, so the commands +/// share one list: a copy each made a 64-command submission hold every input 64 times, for as +/// long as its commands stayed queued. +pub(crate) struct Inputs { + fences: KVVec, + /// One fence for all of them, past [`super::job::MERGED_DEPENDENCIES`]: what each command's + /// scheduler job waits on instead of every input. + merged: Option, +} + +impl Inputs { + /// `None` when there is nothing to wait for. Userspace sets the count, so the list is charged + /// to the caller and needs no contiguous pages. + pub(crate) fn new<'a>(inputs: impl IntoIterator) + -> Result>> + { + let mut fences = KVVec::new(); + for fence in inputs { + // An input that already signalled without error orders nothing and has no status left + // to consume. Keeping it would send a render through the scheduler thread instead of + // inline publication: most compositor and client renders carry such buffer fences. + if super::job::fence_status(fence) > 0 { + continue; + } + // Keep a container's base fences (a timeline point's, an array's), so inputs that + // share them hold each once. Where collection fails the input itself is kept. + match collect_coalesced(fence) { + Some(leaves) => { + for leaf in leaves.iter() { + // SAFETY: The leaf holds a reference while `leaves` lives, so the fence is + // valid; the new `Fence` takes a reference of its own. + fences.push(unsafe { + bindings::dma_fence_get(leaf.fence); + Fence::from_raw(leaf.fence) + }, GFP_KERNEL_ACCOUNT)?; + } + } + None => fences.push(fence.clone(), GFP_KERNEL_ACCOUNT)?, + } + } + dedup(&mut fences); + if fences.is_empty() { + return Ok(None); + } + let merged = if fences.len() > super::job::MERGED_DEPENDENCIES { + Some(merge(&fences)?) + } else { + None + }; + Ok(Some(kernel::sync::Arc::new(Self { fences, merged }, GFP_KERNEL_ACCOUNT)?)) + } + + #[cfg(CONFIG_KUNIT = "y")] + pub(crate) fn fences(&self) -> &[Fence] { + &self.fences + } + + /// The inputs as one command holds them. + pub(crate) fn for_command(self: &kernel::sync::Arc) -> Result { + Ok(CommandInputs(self.clone())) + } +} + +/// Keeps each fence once and, of the unsignalled healthy fences of one context, only the latest, +/// which signals after every earlier one (as [`collect_coalesced`] does within one input). A failed +/// fence is never folded into another, so every error is still consumed. Context 0 names no +/// timeline. +fn dedup(fences: &mut KVVec) { + use super::dependency::{FenceOrder, FenceOrdering}; + // SAFETY: Each fence is a live reference; a fence's context is fixed once it is published. + let key = |fence: &Fence| (unsafe { (*fence.raw()).context }, fence.raw() as usize); + fences.sort_unstable_by_key(key); + let mut kept = 0; + for index in 0..fences.len() { + if kept > 0 { + let (last, next) = (&fences[kept - 1], &fences[index]); + let ((context, address), (last_context, last_address)) = (key(next), key(last)); + if address == last_address { + continue; + } + if context != 0 + && context == last_context + && super::job::fence_status(last) == 0 + && super::job::fence_status(next) == 0 + { + if matches!(next.order(last), FenceOrdering::Later) { + fences.swap(kept - 1, index); + } + continue; + } + } + fences.swap(kept, index); + kept += 1; + } + fences.truncate(kept); +} + +/// What one command of a submission waits on for the submission's `inputs` (the fences as +/// userspace passed them): the list the commands share, or, when its compute sources take some +/// of them over in firmware (`covered`), a list of its own with the rest. `None`: nothing to wait +/// for. +pub(crate) fn command_inputs<'a>( + shared: Option<&kernel::sync::Arc>, + inputs: impl Iterator + Clone, + covered: impl Fn(&Fence) -> bool, +) -> Result> { + let Some(shared) = shared else { + return Ok(None); + }; + if !inputs.clone().any(|fence| covered(fence)) { + return Ok(Some(shared.for_command()?)); + } + // Rare: the sources take over some inputs. Wait on the others only, in a list of its own. + Inputs::new(inputs.filter(|fence| !covered(fence)))?.map(|own| own.for_command()).transpose() +} + +/// One command's share of its submission's [`Inputs`]. +pub(crate) struct CommandInputs(kernel::sync::Arc); + +impl CommandInputs { + /// Every input, for the status checks before publication. + pub(crate) fn fences(&self) -> &[Fence] { + &self.0.fences + } + + /// What the command's scheduler job waits on for its inputs: each of a few, or one fence + /// merged from many. + pub(crate) fn dependencies(&self) -> &[Fence] { + self.0.merged.as_ref().map_or(&self.0.fences[..], core::slice::from_ref) + } + + #[cfg(CONFIG_KUNIT = "y")] + pub(crate) fn shares_with(&self, other: &Self) -> bool { + kernel::sync::Arc::ptr_eq(&self.0, &other.0) + } +} + use super::fence::Submission; use core::sync::atomic::{AtomicU32, Ordering}; @@ -401,3 +540,143 @@ mod tests { assert!(!hint.has_readers(&readers)); } } + +#[kernel::macros::kunit_tests(asahi_g17_inputs)] +mod inputs_tests { + use super::*; + use crate::g17::{ + fence::{independent, CompletionFence}, + job::MERGED_DEPENDENCIES, + }; + use kernel::{c_str, dma_fence::FenceContexts, sync::LockClassKey}; + + static KEY: Pin<&LockClassKey> = kernel::static_lock_class!(); + + fn contexts() -> FenceContexts { + FenceContexts::new(1, c_str!("asahi_inputs_test"), KEY).unwrap() + } + + fn unsignalled(contexts: &FenceContexts, count: usize) -> KVec { + let mut fences = KVec::new(); + for _ in 0..count { + let fence = Fence::from_fence(&independent(contexts).unwrap()); + fences.push(fence, GFP_KERNEL).unwrap(); + } + fences + } + + #[test] + fn commands_of_one_submission_share_its_inputs() { + let contexts = contexts(); + let fences = unsignalled(&contexts, 64); + let inputs = Inputs::new(fences.iter()).unwrap().unwrap(); + let first = inputs.for_command().unwrap(); + let second = inputs.for_command().unwrap(); + // Every command still checks every input before publication. + assert_eq!(first.fences().len(), 64); + assert_eq!(second.fences().len(), 64); + // But holds no copy of its own, and its scheduler job waits on one merged fence. + assert!(first.shares_with(&second)); + assert!(first.dependencies().len() <= MERGED_DEPENDENCIES); + } + + #[test] + fn a_few_inputs_stay_separate_dependencies() { + let contexts = contexts(); + let fences = unsignalled(&contexts, MERGED_DEPENDENCIES); + let inputs = Inputs::new(fences.iter()).unwrap().unwrap(); + let command = inputs.for_command().unwrap(); + assert_eq!(command.dependencies().len(), MERGED_DEPENDENCIES); + for (dependency, fence) in command.dependencies().iter().zip(fences.iter()) { + assert_eq!(dependency.raw(), fence.raw()); + } + } + + #[test] + fn a_repeated_input_is_kept_once() { + let contexts = contexts(); + let fence = Fence::from_fence(&independent(&contexts).unwrap()); + let inputs = Inputs::new(core::iter::repeat(&fence).take(100)).unwrap().unwrap(); + assert_eq!(inputs.fences().len(), 1); + assert_eq!(inputs.fences()[0].raw(), fence.raw()); + } + + #[test] + fn points_of_one_timeline_keep_the_latest() { + let contexts = contexts(); + let earlier = Fence::from_fence(&contexts.new_fence(0, CompletionFence).unwrap()); + let later = Fence::from_fence(&contexts.new_fence(0, CompletionFence).unwrap()); + let other = Fence::from_fence(&independent(&contexts).unwrap()); + let inputs = Inputs::new([&later, &other, &earlier]).unwrap().unwrap(); + assert_eq!(inputs.fences().len(), 2); + assert!(inputs.fences().iter().any(|fence| fence.raw() == later.raw())); + assert!(inputs.fences().iter().any(|fence| fence.raw() == other.raw())); + } + + #[test] + fn a_container_is_kept_as_its_base_fences() { + let contexts = contexts(); + let fences = unsignalled(&contexts, 2); + let array = merge(&fences).unwrap(); + let inputs = Inputs::new([&array, &fences[0], &fences[1]]).unwrap().unwrap(); + assert_eq!(inputs.fences().len(), 2); + for fence in fences.iter() { + assert!(inputs.fences().iter().any(|kept| kept.raw() == fence.raw())); + } + } + + #[test] + fn sources_cover_inputs_as_passed_not_their_base_fences() { + let contexts = contexts(); + let fences = unsignalled(&contexts, 2); + let container = merge(&fences).unwrap(); + let mut heads = KVec::new(); + heads.push(container.clone(), GFP_KERNEL).unwrap(); + let sources = Sources::new(heads, KVec::new(), KVec::new(), KVec::new()).unwrap(); + // The submission keeps the container's base fences, which the sources do not list. + let inputs = Inputs::new(core::iter::once(&container)).unwrap().unwrap(); + assert!(inputs.fences().iter().all(|fence| !sources.contains_input(fence))); + // Coverage is decided on the inputs as passed, so the command still waits on none. + let covered = |fence: &Fence| sources.contains_input(fence); + assert!(command_inputs(Some(&inputs), core::iter::once(&container), covered).unwrap().is_none()); + // With an input the sources leave, the command waits on that one only, in its own list. + let other = Fence::from_fence(&independent(&contexts).unwrap()); + let both = Inputs::new([&container, &other]).unwrap().unwrap(); + let own = command_inputs(Some(&both), [&container, &other].into_iter(), covered) + .unwrap() + .unwrap(); + assert!(!own.shares_with(&both.for_command().unwrap())); + assert_eq!(own.fences().len(), 1); + assert_eq!(own.fences()[0].raw(), other.raw()); + } + + #[test] + fn a_failed_point_is_never_folded_into_a_later_one() { + let contexts = contexts(); + let failed: kernel::dma_fence::UserFence = + contexts.new_fence(0, CompletionFence).unwrap().into(); + let later = Fence::from_fence(&contexts.new_fence(0, CompletionFence).unwrap()); + failed.set_error(EIO); + failed.signal(); + let failed = Fence::from_fence(&failed); + let inputs = Inputs::new([&later, &failed]).unwrap().unwrap(); + assert_eq!(inputs.fences().len(), 2); + } + + #[test] + fn signalled_inputs_are_left_out() { + let contexts = contexts(); + let done = independent(&contexts).unwrap(); + done.signal(); + let done = Fence::from_fence(&done); + assert!(Inputs::new(core::iter::once(&done)).unwrap().is_none()); + let failed = independent(&contexts).unwrap(); + failed.set_error(EIO); + failed.signal(); + let failed = Fence::from_fence(&failed); + // A failed input keeps its status for the command to consume. + let inputs = Inputs::new([&done, &failed]).unwrap().unwrap(); + assert_eq!(inputs.fences().len(), 1); + assert_eq!(inputs.fences()[0].raw(), failed.raw()); + } +} diff --git a/tools/asahi/g17-command-inputs-tests.py b/tools/asahi/g17-command-inputs-tests.py new file mode 100755 index 0000000000000..df6d364cb69be --- /dev/null +++ b/tools/asahi/g17-command-inputs-tests.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Host test for which of a submission's inputs one G17 command waits on. + +Compiles production `command_inputs()` (`sync_input.rs`) against a model of +`Inputs` (an unsignalled-input list, shared through an `Arc`) to prove: +1. A command whose compute sources take over none of the inputs shares the + submission's list. +2. A command whose sources take over some inputs waits only on the others, in a + list of its own. +3. A command whose sources take over every input not yet signalled waits on + nothing. +""" +import argparse +import os +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +G17 = ROOT / 'drivers/gpu/drm/asahi/g17' + +MUTATIONS = [ + 'wait-on-covered', + 'always-share', +] + + +def item(source, signature): + assert source.count(signature) == 1, signature + start = source.index(signature) + begin = source.index('{', source.index(')', start)) + depth, end = 1, begin + 1 + while depth: + depth += (source[end] == '{') - (source[end] == '}') + end += 1 + return source[start:end] + + +def build_harness(mutation=None): + src = (G17 / 'sync_input.rs').read_text() + select = item(src, 'pub(crate) fn command_inputs<') + + if mutation == 'wait-on-covered': + old = '.filter(|fence| !covered(fence))' + assert old in select + select = select.replace(old, '.filter(|_| true)', 1) + elif mutation == 'always-share': + old = 'if !inputs.clone().any(|fence| covered(fence)) {' + assert old in select + select = select.replace(old, 'if true {', 1) + + return f''' +type Result = std::result::Result; + +mod kernel {{ + pub mod sync {{ + pub use std::sync::Arc; + }} +}} + +#[derive(Clone, Copy, Debug, PartialEq)] +struct Fence {{ + id: u32, + status: i32, +}} + +/// A submission's input fences not yet signalled without error. +struct Inputs {{ + fences: Vec, +}} + +impl Inputs {{ + fn new<'a>(inputs: impl IntoIterator) -> Result>> {{ + let fences: Vec = inputs.into_iter().filter(|fence| fence.status <= 0).copied().collect(); + Ok((!fences.is_empty()).then(|| kernel::sync::Arc::new(Self {{ fences }}))) + }} + fn for_command(self: &kernel::sync::Arc) -> Result {{ + Ok(CommandInputs(self.clone())) + }} +}} + +struct CommandInputs(kernel::sync::Arc); + +{select.replace('pub(crate) ', '')} + +fn ids(inputs: &Option) -> Vec {{ + inputs.as_ref().map_or(Vec::new(), |inputs| inputs.0.fences.iter().map(|fence| fence.id).collect()) +}} + +fn main() {{ + let a = Fence {{ id: 1, status: 0 }}; + let b = Fence {{ id: 2, status: 0 }}; + let done = Fence {{ id: 3, status: 1 }}; + let all = [a, b, done]; + let shared = Inputs::new(all.iter()).unwrap(); + + // 1. No source covers an input: the command shares the submission's list. + let none = command_inputs(shared.as_ref(), all.iter(), |_| false).unwrap(); + assert!(std::sync::Arc::ptr_eq(&none.as_ref().unwrap().0, shared.as_ref().unwrap()), + "an uncovered command must share the submission's list"); + assert_eq!(ids(&none), vec![1, 2]); + + // 2. Sources cover a: the command waits on b only, in a list of its own. + let part = command_inputs(shared.as_ref(), all.iter(), |fence| fence.id == 1).unwrap(); + assert_eq!(ids(&part), vec![2], "a partly covered command must wait on its uncovered inputs only"); + assert!(!std::sync::Arc::ptr_eq(&part.as_ref().unwrap().0, shared.as_ref().unwrap())); + + // 3. Sources cover a and b; done has signalled: nothing to wait for. + let covered = command_inputs(shared.as_ref(), all.iter(), |fence| fence.id != 3).unwrap(); + assert!(covered.is_none(), "a command its sources cover must wait on no input"); + + // 4. Nothing unsignalled in the submission: nothing to wait for. + assert!(command_inputs(None, [done].iter(), |_| false).unwrap().is_none()); + + println!("PASS g17 command inputs"); +}} +''' + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument('--mutation', choices=MUTATIONS) + args = ap.parse_args() + + src = build_harness(args.mutation) + with tempfile.TemporaryDirectory(prefix='g17-command-inputs-') as tmp: + rs = os.path.join(tmp, 'harness.rs') + bin_path = os.path.join(tmp, 'harness') + Path(rs).write_text(src) + c = subprocess.run(['rustc', '-O', rs, '-o', bin_path], capture_output=True, text=True) + if c.returncode != 0: + sys.stderr.write(c.stderr) + return 2 + r = subprocess.run([bin_path], capture_output=True, text=True) + sys.stdout.write(r.stdout) + sys.stderr.write(r.stderr) + return r.returncode + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/asahi/g17-inline-cross-engine-tests.py b/tools/asahi/g17-inline-cross-engine-tests.py index e0eed1337740e..585ed819d67a7 100755 --- a/tools/asahi/g17-inline-cross-engine-tests.py +++ b/tools/asahi/g17-inline-cross-engine-tests.py @@ -36,6 +36,7 @@ 'skip-compute-producer-check', 'skip-render-producer-check', 'copy-try-early-bool', + 'host-deps-skip-shared', ] @@ -58,6 +59,7 @@ def build_harness(mutation=None): has_host_fn = item(job_src, 'pub(crate) fn has_host_dependencies(') has_deps_fn = item(job_src, 'pub(crate) fn has_dependencies(') + inputs_fn = item(job_src, 'fn inputs(&self)') comp_early_fn = item(runtime_src, 'pub(super) fn try_compute_early(') rend_early_fn = item(submit_src, 'pub(in crate::g17) fn try_render_early(') @@ -97,6 +99,10 @@ def build_harness(mutation=None): old = 'if let Err(error) = packet.check_firmware_producers() {' assert old in rend_early_fn rend_early_fn = rend_early_fn.replace(old, 'if let Err::<(), i32>(error) = Ok(()) {', 1) + elif mutation == 'host-deps-skip-shared': + old = 'self.inputs().next().is_some()' + assert old in has_host_fn + has_host_fn = has_host_fn.replace(old, '!self.inputs.is_empty()', 1) elif mutation == 'copy-try-early-bool': assert inline_pub_expr == 'inline && packet.is_published()', inline_pub_expr inline_pub_expr = 'inline' @@ -172,8 +178,18 @@ def build_harness(mutation=None): }} }} +/// A command's share of its submission's input fences. +struct CommandInputs(Vec); + +impl CommandInputs {{ + fn fences(&self) -> &[Fence] {{ + &self.0 + }} +}} + struct Packet {{ inputs: Vec, + shared_inputs: Option, producers: Option, began: Cell, published: Cell, @@ -184,6 +200,7 @@ def build_harness(mutation=None): impl Packet {{ {has_deps_fn.replace('pub(crate) ', '')} {has_host_fn.replace('pub(crate) ', '')} + {inputs_fn} fn check_firmware_producers(&self) -> Result {{ self.producers.unwrap_or(Ok(())) }} @@ -242,8 +259,13 @@ def build_harness(mutation=None): }} fn pkt(inputs: Vec, producers: Option) -> Packet {{ + pkt_shared(inputs, None, producers) +}} + +fn pkt_shared(inputs: Vec, shared: Option>, producers: Option) -> Packet {{ Packet {{ inputs, + shared_inputs: shared.map(CommandInputs), producers, began: Cell::new(false), published: Cell::new(false), @@ -297,6 +319,11 @@ def build_harness(mutation=None): assert!(!b.run_compute_early_guard(&p_host), "compute with host dep must stay on drm_sched"); assert!(!b.run_render_early_guard(&p_host), "render with host dep must stay on drm_sched"); + // A submission's own inputs, shared by its commands, are host waits too. + let p_shared = pkt_shared(vec![], Some(vec![sched_pending]), Some(Ok(()))); + assert!(!b.run_compute_early_guard(&p_shared), "compute with a shared input must stay on drm_sched"); + assert!(!b.run_render_early_guard(&p_shared), "render with a shared input must stay on drm_sched"); + // 5. Failed firmware producer fails consumer unpublished in both compute and render. let p_err_c = pkt(vec![], Some(Err(ECANCELED))); assert!(b.run_compute_early_guard(&p_err_c)); diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index ebac7111a0525..8e94090abc4e9 100644 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -523,10 +523,13 @@ def mutations(flag, names, base, expect=KILL): 'max-channels', 'multi-channel-max'), []), 'g17-m5-effort-tests.py': [([], PASS)] + mutations('--mutation', ('m5-ignores-bound', 'idle-counts-submitted'), []), + 'g17-command-inputs-tests.py': [([], PASS)] + + mutations('--mutation', ('wait-on-covered', 'always-share'), []), 'g17-inline-cross-engine-tests.py': [([], PASS)] + mutations('--mutation', ('always-wait-scheduled', 'skip-unpublished-scheduled', 'block-firmware-early', 'skip-compute-producer-check', - 'skip-render-producer-check', 'copy-try-early-bool'), []), + 'skip-render-producer-check', 'copy-try-early-bool', + 'host-deps-skip-shared'), []), 'g17-direct-stage-prefixes-tests.py': [([], PASS)] + mutations('--mutation', ('reject-staged', 'skip-render-tiling', 'skip-tiling-prefix', 'skip-compute-resolve',