VICTORY_WC_BAR=1 ignores VICTORY_WC_NO_BACK_MIN_KB: small write-combined results go stale (dark lighting, ~1,450 draws a frame missing) #355

Closed
opened 2026-11-27 21:23:10 +00:00 by github-bot · 4 comments
Owner

@⁠MJ26gaming on GitHub · 2026-11-27 21:20 UTC · original

VICTORY_WC_BAR=1 (from 50c15a1) gives every write-combined title buffer a single GPU-upload (BAR) copy whose shader writes are never landed. It does this regardless of VICTORY_WC_NO_BACK_MIN_KB, the cutoff that 2f81d0c added because small write-combined results the title reads back (exposure and similar) went stale.

Where: wc_bar() in crates/victory-gpu/src/shadow.rs (main at ca9c75c, line 2204) takes no length, and the lookup site uses it before the normal shadow allocation. The gpu_writes early return (self.mapped && !self.window) then skips Step::GpuWrite for those copies, while wc_no_back checks self.len >= wc_no_back_min().

Measured: Linux, GE-Proton 11-14, vkd3d-proton master 71cae09, RX 9070 XT, Series S profile, one saved checkpoint (opening cutscene, then the cell), 5-minute runs, with VICTORY_WC_NO_BACK=1 VICTORY_WC_NO_BACK_MIN_KB=1024 in all three rows.

fps mean / median draws/frame in the cell submit thread copy-back
WC_NO_BACK only 29.82 / 30.00 ~4,450 27.5 ms 4.9 ms
+ WC_BAR=1 as on main 30.00 / 30.00 ~3,000 22.1 ms 2.3 ms
+ WC_BAR=1 with the fix below 29.91 / 30.00 ~4,400 24.5 ms —

With the BAR path as on main, 4,272 of 4,348 BAR allocations in the run were under 1 MiB (4,162 under 64 KiB). In captures of the cell, most of the room's fill light is gone and a poster fades (frame RMSE 0.15–0.18 against 0.02–0.06 between ordinary runs). The title issues about 1,450 fewer draws a frame, while pipeline drops (253) and indirect drops (594) are unchanged, which fits stale visibility or lighting results. With the fix, draws and the picture match the run without BAR, and the submit thread still saves about 3 ms over WC_NO_BACK alone.

Fix (attached as a patch, applies to main with offsets): wc_bar(len) honours the write-back cutoff. VICTORY_WC_BAR=1 places only copies with len >= MIN_KB in the BAR, and smaller ones keep the two-sided path and its write-back. VICTORY_WC_BAR=2 keeps the old unrestricted policy for comparison. A unit test (bar_obeys_write_back_policy_unless_legacy_mode_is_selected) covers the policy, and the write-combined and card-steps tests pass under Wine.

Untested on Windows and on NVIDIA. The 30 fps figures are the title's own frame cap.

Found and fixed with AI assistance (Codex for the investigation and patch, Claude Code for review and testing).

From abc8f696db7c32a157b5b19e5ff0146aeeb0f84b Mon Sep 17 00:00:00 2001
From: Codex <codex@localhost>
Date: Fri, 27 Nov 2026 12:02:16 -0800
Subject: [PATCH] WC BAR honours the write-back cutoff (VICTORY_WC_BAR=1); =2
 keeps the unrestricted policy

With VICTORY_WC_BAR=1 every write-combined title buffer got one mapped
GPU-upload copy whose shader writes were never landed, regardless of
VICTORY_WC_NO_BACK_MIN_KB. Of 4,348 BAR allocations in a Series S run,
4,272 were under 1 MiB. Small shader results the title or other copies
read went stale, and the prison cell lost about 1,450 draws a frame
(4,450 -> 3,000). Mode 1 now places only copies at or above the
write-back cutoff in the BAR; smaller ones keep the two-sided path and
its write-back. Mode 2 is the original policy for comparison.

Investigation and patch: Codex (GPT-6.2-Sol); reviewed and committed by Claude.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Lxjd7Q4QtK5T9TJ4GCtkQg
---
 crates/victory-gpu/src/shadow.rs | 43 ++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs
