|
@@ -1445,8 +1445,8 @@ 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.
|
|
|
|
|
- const PER_FRAME: u64 = 192 << 20;
|
|
|
|
|
|
|
+ let memory = crate::host::host().and_then(|h| h.video_memory());
|
|
|
|
|
+ let per_frame = staging_budget_per_frame(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();
|
|
@@ -1460,7 +1460,7 @@ impl State {
|
|
|
// makes room again: so the slots are still looked at (the pass
|
|
// makes room again: so the slots are still looked at (the pass
|
|
|
// returned here, and a slot whose texture had been streamed out
|
|
// returned here, and a slot whose texture had been streamed out
|
|
|
// kept its host copy for as long as the card was full).
|
|
// kept its host copy for as long as the card was full).
|
|
|
- let room = crate::resource::room();
|
|
|
|
|
|
|
+ let room = crate::resource::room(memory);
|
|
|
if !room {
|
|
if !room {
|
|
|
HEAP_TEXTURES_FULL.fetch_add(1, Ordering::Relaxed);
|
|
HEAP_TEXTURES_FULL.fetch_add(1, Ordering::Relaxed);
|
|
|
once!("textures picked by index: the card has no room for more; they wait");
|
|
once!("textures picked by index: the card has no room for more; they wait");
|
|
@@ -1502,7 +1502,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 +2690,38 @@ 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 > 12 * 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(13 * GIB)), 256 * MIB);
|
|
|
|
|
+ assert_eq!(staging_budget_per_frame(Some(14 * GIB)), 256 * 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);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|