New host lists for the title's lists left open for its next reset

At every submission each of the title's lists gets a new host list, from
the pool of landed lists (reset when they landed) or newly made: open and
empty. It was closed at once on the submitting thread, so that the
title's next call on its list, a reset, found it closed, and that reset
then reset allocator and list once more. About 200 empty closes a frame
on the submitting thread (HostList::close under list::detach, 3% of its
samples in profile-y-prof60, about 1 ms a frame) and 200 needless resets
on the threads that translate lists.

Now the new host list is left open and marked with its title calls and
epoch; the title's reset finds it so and skips the D3D12 reset (the rest
of the reset, scratch memory, states, steps, is done as before). If the
title submits the list again without a reset, the host list is closed
when it is taken to run, as before. If anything was recorded into it
before the reset (its title calls or epoch moved), it is closed and
reset as before.

Behaviour-neutral: the lists that run on the card are the same (these are
empty either way). On by default; VICTORY_FRESH_OPEN=0 closes them at
once as before. The frame line "new host lists for the title's lists
left open per frame" counts them, the resets that had nothing to undo and
those closed after all.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-27 01:11:02 +05:30
1 parent ed252ec962
commit a7b86676e7
2 files changed
+106 -12

No files matched your search

+98 -8
View File
@@ -1279,6 +1279,10 @@ pub(crate) struct HostList {
/// The upscaling (`crate::streamline`) recorded in the list, noted for
/// the present after its submission; 0 for none.
upscale: std::sync::atomic::AtomicU64,
/// Left open and empty, as made or reset, for the title's next reset
/// ([`HostList::leave_open`]): that reset finds nothing to undo. The
/// list's title calls and epoch then, each plus one (0: not left open).
left_open: [std::sync::atomic::AtomicU64; 2],
/// Counts the list in [`ALIVE`] while it lives.
_alive: Counted,
/// The texts of the markers `note_op` set, in order (for device-removed
@@ -1294,6 +1298,31 @@ pub(crate) struct HostList {
/// A list's prelude: an allocator and a closed list.
type Prelude = (ID3D12CommandAllocator, ID3D12GraphicsCommandList);
/// Whether the new host list each of the title's lists gets when it is
/// submitted is left open for the title's next reset ([`HostList::leave_open`];
/// `VICTORY_FRESH_OPEN=0`: closed at once and reset again, as before). What
/// runs on the card is the same: those lists are empty either way.
fn fresh_open() -> bool {
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_FRESH_OPEN").is_none_or(|v| v != "0"))
}
/// Since the last frame line: host lists left open ([`fresh_open`]), the
/// title's resets that found one so and did nothing to it, and those closed
/// after all (submitted again without a reset, or recorded into before it).
static FRESH_OPEN: [std::sync::atomic::AtomicU64; 3] = [const { std::sync::atomic::AtomicU64::new(0) }; 3];
/// [`FRESH_OPEN`], for the frame-rate line.
fn fresh_open_line(frames: f64) {
let [open, kept, closed] = [0, 1, 2].map(|i| FRESH_OPEN[i].swap(0, Ordering::Relaxed) as f64 / frames);
if open + kept + closed > 0.0 {
tracing::info!(
"new host lists for the title's lists left open per frame (VICTORY_FRESH_OPEN=0: closed at once): {open:.1}, \
{kept:.1} resets of the title found them so and had nothing to undo, {closed:.2} closed after all"
);
}
}
/// Whether a host list's prelude is made when the list first needs one. A
/// prelude runs the texture transitions and twin copies a list needs before
/// it; lists that name no texture never have one, and every host list was
@@ -4224,6 +4253,7 @@ impl Host {
indirect_run: Mutex::default(),
holding: std::sync::atomic::AtomicBool::new(false),
upscale: std::sync::atomic::AtomicU64::new(0),
left_open: [const { std::sync::atomic::AtomicU64::new(0) }; 2],
_alive: Counted::new(),
#[cfg(feature = "diagnostics")]
notes,
@@ -6387,6 +6417,7 @@ impl HostList {
pub(crate) fn close(&self) {
let _closing = crate::timeline::span("closing a host list");
self.left_open[0].store(0, Ordering::Release);
self.flush_indirect();
self.twins_to_depth();
self.textures_back();
@@ -6436,9 +6467,61 @@ impl HostList {
.splice(at..at, found.into_iter().map(|(shadow, from, to)| Step::Refresh(shadow, from as usize, (to - from) as usize)));
}
/// A new host list for one of the title's lists (`crate::list::detach`),
/// open and empty as it was made or reset: left so, for the title's next
/// call on its list, a reset, which then has nothing to undo
/// ([`fresh_open`]); or closed now, as before.
///
/// Each of the title's lists got a new host list at every submission,
/// closed at once on the submitting thread (an empty list's close, some
/// 5 us in the driver, 200 a frame) and reset again by the title's reset
/// (allocator and list) after the reset that made it ready for reuse.
pub(crate) fn leave_open(&self) {
if !fresh_open() {
self.close();
return;
}
// (The marks first: a reset that sees the list left open sees them.)
self.left_open[1].store(self.epoch() + 1, Ordering::Relaxed);
self.left_open[0].store(self.title_calls() + 1, Ordering::Release);
FRESH_OPEN[0].fetch_add(1, Ordering::Relaxed);
}
/// A host list taken from one of the title's lists to run
/// (`crate::list::detach`): closed first if it was left open
/// ([`HostList::leave_open`]), as it is when the title submits its list
/// again without a reset.
pub(crate) fn close_if_left_open(&self) {
if self.left_open[0].load(Ordering::Acquire) != 0 {
FRESH_OPEN[2].fetch_add(1, Ordering::Relaxed);
self.close();
}
}
/// Whether the list is as [`HostList::leave_open`] left it: nothing was
/// recorded into it since, as far as its title calls and its epoch say.
/// It is no longer marked so; one left open that something was recorded
/// into is closed here, for the reset that follows.
fn still_left_open(&self) -> bool {
let calls = self.left_open[0].swap(0, Ordering::AcqRel);
let epoch = self.left_open[1].swap(0, Ordering::Relaxed);
if calls == 0 {
return false;
}
if calls == self.title_calls() + 1 && epoch == self.epoch() + 1 {
return true;
}
FRESH_OPEN[2].fetch_add(1, Ordering::Relaxed);
// SAFETY: our list, open; what went into it goes with the reset.
let _ = unsafe { self.list.Close() };
false
}
/// Only after the list's last submission finished (every one is waited
/// for).
pub(crate) fn reset(&self) {
// Before the epoch moves on below.
let left_open = self.still_left_open();
self.changed_something();
self.holding.store(false, Ordering::Relaxed);
*self.indirect_run.lock().unwrap_or_else(|e| e.into_inner()) = None;
@@ -6465,14 +6548,20 @@ impl HostList {
give_chunks(std::mem::take(&mut scratch.chunks));
}
}
// SAFETY: the list is not executing.
let reset = unsafe {
self.allocator
.Reset()
.and_then(|()| self.list.Reset(&self.allocator, None))
};
if let Err(e) = reset {
fail(format_args!("a host command list did not reset ({e})"));
// Open and empty since it was made or last reset: the allocator holds
// nothing, the list nothing recorded (`HostList::leave_open`).
if left_open {
FRESH_OPEN[1].fetch_add(1, Ordering::Relaxed);
} else {
// SAFETY: the list is not executing.
let reset = unsafe {
self.allocator
.Reset()
.and_then(|()| self.list.Reset(&self.allocator, None))
};
if let Err(e) = reset {
fail(format_args!("a host command list did not reset ({e})"));
}
}
#[cfg(feature = "diagnostics")]
crate::copystat::add(crate::copystat::C::ResetNs, started.elapsed().as_nanos() as u64);
@@ -8974,6 +9063,7 @@ impl Meter {
spans::line(frames);
crate::shadow::back_line(frames);
submit_split_line(frames);
fresh_open_line(frames);
#[cfg(feature = "diagnostics")]
split_line(frames);
{
+8 -4
View File
@@ -476,14 +476,16 @@ pub(crate) fn detach_parts(lists: &[This]) -> Parts {
continue;
};
// A new host list is open; the title's next call on its list is a
// reset, which wants it closed.
fresh.close();
// reset, which finds it so (or wants it closed).
fresh.leave_open();
// SAFETY: one of our lists, closed and submitted: nothing records
// into it until the title resets it.
let list = unsafe { &mut *this.cast_mut().cast::<List>() };
let Some(host) = list.host.replace(fresh) else {
continue;
};
// (Submitted again without a reset: it runs closed, empty.)
host.close_if_left_open();
let earlier = std::mem::take(&mut list.earlier);
let gate = std::mem::take(&mut list.gate);
let uploads = std::mem::take(&mut *list.uploads.lock().unwrap_or_else(|e| e.into_inner()));
@@ -548,8 +550,8 @@ pub(crate) fn detach(lists: &[This]) -> (Vec<Detached>, Vec<usize>) {
continue;
};
// A new host list is open; the title's next call on its list is a
// reset, which wants it closed.
fresh.close();
// reset, which finds it so (or wants it closed).
fresh.leave_open();
let list = this.cast_mut().cast::<List>();
// SAFETY: one of our lists, closed and submitted: nothing records
// into it until the title resets it.
@@ -557,6 +559,8 @@ pub(crate) fn detach(lists: &[This]) -> (Vec<Detached>, Vec<usize>) {
let Some(host) = (*list).host.replace(fresh) else {
continue;
};
// (Submitted again without a reset: it runs closed, empty.)
host.close_if_left_open();
let uploads =
std::mem::take(&mut *(*list).uploads.lock().unwrap_or_else(|e| e.into_inner()));
let state =