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")) {
|
||||
return;
|
||||
}
|
||||
/// Bytes of texture memory staged per frame.
|
||||
const PER_FRAME: u64 = 192 << 20;
|
||||
let per_frame = staging_budget_per_frame(
|
||||
crate::host::host()
|
||||
.and_then(|h| h.video_memory())
|
||||
.map(|[budget, ..]| budget),
|
||||
);
|
||||
static FRAME: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||
static SPENT: AtomicU64 = AtomicU64::new(0);
|
||||
let frame = crate::frame::current();
|
||||
@@ -1502,7 +1505,7 @@ impl State {
|
||||
const SPAN: std::time::Duration = std::time::Duration::from_millis(250);
|
||||
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
|
||||
@@ -2690,3 +2693,37 @@ pub(crate) fn stencil_ref(list: &HostList, reference: u32) {
|
||||
// SAFETY: an open list.
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user