GPU: zero-copy section-heap windows, lock-free HostHeap::mirror, VIEWS RwLock & Thin LTO #1117

Open
github-bot wants to merge 3 commits from github-bot/gh-1117 into main AGit
Owner

@⁠RealAzemed on GitHub · 2026-11-25 20:12 UTC · original
RealAzemed:perf/section-heaps-lockfree-mirror-rwlock → main · +482 −56 · 7 files · 3 commits · open

Summary

Four self-contained performance improvements independently rebased onto main (orthogonal to #1097):

1. Zero-Copy Section-Heap Windows (VICTORY_INPLACE_SECTIONS=1, default on when VICTORY_INPLACE>=1)

  • crates/victory-gpu/src/inplace.rs & shadow.rs: opens SEC_COMMIT physical-page sections once via OpenExistingHeapFromFileMapping (0 working-set lock, 0 pinned host copies, safe with VirtualProtect and view unmaps since section_outlives_views=true) and places CreatePlacedResource buffers over maximal contiguous mapped runs inside 4 MiB cells.
  • Enforces strict run_end == cell_end in find_section_run and longest_tail reuse for unsized root views (unsized_ask=true) so future mappings inside the same cell can never be truncated by a cached partial window.
  • Clears cached section heap entries on section-handle reuse in title_memory_section, and retires placed windows cleanly via existing title_memory_freeing / in_place_let_go.
  • Measured (Linux Proton / RTX 3070 8 GB, 16 GB RAM): opened 3,967 zero-copy section windows across 1 heap (406–720 MB live, 0 refused, 1,036 cleanly retired on remap, 0 unhandled exceptions in 180s run); cut copies from 76–127 ms -> 10 ms and peak swap by up to 5.1 GB before 16 GB system RAM saturation.

2. Lock-Free HostHeap::mirror Fast Path + Cached gpu_handle (descriptor/host.rs)

  • Adds made_fast: Vec<AtomicU64> (Release/Acquire mirror of made) so the ~98% cache-hit path in HostHeap::mirror returns without locking self.made (~50k mutex acquisitions/frame eliminated). Cleared atomically in unmake() and on null/deferred transitions.
  • Caches gpu: u64 from GetGPUDescriptorHandleForHeapStart() once at heap creation (~10k COM calls/frame eliminated).

3. Zero-Alloc Stack Root Constants (draw.rs)

  • Replaces per-bind vec![0u32; dwords as usize] in State::bind with a stack [0u32; 64] buffer (falling back to heap only if dwords > 64), removing ~6k–10k small heap allocations/frame.

4. VIEWS: RwLock<Views> + Thin LTO (inplace.rs, Cargo.toml)

  • Converts VIEWS from Mutex<Views> to RwLock<Views> so concurrent read queries in watch, texture, and shadow no longer serialize against each other.
  • Adds lto = "thin" to [profile.release] for cross-crate inlining.

Verification

  • cargo xtask policy passes (181 files ok).
  • cargo check --target x86_64-pc-windows-gnu --tests -p victory-gpu passes cleanly.
  • New unit test find_section_run_merges_contiguous_committed_views_and_respects_unsized_tail passes under Proton.
  • Verified across 180s warm-cache runs on Linux Proton (RTX 3070 8 GB / 16 GB RAM): up to 2.10 fps median / 14.9 fps peak (vs 1.75 fps prior / 0.90 fps baseline), 0 unhandled exceptions.
**@⁠RealAzemed** on GitHub · 2026-11-25 20:12 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117) `RealAzemed:perf/section-heaps-lockfree-mirror-rwlock` → `main` · +482 −56 · 7 files · 3 commits · open ## Summary Four self-contained performance improvements independently rebased onto `main` (orthogonal to #1097): ### 1. Zero-Copy Section-Heap Windows (`VICTORY_INPLACE_SECTIONS=1`, default on when `VICTORY_INPLACE>=1`) - `crates/victory-gpu/src/inplace.rs` & `shadow.rs`: opens `SEC_COMMIT` physical-page sections once via `OpenExistingHeapFromFileMapping` (0 working-set lock, 0 pinned host copies, safe with `VirtualProtect` and view unmaps since `section_outlives_views=true`) and places `CreatePlacedResource` buffers over maximal contiguous mapped runs inside 4 MiB cells. - Enforces strict `run_end == cell_end` in `find_section_run` and `longest_tail` reuse for unsized root views (`unsized_ask=true`) so future mappings inside the same cell can never be truncated by a cached partial window. - Clears cached section heap entries on section-handle reuse in `title_memory_section`, and retires placed windows cleanly via existing `title_memory_freeing` / `in_place_let_go`. - Measured (Linux Proton / RTX 3070 8 GB, 16 GB RAM): opened **3,967** zero-copy section windows across 1 heap (**406–720 MB** live, **0 refused**, **1,036** cleanly retired on remap, **0 unhandled exceptions** in 180s run); cut `copies` from **76–127 ms -> 10 ms** and peak swap by up to **5.1 GB** before 16 GB system RAM saturation. ### 2. Lock-Free `HostHeap::mirror` Fast Path + Cached `gpu_handle` (`descriptor/host.rs`) - Adds `made_fast: Vec<AtomicU64>` (Release/Acquire mirror of `made`) so the ~98% cache-hit path in `HostHeap::mirror` returns without locking `self.made` (~50k mutex acquisitions/frame eliminated). Cleared atomically in `unmake()` and on null/deferred transitions. - Caches `gpu: u64` from `GetGPUDescriptorHandleForHeapStart()` once at heap creation (~10k COM calls/frame eliminated). ### 3. Zero-Alloc Stack Root Constants (`draw.rs`) - Replaces per-bind `vec![0u32; dwords as usize]` in `State::bind` with a stack `[0u32; 64]` buffer (falling back to heap only if `dwords > 64`), removing ~6k–10k small heap allocations/frame. ### 4. `VIEWS: RwLock<Views>` + Thin LTO (`inplace.rs`, `Cargo.toml`) - Converts `VIEWS` from `Mutex<Views>` to `RwLock<Views>` so concurrent read queries in `watch`, `texture`, and `shadow` no longer serialize against each other. - Adds `lto = "thin"` to `[profile.release]` for cross-crate inlining. ## Verification - `cargo xtask policy` passes (`181 files ok`). - `cargo check --target x86_64-pc-windows-gnu --tests -p victory-gpu` passes cleanly. - New unit test `find_section_run_merges_contiguous_committed_views_and_respects_unsized_tail` passes under Proton. - Verified across 180s warm-cache runs on Linux Proton (RTX 3070 8 GB / 16 GB RAM): up to **2.10 fps median / 14.9 fps peak** (vs 1.75 fps prior / 0.90 fps baseline), 0 unhandled exceptions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:47 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-25 21:11 UTC · original