index 31750e5d..2ce74f8b 100644
--- a/crates/victory-gpu/src/shadow.rs
+++ b/crates/victory-gpu/src/shadow.rs
@@ -2181,6 +2181,11 @@ fn wc_no_back_min() -> u64 {
     })
 }
 
+/// The active cutoff for leaving a WC copy's shader writes on the card.
+fn wc_no_back_cutoff() -> Option<u64> {
+    wc_no_back().then(wc_no_back_min)
+}
+
 /// Bytes shaders were declared to write in write-combined copies and that
 /// were left on the card ([`wc_no_back`]), since the last frame-rate line.
 pub(crate) static WC_LEFT: AtomicU64 = AtomicU64::new(0);
@@ -2188,7 +2193,9 @@ pub(crate) static WC_LEFT: AtomicU64 = AtomicU64::new(0);
 /// Whether a title buffer in write-combined memory gets one copy, in card
 /// memory the CPU maps (`D3D12_HEAP_TYPE_GPU_UPLOAD`: a resizable BAR, this
 /// PC's 4070 SUPER has a 16 GiB one) instead of two sides
-/// (`VICTORY_WC_BAR=1`; off by default: an experiment).
+/// (`VICTORY_WC_BAR=1`; off by default). Honor the write-back size policy:
+/// small shader results can feed title CPU reads or refreshes of other copies.
+/// `VICTORY_WC_BAR=2` selects the original policy for comparison.
 ///
 /// Refreshes write title memory into the mapping through the bus (as they
 /// write a CPU's side now); shaders read and write the card's memory; there
@@ -2204,9 +2211,18 @@ pub(crate) static WC_LEFT: AtomicU64 = AtomicU64::new(0);
 /// fifth of the budget is free; the PC's memory of the CPU's side is saved.
 /// Copies already made, or turned down for room, keep their two sides or
 /// stay in the PC's memory.
