GPU: verify host heap coherency before enabling in-place memory (#500) #569

Open
github-bot wants to merge 1 commit from github-bot/gh-569 into a-publier AGit
Owner

@⁠BlueCatsz on GitHub · 2026-11-27 11:55 UTC · original
BlueCatsz:fix/inplace-verify-host-heap-coherency → a-publier · +206 −0 · 2 files · 1 commits · open

Addresses #500.

Problem

Under Linux/Wine + vkd3d-proton (RADV), enabling VICTORY_PORT_CONSTANTS=1 (Renderer Port 1, e.g. --ports12) causes a black screen from frame 1 (even on menus), while VICTORY_PORT_DESCRIPTORS=1 (Port 2) alone renders normally.

Probing on RX 9070 XT / CachyOS Linux with VKD3D_DEBUG=warn and VICTORY_INPLACE_PROBE=1 showed why:

  • port::open_region maps a second view via MapViewOfFile (a file-backed MAP_SHARED mapping under Wine) and calls OpenExistingHeapFromAddress1.
  • On RADV (amdgpu rejects importing file-backed MAP_SHARED userptr mappings), vkd3d_import_host_memory logs Failed to import host memory, hr 0x8007000e and then silently returns S_OK with a disconnected, zero-filled host-visible allocation (private VirtualAlloc reports reads true, writes true, whereas section views report reads false, writes false).
  • Because port::place_for and inplace::place_for trusted Ok(heap) without checking CPU↔GPU coherency, Port 1 stopped copying the title's 32-bit graphics heap (refused: 0 by the host) and the GPU read all zeros.

Change

  • crates/victory-gpu/src/inplace.rs:
    • Added verify_buffer_coherent, verify_part_coherent, verify_private_part_coherent, and verify_section_view_coherent to test CPU→GPU (initial + updated bytes) and GPU→CPU coherency once against a temporary 64 KiB allocation/section view (dropping GPU objects before freeing/unmapping).
    • Gated inplace::place_for with a cached OnceLock coherency check so non-coherent heaps log a single warning, increment STATS[5] (refused by the host), and fall back to host copies.
    • Added WARP unit tests covering disconnected buffers (warp_verify_buffer_coherent_rejects_disconnected_buffer), private parts (warp_verify_private_part_coherent_succeeds), and section views (warp_verify_section_view_coherent_succeeds).
  • crates/victory-gpu/src/port.rs:
    • Gated port::place_for with a cached OnceLock check via verify_section_view_coherent(&host.device) so disconnected section-view heaps log a single warning, increment STATS[5] (refused by the host), and fall back cleanly to host copies.

No Wine version checks are used—native Windows (and any future Linux/driver configuration with coherent section-view import) passes automatically.

Verification

  • Stock windows-latest CI on fork (run 45992434821):
    • Clippy (default & --all-features, -D warnings): passed
    • Default tests (cargo test --workspace --locked, 399 passed including all 3 new WARP tests and policy::tests::repository_passes_policy): passed
    • Diagnostics tests (cargo test --workspace --all-features --locked -- --test-threads=1): passed
    • check: passed
  • RX 9070 XT + CachyOS Linux live test (diag build, Mesa RADV 26.3.1, proton-cachyos-slr + patched wineserver (CachyOS/wine-cachyos#50) + vkd3d-proton 71cae09, retail 1.0.2.1):
    • VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_DESCRIPTORS=1: previously 100% black screen (refused: 0 by the host); now logs one coherency warning, falls back cleanly (0 regions, refused: 2 by the host), Port 2 stays active, and menus + opening scene render normally (13.2–16.3 fps).
    • VICTORY_INPLACE=1: private memory coherency check passes on RADV (0 refused by the host, 74 windows / 340 MB placed in place).

AI assistance disclosure: analysis, implementation, and verification summaries were drafted with AI assistance; all code changes, CI runs, and hardware test runs were reviewed and verified locally.

**@⁠BlueCatsz** on GitHub · 2026-11-27 11:55 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/569) `BlueCatsz:fix/inplace-verify-host-heap-coherency` → `a-publier` · +206 −0 · 2 files · 1 commits · open Addresses #500. ### Problem Under Linux/Wine + `vkd3d-proton` (RADV), enabling `VICTORY_PORT_CONSTANTS=1` (Renderer Port 1, e.g. `--ports12`) causes a black screen from frame 1 (even on menus), while `VICTORY_PORT_DESCRIPTORS=1` (Port 2) alone renders normally. Probing on RX 9070 XT / CachyOS Linux with `VKD3D_DEBUG=warn` and `VICTORY_INPLACE_PROBE=1` showed why: - `port::open_region` maps a second view via `MapViewOfFile` (a file-backed `MAP_SHARED` mapping under Wine) and calls `OpenExistingHeapFromAddress1`. - On RADV (`amdgpu` rejects importing file-backed `MAP_SHARED` userptr mappings), `vkd3d_import_host_memory` logs `Failed to import host memory, hr 0x8007000e` and then **silently returns `S_OK`** with a disconnected, zero-filled host-visible allocation (private `VirtualAlloc` reports `reads true, writes true`, whereas section views report `reads false, writes false`). - Because `port::place_for` and `inplace::place_for` trusted `Ok(heap)` without checking CPU↔GPU coherency, Port 1 stopped copying the title's 32-bit graphics heap (`refused: 0 by the host`) and the GPU read all zeros. ### Change - **`crates/victory-gpu/src/inplace.rs`**: - Added `verify_buffer_coherent`, `verify_part_coherent`, `verify_private_part_coherent`, and `verify_section_view_coherent` to test CPU→GPU (initial + updated bytes) and GPU→CPU coherency once against a temporary 64 KiB allocation/section view (dropping GPU objects before freeing/unmapping). - Gated `inplace::place_for` with a cached `OnceLock` coherency check so non-coherent heaps log a single warning, increment `STATS[5]` (`refused by the host`), and fall back to host copies. - Added WARP unit tests covering disconnected buffers (`warp_verify_buffer_coherent_rejects_disconnected_buffer`), private parts (`warp_verify_private_part_coherent_succeeds`), and section views (`warp_verify_section_view_coherent_succeeds`). - **`crates/victory-gpu/src/port.rs`**: - Gated `port::place_for` with a cached `OnceLock` check via `verify_section_view_coherent(&host.device)` so disconnected section-view heaps log a single warning, increment `STATS[5]` (`refused by the host`), and fall back cleanly to host copies. No Wine version checks are used—native Windows (and any future Linux/driver configuration with coherent section-view import) passes automatically. ### Verification - **Stock `windows-latest` CI on fork** ([run `45992434821`](https://github.com/BlueCatsz/VIctory-Belobug-AMD/actions/runs/45992434821)): - `Clippy` (default & `--all-features`, `-D warnings`): passed - `Default tests` (`cargo test --workspace --locked`, `399 passed` including all 3 new WARP tests and `policy::tests::repository_passes_policy`): passed - `Diagnostics tests` (`cargo test --workspace --all-features --locked -- --test-threads=1`): passed - `check`: passed - **RX 9070 XT + CachyOS Linux live test** (`diag` build, Mesa RADV 26.3.1, `proton-cachyos-slr` + patched `wineserver` (`CachyOS/wine-cachyos#50`) + `vkd3d-proton` `71cae09`, retail 1.0.2.1): - `VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_DESCRIPTORS=1`: previously 100% black screen (`refused: 0 by the host`); now logs one coherency warning, falls back cleanly (`0 regions`, `refused: 2 by the host`), Port 2 stays active, and menus + opening scene render normally (`13.2–16.3 fps`). - `VICTORY_INPLACE=1`: private memory coherency check passes on RADV (`0 refused by the host`, `74 windows / 340 MB` placed in place). --- *AI assistance disclosure: analysis, implementation, and verification summaries were drafted with AI assistance; all code changes, CI runs, and hardware test runs were reviewed and verified locally.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:09:10 +00:00
Author
Owner

@⁠gw1337x on GitHub · 2026-11-27 13:09 UTC · original

Windows check on RDNA 3, with VICTORY_PORT_CONSTANTS=1 on (part of the setting I test with). Memory Integrity was off.

PC: Ryzen 7 9800X3D, RX 7800 XT, 32 GB. Test: 270 s hands-off boat scene, RT off, Belobug launcher settings plus the 5 port switches, warm caches. #569 (ec93791) on 4eb6cfd vs 4eb6cfd, interleaved (PR, base, PR, base).

#569 run 1 #569 run 2 base run 1 base run 2
"not coherent" warnings 0 0 - -
Port 1 regions in place 1 (185 MB) 1 (185 MB) 1 (185 MB) 1 (185 MB)
Steady fps (log, last minute) 28.6 28.4 28.6 28.6
Card running per frame at 240 s 31.4 ms 32.0 ms 31.7 ms 31.2 ms
Device loss 0 0 0 0

The port 1 region is placed only after section_view_coherent() returns Ok, so the section-view probe ran and passed on this card and driver, and port 1 keeps working as before. No change in fps or card time.

Not covered: the private-memory probe in inplace::place_for (I didn't check whether my setting reaches that path), and Linux/Wine, which I can't test here.

AI-assisted (Claude Code); numbers from the run logs.

**@⁠gw1337x** on GitHub · 2026-11-27 13:09 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/569#issuecomment-7219138531) Windows check on RDNA 3, with `VICTORY_PORT_CONSTANTS=1` on (part of the setting I test with). Memory Integrity was off. PC: Ryzen 7 9800X3D, RX 7800 XT, 32 GB. Test: 270 s hands-off boat scene, RT off, Belobug launcher settings plus the 5 port switches, warm caches. #569 (`ec93791`) on `4eb6cfd` vs `4eb6cfd`, interleaved (PR, base, PR, base). | | #569 run 1 | #569 run 2 | base run 1 | base run 2 | |---|---|---|---|---| | "not coherent" warnings | 0 | 0 | - | - | | Port 1 regions in place | 1 (185 MB) | 1 (185 MB) | 1 (185 MB) | 1 (185 MB) | | Steady fps (log, last minute) | 28.6 | 28.4 | 28.6 | 28.6 | | Card running per frame at 240 s | 31.4 ms | 32.0 ms | 31.7 ms | 31.2 ms | | Device loss | 0 | 0 | 0 | 0 | The port 1 region is placed only after `section_view_coherent()` returns `Ok`, so the section-view probe ran and passed on this card and driver, and port 1 keeps working as before. No change in fps or card time. Not covered: the private-memory probe in `inplace::place_for` (I didn't check whether my setting reaches that path), and Linux/Wine, which I can't test here. AI-assisted (Claude Code); numbers from the run logs.
Author
Owner

@⁠lvndrpup on GitHub · 2026-11-27 14:15 UTC · original · reviewed

Tested on an RTX 3060 Ti (Windows 11, debug build), head ec93791 on base 4eb6cfd. The bug needs Wine's file-backed mappings, so there's nothing to compare on the base here. What I checked is that the new checks don't turn port 1 or VICTORY_INPLACE off on NVIDIA.

head ec93791
verify_private_part_coherent and verify_section_view_coherent on the card (adapter 0, NVIDIA GeForce RTX 3060 Ti), from the test below Ok for both, 3 of 3 runs
the three new WARP tests pass
cargo test -p victory-gpu --lib inplace::, port:: 12 passed, 2 passed
cargo test -p victory-gpu --lib, one run 399 passed, 34 ignored (plus the test below)
cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --all-features clean

Both checks pass on this card and driver, so both paths keep placing memory as before. With gw1337x's RX 7800 XT run, that covers the section-view check on both vendors on Windows, and the private check on NVIDIA. I can't run the Wine/RADV case.

The test I added to inplace.rs, in case someone wants it on another card (the PR's tests use WARP):

#[cfg(test)]
mod card_probe {
    use super::*;
    use windows::core::Interface;
    #[test]
    fn card_probe() {
        use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_12_0;
        use windows::Win32::Graphics::Dxgi::*;
        unsafe {
            let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
            let adapter: IDXGIAdapter1 = factory.EnumAdapters1(0).unwrap();
            let name = String::from_utf16_lossy(&adapter.GetDesc1().unwrap().Description);
            println!("adapter: {}", name.trim_end_matches('\0'));
            let mut device: Option<ID3D12Device> = None;
            D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device).unwrap();
            let device = device.unwrap();
            println!("private: {:?}", verify_private_part_coherent(&device));
            println!("section view: {:?}", verify_section_view_coherent(&device));
        }
    }
}

Run it with cargo test -p victory-gpu --lib card_probe -- --nocapture. It merges cleanly with #421, the other open PR on inplace.rs that still merges with a-publier.

**@⁠lvndrpup** on GitHub · 2026-11-27 14:15 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/569#pullrequestreview-6089462702) · **reviewed** Tested on an RTX 3060 Ti (Windows 11, debug build), head `ec93791` on base `4eb6cfd`. The bug needs Wine's file-backed mappings, so there's nothing to compare on the base here. What I checked is that the new checks don't turn port 1 or `VICTORY_INPLACE` off on NVIDIA. | | head `ec93791` | |---|---| | `verify_private_part_coherent` and `verify_section_view_coherent` on the card (adapter 0, NVIDIA GeForce RTX 3060 Ti), from the test below | `Ok` for both, 3 of 3 runs | | the three new WARP tests | pass | | `cargo test -p victory-gpu --lib inplace::`, `port::` | 12 passed, 2 passed | | `cargo test -p victory-gpu --lib`, one run | 399 passed, 34 ignored (plus the test below) | | `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--all-features` | clean | Both checks pass on this card and driver, so both paths keep placing memory as before. With gw1337x's RX 7800 XT run, that covers the section-view check on both vendors on Windows, and the private check on NVIDIA. I can't run the Wine/RADV case. The test I added to `inplace.rs`, in case someone wants it on another card (the PR's tests use WARP): ```rust #[cfg(test)] mod card_probe { use super::*; use windows::core::Interface; #[test] fn card_probe() { use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_12_0; use windows::Win32::Graphics::Dxgi::*; unsafe { let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap(); let adapter: IDXGIAdapter1 = factory.EnumAdapters1(0).unwrap(); let name = String::from_utf16_lossy(&adapter.GetDesc1().unwrap().Description); println!("adapter: {}", name.trim_end_matches('\0')); let mut device: Option<ID3D12Device> = None; D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device).unwrap(); let device = device.unwrap(); println!("private: {:?}", verify_private_part_coherent(&device)); println!("section view: {:?}", verify_section_view_coherent(&device)); } } } ``` Run it with `cargo test -p victory-gpu --lib card_probe -- --nocapture`. It merges cleanly with #421, the other open PR on `inplace.rs` that still merges with `a-publier`.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 15:56 UTC · original

Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At ec93791: victory-gpu 399 passed, 0 failed, 34 ignored.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 15:56 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/569#issuecomment-7222661485) Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At `ec93791`: `victory-gpu` 399 passed, 0 failed, 34 ignored. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠DecayingEagle on GitHub · 2026-11-27 17:13 UTC · original

Second Linux confirmation on RX 7900 XT / RADV Mesa 26.3.1 / Wine 11.22, vkd3d-proton 71cae09, DXVK's DXGI, Rust 1.98.1 MSVC cross-target. Tested ec937910 on a-publier@4eb6cfd; the reporting guard from #586 was also present.

The WARP-only helper returns None under DXVK because its WARP request returns a hardware adapter. The new tests therefore initially reported success without executing their assertions. For hardware validation I added a local, test-only opt-in to inplace::tests::warp: retain its software-only default, accept hardware only when explicitly requested, print the actual adapter and assert Device13. The real run named RX 7900 XT, software=false.

  • The disconnected-buffer rejection and private-memory coherency checks both executed on the card and passed.
  • The section-view probe rejected the mapping: the GPU's initial read did not match CPU bytes. The Windows/WARP test expecting coherent section memory consequently fails when explicitly forced onto this Linux hardware; this is the driver behavior the guard needs to handle, not independent WARP validation.
  • In a separate local integration with the existing renderer patches, VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_DESCRIPTORS=1 logged the section-coherency warning and fell back to copies. Menus and opening scenes rendered instead of a black window; I inspected the captures locally. The 180-second run ended at its planned limit with no recorded title/device/kernel fault. The normal-profile 180-second control also completed.
  • Both workspace/all-target Clippy configurations and policy passed on the PR staging tree. The integrated runtime passed 60 targeted checks and release/diagnostic builds.

No FPS gain or later-mission crash fix is claimed. The local default keeps Port 1 disabled; the opt-in run verifies its fallback. No game assets or captures attached. Testing, the test-helper adaptation and this report assisted by OpenAI Codex.

**@⁠DecayingEagle** on GitHub · 2026-11-27 17:13 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/569#issuecomment-7224164304) Second Linux confirmation on **RX 7900 XT / RADV Mesa 26.3.1 / Wine 11.22**, vkd3d-proton `71cae09`, DXVK's DXGI, Rust 1.98.1 MSVC cross-target. Tested `ec937910` on `a-publier@4eb6cfd`; the reporting guard from #586 was also present. The WARP-only helper returns `None` under DXVK because its WARP request returns a hardware adapter. The new tests therefore initially reported success without executing their assertions. For hardware validation I added a **local, test-only opt-in** to `inplace::tests::warp`: retain its software-only default, accept hardware only when explicitly requested, print the actual adapter and assert Device13. The real run named RX 7900 XT, `software=false`. - The disconnected-buffer rejection and private-memory coherency checks both executed on the card and passed. - The section-view probe rejected the mapping: the GPU's initial read did not match CPU bytes. The Windows/WARP test expecting coherent section memory consequently fails when explicitly forced onto this Linux hardware; this is the driver behavior the guard needs to handle, not independent WARP validation. - In a separate local integration with the existing renderer patches, **`VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_DESCRIPTORS=1`** logged the section-coherency warning and fell back to copies. Menus and opening scenes rendered instead of a black window; I inspected the captures locally. The 180-second run ended at its planned limit with no recorded title/device/kernel fault. The normal-profile 180-second control also completed. - Both workspace/all-target Clippy configurations and policy passed on the PR staging tree. The integrated runtime passed 60 targeted checks and release/diagnostic builds. No FPS gain or later-mission crash fix is claimed. The local default keeps Port 1 disabled; the opt-in run verifies its fallback. No game assets or captures attached. Testing, the test-helper adaptation and this report assisted by OpenAI Codex.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/569/head:github-bot/gh-569'
git switch 'github-bot/gh-569'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-569'
git switch 'github-bot/gh-569'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-569'
git switch 'github-bot/gh-569'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-569'
git switch 'a-publier'
git merge --squash 'github-bot/gh-569'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-569'
git switch 'a-publier'
git merge 'github-bot/gh-569'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.