The new section window can also be used for shader writes. At 3c85889, section_windows_on() checks the in-place level and VICTORY_INPLACE_SECTIONS, then Shadow::placed sets place. Shadow::gpu_writes (shadow.rs:2436) returns immediately for that shadow. With late waits or relay enabled, the CPU can therefore observe the section before the outstanding GPU write has completed, and the flight has no range recorded to make the CPU wait. This is the window case discussed on #358, extended to committed sections here.

Could you gate the new placement on synchronous completion as well, or track those writes through completion? I’m testing the section path on RADV with VICTORY_LATE_WAIT=0 VICTORY_RELAY=0.

**@⁠UwUCammie** on GitHub · 2026-11-25 21:11 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7174734200) The new section window can also be used for shader writes. At `3c85889`, `section_windows_on()` checks the in-place level and `VICTORY_INPLACE_SECTIONS`, then `Shadow::placed` sets `place`. `Shadow::gpu_writes` (shadow.rs:2436) returns immediately for that shadow. With late waits or relay enabled, the CPU can therefore observe the section before the outstanding GPU write has completed, and the flight has no range recorded to make the CPU wait. This is the window case discussed on #358, extended to committed sections here. Could you gate the new placement on synchronous completion as well, or track those writes through completion? I’m testing the section path on RADV with `VICTORY_LATE_WAIT=0 VICTORY_RELAY=0`.
Author
Owner

@⁠zocram4cc on GitHub · 2026-11-25 21:21 UTC · original

A data point from RADV that bears on the section path. It was measured on an RX 6900 XT (Mesa 26.3.1, vkd3d-proton 3.2.0, Proton Experimental), not an NVIDIA card.

On Proton, OpenExistingHeapFromFileMapping is vkd3d-proton's, and it maps a view, imports it and unmaps it at once (device.c d3d12_device_OpenExistingHeapFromFileMapping):

addr = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
hr = d3d12_device_OpenExistingHeapFromAddress(iface, addr, riid, heap);
UnmapViewOfFile(addr);

Under Wine a section view is memfd-backed (shared) memory. On RADV/amdgpu I saw two outcomes with a 64 KiB SEC_COMMIT section, a buffer placed in the heap, and a pattern written by the CPU through a view and read back by the GPU (and the reverse):

  • With the stock libdrm, the import is refused: vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e. libdrm sets AMDGPU_GEM_USERPTR_ANONONLY and the kernel refuses a VMA with a file. vkd3d-proton then silently allocates separate memory: the call returns S_OK, the placement works, and the GPU reads and writes bytes the title never sees (stale both ways).
  • When the import does succeed (a libdrm without ANONONLY), the next submission that touches it is rejected (radv/amdgpu: The CS has been rejected ... (-14)) and the device is lost. The view it imported is already gone.

So on RADV, "0 refused" and fewer copies can mean the windows are served from a private copy, not the title's pages. A byte check would tell. Write a pattern through the title's view after opening, CopyBufferRegion from the placed buffer into a readback buffer, and compare; then the other way round. Your RTX 3070 driver may behave differently. If it pins the pages at import, the unmap might not matter there, but I haven't tested NVIDIA.

