Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/victory-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4330,6 +4330,7 @@ impl Host {
let bytes: u64 = ranges.iter().map(|&(a, b)| (b - a) as u64).sum();
crate::shadow::CARD_STATS[0].fetch_add(bytes, Ordering::Relaxed);
crate::shadow::CARD_STATS[1].fetch_add(ranges.len() as u64, Ordering::Relaxed);
crate::land::title_sent(shadow.span(), ranges);
#[cfg(feature = "diagnostics")]
traffic::moved(traffic::UP, shadow.span(), ranges.iter().copied());
if own.is_none() && before.is_some() && !ranges.is_empty() {
Expand Down Expand Up @@ -4641,6 +4642,9 @@ impl Host {
continue;
}
let (lo, hi) = r.shadow.card_piece(&r.span, p);
if land::left_on_card(r.shadow.span(), lo) {
continue;
}
if lo < hi && !seen.contains(&(copy, lo, hi)) {
let key = (r.shadow.id(), r.shadow.span().0 as usize + lo, hi - lo);
if fetch.as_ref().is_some_and(|f| f.had.holds(behind, key)) {
Expand Down
84 changes: 84 additions & 0 deletions crates/victory-gpu/src/land.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,90 @@ pub(crate) fn skip_on() -> bool {
*ON.get_or_init(|| std::env::var_os("VICTORY_LAND_SKIP").is_some_and(|v| v == "1"))
}

/// Copies left on the card (`VICTORY_LAND_NOT=<lengths>`, hex, comma
/// separated; unset: none): what shaders write in a host copy of one of these
/// lengths is not fetched into title memory, except in the 64 KiB pieces the
/// title has sent bytes up into within the last [`SENT_FRAMES`] frames
/// ([`title_sent`]), which land as before. For memory only shaders use,
/// which the title's code neither reads nor writes after it set it up (the
/// title writes all of each at the load): the card's side is the one that
/// counts, and the title's lists find it there. In this title the upscaler
/// chain's 0x1412200 bytes (21 MB fetched a frame) and three buffers shaders
/// fill (0x2d00000, 0x5265c0, 0x1cc000: 14 MB a frame; the first of them
/// has a piece or two sent up now and then, which keep landing): n-ab-land,
/// -3.0 and -2.6 ms a frame, -5.6 together, the same draws a frame. Then
/// 0x3200000 (the title and the shaders write pieces apart), 0xc00000 and
/// 0x2a3000, 11 MB a frame: n-ab-landc, 39.0 -> 37.5 ms. Copies both write
/// pieces of (the 174 MB ring, 0x1900000, 0x564000) are left as they are.
pub(crate) fn left_on_card(span: (u64, u64), offset: usize) -> bool {
listed(span.1)
&& caught(span)
&& sent()
.lock()
.unwrap_or_else(|e| e.into_inner())
.get(&(span.0, (offset >> 16) as u32))
.is_none_or(|&at| crate::frame::current().saturating_sub(at) > SENT_FRAMES)
}

/// How long a piece of [`left_on_card`]'s copies the title sent up keeps
/// landing: about ten seconds.
const SENT_FRAMES: u64 = 300;

/// Says in the log each copy a listed length catches, the first time: a
/// length is no name, and another buffer of the same size would be left on
/// the card too. Always true.
fn caught(span: (u64, u64)) -> bool {
static SEEN: OnceLock<Mutex<std::collections::HashSet<(u64, u64)>>> = OnceLock::new();
let mut seen = SEEN.get_or_init(Default::default).lock().unwrap_or_else(|e| e.into_inner());
if seen.insert(span) {
let of_length = seen.iter().filter(|s| s.1 == span.1).count();
tracing::info!(
"a host copy of a listed length stays on the card (VICTORY_LAND_NOT): {:#x}+{:#x}, {of_length} of that length so far",
span.0,
span.1
);
}
true
}

/// Offsets `ranges` of the copy of `span` were sent up: their pieces land
/// for a while ([`left_on_card`]).
pub(crate) fn title_sent(span: (u64, u64), ranges: &[(usize, usize)]) {
if !listed(span.1) {
return;
}
let now = crate::frame::current();
let mut sent = sent().lock().unwrap_or_else(|e| e.into_inner());
for &(from, to) in ranges.iter().filter(|r| r.0 < r.1) {
for p in (from >> 16) as u32..=((to - 1) >> 16) as u32 {
sent.insert((span.0, p), now);
}
}
}

fn listed(len: u64) -> bool {
static LIST: OnceLock<Vec<u64>> = OnceLock::new();
let list = LIST.get_or_init(|| {
let list: Vec<u64> = std::env::var("VICTORY_LAND_NOT")
.unwrap_or_default()
.split(',')
.filter_map(|v| u64::from_str_radix(v.trim().trim_start_matches("0x"), 16).ok())
.collect();
if !list.is_empty() {
tracing::info!(?list, "host copies of these lengths stay on the card, but for pieces the title sends up (VICTORY_LAND_NOT)");
}
list
});
!list.is_empty() && list.contains(&len)
}

/// Of [`left_on_card`]'s copies, the pieces the title sent up: (title
/// address, piece) → the frame it last did.
fn sent() -> &'static Mutex<std::collections::HashMap<(u64, u32), u64>> {
static SENT: OnceLock<Mutex<std::collections::HashMap<(u64, u32), u64>>> = OnceLock::new();
SENT.get_or_init(Default::default)
}

/// Since the last frame-rate line; microseconds first.
pub(crate) mod stat {
/// Which pieces to fetch; their list recorded and sent.
Expand Down
9 changes: 9 additions & 0 deletions crates/victory-gpu/src/list/thin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ fn start() {
let worker = move || {
crate::cores::keep_many_on_fast_cores("victory-list");
crate::queue::no_drain_here();
// Below the title's threads and the submitting one, which the
// frame waits for more than for a list's translation
// (`VICTORY_LIST_LOW=1`; off by default): n-ab-prio, 37.2 -> 36.3 ms a
// frame, the chain's "woken, not running yet" being ~3 ms.
if std::env::var_os("VICTORY_LIST_LOW").is_some_and(|v| v == "1") {
use windows_sys::Win32::System::Threading::{GetCurrentThread, SetThreadPriority, THREAD_PRIORITY_BELOW_NORMAL};
// SAFETY: this thread's own priority.
unsafe { SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL) };
}
loop {
let recording = {
let mut ready = held(&READY);
Expand Down
Loading