gpu: scale texture VRAM floor and per-frame staging budget from VRAM

This commit is contained in:
fever308 committed 2026-11-24 14:53:05 -06:00
1 parent 16849898f3
commit 9beff3cd4b
2 files changed
+73 -11

No files matched your search

+33 -8
View File
@@ -1354,17 +1354,28 @@ pub(crate) fn host_made<'a>(
Some(unsafe { &*std::ptr::from_ref(&host.texture) })
}
/// Unconditional host-texture floor for a given local VRAM budget (`None` when
/// the adapter does not report one): up to 2 GiB, capped at a quarter of the
/// reported budget so 4–6 GiB cards do not bypass the budget check early.
#[cfg(any(windows, test))]
fn texture_floor_bytes(vram_budget: Option<u64>) -> u64 {
const MAX_FLOOR: u64 = 2 << 30;
match vram_budget {
Some(budget) => MAX_FLOOR.min(budget / 4),
None => MAX_FLOOR,
}
}
/// Whether more host copies of textures the title fills may be made for
/// shaders that pick textures by index (`draw.rs` `heap_textures`): always
/// up to `FLOOR` bytes of them, beyond that while the card's memory in use
/// by this process is under nine tenths of the budget the system gives it
/// (`VICTORY_TEXTURE_BUDGET_MB` sets a limit on those copies' bytes
/// instead). Past the budget the system moves the card's memory into the
/// PC's, which ended runs 20 and 24.
/// up to [`texture_floor_bytes`] bytes of them, beyond that while the card's
/// memory in use by this process is under nine tenths of the budget the system
/// gives it (`VICTORY_TEXTURE_BUDGET_MB` sets a limit on those copies' bytes
/// instead). Past the budget the system moves the card's memory into the PC's,
/// which ended runs 20 and 24.
#[cfg(windows)]
pub(crate) fn room() -> bool {
use std::sync::atomic::Ordering::Relaxed;
const FLOOR: u64 = 2 << 30;
const WITHOUT_BUDGET: u64 = 4 << 30;
static LIMIT: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new();
let limit = *LIMIT.get_or_init(|| {
@@ -1375,10 +1386,12 @@ pub(crate) fn room() -> bool {
if let Some(limit) = limit {
return filled < limit;
}
if filled < FLOOR {
let memory = crate::host::host().and_then(|h| h.video_memory());
let floor = texture_floor_bytes(memory.map(|[budget, ..]| budget));
if filled < floor {
return true;
}
match crate::host::host().and_then(|h| h.video_memory()) {
match memory {
Some([budget, used, ..]) => used < budget / 10 * 9,
None => filled < WITHOUT_BUDGET,
}
@@ -3407,4 +3420,16 @@ float4 lit() : SV_Target { return 1.0; }
assert_eq!(slot::<Release>(heap, 0x10)(heap), 1);
assert_eq!(slot::<Release>(placed, 0x10)(placed), 0);
}
#[test]
fn texture_floor_scales_with_vram_budget() {
const GIB: u64 = 1 << 30;
assert_eq!(texture_floor_bytes(None), 2 * GIB);
assert_eq!(texture_floor_bytes(Some(4 * GIB)), GIB);
assert_eq!(texture_floor_bytes(Some(6 * GIB)), 6 * GIB / 4);
assert_eq!(texture_floor_bytes(Some(8 * GIB)), 2 * GIB);
assert_eq!(texture_floor_bytes(Some(12 * GIB)), 2 * GIB);
assert_eq!(texture_floor_bytes(Some(24 * GIB)), 2 * GIB);
assert_eq!(texture_floor_bytes(Some(32 * GIB)), 2 * GIB);
}
}