瀏覽代碼

gpu: share video_memory query in heap_textures and lower 16 GB cutoff to 12 GiB

fever308 3 天之前
父節點
當前提交
010b90a117
共有 2 個文件被更改,包括 7 次插入 和 10 次删除
  1. 6 8
      crates/victory-gpu/src/draw.rs
  2. 1 2
      crates/victory-gpu/src/resource.rs

+ 6 - 8
crates/victory-gpu/src/draw.rs

@@ -1445,11 +1445,8 @@ impl State {
         if !*ON.get_or_init(|| std::env::var_os("VICTORY_HEAP_TEXTURES").is_none_or(|v| v != "0")) {
             return;
         }
-        let per_frame = staging_budget_per_frame(
-            crate::host::host()
-                .and_then(|h| h.video_memory())
-                .map(|[budget, ..]| budget),
-        );
+        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 SPENT: AtomicU64 = AtomicU64::new(0);
         let frame = crate::frame::current();
@@ -1463,7 +1460,7 @@ impl State {
         // makes room again: so the slots are still looked at (the pass
         // returned here, and a slot whose texture had been streamed out
         // 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 {
             HEAP_TEXTURES_FULL.fetch_add(1, Ordering::Relaxed);
             once!("textures picked by index: the card has no room for more; they wait");
@@ -2702,7 +2699,7 @@ fn staging_budget_per_frame(vram_budget: Option<u64>) -> u64 {
     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,
+        Some(budget) if budget > 12 * GIB => 256 * MIB,
         _ => 192 * MIB,
     }
 }
@@ -2720,7 +2717,8 @@ mod tests {
         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(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);

+ 1 - 2
crates/victory-gpu/src/resource.rs

@@ -1374,7 +1374,7 @@ fn texture_floor_bytes(vram_budget: Option<u64>) -> u64 {
 /// 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 {
+pub(crate) fn room(memory: Option<[u64; 4]>) -> bool {
     use std::sync::atomic::Ordering::Relaxed;
     const WITHOUT_BUDGET: u64 = 4 << 30;
     static LIMIT: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new();
@@ -1386,7 +1386,6 @@ pub(crate) fn room() -> bool {
     if let Some(limit) = limit {
         return filled < limit;
     }
-    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;