-fn wc_bar() -> bool {
-    static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
-    *ON.get_or_init(|| std::env::var_os("VICTORY_WC_BAR").is_some_and(|v| v == "1"))
+fn wc_bar(len: u64) -> bool {
+    static MODE: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
+    let mode = MODE.get_or_init(|| std::env::var("VICTORY_WC_BAR").ok());
+    wc_bar_allowed(mode.as_deref(), wc_no_back_cutoff(), len)
+}
+
+fn wc_bar_allowed(mode: Option<&str>, cutoff: Option<u64>, len: u64) -> bool {
+    match mode {
+        Some("1") => cutoff.is_some_and(|min| len >= min),
+        Some("2") => true,
+        _ => false,
+    }
 }
 
 /// A buffer of `size` bytes in card memory the CPU maps, for [`wc_bar`],
@@ -3233,7 +3249,7 @@ impl Shadow {
         // (`VICTORY_WC_NO_BACK`, and always for `VICTORY_WC_BAR`'s copies,
         // which the CPU would read through the bus): what shaders write stays
         // on the card.
-        if (self.card.is_some() && wc_no_back() && self.len >= wc_no_back_min() || self.mapped && !self.window)
+        if (self.card.is_some() && wc_no_back_cutoff().is_some_and(|min| self.len >= min) || self.mapped && !self.window)
             && self.write_combined()
         {
             self.written.store(true, Ordering::Relaxed);
@@ -5296,7 +5312,7 @@ fn lookup(address: u64, len: u64, any: bool) -> Option<Arc<Shadow>> {
         // Write-combined memory with `VICTORY_WC_BAR`: one buffer in the card's
         // memory that the CPU maps, no CPU's side, nothing sent, and what
         // shaders write stays there ([`wc_bar`]).
-        if wc_bar()
+        if wc_bar(len)
             && is_write_combined(key.0, len)
             && let Some((buffer, data)) = wc_mapped_for(size)
         {
@@ -5763,7 +5779,20 @@ pub(crate) fn exact_line(frames: f64) {
 
 #[cfg(test)]
 mod write_combined_tests {
-    use super::{is_write_combined, title_memory_write_combined, write_combined_freed};
+    use super::{is_write_combined, title_memory_write_combined, wc_bar_allowed, write_combined_freed};
+
+    #[test]
+    fn bar_obeys_write_back_policy_unless_legacy_mode_is_selected() {
+        let min = 1 << 20;
+        assert!(!wc_bar_allowed(None, Some(min), min));
+        assert!(!wc_bar_allowed(Some("0"), Some(min), min));
+        assert!(!wc_bar_allowed(Some("1"), None, min));
+        assert!(!wc_bar_allowed(Some("1"), Some(min), min - 1));
+        assert!(wc_bar_allowed(Some("1"), Some(min), min));
+        assert!(wc_bar_allowed(Some("1"), Some(0), 4));
+        assert!(wc_bar_allowed(Some("2"), None, 4));
+        assert!(wc_bar_allowed(Some("2"), Some(min), 4));
+    }
 
     /// A copy counts as write-combined only inside one such region, and not
     /// after the region is let go (part of it or the whole allocation).
-- 
2.56.1
**@⁠MJ26gaming** on GitHub · 2026-11-27 21:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/355) `VICTORY_WC_BAR=1` (from `50c15a1`) gives every write-combined title buffer a single GPU-upload (BAR) copy whose shader writes are never landed. It does this regardless of `VICTORY_WC_NO_BACK_MIN_KB`, the cutoff that `2f81d0c` added because small write-combined results the title reads back (exposure and similar) went stale. **Where:** `wc_bar()` in `crates/victory-gpu/src/shadow.rs` (`main` at `ca9c75c`, line 2204) takes no length, and the `lookup` site uses it before the normal shadow allocation. The `gpu_writes` early return (`self.mapped && !self.window`) then skips `Step::GpuWrite` for those copies, while `wc_no_back` checks `self.len >= wc_no_back_min()`. **Measured:** Linux, GE-Proton 11-14, vkd3d-proton master `71cae09`, RX 9070 XT, Series S profile, one saved checkpoint (opening cutscene, then the cell), 5-minute runs, with `VICTORY_WC_NO_BACK=1 VICTORY_WC_NO_BACK_MIN_KB=1024` in all three rows. | | fps mean / median | draws/frame in the cell | submit thread | copy-back | |---|---|---|---|---| | WC_NO_BACK only | 29.82 / 30.00 | ~4,450 | 27.5 ms | 4.9 ms | | + WC_BAR=1 as on main | 30.00 / 30.00 | **~3,000** | 22.1 ms | 2.3 ms | | + WC_BAR=1 with the fix below | 29.91 / 30.00 | ~4,400 | 24.5 ms | — | With the BAR path as on `main`, 4,272 of 4,348 BAR allocations in the run were under 1 MiB (4,162 under 64 KiB). In captures of the cell, most of the room's fill light is gone and a poster fades (frame RMSE 0.15–0.18 against 0.02–0.06 between ordinary runs). The title issues about 1,450 fewer draws a frame, while pipeline drops (253) and indirect drops (594) are unchanged, which fits stale visibility or lighting results. With the fix, draws and the picture match the run without BAR, and the submit thread still saves about 3 ms over `WC_NO_BACK` alone. **Fix (attached as a patch, applies to `main` with offsets):** `wc_bar(len)` honours the write-back cutoff. `VICTORY_WC_BAR=1` places only copies with `len >= MIN_KB` in the BAR, and smaller ones keep the two-sided path and its write-back. `VICTORY_WC_BAR=2` keeps the old unrestricted policy for comparison. A unit test (`bar_obeys_write_back_policy_unless_legacy_mode_is_selected`) covers the policy, and the write-combined and card-steps tests pass under Wine. Untested on Windows and on NVIDIA. The 30 fps figures are the title's own frame cap. Found and fixed with AI assistance (Codex for the investigation and patch, Claude Code for review and testing). ```diff From abc8f696db7c32a157b5b19e5ff0146aeeb0f84b Mon Sep 17 00:00:00 2001 From: Codex <codex@localhost> Date: Fri, 27 Nov 2026 12:02:16 -0800 Subject: [PATCH] WC BAR honours the write-back cutoff (VICTORY_WC_BAR=1); =2 keeps the unrestricted policy With VICTORY_WC_BAR=1 every write-combined title buffer got one mapped GPU-upload copy whose shader writes were never landed, regardless of VICTORY_WC_NO_BACK_MIN_KB. Of 4,348 BAR allocations in a Series S run, 4,272 were under 1 MiB. Small shader results the title or other copies read went stale, and the prison cell lost about 1,450 draws a frame (4,450 -> 3,000). Mode 1 now places only copies at or above the write-back cutoff in the BAR; smaller ones keep the two-sided path and its write-back. Mode 2 is the original policy for comparison. Investigation and patch: Codex (GPT-6.2-Sol); reviewed and committed by Claude. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Lxjd7Q4QtK5T9TJ4GCtkQg --- crates/victory-gpu/src/shadow.rs | 43 ++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs index 31750e5d..2ce74f8b 100644 --- a/crates/victory-gpu/src/shadow.rs +++ b/crates/victory-gpu/src/shadow.rs @@ -2181,6 +2181,11 @@ fn wc_no_back_min() -> u64 { }) } +/// The active cutoff for leaving a WC copy's shader writes on the card. +fn wc_no_back_cutoff() -> Option<u64> { + wc_no_back().then(wc_no_back_min) +} + /// Bytes shaders were declared to write in write-combined copies and that /// were left on the card ([`wc_no_back`]), since the last frame-rate line. pub(crate) static WC_LEFT: AtomicU64 = AtomicU64::new(0); @@ -2188,7 +2193,9 @@ pub(crate) static WC_LEFT: AtomicU64 = AtomicU64::new(0); /// Whether a title buffer in write-combined memory gets one copy, in card /// memory the CPU maps (`D3D12_HEAP_TYPE_GPU_UPLOAD`: a resizable BAR, this /// PC's 4070 SUPER has a 16 GiB one) instead of two sides -/// (`VICTORY_WC_BAR=1`; off by default: an experiment). +/// (`VICTORY_WC_BAR=1`; off by default). Honor the write-back size policy: +/// small shader results can feed title CPU reads or refreshes of other copies. +/// `VICTORY_WC_BAR=2` selects the original policy for comparison. /// /// Refreshes write title memory into the mapping through the bus (as they /// write a CPU's side now); shaders read and write the card's memory; there @@ -2204,9 +2211,18 @@ pub(crate) static WC_LEFT: AtomicU64 = AtomicU64::new(0); /// fifth of the budget is free; the PC's memory of the CPU's side is saved. /// Copies already made, or turned down for room, keep their two sides or /// stay in the PC's memory. -fn wc_bar() -> bool { - static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new(); - *ON.get_or_init(|| std::env::var_os("VICTORY_WC_BAR").is_some_and(|v| v == "1")) +fn wc_bar(len: u64) -> bool { + static MODE: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new(); + let mode = MODE.get_or_init(|| std::env::var("VICTORY_WC_BAR").ok()); + wc_bar_allowed(mode.as_deref(), wc_no_back_cutoff(), len) +} + +fn wc_bar_allowed(mode: Option<&str>, cutoff: Option<u64>, len: u64) -> bool { + match mode { + Some("1") => cutoff.is_some_and(|min| len >= min), + Some("2") => true, + _ => false, + } } /// A buffer of `size` bytes in card memory the CPU maps, for [`wc_bar`], @@ -3233,7 +3249,7 @@ impl Shadow { // (`VICTORY_WC_NO_BACK`, and always for `VICTORY_WC_BAR`'s copies, // which the CPU would read through the bus): what shaders write stays // on the card. - if (self.card.is_some() && wc_no_back() && self.len >= wc_no_back_min() || self.mapped && !self.window) + if (self.card.is_some() && wc_no_back_cutoff().is_some_and(|min| self.len >= min) || self.mapped && !self.window) && self.write_combined() { self.written.store(true, Ordering::Relaxed); @@ -5296,7 +5312,7 @@ fn lookup(address: u64, len: u64, any: bool) -> Option<Arc<Shadow>> { // Write-combined memory with `VICTORY_WC_BAR`: one buffer in the card's // memory that the CPU maps, no CPU's side, nothing sent, and what // shaders write stays there ([`wc_bar`]). - if wc_bar() + if wc_bar(len) && is_write_combined(key.0, len) && let Some((buffer, data)) = wc_mapped_for(size) { @@ -5763,7 +5779,20 @@ pub(crate) fn exact_line(frames: f64) { #[cfg(test)] mod write_combined_tests { - use super::{is_write_combined, title_memory_write_combined, write_combined_freed}; + use super::{is_write_combined, title_memory_write_combined, wc_bar_allowed, write_combined_freed}; + + #[test] + fn bar_obeys_write_back_policy_unless_legacy_mode_is_selected() { + let min = 1 << 20; + assert!(!wc_bar_allowed(None, Some(min), min)); + assert!(!wc_bar_allowed(Some("0"), Some(min), min)); + assert!(!wc_bar_allowed(Some("1"), None, min)); + assert!(!wc_bar_allowed(Some("1"), Some(min), min - 1)); + assert!(wc_bar_allowed(Some("1"), Some(min), min)); + assert!(wc_bar_allowed(Some("1"), Some(0), 4)); + assert!(wc_bar_allowed(Some("2"), None, 4)); + assert!(wc_bar_allowed(Some("2"), Some(min), 4)); + } /// A copy counts as write-combined only inside one such region, and not /// after the region is let go (part of it or the whole allocation). -- 2.56.1 ```
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:23:10 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-27 23:00 UTC · original

Vou implementar a correcao descrita nesta issue (wc_bar(len) honrar o cutoff de write-back; modo 2 mantem politica antiga) com teste sintetico em crates/victory-gpu/src/shadow.rs. AI-assisted (Hy4 flash), sem dados de jogo.

**@⁠cloph-dsp** on GitHub · 2026-11-27 23:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/355#issuecomment-7229797317) Vou implementar a correcao descrita nesta issue (wc_bar(len) honrar o cutoff de write-back; modo 2 mantem politica antiga) com teste sintetico em crates/victory-gpu/src/shadow.rs. AI-assisted (Hy4 flash), sem dados de jogo.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-27 23:16 UTC · original

Implementado e aberto em #481 (branch cloph-dsp:fix/wc-bar-writeback-cutoff, commit 35252c8). wc_bar(len) honra o cutoff de write-back no modo 1; modo 2 mantem a politica antiga; teste sintetico shadow::write_combined_tests::bar_obeys_write_back_policy_unless_legacy_mode_is_selected passa (2/2 no modulo), diff --check limpo. Windows/Rust 1.100.0/MSVC, cargo test --locked, CARGO_TARGET_DIR proprio, AI-assisted (Hy4 flash), sem dados de jogo.

**@⁠cloph-dsp** on GitHub · 2026-11-27 23:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/355#issuecomment-7230014720) Implementado e aberto em https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/481 (branch cloph-dsp:fix/wc-bar-writeback-cutoff, commit 35252c8). wc_bar(len) honra o cutoff de write-back no modo 1; modo 2 mantem a politica antiga; teste sintetico shadow::write_combined_tests::bar_obeys_write_back_policy_unless_legacy_mode_is_selected passa (2/2 no modulo), diff --check limpo. Windows/Rust 1.100.0/MSVC, cargo test --locked, CARGO_TARGET_DIR proprio, AI-assisted (Hy4 flash), sem dados de jogo.
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-28 00:43 UTC · original

Thanks @⁠MJ26gaming and @⁠cloph-dsp, noted. Pull requests are on hold for the moment. I'll look at #481 when I get back to them.

**@⁠trustno1-coder** on GitHub · 2026-11-28 00:43 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/355#issuecomment-7231148782) Thanks @⁠MJ26gaming and @⁠cloph-dsp, noted. Pull requests are on hold for the moment. I'll look at #481 when I get back to them.
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-29 15:51 UTC · original

Closing this since there's been no reply for over a day. If it still happens on the latest release, comment here with the log and it will be reopened.

**@⁠trustno1-coder** on GitHub · 2026-11-29 15:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/355#issuecomment-7258424053) Closing this since there's been no reply for over a day. If it still happens on the latest release, comment here with the log and it will be reopened.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA#355
No description provided.