What did alias both ways here: OpenExistingHeapFromAddress/...Address1 on private VirtualAlloc memory. A section view that we keep mapped also aliases when opened by address, but on RADV only with ANONONLY dropped from libdrm.

This adds to @⁠UwUCammie's flight point above: there, writes through the window are not waited for; here, they may not reach title memory at all.

**@⁠zocram4cc** on GitHub · 2026-11-25 21:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7174973883) A data point from RADV that bears on the section path. It was measured on an RX 6900 XT (Mesa 26.3.1, vkd3d-proton 3.2.0, Proton Experimental), not an NVIDIA card. On Proton, `OpenExistingHeapFromFileMapping` is vkd3d-proton's, and it maps a view, imports it and **unmaps it at once** ([device.c `d3d12_device_OpenExistingHeapFromFileMapping`](https://github.com/HansKristian-Work/vkd3d-proton/blob/71cae091b06571e51446cf2a937f0b04c237c04d/libs/vkd3d/device.c#L7636-L7657)): ```c addr = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0); hr = d3d12_device_OpenExistingHeapFromAddress(iface, addr, riid, heap); UnmapViewOfFile(addr); ``` Under Wine a section view is memfd-backed (shared) memory. On RADV/amdgpu I saw two outcomes with a 64 KiB `SEC_COMMIT` section, a buffer placed in the heap, and a pattern written by the CPU through a view and read back by the GPU (and the reverse): - With the stock libdrm, the import is refused: `vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e`. libdrm sets `AMDGPU_GEM_USERPTR_ANONONLY` and the kernel refuses a VMA with a file. vkd3d-proton then **silently allocates separate memory**: the call returns S_OK, the placement works, and the GPU reads and writes bytes the title never sees (stale both ways). - When the import does succeed (a libdrm without ANONONLY), the next submission that touches it is rejected (`radv/amdgpu: The CS has been rejected ... (-14)`) and the device is lost. The view it imported is already gone. So on RADV, "0 refused" and fewer copies can mean the windows are served from a private copy, not the title's pages. A byte check would tell. Write a pattern through the title's view after opening, `CopyBufferRegion` from the placed buffer into a readback buffer, and compare; then the other way round. Your RTX 3070 driver may behave differently. If it pins the pages at import, the unmap might not matter there, but I haven't tested NVIDIA. What did alias both ways here: `OpenExistingHeapFromAddress`/`...Address1` on private `VirtualAlloc` memory. A section view that *we* keep mapped also aliases when opened by address, but on RADV only with ANONONLY dropped from libdrm. This adds to @⁠UwUCammie's flight point above: there, writes through the window are not waited for; here, they may not reach title memory at all.
Author
Owner

@⁠RealAzemed on GitHub · 2026-11-25 21:30 UTC · original

Thanks @⁠UwUCammie and @⁠zocram4cc — both great catches! Updated in ed0ac8c:

  1. Opt-in & synchronous-only gate (@⁠UwUCammie): VICTORY_INPLACE_SECTIONS=1 is now strictly opt-in (off by default) and refused whenever crate::host::late() || crate::host::relay() is active (logging a warning and falling back to copies), matching the #358 / VICTORY_INPLACE=2 synchronous-completion rule since Shadow::placed skips Shadow::gpu_writes.
  2. One-time live CPU<->GPU aliasing round-trip self-test (@⁠zocram4cc): On first use, place_section_window() now runs the existing inplace::section() probe on a temporary SEC_COMMIT section and caches section_reads && section_writes && section_outlives_views (CPU write via view -> GPU CopyBufferRegion readback, GPU write -> CPU read via view, and unmap -> GPU write -> remap read). Any driver/wrapper where OpenExistingHeapFromFileMapping silently falls back to non-aliasing private memory while returning S_OK (like stock libdrm/RADV with AMDGPU_GEM_USERPTR_ANONONLY) fails the byte check, logs a warning, and automatically falls back to copies.

For reference on NVIDIA Linux/Proton (RTX 3070, driver 620.73.04, Proton Experimental / vkd3d-proton), our earlier VICTORY_INPLACE_PROBE=1 run passed all three (section_reads=true, section_writes=true, section_outlives_views=true), so NVIDIA's import pins/aliases the backing pages across the UnmapViewOfFile — while keeping VICTORY_INPLACE_SECTIONS opt-in + verified ensures RADV/amdgpu users are never silently given stale private buffers or an unrequested probe.

