gpu: scale texture VRAM floor and per-frame staging budget from VRAM
This commit is contained in:
1 parent
16849898f3
commit
9beff3cd4b
2 files changed
+73
-11
No files matched your search
@@ -1445,8 +1445,11 @@ impl State {
|
|||||||
if !*ON.get_or_init(|| std::env::var_os("VICTORY_HEAP_TEXTURES").is_none_or(|v| v != "0")) {
|
if !*ON.get_or_init(|| std::env::var_os("VICTORY_HEAP_TEXTURES").is_none_or(|v| v != "0")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/// Bytes of texture memory staged per frame.
|
let per_frame = staging_budget_per_frame(
|
||||||
const PER_FRAME: u64 = 192 << 20;
|
crate::host::host()
|
||||||
|
.and_then(|h| h.video_memory())
|
||||||
|
.map(|[budget, ..]| budget),
|
||||||
|
);
|
||||||
static FRAME: AtomicU64 = AtomicU64::new(u64::MAX);
|
static FRAME: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||||
static SPENT: AtomicU64 = AtomicU64::new(0);
|
static SPENT: AtomicU64 = AtomicU64::new(0);
|
||||||
let frame = crate::frame::current();
|
let frame = crate::frame::current();
|
||||||
@@ -1502,7 +1505,7 @@ impl State {
|
|||||||
const SPAN: std::time::Duration = std::time::Duration::from_millis(250);
|
const SPAN: std::time::Duration = std::time::Duration::from_millis(250);
|
||||||
let began = std::time::Instant::now();
|
let began = std::time::Instant::now();
|
||||||
for (index, write) in due {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
// A placed texture whose memory is not mapped (not streamed in
|
// A placed texture whose memory is not mapped (not streamed in
|
||||||
@@ -2690,3 +2693,37 @@ pub(crate) fn stencil_ref(list: &HostList, reference: u32) {
|
|||||||
// SAFETY: an open list.
|
// SAFETY: an open list.
|
||||||
unsafe { list.list.OMSetStencilRef(reference) };
|
unsafe { list.list.OMSetStencilRef(reference) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Per-frame texture staging byte budget scaled from the adapter's local VRAM
|
||||||
|
/// budget (`None` keeps the 192 MiB 12 GiB baseline).
|
||||||
|
fn staging_budget_per_frame(vram_budget: Option<u64>) -> u64 {
|
||||||
|
const GIB: u64 = 1 << 30;
|
||||||
|
const MIB: u64 = 1 << 20;
|
||||||
|
match vram_budget {
|
||||||
|
Some(budget) if budget <= 6 * GIB => 96 * MIB,
|
||||||
|
Some(budget) if budget >= 20 * GIB => 384 * MIB,
|
||||||
|
Some(budget) if budget > 14 * GIB => 256 * MIB,
|
||||||
|
_ => 192 * MIB,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::staging_budget_per_frame;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn staging_budget_scales_with_vram_budget() {
|
||||||
|
const GIB: u64 = 1 << 30;
|
||||||
|
const MIB: u64 = 1 << 20;
|
||||||
|
assert_eq!(staging_budget_per_frame(None), 192 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(4 * GIB)), 96 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(6 * GIB)), 96 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(8 * GIB)), 192 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(12 * GIB)), 192 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(14 * GIB)), 192 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(16 * GIB)), 256 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(20 * GIB)), 384 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(24 * GIB)), 384 * MIB);
|
||||||
|
assert_eq!(staging_budget_per_frame(Some(32 * GIB)), 384 * MIB);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1354,17 +1354,28 @@ pub(crate) fn host_made<'a>(
|
|||||||
Some(unsafe { &*std::ptr::from_ref(&host.texture) })
|
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
|
/// Whether more host copies of textures the title fills may be made for
|
||||||
/// shaders that pick textures by index (`draw.rs` `heap_textures`): always
|
/// 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
|
/// up to [`texture_floor_bytes`] bytes of them, beyond that while the card's
|
||||||
/// by this process is under nine tenths of the budget the system gives it
|
/// memory in use by this process is under nine tenths of the budget the system
|
||||||
/// (`VICTORY_TEXTURE_BUDGET_MB` sets a limit on those copies' bytes
|
/// 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
|
/// instead). Past the budget the system moves the card's memory into the PC's,
|
||||||
/// PC's, which ended runs 20 and 24.
|
/// which ended runs 20 and 24.
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub(crate) fn room() -> bool {
|
pub(crate) fn room() -> bool {
|
||||||
use std::sync::atomic::Ordering::Relaxed;
|
use std::sync::atomic::Ordering::Relaxed;
|
||||||
const FLOOR: u64 = 2 << 30;
|
|
||||||
const WITHOUT_BUDGET: u64 = 4 << 30;
|
const WITHOUT_BUDGET: u64 = 4 << 30;
|
||||||
static LIMIT: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new();
|
static LIMIT: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new();
|
||||||
let limit = *LIMIT.get_or_init(|| {
|
let limit = *LIMIT.get_or_init(|| {
|
||||||
@@ -1375,10 +1386,12 @@ pub(crate) fn room() -> bool {
|
|||||||
if let Some(limit) = limit {
|
if let Some(limit) = limit {
|
||||||
return filled < 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;
|
return true;
|
||||||
}
|
}
|
||||||
match crate::host::host().and_then(|h| h.video_memory()) {
|
match memory {
|
||||||
Some([budget, used, ..]) => used < budget / 10 * 9,
|
Some([budget, used, ..]) => used < budget / 10 * 9,
|
||||||
None => filled < WITHOUT_BUDGET,
|
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>(heap, 0x10)(heap), 1);
|
||||||
assert_eq!(slot::<Release>(placed, 0x10)(placed), 0);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user