Take the test/fx-prs branch of asdaasdsaddf's fork (as one commit)
Double-precision shader instructions (v_cvt_f32_f64, v_add_f64 sums, the makeDouble overload name and flag), a first half of a paired interpolation read as data, sooner eviction of idle textures and caches under memory pressure, a retried DirectStorage destination write, the texture catch-up budget, VICTORY_FIRSTLANE_OWN, and zlib-rs in place of miniz_oxide. Left out: the fork's personal launcher scripts and its readme. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
2119b0e44c
commit
3bff182ef4
22 files changed
+1147
-64
No files matched your search
@@ -184,11 +184,10 @@ fn save_as(name: &str, width: u32, height: u32, pitch: usize, bgra: bool, rows:
|
||||
header.extend(h.to_be_bytes());
|
||||
header.extend([8, 2, 0, 0, 0]); // 8-bit RGB
|
||||
chunk(&mut png, b"IHDR", &header);
|
||||
chunk(
|
||||
&mut png,
|
||||
b"IDAT",
|
||||
&miniz_oxide::deflate::compress_to_vec_zlib(&raw, 3),
|
||||
);
|
||||
let mut compressed = vec![0u8; zlib_rs::compress_bound(raw.len())];
|
||||
let (idat, rc) = zlib_rs::compress_slice(&mut compressed, &raw, zlib_rs::DeflateConfig::new(3));
|
||||
debug_assert_eq!(rc, zlib_rs::ReturnCode::Ok);
|
||||
chunk(&mut png, b"IDAT", idat);
|
||||
chunk(&mut png, b"IEND", &[]);
|
||||
let path = folder.join(format!("{name}.png"));
|
||||
match std::fs::write(&path, png) {
|
||||
|
||||
@@ -1446,7 +1446,12 @@ impl State {
|
||||
return;
|
||||
}
|
||||
/// Bytes of texture memory staged per frame.
|
||||
const PER_FRAME: u64 = 192 << 20;
|
||||
// `VICTORY_TEXTURE_STAGE_MB` raises it: a backlog of tens of thousands of
|
||||
// textures (a scene's first minutes) then drains in fewer frames.
|
||||
static PER_FRAME_MB: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
|
||||
let per_frame: u64 = *PER_FRAME_MB.get_or_init(|| {
|
||||
std::env::var("VICTORY_TEXTURE_STAGE_MB").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(192)
|
||||
}) << 20;
|
||||
static FRAME: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||
static SPENT: AtomicU64 = AtomicU64::new(0);
|
||||
let frame = crate::frame::current();
|
||||
@@ -1499,10 +1504,19 @@ impl State {
|
||||
// records the frame, and making and staging 192 MB of textures took
|
||||
// 1.6-2.2 s of each of the world's first twenty frames (run 20).
|
||||
// The rest waits for the next frames, as it does past the bytes.
|
||||
const SPAN: std::time::Duration = std::time::Duration::from_millis(250);
|
||||
static SPAN_MS: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
|
||||
let span = std::time::Duration::from_millis(*SPAN_MS.get_or_init(|| {
|
||||
std::env::var("VICTORY_TEXTURE_STAGE_MS").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(250)
|
||||
}));
|
||||
// A backlog (a scene's first minutes: 22,000 slots due, 2-3 minutes of black
|
||||
// surfaces at 192 MB a frame) gets three times the bytes and the time until it
|
||||
// drains; `VICTORY_TEXTURE_CATCHUP=0` keeps the plain budget.
|
||||
static CATCHUP: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
let catchup = *CATCHUP.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_CATCHUP").is_none_or(|v| v != "0"));
|
||||
let (per_frame, span) = if catchup && due.len() >= 1024 { (per_frame * 3, span * 3) } else { (per_frame, span) };
|
||||
let began = std::time::Instant::now();
|
||||
for (index, write) in due {
|
||||
if SPENT.load(Ordering::Relaxed) >= PER_FRAME || began.elapsed() > SPAN {
|
||||
if SPENT.load(Ordering::Relaxed) >= per_frame || began.elapsed() > span {
|
||||
break;
|
||||
}
|
||||
// A placed texture whose memory is not mapped (not streamed in
|
||||
|
||||
@@ -106,6 +106,60 @@ pub(crate) fn long_ago(moment: u64, ms: u64, frames: u64) -> bool {
|
||||
(now >> 32).saturating_sub(moment >> 32) >= frames && tenths * 100 >= ms
|
||||
}
|
||||
|
||||
/// Available physical RAM on the host in bytes, from `GlobalMemoryStatusEx`.
|
||||
pub(crate) fn available_physical_ram() -> Option<u64> {
|
||||
use windows_sys::Win32::System::SystemInformation::{GlobalMemoryStatusEx, MEMORYSTATUSEX};
|
||||
// SAFETY: plain data the call fills in.
|
||||
let mut m: MEMORYSTATUSEX = unsafe { std::mem::zeroed() };
|
||||
m.dwLength = std::mem::size_of::<MEMORYSTATUSEX>() as u32;
|
||||
// SAFETY: a sized structure.
|
||||
let ok = unsafe { GlobalMemoryStatusEx(&mut m) } != 0;
|
||||
ok.then_some(m.ullAvailPhys)
|
||||
}
|
||||
|
||||
/// Effective idle timeout (in milliseconds) for VRAM-backed host textures,
|
||||
/// scaled down under VRAM pressure. Never returns less than 1,000 ms so
|
||||
/// handles not yet recorded into a list or slot remain protected.
|
||||
pub(crate) fn vram_idle_ms(video_memory: Option<[u64; 4]>) -> u64 {
|
||||
const NORMAL_MS: u64 = 5_000;
|
||||
const MODERATE_MS: u64 = 2_500;
|
||||
const HIGH_MS: u64 = 1_000;
|
||||
let Some([budget, used, ..]) = video_memory else {
|
||||
return NORMAL_MS;
|
||||
};
|
||||
if budget == 0 {
|
||||
return NORMAL_MS;
|
||||
}
|
||||
let used_pct = (u128::from(used) * 100) / u128::from(budget);
|
||||
if used_pct >= 85 {
|
||||
HIGH_MS
|
||||
} else if used_pct >= 75 {
|
||||
MODERATE_MS
|
||||
} else {
|
||||
NORMAL_MS
|
||||
}
|
||||
}
|
||||
|
||||
/// Effective idle timeout (in milliseconds) for system-RAM caches (staging
|
||||
/// buffers, loose shadows, and the mapped pipeline library), scaled down
|
||||
/// when free physical RAM is low. Never returns less than 2,000 ms.
|
||||
pub(crate) fn ram_idle_ms(avail_phys: Option<u64>) -> u64 {
|
||||
const GIB: u64 = 1024 * 1024 * 1024;
|
||||
const NORMAL_MS: u64 = 10_000;
|
||||
const MODERATE_MS: u64 = 5_000;
|
||||
const HIGH_MS: u64 = 2_000;
|
||||
let Some(avail) = avail_phys else {
|
||||
return NORMAL_MS;
|
||||
};
|
||||
if avail < 2 * GIB {
|
||||
HIGH_MS
|
||||
} else if avail < 4 * GIB {
|
||||
MODERATE_MS
|
||||
} else {
|
||||
NORMAL_MS
|
||||
}
|
||||
}
|
||||
|
||||
/// How many references are held on a host object (its COM count): ours
|
||||
/// all, since the host's views and commands hold none. A buffer or texture
|
||||
/// with one is held by its owner alone: no descriptor slot keeps it
|
||||
@@ -6479,4 +6533,40 @@ mod batch { // Batch::texture_due lives here; `mod tests` is already taken at
|
||||
before.as_secs_f64() / after.as_secs_f64()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vram_idle_ms_scales_with_pressure() {
|
||||
use super::vram_idle_ms;
|
||||
let gib = 1024 * 1024 * 1024;
|
||||
// Normal (< 75%)
|
||||
assert_eq!(vram_idle_ms(Some([10 * gib, 0, 0, 0])), 5_000);
|
||||
assert_eq!(vram_idle_ms(Some([10 * gib, 7 * gib, 0, 0])), 5_000);
|
||||
assert_eq!(vram_idle_ms(Some([100, 74, 0, 0])), 5_000);
|
||||
// Moderate (75%..85%)
|
||||
assert_eq!(vram_idle_ms(Some([100, 75, 0, 0])), 2_500);
|
||||
assert_eq!(vram_idle_ms(Some([100, 84, 0, 0])), 2_500);
|
||||
// High (>= 85%, including over-budget)
|
||||
assert_eq!(vram_idle_ms(Some([100, 85, 0, 0])), 1_000);
|
||||
assert_eq!(vram_idle_ms(Some([10 * gib, 12 * gib, 0, 0])), 1_000);
|
||||
// Missing or zero budget falls back to normal
|
||||
assert_eq!(vram_idle_ms(None), 5_000);
|
||||
assert_eq!(vram_idle_ms(Some([0, 100, 0, 0])), 5_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ram_idle_ms_scales_with_pressure() {
|
||||
use super::ram_idle_ms;
|
||||
let gib = 1024 * 1024 * 1024;
|
||||
// Normal (>= 4 GiB)
|
||||
assert_eq!(ram_idle_ms(Some(8 * gib)), 10_000);
|
||||
assert_eq!(ram_idle_ms(Some(4 * gib)), 10_000);
|
||||
// Moderate (2 GiB..4 GiB)
|
||||
assert_eq!(ram_idle_ms(Some(4 * gib - 1)), 5_000);
|
||||
assert_eq!(ram_idle_ms(Some(2 * gib)), 5_000);
|
||||
// High (< 2 GiB)
|
||||
assert_eq!(ram_idle_ms(Some(2 * gib - 1)), 2_000);
|
||||
assert_eq!(ram_idle_ms(Some(0)), 2_000);
|
||||
// Missing falls back to normal
|
||||
assert_eq!(ram_idle_ms(None), 10_000);
|
||||
}
|
||||
}
|
||||
@@ -363,13 +363,16 @@ pub(crate) fn removal_note() -> String {
|
||||
/// (hundreds of thousands of pages), once after each burst of loads.
|
||||
/// `VICTORY_LIBRARY_TRIM=0`: the pages stay until Windows takes them.
|
||||
pub(crate) fn trim() {
|
||||
const QUIET_MS: u64 = 10_000;
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
let (at, len) = (VIEW[0].load(Ordering::Relaxed), VIEW[1].load(Ordering::Relaxed));
|
||||
if at == 0
|
||||
|| TRIMMED.load(Ordering::Relaxed)
|
||||
|| crate::host::now_ms() < LOADED_AT.load(Ordering::Relaxed) + QUIET_MS
|
||||
|| !*ON.get_or_init(|| std::env::var_os("VICTORY_LIBRARY_TRIM").is_none_or(|v| v != "0"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
let quiet_ms = crate::host::ram_idle_ms(crate::host::available_physical_ram());
|
||||
if crate::host::now_ms() < LOADED_AT.load(Ordering::Relaxed) + quiet_ms
|
||||
|| TRIMMED.swap(true, Ordering::Relaxed)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -1410,12 +1410,12 @@ pub(crate) fn room() -> bool {
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn let_go_idle() {
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
const IDLE_MS: u64 = 5_000;
|
||||
const IDLE_FRAMES: u64 = 4;
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
if !*ON.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_SWEEP").is_none_or(|v| v != "0")) {
|
||||
return;
|
||||
}
|
||||
let idle_ms = crate::host::vram_idle_ms(crate::host::host().and_then(|h| h.video_memory()));
|
||||
// For the trail (`crate::host::trail`): how many went, their bytes,
|
||||
// and the first one.
|
||||
let (mut went, mut bytes, mut first) = (0u64, 0u64, None);
|
||||
@@ -1430,7 +1430,7 @@ pub(crate) fn let_go_idle() {
|
||||
let gone = {
|
||||
let mut made = r.host.made.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let idle = made.as_ref().is_some_and(|(host, _)| {
|
||||
crate::host::long_ago(r.host.used.load(Relaxed), IDLE_MS, IDLE_FRAMES)
|
||||
crate::host::long_ago(r.host.used.load(Relaxed), idle_ms, IDLE_FRAMES)
|
||||
&& std::sync::Arc::strong_count(host) == 1
|
||||
&& crate::host::references(&host.texture) == 1
|
||||
});
|
||||
|
||||
@@ -1565,17 +1565,20 @@ pub(crate) fn window_use() -> [u64; 8] {
|
||||
/// The next read of that memory makes a new copy and copies the window
|
||||
/// again. Called before a submission starts, by the thread that submits.
|
||||
pub(crate) fn let_go_idle() {
|
||||
const IDLE_MS: u64 = 10_000;
|
||||
const IDLE_FRAMES: u64 = 4;
|
||||
let gone: Vec<Arc<Shadow>> = {
|
||||
// Held from the look to the removal: `loose` hands a copy out
|
||||
// under the same lock, so none is handed out in between.
|
||||
let mut map = LOOSE.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if map.is_empty() {
|
||||
return;
|
||||
}
|
||||
let idle_ms = crate::host::ram_idle_ms(crate::host::available_physical_ram());
|
||||
let idle: Vec<(u64, u64)> = map
|
||||
.iter()
|
||||
.filter(|(_, s)| {
|
||||
Arc::strong_count(s) == 1
|
||||
&& crate::host::long_ago(s.used.load(Ordering::Relaxed), IDLE_MS, IDLE_FRAMES)
|
||||
&& crate::host::long_ago(s.used.load(Ordering::Relaxed), idle_ms, IDLE_FRAMES)
|
||||
&& crate::host::references(&s.buffer) == 1
|
||||
})
|
||||
.map(|(key, _)| *key)
|
||||
|
||||
@@ -422,19 +422,22 @@ pub(crate) fn let_go() -> [u64; 2] {
|
||||
/// Called before a submission starts, by the thread that submits.
|
||||
pub(crate) fn let_go_idle() {
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
const IDLE_MS: u64 = 10_000;
|
||||
const IDLE_FRAMES: u64 = 4;
|
||||
let mut map = STAGING.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let Some(map) = map.as_mut() else {
|
||||
return;
|
||||
};
|
||||
if map.is_empty() {
|
||||
return;
|
||||
}
|
||||
let idle_ms = crate::host::ram_idle_ms(crate::host::available_physical_ram());
|
||||
// A list that recorded an upload or a check holds the staging until it
|
||||
// is reset: one only the table holds is named by no list, recorded or
|
||||
// running.
|
||||
let (mut went, mut bytes) = (0u64, 0u64);
|
||||
map.retain(|_, s| {
|
||||
let keep = Arc::strong_count(s) > 1
|
||||
|| !crate::host::long_ago(s.used.load(Relaxed), IDLE_MS, IDLE_FRAMES);
|
||||
|| !crate::host::long_ago(s.used.load(Relaxed), idle_ms, IDLE_FRAMES);
|
||||
if !keep {
|
||||
LET_GO[0].fetch_add(1, Relaxed);
|
||||
LET_GO[1].fetch_add(s.bytes, Relaxed);
|
||||
|
||||
Reference in new issue
Block a user