Merge day/submit: the panel, parts of submissions prepared as one (VICTORY_JOIN_PARTS, off), fills cut free of copies

A submission whose lists are still being translated is unfolded where the
one before it may take it along.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 12:55:14 -06:00
commit fa8cd8071c
10 files changed
+1300 -112

No files matched your search

+198 -16
View File
@@ -74,6 +74,14 @@ pub(super) trait Work: Send {
}
/// Waits until a folded one is free to go.
fn settle(_: &Self::Ask) {}
/// Takes `next`, what its queue was given behind it, along to be done with
/// it; or gives it back. Whether it is a submission that was taken.
fn take_along(&mut self, next: Self) -> Result<bool, Self>
where
Self: Sized,
{
Err(next)
}
/// Does it. `forced`: its wait was not met.
fn go(self, forced: bool);
}
@@ -245,6 +253,17 @@ impl<W: Work> Lane<W> {
while self.step(limit) {}
}
/// The parts of `entry`, which stands for them, in place `at`.
fn unfold(state: &mut State<W>, at: usize, entry: Entry<W>) {
let (number, queue, runs) = (entry.number, entry.queue, usize::from(entry.what.runs()));
let parts = entry.what.unfold();
state.runs -= runs;
state.runs += parts.iter().filter(|p| p.runs()).count();
for (i, what) in parts.into_iter().enumerate() {
state.items.insert(at + i, Entry { number, queue, what });
}
}
/// Does one entry: the oldest that is the first of its queue and free to
/// run. Whether there was one. Only one thread calls this.
fn step(&self, limit: u64) -> bool {
@@ -286,7 +305,7 @@ impl<W: Work> Lane<W> {
(first, true)
}
};
let entry = {
let mut entry = {
let mut state = self.lock();
let Some(at) = state.items.iter().position(|e| e.number == number) else {
return false;
@@ -297,31 +316,56 @@ impl<W: Work> Lane<W> {
state.running = Some(entry.queue);
entry
};
let (shows, runs) = (entry.what.shows(), entry.what.runs());
let (shows, mut runs) = (entry.what.shows(), usize::from(entry.what.runs()));
if entry.what.folded() {
// Its parts take its place: behind everything before it, before
// everything after it (they share its number; the first of them
// is found first).
let (number, queue) = (entry.number, entry.queue);
let parts = entry.what.unfold();
let mut state = self.lock();
state.running = None;
state.runs -= usize::from(runs);
state.runs += parts.iter().filter(|p| p.runs()).count();
let place = state.items.iter().position(|e| e.number > number).unwrap_or(state.items.len());
for (i, what) in parts.into_iter().enumerate() {
state.items.insert(place + i, Entry { number, queue, what });
}
let at = state.items.iter().position(|e| e.number > entry.number).unwrap_or(state.items.len());
Self::unfold(&mut state, at, entry);
drop(state);
self.moved.notify_all();
return true;
}
// What follows it in its queue, if that can go with it. (Nobody else
// takes anything out, and what comes in goes to the end.)
while runs > 0 && !forced {
let next = {
let mut state = self.lock();
let at = state.items.iter().position(|e| e.queue == entry.queue && e.number < limit);
at.and_then(|at| Some((at, state.items.remove(at)?)))
};
let Some((at, next)) = next else {
break;
};
// (Back where it was: parts of one submission share a number.)
if next.what.folded() {
let free = next.what.ask().is_none_or(|ask| W::met(&ask));
let mut state = self.lock();
if free {
Self::unfold(&mut state, at, next);
continue;
}
state.items.insert(at, next);
break;
}
let Entry { number, queue, what } = next;
match entry.what.take_along(what) {
Ok(run) => runs += usize::from(run),
Err(what) => {
self.lock().items.insert(at, Entry { number, queue, what });
break;
}
}
}
entry.what.go(forced);
{
let mut state = self.lock();
state.running = None;
state.presents -= usize::from(shows);
state.runs -= usize::from(runs);
state.runs -= runs;
}
self.moved.notify_all();
true
@@ -342,6 +386,9 @@ enum Job {
/// A submission whose lists are being translated ([`crate::list::thin`]):
/// the parts of it are known when they are.
Lists(usize, Recordings),
/// Parts taken along with a submission ([`crate::host::joins`]): where they
/// begin in the order, and the signals given behind them.
Joined(usize, Vec<crate::list::Detached>, Vec<usize>, Vec<usize>, Vec<(usize, u64)>),
/// A signal of the queue's.
Signal(usize, u64),
/// A frame is shown: the texture and the state its lists leave it in.
@@ -408,13 +455,73 @@ impl Work for Job {
}
fn runs(&self) -> bool {
matches!(self, Job::Run(..) | Job::Lists(..))
matches!(self, Job::Run(..) | Job::Joined(..) | Job::Lists(..))
}
fn take_along(&mut self, next: Job) -> Result<bool, Job> {
let (most, most_lists) = crate::host::joins();
if most < 2 {
return Err(next);
}
// Nothing but waits and signals that a submission may follow.
let (count, lists, signals) = match self {
Job::Run(_, lists, order) => (1, (&*lists, &*order), &[][..]),
Job::Joined(_, lists, order, parts, signals) => (1 + parts.len(), (&*lists, &*order), &signals[..]),
_ => return Err(next),
};
let hosts = || lists.1.iter().map(|&i| lists.0[i].host());
match &next {
Job::Value(wait) => {
let met = wait.met()
|| crate::host::late_met_known(wait) == Some(true)
|| hosts().any(|list| crate::host::will_meet(list, wait));
if !met {
return Err(next);
}
}
&Job::Wait(fence, value) => {
if crate::fence::completed(fence as This) < value && !signals.iter().any(|&(f, v)| f == fence && v >= value) {
return Err(next);
}
}
Job::Signal(..) => {}
Job::Run(_, more, order) => {
let runs: Vec<&crate::host::HostList> = order.iter().map(|&i| more[i].host()).collect();
if count >= most || lists.1.len() + runs.len() > most_lists || !crate::host::joinable(hosts(), &runs) {
return Err(next);
}
}
Job::Joined(..) | Job::Present(..) | Job::Lists(..) => return Err(next),
}
let taken = std::mem::replace(self, Job::Wait(0, 0));
let (queue, mut lists, mut order, mut parts, mut signals) = match taken {
Job::Run(queue, lists, order) => (queue, lists, order, Vec::new(), Vec::new()),
Job::Joined(queue, lists, order, parts, signals) => (queue, lists, order, parts, signals),
other => {
*self = other;
return Err(next);
}
};
let run = matches!(next, Job::Run(..));
match next {
Job::Run(_, more, then) => {
parts.push(order.len());
order.extend(then.into_iter().map(|i| i + lists.len()));
lists.extend(more);
STATS[JOINED].fetch_add(1, Relaxed);
}
Job::Signal(fence, value) => signals.push((fence, value)),
_ => {}
}
*self = Job::Joined(queue, lists, order, parts, signals);
Ok(run)
}
fn go(self, forced: bool) {
let began = Instant::now();
let _doing = crate::timeline::span(match self {
Job::Run(..) => "the line: a submission",
Job::Joined(..) => "the line: submissions joined",
Job::Present(..) => "the line: a present",
Job::Signal(..) => "the line: a signal",
_ => "the line: a wait that is met",
@@ -439,6 +546,24 @@ impl Work for Job {
}
QUEUED.fetch_sub(1, Relaxed);
}
Job::Joined(queue, lists, order, parts, signals) => {
let _ = queue;
#[cfg(feature = "diagnostics")]
crate::capture::op(queue, || {
format!("RUN {} parts of submissions in one, {} lists (its thread's)", 1 + parts.len(), order.len())
});
match crate::host::host() {
Some(host) => host.execute_parts(lists, order, &parts),
None => drop(lists),
}
// (A part that had no list is one all the same.)
QUEUED.fetch_sub(1 + parts.len() as u64, Relaxed);
for (fence, value) in signals {
if !crate::host::late_signal(fence, value) {
crate::fence::set(fence as This, value);
}
}
}
Job::Signal(fence, value) => {
if !crate::host::late_signal(fence, value) {
crate::fence::set(fence as This, value);
@@ -469,7 +594,7 @@ static QUEUED: AtomicU64 = AtomicU64::new(0);
/// threads of the title waited, in microseconds, for room in the line, at a
/// present, and for a drain, and the drains; what our thread worked; waits
/// not met at a present.
static STATS: [AtomicU64; 10] = [const { AtomicU64::new(0) }; 10];
static STATS: [AtomicU64; 11] = [const { AtomicU64::new(0) }; 11];
const RUNS: usize = 0;
const PRESENTS: usize = 1;
const DEPTH: usize = 2;
@@ -480,6 +605,8 @@ const DRAINING: usize = 6;
const DRAINS: usize = 7;
const BUSY: usize = 8;
const FORCED: usize = 9;
/// Parts prepared together with the one before them.
const JOINED: usize = 10;
/// How many submissions may be in the line when a submit call returns
/// (`VICTORY_SUBMIT_DEPTH`; 64: about two frames of the title's).
@@ -701,7 +828,8 @@ pub(super) fn line(frames: f64) {
tracing::info!(
"submissions prepared by a thread of ours, per frame (VICTORY_ASYNC_SUBMIT): {:.1} in {:.1} presents, {:.1} in the line \
when one was added (at most {:.0}); that thread worked {:.1} ms; threads of the title waited {:.1} ms for room in the \
line, {:.1} ms at presents, {:.1} ms in {:.1} drains; waits not met at a present {:.2}",
line, {:.1} ms at presents, {:.1} ms in {:.1} drains; waits not met at a present {:.2}; {:.1} of the \
submissions were prepared together with the one before them (VICTORY_JOIN_PARTS)",
s[RUNS] / frames,
s[PRESENTS] / frames,
s[DEPTH] / s[RUNS].max(1.0),
@@ -711,7 +839,8 @@ pub(super) fn line(frames: f64) {
ms(AT_PRESENT),
ms(DRAINING),
s[DRAINS] / frames,
s[FORCED] / frames
s[FORCED] / frames,
s[JOINED] / frames
);
}
@@ -731,6 +860,8 @@ mod tests {
Slow(&'static str, Log, Arc<(Mutex<bool>, Condvar)>),
Signal(usize, u64, Log),
Present(&'static str, Log),
/// Takes others of its kind, waits that are met, and signals along.
Group(Vec<&'static str>, Log, Vec<(usize, u64)>),
}
impl Work for T {
@@ -748,7 +879,24 @@ mod tests {
matches!(self, T::Present(..))
}
fn runs(&self) -> bool {
matches!(self, T::Run(..) | T::Slow(..))
matches!(self, T::Run(..) | T::Slow(..) | T::Group(..))
}
fn take_along(&mut self, next: T) -> Result<bool, T> {
let T::Group(names, _, signals) = self else {
return Err(next);
};
match next {
T::Group(more, ..) if names.len() < 3 => {
names.extend(more);
Ok(true)
}
T::Wait(f, v) if crate::fence::completed(f as This) >= v || signals.contains(&(f, v)) => Ok(false),
T::Signal(f, v, _) => {
signals.push((f, v));
Ok(false)
}
other => Err(other),
}
}
fn go(self, forced: bool) {
match self {
@@ -769,6 +917,12 @@ mod tests {
log.lock().unwrap().push(format!("signal {value}"));
crate::fence::set(fence as This, value);
}
T::Group(names, log, signals) => {
log.lock().unwrap().push(names.join("+"));
for (fence, value) in signals {
crate::fence::set(fence as This, value);
}
}
}
}
}
@@ -814,6 +968,34 @@ mod tests {
assert!(done);
}
/// A submission takes what follows it in its queue along, up to what it
/// cannot take, which stays at its place; the counts come out even.
#[test]
fn submissions_take_those_behind_them_along() {
let lane = Lane::new();
let log: Log = Default::default();
let f = fence();
let part = |name| T::Group(vec![name], log.clone(), Vec::new());
lane.push(1, [part("a"), T::Wait(f, 0), part("b")]);
lane.push(2, [part("other queue"), T::Wait(f, 1), part("behind a's signal")]);
lane.push(1, [T::Signal(f, 1, log.clone()), T::Wait(f, 1), part("c"), part("d")]);
lane.push(1, [T::Wait(f, 9), part("held"), T::Present("present", log.clone()), part("next frame")]);
// What came after the look was asked for is not touched.
let limit = lane.lock().next;
lane.push(1, [part("later")]);
lane.look(limit);
assert_eq!(
*log.lock().unwrap(),
["a+b+c", "other queue+behind a's signal", "d", "held", "present", "next frame"],
"{:?}",
lane.lock().items.len()
);
look(&lane);
assert_eq!(log.lock().unwrap().last().unwrap(), "later");
let state = lane.lock();
assert_eq!((state.presents, state.runs, state.items.len()), (0, 0, 0));
}
/// A wait that nothing meets holds its queue until a present, which
/// comes behind everything given before it and before what comes after.
#[test]