**@⁠RealAzemed** on GitHub · 2026-11-25 21:30 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7175173411) Thanks @⁠UwUCammie and @⁠zocram4cc — both great catches! Updated in `ed0ac8c`: 1. **Opt-in & synchronous-only gate (@⁠UwUCammie)**: `VICTORY_INPLACE_SECTIONS=1` is now strictly opt-in (off by default) and refused whenever `crate::host::late() || crate::host::relay()` is active (logging a warning and falling back to copies), matching the `#358` / `VICTORY_INPLACE=2` synchronous-completion rule since `Shadow::placed` skips `Shadow::gpu_writes`. 2. **One-time live CPU<->GPU aliasing round-trip self-test (@⁠zocram4cc)**: On first use, `place_section_window()` now runs the existing `inplace::section()` probe on a temporary `SEC_COMMIT` section and caches `section_reads && section_writes && section_outlives_views` (CPU write via view -> GPU `CopyBufferRegion` readback, GPU write -> CPU read via view, and unmap -> GPU write -> remap read). Any driver/wrapper where `OpenExistingHeapFromFileMapping` silently falls back to non-aliasing private memory while returning `S_OK` (like stock libdrm/RADV with `AMDGPU_GEM_USERPTR_ANONONLY`) fails the byte check, logs a warning, and automatically falls back to copies. For reference on NVIDIA Linux/Proton (RTX 3070, driver 620.73.04, Proton Experimental / vkd3d-proton), our earlier `VICTORY_INPLACE_PROBE=1` run passed all three (`section_reads=true`, `section_writes=true`, `section_outlives_views=true`), so NVIDIA's import pins/aliases the backing pages across the `UnmapViewOfFile` — while keeping `VICTORY_INPLACE_SECTIONS` opt-in + verified ensures RADV/amdgpu users are never silently given stale private buffers or an unrequested probe.
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-25 21:42 UTC · original

I finished a matched run on the RX 7900 XT (RADV 26.3.1, Wine 11.22, vkd3d-proton). Both runs used the same local build with the section patch from before ed0ac8c, the same inputs, VICTORY_INPLACE=1, and synchronous submission (LATE_WAIT=0, RELAY=0).

Section windows Presents / elapsed in the first room Average FPS Draws/frame
Off 150 / 72.36 s 2.07 5,003
On 157 / 73.67 s 2.13 4,973

I counted complete reporting intervals inside seconds 150–225, including stalls. The enabled run reported 2,323 live section windows (420 MB) in one heap. That confirms the path was taken. One run each puts the frame rates close together. These measurements predate the new byte-coherence probe, so they don’t establish whether the imported bytes aliased on this driver.

**@⁠UwUCammie** on GitHub · 2026-11-25 21:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7175428512) I finished a matched run on the RX 7900 XT (RADV 26.3.1, Wine 11.22, vkd3d-proton). Both runs used the same local build with the section patch from before ed0ac8c, the same inputs, `VICTORY_INPLACE=1`, and synchronous submission (`LATE_WAIT=0`, `RELAY=0`). | Section windows | Presents / elapsed in the first room | Average FPS | Draws/frame | |---|---:|---:|---:| | Off | 150 / 72.36 s | 2.07 | 5,003 | | On | 157 / 73.67 s | 2.13 | 4,973 | I counted complete reporting intervals inside seconds 150–225, including stalls. The enabled run reported 2,323 live section windows (420 MB) in one heap. That confirms the path was taken. One run each puts the frame rates close together. These measurements predate the new byte-coherence probe, so they don’t establish whether the imported bytes aliased on this driver.
Author
Owner

@⁠Proudnoob4 on GitHub · 2026-11-25 22:16 UTC · original

AI-assisted testing (Gemini in OpenCode); measured locally on my own machine.

Native Windows 10 / RTX 4080 data point (ed0ac8c, bundled speed stack)

