Give up the render-target reserve once targets settle; log the room test

The texture queue makes no new host copies while in use + kept for
buffer copies + kept for render targets reaches 90 % of the card's
budget. The target reserve (VICTORY_CARD_ROOM_FOR_TARGETS_MB, 3,072 MB
less the targets made) never expired: at 1440p targets level off at
2.1-2.9 GB, so 160-990 MB stayed kept for targets that never came while
thousands of textures waited (diag run 16:28, 10:59:54: 8,722 MB in use
+ 836 kept for targets against a line of 9,527 MB: no room). Now once
targets hold half the reserve or more and have not grown by 64 MiB for
VICTORY_CARD_ROOM_FOR_TARGETS_SETTLE_MS (20,000; 0: kept, as before),
nothing is kept; growth of 64 MiB brings it back.

Release builds logged no term of the room test after the world loaded.
The 5-second texture line now gives them (in use, free texture blocks,
kept for buffer copies and for targets, the line, room or not), and where
the pass's time goes (looks again at uploaded slots, mapped-memory
queries, host-copy digests, making copies and staging), since the pass
hits VICTORY_TEXTURE_STAGE_MS every frame for about 20 textures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-26 16:47:19 +05:30
1 parent 3cb7b8f1d0
commit 21b040da07
3 files changed
+151 -7

No files matched your search

