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:
1 parent
3cb7b8f1d0
commit
21b040da07
3 files changed
+151
-7
No files matched your search
@@ -881,6 +881,24 @@ pub(crate) static HEAP_TEXTURES_QUEUE: [AtomicU64; 5] = [const { AtomicU64::new(
|
||||
/// the ones whose first page was not there (asked by the first page alone,
|
||||
/// as before, they counted as not there at all).
|
||||
pub(crate) static HEAP_TEXTURES_PARTLY: [AtomicU64; 3] = [const { AtomicU64::new(0) }; 3];
|
||||
|
||||
/// Microseconds the pass over textures picked by index spent, since the
|
||||
/// last 5-second line, on: looks again at slots uploaded whole (a
|
||||
/// fingerprint of 48 KiB), asking how much of a texture's memory is mapped,
|
||||
/// asking whether a host copy holds what memory holds (a digest of all of
|
||||
/// it), and making host copies and staging their uploads (`readable`); and
|
||||
/// the passes in all. The pass stops at `VICTORY_TEXTURE_STAGE_MS` (16 in
|
||||
/// the launcher), and in play it ran 18-20 ms a frame for about 20
|
||||
/// textures: these say what took the time.
|
||||
pub(crate) static HEAP_TEXTURE_MICROS: [AtomicU64; 5] = [const { AtomicU64::new(0) }; 5];
|
||||
|
||||
/// `f`'s result, its time added to [`HEAP_TEXTURE_MICROS`]' place `slot`.
|
||||
fn timed<T>(slot: usize, f: impl FnOnce() -> T) -> T {
|
||||
let started = std::time::Instant::now();
|
||||
let out = f();
|
||||
HEAP_TEXTURE_MICROS[slot].fetch_add(started.elapsed().as_micros() as u64, Ordering::Relaxed);
|
||||
out
|
||||
}
|
||||
static DROPPED: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
/// Marks the last traced draw as not run on the host.
|
||||
@@ -2949,7 +2967,8 @@ impl State {
|
||||
// was shown four frames late, over and over.
|
||||
let mut again_in = RECHECK_FRAMES[0];
|
||||
if let Some((at, len, print, looks, uploaded)) = host.texture_slot_checked(index) {
|
||||
if crate::texture::fingerprint(at, len) == print {
|
||||
let looked = timed(0, || crate::texture::fingerprint(at, len));
|
||||
if looked == print {
|
||||
HEAP_TEXTURES_RECHECKED[0].fetch_add(1, Ordering::Relaxed);
|
||||
match RECHECK_FRAMES.get(usize::from(looks) + 1) {
|
||||
Some(wait) => {
|
||||
@@ -2990,7 +3009,7 @@ impl State {
|
||||
let address = u64::from(desc[10]) | u64::from(desc[11]) << 32;
|
||||
let first = crate::resource::first_mip(&desc);
|
||||
let len = crate::resource::placed_bytes_from(&resource, first).unwrap_or(1);
|
||||
let mapped = crate::texture::mapped_bytes(address as *const u8, len as usize);
|
||||
let mapped = timed(1, || crate::texture::mapped_bytes(address as *const u8, len as usize));
|
||||
if mapped == 0 {
|
||||
HEAP_TEXTURES_AWAY.fetch_add(1, Ordering::Relaxed);
|
||||
// Streamed out: what the slot showed is let go.
|
||||
@@ -3135,7 +3154,7 @@ impl State {
|
||||
(Some(_), Some(View::Placed(_, _, desc))) => crate::resource::first_mip(desc),
|
||||
_ => 0,
|
||||
};
|
||||
let same = !tabled && crate::texture::unchanged(resource, first);
|
||||
let same = !tabled && timed(2, || crate::texture::unchanged(resource, first));
|
||||
if same {
|
||||
HEAP_TEXTURES_SAME.fetch_add(1, Ordering::Relaxed);
|
||||
if let (Some(sync), Some(key), Some(handle)) = (sync.as_deref_mut(), bake_key, heap.handle(index)) {
|
||||
@@ -3196,7 +3215,7 @@ impl State {
|
||||
// (What was found mapped of it a moment ago is not asked
|
||||
// again, unless the host copy may need more.)
|
||||
crate::texture::PICKING.set(Some(there.filter(|_| partly.is_none()).unwrap_or(u64::MAX)));
|
||||
readable(list, sampled.kind, view);
|
||||
timed(3, || readable(list, sampled.kind, view));
|
||||
crate::texture::PICKING.set(None);
|
||||
}
|
||||
// A failed or deferred staging allocation leaves this slot due.
|
||||
@@ -3300,6 +3319,7 @@ impl State {
|
||||
if sync.is_none() && baking && served {
|
||||
BAKE_SERVED.store(host.texture_news().0 + 1, Ordering::Relaxed);
|
||||
}
|
||||
HEAP_TEXTURE_MICROS[4].fetch_add(began.elapsed().as_micros() as u64, Ordering::Relaxed);
|
||||
served
|
||||
}
|
||||
|
||||
|
||||
@@ -8841,6 +8841,28 @@ impl Meter {
|
||||
crate::descriptor::host::STALE[3].load(Ordering::Relaxed),
|
||||
crate::descriptor::host::STALE[4].load(Ordering::Relaxed)
|
||||
);
|
||||
// What the queue's room test (`crate::resource::room`) weighs.
|
||||
if let Some([budget, used, blocks, buffers, targets, line]) =
|
||||
crate::resource::room_terms(host().and_then(|h| h.video_memory()))
|
||||
{
|
||||
let weighed = used.saturating_sub(blocks) + buffers + targets;
|
||||
tracing::info!(
|
||||
"the texture queue's room: {used} MB in use - {blocks} MB free in texture blocks + {buffers} MB kept for \
|
||||
card copies of title buffers + {targets} MB kept for render targets = {weighed} MB against a line of \
|
||||
{line} MB ({} % of a budget of {budget} MB): {}",
|
||||
crate::resource::room_percent(),
|
||||
if weighed < line { "room" } else { "no room, new textures wait" }
|
||||
);
|
||||
}
|
||||
let [looks, mapped, same, made, all] =
|
||||
[0, 1, 2, 3, 4].map(|i| crate::draw::HEAP_TEXTURE_MICROS[i].swap(0, Ordering::Relaxed) / 1000);
|
||||
if all > 0 {
|
||||
tracing::info!(
|
||||
"the pass over textures picked by index, in the last 5 seconds: {all} ms in all, of them {looks} ms looking again at slots uploaded whole, {mapped} ms asking what of a texture's memory is mapped, {same} ms asking whether a host copy holds what memory holds, {made} ms making host copies and staging uploads; uploaded since the start: {} textures, {} MB",
|
||||
crate::draw::HEAP_TEXTURES.load(Ordering::Relaxed),
|
||||
crate::draw::HEAP_TEXTURE_BYTES.load(Ordering::Relaxed) >> 20
|
||||
);
|
||||
}
|
||||
}
|
||||
if crate::resource::held_only() {
|
||||
let [copies, bytes, grown, whole] = [0, 1, 2, 3].map(|i| crate::resource::HELD[i].load(Ordering::Relaxed));
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in new issue
Block a user