Setup: Windows 10 Pro 22H2 (Agility SDK 1.620.2), i5-13600K (6P+8E), 32 GB RAM, RTX 4080 16 GB (driver 621.01), Series X profile, diagnostics release build (9c184b3 + #1117 ed0ac8c + #1014 + #1016 + #1029 + #1032 + #1044 + #1058 + #1059 + #1066 + #1097 + #1138 + #1146 + #1158 + #1159), warm cache.

  • Merge with #1097 (a8bcf21d): orthogonal as noted; only minor conflict in inplace.rs (views() -> views_read() in #1097's new helpers) and watch.rs (BlockSet). 42/42 inplace/watch/plaincopy/queue unit tests passed, including both find_section_run_merges_contiguous_committed_views_and_respects_unsized_tail and placeholder_fast_path_tracks_mapped_bytes_and_blocks.
  • Note on #1146: #1146 introduces the same atomic mirror pattern (made_now) as #1117's made_fast, plus sharded HostHeap::kept locks; unified on made_now when bundling both.
  • Runtime (with VICTORY_LATE_WAIT=3 VICTORY_RELAY=2, so VICTORY_INPLACE_SECTIONS stays off per ed0ac8c):
    • Thin LTO + VIEWS RwLock + lock-free mirror ran cleanly across 5 runs (330–360 s each, 0 crashes/device removals, crisp world frames through frame-4096.png).
    • Best run (fxnext_turbo): 8.50 fps median, 9.20 p90, 9.30 max, usual frame 113 ms, GPU title lists 38.8 ms (cardmeter 40.8 ms), copy-back 23.2 ms.
    • Earlier paired check before #1066/#1146 (fxnext_clean vs fx_stack3 at similar ~170 MB/frame): copies dropped from 43.3 ms to 29.8 ms (bundled with c36971b 64-byte changed_runs).
  • VICTORY_INPLACE_SECTIONS=1 live aliasing self-test under LATE_WAIT=0 RELAY=0 on native Win10/RTX 4080 is unmeasured so far; happy to run a dedicated sync probe if helpful.
**@⁠Proudnoob4** on GitHub · 2026-11-25 22:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7176157926) *AI-assisted testing (Gemini in OpenCode); measured locally on my own machine.* ### Native Windows 10 / RTX 4080 data point (`ed0ac8c`, bundled speed stack) **Setup:** Windows 10 Pro 22H2 (Agility SDK 1.620.2), i5-13600K (6P+8E), 32 GB RAM, RTX 4080 16 GB (driver 621.01), Series X profile, diagnostics release build (`9c184b3` + `#1117` `ed0ac8c` + `#1014` + `#1016` + `#1029` + `#1032` + `#1044` + `#1058` + `#1059` + `#1066` + `#1097` + `#1138` + `#1146` + `#1158` + `#1159`), warm cache. - **Merge with `#1097` (`a8bcf21d`):** orthogonal as noted; only minor conflict in `inplace.rs` (`views()` -> `views_read()` in `#1097`'s new helpers) and `watch.rs` (`BlockSet`). `42/42` `inplace`/`watch`/`plaincopy`/`queue` unit tests passed, including both `find_section_run_merges_contiguous_committed_views_and_respects_unsized_tail` and `placeholder_fast_path_tracks_mapped_bytes_and_blocks`. - **Note on `#1146`:** `#1146` introduces the same atomic mirror pattern (`made_now`) as `#1117`'s `made_fast`, plus sharded `HostHeap::kept` locks; unified on `made_now` when bundling both. - **Runtime (with `VICTORY_LATE_WAIT=3 VICTORY_RELAY=2`, so `VICTORY_INPLACE_SECTIONS` stays off per `ed0ac8c`):** - Thin LTO + `VIEWS` `RwLock` + lock-free mirror ran cleanly across 5 runs (330–360 s each, 0 crashes/device removals, crisp world frames through `frame-4096.png`). - Best run (`fxnext_turbo`): **8.50 fps median, 9.20 p90, 9.30 max**, `usual frame 113 ms`, GPU title lists `38.8 ms` (`cardmeter 40.8 ms`), `copy-back 23.2 ms`. - Earlier paired check before `#1066`/`#1146` (`fxnext_clean` vs `fx_stack3` at similar ~170 MB/frame): `copies` dropped from `43.3 ms` to `29.8 ms` (bundled with `c36971b` 64-byte `changed_runs`). - `VICTORY_INPLACE_SECTIONS=1` live aliasing self-test under `LATE_WAIT=0 RELAY=0` on native Win10/RTX 4080 is **unmeasured** so far; happy to run a dedicated sync probe if helpful.
Author
Owner

@⁠Filip722 on GitHub · 2026-11-25 22:19 UTC · original · edited 2026-11-26 08:55 UTC

I tested the section-import path from ed0ac8c on main 9c184b3 with #830’s Wine file backing, using a synthetic 2 MiB writable file mapping with the same creation flags and lifetime. Bazzite 44, RTX 5060 Laptop 8 GB, NVIDIA 615.78.08, GE-Proton11-14 and vkd3d-proton cae8353ed7959c4+.

The production pagefile-backed round-trip gate passed on this adapter. With the file mapping, both OpenExistingHeapFromFileMapping and placed resource creation succeeded. GPU readback did not match the CPU view. GPU writes were absent in both the original CPU view and a replacement view. The section-range fixture passed, and the file-backed GPU fixture failed its first byte-coherence assertion. I did not run the title with section imports enabled.

When this is combined with #830, the gate needs to account for the actual backing type. A safe narrow change is to keep file-backed sections on the existing copy path until their own aliasing test passes, while retaining the pagefile-backed fast path on devices that pass its gate.

Test and report prepared with assistance from OpenAI Codex (GPT-6.2-Sol High).

Follow-up verification: The failure also reproduced on the same direct-I/O ext4 scratch filesystem used by our #830 title runs. I tested a local guard that carries the actual file_backed flag from physical_section into title_memory_section and rejects it in find_section_run before any D3D12 import. The same committed range was accepted with anonymous backing and refused with file backing. The two focused range tests, the Windows MSVC application check and the asset-policy check passed. This guard preserves the existing copy fallback for file-backed sections.