+105 -3
View File
@@ -1848,9 +1848,19 @@ pub(crate) fn room(memory: Option<[u64; 4]>) -> bool {
/// 238), and the queue was refused from the first world frame on. With
/// their room kept, the queue stops that much earlier while the world
/// loads and gets it back as the targets are made.
///
/// Once the world's targets are made (half of the reserve or more) and
/// have not grown by 64 MiB for `VICTORY_CARD_ROOM_FOR_TARGETS_SETTLE_MS`
/// (20,000; 0: kept for the run, as before), nothing is kept: at 1440p the
/// targets level off at 2.1-2.9 GB, and the rest of the 3,072 MB (990 MB
/// at the first world frame, 160-640 MB in play) stayed reserved for
/// targets that never came while thousands of textures waited for room
/// (2026-11-26 diag run 16:28, 10:59:54: 8,722 MB in use + 836 MB kept
/// for targets against a line of 9,527 MB). The reserve comes back when
/// the targets grow by 64 MiB again (a new scene's), for as long again.
#[cfg(windows)]
pub(crate) fn targets_room_kept() -> u64 {
use std::sync::atomic::Ordering::Relaxed;
use std::sync::atomic::{AtomicU64, Ordering::Relaxed};
static MOST: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
let most = *MOST.get_or_init(|| {
std::env::var("VICTORY_CARD_ROOM_FOR_TARGETS_MB")
@@ -1858,9 +1868,76 @@ pub(crate) fn targets_room_kept() -> u64 {
.and_then(|v| v.trim().parse::<u64>().ok())
.map_or(3072 << 20, |mb| mb.min(8192) << 20)
});
static SETTLE: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
let settle = *SETTLE.get_or_init(|| {
std::env::var("VICTORY_CARD_ROOM_FOR_TARGETS_SETTLE_MS")
.ok()
.and_then(|v| v.trim().parse::<u64>().ok())
.unwrap_or(20_000)
});
// Every host texture's bytes less those of the copies the title fills.
let targets = HOST_TEXTURES[1].load(Relaxed).saturating_sub(KINDS[1].load(Relaxed));
most.saturating_sub(targets)
// The targets' bytes at their last change of 64 MiB or more, and when
// they last grew by that much.
static GREW: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
let now = crate::host::now_ms();
let (last, since) = (GREW[0].load(Relaxed), GREW[1].load(Relaxed));
let (last, since) = targets_seen(last, since, targets, now);
GREW[0].store(last, Relaxed);
GREW[1].store(since, Relaxed);
targets_kept(most, targets, now.saturating_sub(since), settle)
}
/// [`targets_room_kept`]'s record of the targets' bytes (`last`) and of
/// when they last grew by 64 MiB (`since`, ms), with `targets` now: a fall
/// of 64 MiB lowers the record (so that growing back counts as growth), a
/// growth of 64 MiB raises it and restarts the clock.
#[cfg(any(windows, test))]
fn targets_seen(last: u64, since: u64, targets: u64, now: u64) -> (u64, u64) {
const STEP: u64 = 64 << 20;
if targets >= last.saturating_add(STEP) {
(targets, now)
} else if targets.saturating_add(STEP) <= last {
(targets, since)
} else {
(last, since)
}
}
/// What [`targets_room_kept`] keeps of `most`: what the targets do not
/// hold yet, or nothing once they hold half of it or more and have not
/// grown for `settle` ms (`still_ms`; `settle` 0: always kept).
#[cfg(any(windows, test))]
fn targets_kept(most: u64, targets: u64, still_ms: u64, settle: u64) -> u64 {
if settle > 0 && targets >= most / 2 && still_ms >= settle {
0
} else {
most.saturating_sub(targets)
}
}
/// What [`room`] weighs now, in MB, for the log: the card's budget, its
/// use, the free part of the texture blocks, what is kept for card copies
/// of title buffers and for render targets, and the line. `None` without
/// the system's numbers, or under `VICTORY_TEXTURE_BUDGET_MB` (which
/// weighs the textures' own bytes instead).
#[cfg(windows)]
pub(crate) fn room_terms(memory: Option<[u64; 4]>) -> Option<[u64; 6]> {
if std::env::var_os("VICTORY_TEXTURE_BUDGET_MB").is_some() {
return None;
}
let [budget, used, ..] = memory?;
Some(
[
budget,
used,
crate::pool::texture_room(),
crate::shadow::card_room_kept(),
targets_room_kept(),
budget / 100 * room_percent(),
]
.map(|bytes| bytes >> 20),
)
}
/// [`room`] as it was at most a tenth of a second ago, for a question
@@ -1889,7 +1966,7 @@ pub(crate) fn room_lately() -> bool {
/// 1 MiB up take 449 MB more of the card than before (941 against 492),
/// and 94 gives the textures about that much back.
#[cfg(windows)]
fn room_percent() -> u64 {
pub(crate) fn room_percent() -> u64 {
static PERCENT: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
*PERCENT.get_or_init(|| {
std::env::var("VICTORY_TEXTURE_ROOM_PERCENT")
@@ -4673,6 +4750,31 @@ float4 lit() : SV_Target { return 1.0; }
assert_eq!(texture_floor_bytes(Some(32 * GIB)), 2 * GIB);
}
/// The room kept for render targets goes once the world's targets are
/// made and have stopped growing, and comes back when they grow again.
#[test]
fn room_for_targets_is_given_up_once_they_settle() {
const MIB: u64 = 1 << 20;
let most = 3072 * MIB;
// Before the world: kept, however long.
assert_eq!(targets_kept(most, 652 * MIB, 60_000, 20_000), 2420 * MIB);
// The world's first frames: still growing.
assert_eq!(targets_kept(most, 2083 * MIB, 5_000, 20_000), 989 * MIB);
// Settled: nothing kept.
assert_eq!(targets_kept(most, 2432 * MIB, 20_000, 20_000), 0);
// `VICTORY_CARD_ROOM_FOR_TARGETS_SETTLE_MS=0`: kept as before.
assert_eq!(targets_kept(most, 2432 * MIB, 600_000, 0), 640 * MIB);
// Growth of 64 MiB restarts the clock; less does not.
assert_eq!(targets_seen(2000 * MIB, 1_000, 2050 * MIB, 9_000), (2000 * MIB, 1_000));
assert_eq!(targets_seen(2000 * MIB, 1_000, 2064 * MIB, 9_000), (2064 * MIB, 9_000));
// A fall lowers the record without restarting it, so growing back
// counts as growth.
let (last, since) = targets_seen(2400 * MIB, 1_000, 1000 * MIB, 9_000);
assert_eq!((last, since), (1000 * MIB, 1_000));
assert_eq!(targets_seen(last, since, 2400 * MIB, 30_000), (2400 * MIB, 30_000));
}
/// A placed texture viewed from a later level has a host copy of that
/// and the smaller levels; a view from an earlier one gets another.
#[cfg(windows)]