**@⁠Filip722** on GitHub · 2026-11-25 22:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7176211359) · edited 2026-11-26 08:55 UTC I tested the section-import path from `ed0ac8c` on main `9c184b3` with #830’s Wine file backing, using a synthetic 2 MiB writable file mapping with the same creation flags and lifetime. Bazzite 44, RTX 5060 Laptop 8 GB, NVIDIA 615.78.08, GE-Proton11-14 and vkd3d-proton `cae8353ed7959c4+`. The production pagefile-backed round-trip gate passed on this adapter. With the file mapping, both `OpenExistingHeapFromFileMapping` and placed resource creation succeeded. GPU readback did not match the CPU view. GPU writes were absent in both the original CPU view and a replacement view. The section-range fixture passed, and the file-backed GPU fixture failed its first byte-coherence assertion. I did not run the title with section imports enabled. When this is combined with #830, the gate needs to account for the actual backing type. A safe narrow change is to keep file-backed sections on the existing copy path until their own aliasing test passes, while retaining the pagefile-backed fast path on devices that pass its gate. Test and report prepared with assistance from OpenAI Codex (GPT-6.2-Sol High). **Follow-up verification:** The failure also reproduced on the same direct-I/O ext4 scratch filesystem used by our #830 title runs. I tested a local guard that carries the actual `file_backed` flag from `physical_section` into `title_memory_section` and rejects it in `find_section_run` before any D3D12 import. The same committed range was accepted with anonymous backing and refused with file backing. The two focused range tests, the Windows MSVC application check and the asset-policy check passed. This guard preserves the existing copy fallback for file-backed sections.
Author
Owner

@⁠LeonardoS11 on GitHub · 2026-11-25 23:44 UTC · original

A data point from an NVIDIA card. We took the part that places windows outside buffers over the title's committed sections (no copy) onto an integration branch and measured it on an RTX 3080 Ti 12 GB, Windows 11 26200, Series S profile, fixed room of the prologue.

  • It works: 871 windows alive in place, about 130 MB no longer copied; 1,243 windows fell back to the copying path.
  • The gain from the copies alone is about 9 ms a frame.
  • But it needs VICTORY_RELAY=0 and VICTORY_LATE_WAIT=0, and running the submission synchronous costs about 80 ms a frame here (187 ms a frame against 110 ms with the relay on), so the net is a loss on this machine. If the in-place windows could live with the relay thread, the 9 ms would be a real gain.

The lock-free HostHeap::mirror and the VIEWS RwLock we have not measured apart.

Written with Claude Code.

**@⁠LeonardoS11** on GitHub · 2026-11-25 23:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7177976031) A data point from an NVIDIA card. We took the part that places windows outside buffers over the title's committed sections (no copy) onto an integration branch and measured it on an RTX 3080 Ti 12 GB, Windows 11 26200, Series S profile, fixed room of the prologue. - It works: 871 windows alive in place, about 130 MB no longer copied; 1,243 windows fell back to the copying path. - The gain from the copies alone is about 9 ms a frame. - But it needs `VICTORY_RELAY=0` and `VICTORY_LATE_WAIT=0`, and running the submission synchronous costs about 80 ms a frame here (187 ms a frame against 110 ms with the relay on), so the net is a loss on this machine. If the in-place windows could live with the relay thread, the 9 ms would be a real gain. The lock-free `HostHeap::mirror` and the VIEWS RwLock we have not measured apart. Written with Claude Code.
Author
Owner

@⁠RealAzemed on GitHub · 2026-11-26 00:28 UTC · original

Thanks everyone for all the hardware data points — huge help! Pushed 8cc889c addressing both @⁠LeonardoS11 / @⁠UwUCammie and @⁠Filip722:

1. In-place section windows now work with VICTORY_LATE_WAIT & VICTORY_RELAY (@⁠LeonardoS11, @⁠UwUCammie)

Instead of blocking VICTORY_INPLACE_SECTIONS=1 whenever late waits or the relay thread are active, Shadow::gpu_writes now tracks declared GPU write ranges for in-place shadows onto flights when host::late() is enabled:

  • Declared ranges are merged into line.written and a dedicated line.placed_written set (empty on the common read-only path, zero snapshot/compare/copy-back — hand_back and relay_hand_back skip shadow.in_place() alongside shadow.carded()).
  • late_met settles on line.written, blocked_by never bypasses line.placed_written via fill_ahead (since placed windows don't go through copy_back/relay_merge), and in_place_let_go calls settle_if_placed_written(at, end) (waiting via relay_wait or a direct fence wait without taking host.submitted, so it is safe while xmem holds MAPPING) before remapping pages with an in-flight GPU write.
  • VICTORY_INPLACE_SECTIONS=1 remains opt-in and still requires the one-time live CPU<->GPU aliasing round-trip self-test (section_reads && section_writes && section_outlives_views).

@⁠LeonardoS11 — this should let you re-test the ~9 ms/frame savings with VICTORY_RELAY and VICTORY_LATE_WAIT enabled (without the ~80 ms synchronous penalty)!

2. File-backed section guard for #830 (@⁠Filip722)

  • Added pub fn title_memory_section_backing(section, bytes, committed, file_backed) (keeping title_memory_section unchanged as file_backed = false for full backwards compatibility) and updated find_section_run to reject file_backed == true before any D3D12 import, with unit-test coverage in find_section_run_merges_contiguous_committed_views_and_respects_unsized_tail (passes under Proton, cargo xtask policy 181 files ok).
  • When integrating with #830, passing file_backed = true keeps file-backed scratch sections safely on the copy path while anonymous pagefile-backed sections keep the fast path.

3. @⁠Proudnoob4 & @⁠UwUCammie

  • @⁠Proudnoob4: Awesome 8.50 fps median / 9.30 max result! Happy to drop/align made_fast with #1146's made_now if #1146 lands first.
  • @⁠UwUCammie: Thanks for the matched RX 7900 XT numbers — if you ever try 8cc889c with VICTORY_INPLACE_SECTIONS=1 on RADV, the startup probe log line (section_reads, section_writes, section_outlives_views) will immediately show whether RADV aliased or fell back cleanly.
**@⁠RealAzemed** on GitHub · 2026-11-26 00:28 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7178802801) Thanks everyone for all the hardware data points — huge help! Pushed `8cc889c` addressing both @⁠LeonardoS11 / @⁠UwUCammie and @⁠Filip722: ### 1. In-place section windows now work with `VICTORY_LATE_WAIT` & `VICTORY_RELAY` (@⁠LeonardoS11, @⁠UwUCammie) Instead of blocking `VICTORY_INPLACE_SECTIONS=1` whenever late waits or the relay thread are active, `Shadow::gpu_writes` now tracks declared GPU write ranges for in-place shadows onto flights when `host::late()` is enabled: - Declared ranges are merged into `line.written` **and** a dedicated `line.placed_written` set (empty on the common read-only path, zero snapshot/compare/copy-back — `hand_back` and `relay_hand_back` skip `shadow.in_place()` alongside `shadow.carded()`). - `late_met` settles on `line.written`, `blocked_by` never bypasses `line.placed_written` via `fill_ahead` (since placed windows don't go through `copy_back`/`relay_merge`), and `in_place_let_go` calls `settle_if_placed_written(at, end)` (waiting via `relay_wait` or a direct fence wait without taking `host.submitted`, so it is safe while `xmem` holds `MAPPING`) before remapping pages with an in-flight GPU write. - `VICTORY_INPLACE_SECTIONS=1` remains **opt-in** and still requires the one-time live CPU<->GPU aliasing round-trip self-test (`section_reads && section_writes && section_outlives_views`). @⁠LeonardoS11 — this should let you re-test the ~9 ms/frame savings **with `VICTORY_RELAY` and `VICTORY_LATE_WAIT` enabled** (without the ~80 ms synchronous penalty)! ### 2. File-backed section guard for #830 (@⁠Filip722) - Added `pub fn title_memory_section_backing(section, bytes, committed, file_backed)` (keeping `title_memory_section` unchanged as `file_backed = false` for full backwards compatibility) and updated `find_section_run` to reject `file_backed == true` before any D3D12 import, with unit-test coverage in `find_section_run_merges_contiguous_committed_views_and_respects_unsized_tail` (passes under Proton, `cargo xtask policy` 181 files ok). - When integrating with #830, passing `file_backed = true` keeps file-backed scratch sections safely on the copy path while anonymous pagefile-backed sections keep the fast path. ### 3. @⁠Proudnoob4 & @⁠UwUCammie - @⁠Proudnoob4: Awesome 8.50 fps median / 9.30 max result! Happy to drop/align `made_fast` with #1146's `made_now` if #1146 lands first. - @⁠UwUCammie: Thanks for the matched RX 7900 XT numbers — if you ever try `8cc889c` with `VICTORY_INPLACE_SECTIONS=1` on RADV, the startup probe log line (`section_reads`, `section_writes`, `section_outlives_views`) will immediately show whether RADV aliased or fell back cleanly.
Author
Owner

@⁠SkillIssueXO on GitHub · 2026-11-26 02:08 UTC · original

A local Series X census on RTX 5070 Ti with 64f3a82e plus local diagnostics found 116 title buffers covering 426 MiB that each span one contiguous run of section views. The same sample had 18 scattered title buffers covering 325 MiB. The whole-window census found one 4 MiB contiguous window outside title buffers. This census classifies the full existing window extent and does not count smaller runs eligible for the PR’s clipping logic. The Windows run registered three reserved sections of 185, 710 and 6,236 MiB.

In the standalone fixture on the same RTX card, a 2 MiB anonymous SEC_COMMIT section opened and accepted the cross-adapter UAV buffer at a nonzero aligned offset. CPU and GPU visibility survived replacing the CPU view. The SEC_RESERVE control returned 0x80070057. For the fixture’s private-memory GPU copy, host write-watch reported 0 of the 16 written pages on NVIDIA and 16 on WARP. These are independent eligibility and coherence measurements. AI-assisted testing. Asset-free data.

**@⁠SkillIssueXO** on GitHub · 2026-11-26 02:08 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7180502312) A local Series X census on RTX 5070 Ti with `64f3a82e` plus local diagnostics found 116 title buffers covering 426 MiB that each span one contiguous run of section views. The same sample had 18 scattered title buffers covering 325 MiB. The whole-window census found one 4 MiB contiguous window outside title buffers. This census classifies the full existing window extent and does not count smaller runs eligible for the PR’s clipping logic. The Windows run registered three reserved sections of 185, 710 and 6,236 MiB. In the standalone fixture on the same RTX card, a 2 MiB anonymous `SEC_COMMIT` section opened and accepted the cross-adapter UAV buffer at a nonzero aligned offset. CPU and GPU visibility survived replacing the CPU view. The `SEC_RESERVE` control returned `0x80070057`. For the fixture’s private-memory GPU copy, host write-watch reported 0 of the 16 written pages on NVIDIA and 16 on WARP. These are independent eligibility and coherence measurements. AI-assisted testing. Asset-free data.
Author
Owner

@⁠Filip722 on GitHub · 2026-11-26 16:34 UTC · original · edited 2026-11-26 18:27 UTC

A follow-up test on an RTX 5060 Laptop GPU (8 GB, driver 615.78.08) with GE-Proton11-14 and vkd3d-proton 3.2.0 confirms a live import of a 174 MiB registered graphics buffer from a committed anonymous section. In a local adaptation, ordering fresh slices before mapping made the buffer contiguous within its section. The production CPU/GPU coherence check passed and the game rendered the prison view with visible camera movement.

In a matched 54-second replay with synchronous submission, enabling the import raised throughput from 3.05 to 3.60 completed Presents per second and reduced median copy-back from 108.3 to 61.1 ms per frame. Median/p95 intervals moved from 325/359 to 268/337 ms. Both arms used the same executable, ordered section and checkpoint. The import path required anonymous committed backing.

I also tested the import with overlapping submissions after carrying forward this PR's placed-write dependency checks. Across the same elapsed 54 seconds in the prison view, import off measured 5.53 FPS and import on measured 6.28 FPS. Median/p95 intervals were 176/212 ms and 156/179 ms. Median copy-back was 93.4 ms and 73.0 ms, respectively. Both measured runs had compilation idle.

On a newer baseline (main 52ac4ec0f8 with the same Wine bring-up, the #1234 wait policy and the late-placement dependency port), I compared direct import disabled and enabled in a single executable. GE-Proton11-14, vkd3d-proton 3.2.0 and RTX 5060 Laptop 8 GB were unchanged. The coherence probe passed and the 174 MiB buffer was imported. In the same 37.9-second stationary window, disabled produced 148 Presents at 3.91 FPS and enabled 147 at 3.90 FPS. The separate 54-second view-matched windows gave 3.86 and 3.92 FPS. Median forward bytes fell from about 149 to 135 MB per frame. This run isolates the import switch with late placement waits enabled in both arms. Camera response and the three focused late-placement tests passed.

Assisted by Codex (GPT-6.2-Sol High).

**@⁠Filip722** on GitHub · 2026-11-26 16:34 UTC · [original](https://github.com/fxceless/victory-fork/pull/1117#issuecomment-7197820827) · edited 2026-11-26 18:27 UTC A follow-up test on an RTX 5060 Laptop GPU (8 GB, driver 615.78.08) with GE-Proton11-14 and vkd3d-proton 3.2.0 confirms a live import of a 174 MiB registered graphics buffer from a committed anonymous section. In a local adaptation, ordering fresh slices before mapping made the buffer contiguous within its section. The production CPU/GPU coherence check passed and the game rendered the prison view with visible camera movement. In a matched 54-second replay with synchronous submission, enabling the import raised throughput from 3.05 to 3.60 completed Presents per second and reduced median copy-back from 108.3 to 61.1 ms per frame. Median/p95 intervals moved from 325/359 to 268/337 ms. Both arms used the same executable, ordered section and checkpoint. The import path required anonymous committed backing. I also tested the import with overlapping submissions after carrying forward this PR's placed-write dependency checks. Across the same elapsed 54 seconds in the prison view, import off measured 5.53 FPS and import on measured 6.28 FPS. Median/p95 intervals were 176/212 ms and 156/179 ms. Median copy-back was 93.4 ms and 73.0 ms, respectively. Both measured runs had compilation idle. On a newer baseline (main 52ac4ec0f8a03f103c146e60228e53612759d435 with the same Wine bring-up, the #1234 wait policy and the late-placement dependency port), I compared direct import disabled and enabled in a single executable. GE-Proton11-14, vkd3d-proton 3.2.0 and RTX 5060 Laptop 8 GB were unchanged. The coherence probe passed and the 174 MiB buffer was imported. In the same 37.9-second stationary window, disabled produced 148 Presents at 3.91 FPS and enabled 147 at 3.90 FPS. The separate 54-second view-matched windows gave 3.86 and 3.92 FPS. Median forward bytes fell from about 149 to 135 MB per frame. This run isolates the import switch with late placement waits enabled in both arms. Camera response and the three focused late-placement tests passed. Assisted by Codex (GPT-6.2-Sol High).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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