gpu: opt-in lazy GPU write-back (VEH), O(dirty) CopiedPages, AVX2 shadow & AdapterKey PSO (vitutu1#20 handover) #51

Closed
Vladimir-Human wants to merge 85 commits from upstream-pr/51 into main
Vladimir-Human commented 2026-11-25 21:40:57 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T21:40:57Z.


Summary

AI-assisted handover and major reliability/performance upgrade of vitutu1/victory-perf PR #20 (since that repository is now unavailable), bringing four opt-in / zero-regression subsystems onto PastiiJay/klbf-lab beta:

  1. Opt-in Lazy GPU-Resident Write-Back (VICTORY_LAZY_COPYBACK=1, default OFF):
    • Avoids copying 42–100+ MB/frame of shader-written buffers back over PCIe every frame when title CPU code never reads those pages.
    • Tracks clean eligible whole-page-aligned regions with PAGE_NOACCESS and an acyclic VEH fault handler (lazy_on_fault, never acquiring Level 0 watch/Shadow/BUFFERS/CARD_WORK/host.submitted locks); flushes only actually accessed 64 KiB pages on demand, using atomic dual-view MapViewOfFile writes before restoring PAGE_READWRITE for section-backed MEM_MAPPED console heaps (zero torn-read window).
    • Preserves coherence across DirectStorage title_memory_written (lazy_release_written_range with partial-page complement copy and pending-write FlushedBaseline preservation), VICTORY_RELAY / late_exact (Shadow::writing pending carve-out, stale_under_writes/merge_under_writes settle on LAZY_RESYNC, Step::GpuWrite settle in stale_under_flights), host::{copy_mapped, read_into, write_mapped} lazy_flush_and_hold range barrier, multi-flight FlushedBaseline subrange consumption, overlapping Shadow::exact / nested views (lazy_flush_other_shadows), shadow::unregister, and watch::Remapping (LazyRemapGuard).
    • Completely inert (0 overhead, unchanged paths) unless VICTORY_LAZY_COPYBACK=1 is set.
  2. O(dirty) CopiedPages & AVX2 Shadow/Merge Acceleration:
    • Replaces linear full-shadow scans with a 64-page uncopied_bits bitmask and lock-released plan_stale / plan_stale_filtered, plus AVX2 first_difference / last_difference, changed_runs, merge_piece, merge_sync_card, merge_gpu_into_title_runs, and merge_back_piece (preserving title-wins conflict handling).
  3. Opt-in ReBAR Upload Path (VICTORY_REBAR=1|2, default OFF):
    • Explicit D3D12_HEAP_TYPE_GPU_UPLOAD path with write-combining fences (_mm_sfence() after WC stores; _mm_mfence() + VMOVNTDQA + RAII MfenceOnExit for reads).
  4. Adapter-Keyed PSO Library Isolation (AdapterKey):
    • Keys pipeline/library.rs cache filenames by (vendor, device, revision, software) ({:04x}-{:04x}-r{:02x}-{sw|hw}) with strict Release/Acquire publish ordering (VIEW[1] / LOADED_AT / TRIMMED before VIEW[0]). Subsystem ID and driver version are deliberately omitted from the filename key so driver updates reopen the same file and fall back cleanly to an empty library if D3D12 rejects old blobs.

Verification (6b174ce6f, monotonic hardening on top of 7d31a81e)

  • Scope: only 4 files touched (host.rs, pipeline/library.rs, shadow.rs, watch.rs; shadow.rs = 410,902 B < 512 KiB), xtask policy --staged exit 0, clean merge-tree vs beta (78ad571).
  • cargo clippy -p victory-gpu --all-targets --locked (+ --all-features): 0 warnings in all modified/added code.
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked --all-features -- --test-threads=1: 185 passed; 0 failed; 5 ignored (0 D3D12 debug errors; includes all F1–F5 + 5 relay/VEH concurrency regression tests).
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- --test-threads=1: 177 passed; 0 failed; 5 ignored (0 D3D12 debug errors).
  • --release RTX 4070 SUPER / i5-13400F benchmarks (7d31a81e):
    • bench_lazy_copyback (64 MiB carded VRAM, 30 frames): 0% CPU reads 37.299 -> 0.585 ms/frame (63.78x, 0.00 MB/f readback/upload, 0.0 VEH faults/f); 2% sparse CPU reads 37.454 -> 9.001 ms/frame (4.16x, 1.25 MB/f, 20.0 faults/f).
    • bench_shadow_and_rebar: plan_stale 11.4 ns/call, 64 MiB AVX2 first+last 0.38 ms (175.5 GB/s), ReBAR GPU_UPLOAD 32 MiB write+SFENCE 3.10 ms (10.8 GB/s).

(Completes 10/10 open vitutu1/victory-perf PR handovers onto PastiiJay/klbf-lab beta: #15, #16, #29, #41, #42, #43, #44, #46, #50, and this PR.)

Co-Authored-By: AI Assistant

<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5499641971 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T21:40:57Z. --- ## Summary AI-assisted handover and major reliability/performance upgrade of `vitutu1/victory-perf` PR #20 (since that repository is now unavailable), bringing four opt-in / zero-regression subsystems onto `PastiiJay/klbf-lab` `beta`: 1. **Opt-in Lazy GPU-Resident Write-Back (`VICTORY_LAZY_COPYBACK=1`, default OFF)**: - Avoids copying 42–100+ MB/frame of shader-written buffers back over PCIe every frame when title CPU code never reads those pages. - Tracks clean eligible whole-page-aligned regions with `PAGE_NOACCESS` and an acyclic VEH fault handler (`lazy_on_fault`, never acquiring Level 0 `watch`/`Shadow`/`BUFFERS`/`CARD_WORK`/`host.submitted` locks); flushes only actually accessed 64 KiB pages on demand, using atomic dual-view `MapViewOfFile` writes before restoring `PAGE_READWRITE` for section-backed `MEM_MAPPED` console heaps (zero torn-read window). - Preserves coherence across DirectStorage `title_memory_written` (`lazy_release_written_range` with partial-page complement copy and pending-write `FlushedBaseline` preservation), `VICTORY_RELAY` / `late_exact` (`Shadow::writing` pending carve-out, `stale_under_writes`/`merge_under_writes` settle on `LAZY_RESYNC`, `Step::GpuWrite` settle in `stale_under_flights`), `host::{copy_mapped, read_into, write_mapped}` `lazy_flush_and_hold` range barrier, multi-flight `FlushedBaseline` subrange consumption, overlapping `Shadow::exact` / nested views (`lazy_flush_other_shadows`), `shadow::unregister`, and `watch::Remapping` (`LazyRemapGuard`). - Completely inert (`0` overhead, unchanged paths) unless `VICTORY_LAZY_COPYBACK=1` is set. 2. **O(dirty) `CopiedPages` & AVX2 Shadow/Merge Acceleration**: - Replaces linear full-shadow scans with a 64-page `uncopied_bits` bitmask and lock-released `plan_stale` / `plan_stale_filtered`, plus AVX2 `first_difference` / `last_difference`, `changed_runs`, `merge_piece`, `merge_sync_card`, `merge_gpu_into_title_runs`, and `merge_back_piece` (preserving title-wins conflict handling). 3. **Opt-in ReBAR Upload Path (`VICTORY_REBAR=1|2`, default OFF)**: - Explicit `D3D12_HEAP_TYPE_GPU_UPLOAD` path with write-combining fences (`_mm_sfence()` after WC stores; `_mm_mfence()` + `VMOVNTDQA` + RAII `MfenceOnExit` for reads). 4. **Adapter-Keyed PSO Library Isolation (`AdapterKey`)**: - Keys `pipeline/library.rs` cache filenames by `(vendor, device, revision, software)` (`{:04x}-{:04x}-r{:02x}-{sw|hw}`) with strict `Release`/`Acquire` publish ordering (`VIEW[1]` / `LOADED_AT` / `TRIMMED` before `VIEW[0]`). Subsystem ID and driver version are deliberately omitted from the filename key so driver updates reopen the same file and fall back cleanly to an empty library if D3D12 rejects old blobs. ### Verification (`6b174ce6f`, monotonic hardening on top of `7d31a81e`) - Scope: only 4 files touched (`host.rs`, `pipeline/library.rs`, `shadow.rs`, `watch.rs`; `shadow.rs` = 410,902 B < 512 KiB), `xtask policy --staged` exit 0, clean `merge-tree` vs `beta` (`78ad571`). - `cargo clippy -p victory-gpu --all-targets --locked` (+ `--all-features`): **0 warnings** in all modified/added code. - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked --all-features -- --test-threads=1`: **185 passed; 0 failed; 5 ignored** (0 D3D12 debug errors; includes all F1–F5 + 5 relay/VEH concurrency regression tests). - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- --test-threads=1`: **177 passed; 0 failed; 5 ignored** (0 D3D12 debug errors). - `--release` RTX 4070 SUPER / i5-13400F benchmarks (`7d31a81e`): - `bench_lazy_copyback` (64 MiB carded VRAM, 30 frames): `0%` CPU reads `37.299 -> 0.585 ms/frame` (**63.78x**, `0.00 MB/f` readback/upload, `0.0` VEH faults/f); `2%` sparse CPU reads `37.454 -> 9.001 ms/frame` (**4.16x**, `1.25 MB/f`, `20.0` faults/f). - `bench_shadow_and_rebar`: `plan_stale` `11.4 ns/call`, 64 MiB AVX2 `first+last` `0.38 ms` (`175.5 GB/s`), ReBAR `GPU_UPLOAD` 32 MiB write+SFENCE `3.10 ms` (`10.8 GB/s`). *(Completes 10/10 open `vitutu1/victory-perf` PR handovers onto `PastiiJay/klbf-lab` `beta`: #15, #16, #29, #41, #42, #43, #44, #46, #50, and this PR.)* Co-Authored-By: AI Assistant
PastiiJay commented 2026-11-25 21:43:30 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:43:30Z.


Thanks a lot @Vladimir-Human, and again for carrying vitutu1/victory-perf #20 over with credit. What we keep: lazy GPU write-back (VICTORY_LAZY_COPYBACK=1) and the ReBAR upload path (VICTORY_REBAR) are both off by default; the O(dirty) CopiedPages with AVX2 merges and the adapter-keyed pipeline library are always on; and the victory-gpu suite passes on your side with the D3D12 debug layer, plus the rest of the workspace.

Since we test one change at a time on the RX 9070 XT, we'll run it in steps: first the PR with both switches off (that measures the always-on parts), then VICTORY_LAZY_COPYBACK=1 alone, then VICTORY_REBAR alone, each against our reference build for fps, picture and stability, and post each result here. If it's easy for you, splitting the always-on parts and the two opt-in switches into separate PRs would make it simpler to merge what works on its own; no obligation, we can also test it as it is.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7175457249 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7175457249). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T21:43:30Z. --- Thanks a lot @Vladimir-Human, and again for carrying vitutu1/victory-perf #20 over with credit. What we keep: lazy GPU write-back (`VICTORY_LAZY_COPYBACK=1`) and the ReBAR upload path (`VICTORY_REBAR`) are both off by default; the O(dirty) `CopiedPages` with AVX2 merges and the adapter-keyed pipeline library are always on; and the `victory-gpu` suite passes on your side with the D3D12 debug layer, plus the rest of the workspace. Since we test one change at a time on the RX 9070 XT, we'll run it in steps: first the PR with both switches off (that measures the always-on parts), then `VICTORY_LAZY_COPYBACK=1` alone, then `VICTORY_REBAR` alone, each against our reference build for fps, picture and stability, and post each result here. If it's easy for you, splitting the always-on parts and the two opt-in switches into separate PRs would make it simpler to merge what works on its own; no obligation, we can also test it as it is.
HandshakeHackin commented 2026-11-25 21:53:19 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-25T21:53:19Z.


I verified the pipeline-cache part of 7d31a81 on hosted Windows. The adapter-filename and legacy-fallback tests passed. I then ran the WARP child directly and required it to save and reload its compute pipeline. It wrote host-pipelines-1414-008c-r00-sw.bin (1,874 bytes) in each of two temporary directories. Both the synthetic hardware-named file and the unsuffixed legacy fixture retained their original bytes. Windows test log

One detail for the PR summary and driver-update retests: the filename key here uses vendor ID, device ID, revision and the software/hardware flag. It omits the subsystem ID and driver version. A driver update can therefore reopen the same filename; D3D12 can reject the old contents and the code then starts an empty library. Adapter key · Rejected-cache handling

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7175666740 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7175666740). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-25T21:53:19Z. --- I verified the pipeline-cache part of `7d31a81` on hosted Windows. The adapter-filename and legacy-fallback tests passed. I then ran the WARP child directly and required it to save and reload its compute pipeline. It wrote `host-pipelines-1414-008c-r00-sw.bin` (1,874 bytes) in each of two temporary directories. Both the synthetic hardware-named file and the unsuffixed legacy fixture retained their original bytes. [Windows test log](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45707827754/job/139534222203) One detail for the PR summary and driver-update retests: the filename key here uses vendor ID, device ID, revision and the software/hardware flag. It omits the subsystem ID and driver version. A driver update can therefore reopen the same filename; D3D12 can reject the old contents and the code then starts an empty library. [Adapter key](https://github.com/PastiiJay/klbf-lab/blob/7d31a81ed4f35930b9a205ae620ea2942563ccec/crates/victory-gpu/src/pipeline/library.rs#L423-L467) · [Rejected-cache handling](https://github.com/PastiiJay/klbf-lab/blob/7d31a81ed4f35930b9a205ae620ea2942563ccec/crates/victory-gpu/src/pipeline/library.rs#L644-L672)
PastiiJay commented 2026-11-25 21:54:39 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:54:39Z.


Thanks @HandshakeHackin, confirmed on our side: the key in 7d31a81 is vendor, device and revision (plus the software flag), and the code comment says leaving out the driver version is deliberate, so old caches aren't orphaned on a driver update. So the code looks intentional and it's the PR summary that lists subsystem and driver too.

That matters for our testers, since the pipeline pre-build is long: after a driver update the same file is reopened, and if D3D12 rejects it the library starts empty. When we test #51 we'll include one run right after a driver update to see that case. @Vladimir-Human, could you align the summary with the code when you have a moment?

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7175695760 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7175695760). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T21:54:39Z. --- Thanks @HandshakeHackin, confirmed on our side: the key in `7d31a81` is vendor, device and revision (plus the software flag), and the code comment says leaving out the driver version is deliberate, so old caches aren't orphaned on a driver update. So the code looks intentional and it's the PR summary that lists subsystem and driver too. That matters for our testers, since the pipeline pre-build is long: after a driver update the same file is reopened, and if D3D12 rejects it the library starts empty. When we test #51 we'll include one run right after a driver update to see that case. @Vladimir-Human, could you align the summary with the code when you have a moment?
Vladimir-Human commented 2026-11-25 23:13:26 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T23:13:26Z.


@PastiiJay @HandshakeHackin Thank you both for the thorough check and feedback!

  1. PR summary aligned with code (AdapterKey): Updated item 4 in the PR description to state the exact filename key used in pipeline/library.rs: (vendor, device, revision, software) ({:04x}-{:04x}-r{:02x}-{sw|hw}), deliberately omitting subsystem ID and driver version so driver updates reopen the same cache file and fall back cleanly to an empty library if D3D12 rejects old blobs.
  2. Hardening update pushed (6b174ce6f9 on top of 7d31a81ed4): While auditing concurrency edge cases across ports, we caught and fixed 6 subtle VICTORY_LAZY_COPYBACK=1 / VICTORY_RELAY edge cases and added 5 targeted regression tests in crates/victory-gpu/src/{shadow.rs,host.rs}:
    • Set restore_rw = true immediately on transition_clean_guard_to_noaccess before checking was_written_since (prevents stranding PAGE_NOACCESS on concurrent MEM_MAPPED write races).
    • Skip page-expanded self.pending ranges during Shadow::writing / lazy_resync_range / lazy_prepare_update and include Step::GpuWrite in stale_under_flights when writes_pending() && has_lazy_resync_under_writes().
    • Re-check is_lazy_held / LAZY_RESYNC per-page before and after read_into inside Shadow::merge_under_writes.
    • Preserve FlushedBaseline (without overwriting title memory) on full-page title_memory_written when shadow.writes_pending() is true.
    • Hold scoped LazyRemapGuard barriers across host::{copy_mapped, read_into, write_mapped} to close concurrent relay re-arming TOCTOU.
    • Replace deprecated AtomicU64::fetch_update calls in rebar with compare_exchange_weak loops (0 warnings on newer rustc).
    • Re-verified on RTX 4070 SUPER (D3D12_DEBUG=1): 185/185 (--all-features), 177/177 (default features), 0 D3D12 debug errors, 0 clippy warnings in modified files, shadow.rs = 410,902 B (< 512 KiB), xtask policy --staged exit 0.
  3. Splitting: Happy to split CopiedPages+AVX2 / AdapterKey PSO / VICTORY_LAZY_COPYBACK=1 / VICTORY_REBAR into separate PRs if that helps after your queued RX 9070 XT checks — just let me know! Meanwhile both new paths (VICTORY_LAZY_COPYBACK, VICTORY_REBAR) stay off by default so baseline behavior is easy to A/B test.
<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7177283749 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7177283749). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T23:13:26Z. --- @PastiiJay @HandshakeHackin Thank you both for the thorough check and feedback! 1. **PR summary aligned with code (`AdapterKey`)**: Updated item 4 in the PR description to state the exact filename key used in `pipeline/library.rs`: `(vendor, device, revision, software)` (`{:04x}-{:04x}-r{:02x}-{sw|hw}`), deliberately omitting subsystem ID and driver version so driver updates reopen the same cache file and fall back cleanly to an empty library if D3D12 rejects old blobs. 2. **Hardening update pushed (`6b174ce6f9` on top of `7d31a81ed4`)**: While auditing concurrency edge cases across ports, we caught and fixed 6 subtle `VICTORY_LAZY_COPYBACK=1` / `VICTORY_RELAY` edge cases and added 5 targeted regression tests in `crates/victory-gpu/src/{shadow.rs,host.rs}`: - Set `restore_rw = true` immediately on `transition_clean_guard_to_noaccess` before checking `was_written_since` (prevents stranding `PAGE_NOACCESS` on concurrent `MEM_MAPPED` write races). - Skip page-expanded `self.pending` ranges during `Shadow::writing` / `lazy_resync_range` / `lazy_prepare_update` and include `Step::GpuWrite` in `stale_under_flights` when `writes_pending() && has_lazy_resync_under_writes()`. - Re-check `is_lazy_held` / `LAZY_RESYNC` per-page before and after `read_into` inside `Shadow::merge_under_writes`. - Preserve `FlushedBaseline` (without overwriting title memory) on full-page `title_memory_written` when `shadow.writes_pending()` is true. - Hold scoped `LazyRemapGuard` barriers across `host::{copy_mapped, read_into, write_mapped}` to close concurrent relay re-arming TOCTOU. - Replace deprecated `AtomicU64::fetch_update` calls in `rebar` with `compare_exchange_weak` loops (`0` warnings on newer `rustc`). - Re-verified on RTX 4070 SUPER (`D3D12_DEBUG=1`): **185/185** (`--all-features`), **177/177** (default features), `0` D3D12 debug errors, `0` clippy warnings in modified files, `shadow.rs` = 410,902 B (< 512 KiB), `xtask policy --staged` exit `0`. 3. **Splitting**: Happy to split `CopiedPages`+AVX2 / `AdapterKey` PSO / `VICTORY_LAZY_COPYBACK=1` / `VICTORY_REBAR` into separate PRs if that helps after your queued RX 9070 XT checks — just let me know! Meanwhile both new paths (`VICTORY_LAZY_COPYBACK`, `VICTORY_REBAR`) stay off by default so baseline behavior is easy to A/B test.
PastiiJay commented 2026-11-25 23:14:56 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T23:14:56Z.


Thanks a lot @Vladimir-Human, quick and thorough. What we keep: the summary now matches the cache key in the code, 6b174ce6f9 hardens six lazy-copyback / relay edge cases with five new regression tests, and both opt-in paths stay off by default.

On splitting: yes please, when it's convenient for you. Separate PRs for CopiedPages+AVX2, the adapter-keyed pipeline library, lazy copy-back and ReBAR would let us run each one on the RX 9070 XT on its own and merge what works without waiting for the rest. We'll post results in each PR.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7177312157 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7177312157). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T23:14:56Z. --- Thanks a lot @Vladimir-Human, quick and thorough. What we keep: the summary now matches the cache key in the code, `6b174ce6f9` hardens six lazy-copyback / relay edge cases with five new regression tests, and both opt-in paths stay off by default. On splitting: yes please, when it's convenient for you. Separate PRs for `CopiedPages`+AVX2, the adapter-keyed pipeline library, lazy copy-back and ReBAR would let us run each one on the RX 9070 XT on its own and merge what works without waiting for the rest. We'll post results in each PR.
Vladimir-Human commented 2026-11-25 23:43:35 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T23:43:35Z.


Uncontested --release benchmark on idle i5-13400F / RTX 4070 SUPER after hardening commit 6b174ce6:

  • bench_lazy_copyback (64 MiB carded VRAM): 0% CPU reads 37.868 -> 0.566 ms/frame (66.88x, 0.00 MB/f readback/upload, 0.0 VEH faults/f); 2% sparse CPU reads 37.524 -> 8.622 ms/frame (4.35x, 1.25 MB/f, 20.0 faults/f).
  • bench_shadow_and_rebar: plan_stale (160 MiB, 4 dirty) 11.1 ns/call; 64 MiB AVX2 first+last 0.40 ms (169.6 GB/s), merge_piece 4.58 ms, changed_runs 5.26 ms; ReBAR GPU_UPLOAD 32 MiB write+SFENCE 3.09 ms (10.9 GB/s).
<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7177962865 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7177962865). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T23:43:35Z. --- Uncontested `--release` benchmark on idle `i5-13400F` / `RTX 4070 SUPER` after hardening commit `6b174ce6`: - `bench_lazy_copyback` (64 MiB carded VRAM): `0%` CPU reads `37.868 -> 0.566 ms/frame` (**66.88x**, `0.00 MB/f` readback/upload, `0.0` VEH faults/f); `2%` sparse CPU reads `37.524 -> 8.622 ms/frame` (**4.35x**, `1.25 MB/f`, `20.0` faults/f). - `bench_shadow_and_rebar`: `plan_stale` (160 MiB, 4 dirty) `11.1 ns/call`; 64 MiB AVX2 `first+last` `0.40 ms` (`169.6 GB/s`), `merge_piece` `4.58 ms`, `changed_runs` `5.26 ms`; ReBAR `GPU_UPLOAD` 32 MiB `write+SFENCE` `3.09 ms` (`10.9 GB/s`).
PastiiJay commented 2026-11-25 23:44:08 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T23:44:08Z.


Thanks @Vladimir-Human, good to have the micro-benchmarks: lazy copy-back going from ~38 to ~0.6 ms/frame when the CPU reads nothing is a big ceiling. The real test is in-game though, so we'll see how much of that survives on the RX 9070 XT once the split PRs land.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7177975320 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7177975320). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T23:44:08Z. --- Thanks @Vladimir-Human, good to have the micro-benchmarks: lazy copy-back going from ~38 to ~0.6 ms/frame when the CPU reads nothing is a big ceiling. The real test is in-game though, so we'll see how much of that survives on the RX 9070 XT once the split PRs land.
Vladimir-Human commented 2026-11-26 00:48:11 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T00:48:11Z.


Split #51 into 4 clean, independent PRs on beta (each passes VICTORY_D3D12_DEBUG=1 tests + xtask policy --staged, with zero cross-dependencies so they can be merged or reverted individually):

  1. Part 1/4 — Adapter-keyed PSO pipeline cache: https://github.com/PastiiJay/klbf-lab/pull/56
  2. Part 2/4 — CopiedPages O(dirty) bitmask, lock-free has_pending/has_dirty/has_sent mirrors, AVX2 merge/diff & WideDone: https://github.com/PastiiJay/klbf-lab/pull/57
  3. Part 3/4 — Opt-in ReBAR (D3D12_HEAP_TYPE_GPU_UPLOAD) + VRAM headroom guard & WC streaming helpers: https://github.com/PastiiJay/klbf-lab/pull/58
  4. Part 4/4 — Opt-in VEH lazy GPU-to-CPU copy-back: https://github.com/PastiiJay/klbf-lab/pull/59

Leaving #51 open until you'd like to close it once the split queue lands.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7179128059 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7179128059). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T00:48:11Z. --- Split #51 into 4 clean, independent PRs on `beta` (each passes `VICTORY_D3D12_DEBUG=1` tests + `xtask policy --staged`, with zero cross-dependencies so they can be merged or reverted individually): 1. **Part 1/4 — Adapter-keyed PSO pipeline cache**: https://github.com/PastiiJay/klbf-lab/pull/56 2. **Part 2/4 — `CopiedPages` O(dirty) bitmask, lock-free `has_pending`/`has_dirty`/`has_sent` mirrors, AVX2 merge/diff & `WideDone`**: https://github.com/PastiiJay/klbf-lab/pull/57 3. **Part 3/4 — Opt-in ReBAR (`D3D12_HEAP_TYPE_GPU_UPLOAD`) + VRAM headroom guard & WC streaming helpers**: https://github.com/PastiiJay/klbf-lab/pull/58 4. **Part 4/4 — Opt-in VEH lazy GPU-to-CPU copy-back**: https://github.com/PastiiJay/klbf-lab/pull/59 Leaving #51 open until you'd like to close it once the split queue lands.
PastiiJay commented 2026-11-26 00:49:06 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T00:49:06Z.


All four parts received (#56-#59), that's much easier to test. We'll go through them one at a time on the RX 9070 XT, starting with #56 and #57, and report in each PR. Closing #51 once they land is fine.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7179143403 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7179143403). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T00:49:06Z. --- All four parts received (#56-#59), that's much easier to test. We'll go through them one at a time on the RX 9070 XT, starting with #56 and #57, and report in each PR. Closing #51 once they land is fine.
Vladimir-Human commented 2026-11-27 08:33:29 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T08:33:29Z.


Backported the concurrency hardening identified by @efsebayern and @TaynanGT (TaynanGT/Vice-Tay#192, c289a95) in 5810d6b:

  • Hold self.copied across copies in Shadow::copy_stale: keeps the copied mutex locked from plan_stale / plan_stale_filtered through self.copy(...) so concurrent refreshes cannot observe stamped at == now pages before their bytes land or race on writing self.data.
  • Skip clean copies in card_dirty: returns early when !c.has_dirty instead of locking and pruning c.sent on clean copies.

Verified locally on Windows (VICTORY_D3D12_DEBUG=1):

  • cargo clippy -p victory-gpu --all-targets & --features diagnostics: 0 warnings in crates/victory-gpu/src/shadow.rs (only pre-existing upstream warnings in untouched files)
  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 48 passed; 0 failed; 2 ignored
  • cargo test -p victory-gpu --features diagnostics --lib shadow:: -- --test-threads=1: 48 passed; 0 failed; 2 ignored
<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7213665388 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7213665388). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T08:33:29Z. --- Backported the concurrency hardening identified by `@efsebayern` and `@TaynanGT` ([TaynanGT/Vice-Tay#192](https://github.com/TaynanGT/Vice-Tay/pull/192), `c289a95`) in `5810d6b`: - **Hold `self.copied` across copies in `Shadow::copy_stale`:** keeps the `copied` mutex locked from `plan_stale` / `plan_stale_filtered` through `self.copy(...)` so concurrent refreshes cannot observe stamped `at == now` pages before their bytes land or race on writing `self.data`. - **Skip clean copies in `card_dirty`:** returns early when `!c.has_dirty` instead of locking and pruning `c.sent` on clean copies. Verified locally on Windows (`VICTORY_D3D12_DEBUG=1`): - `cargo clippy -p victory-gpu --all-targets` & `--features diagnostics`: 0 warnings in `crates/victory-gpu/src/shadow.rs` (only pre-existing upstream warnings in untouched files) - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: `48 passed; 0 failed; 2 ignored` - `cargo test -p victory-gpu --features diagnostics --lib shadow:: -- --test-threads=1`: `48 passed; 0 failed; 2 ignored`
PastiiJay commented 2026-11-27 09:52:37 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T09:52:37Z.


Thanks @Vladimir-Human, and credit to @efsebayern and @TaynanGT for the hardening. We'll review it with the next beta batch. Could you rebase on the current head if it no longer merges cleanly by then?

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7215201672 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7215201672). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T09:52:37Z. --- Thanks @Vladimir-Human, and credit to @efsebayern and @TaynanGT for the hardening. We'll review it with the next beta batch. Could you rebase on the current head if it no longer merges cleanly by then?
TaynanGT commented 2026-11-27 09:58:18 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T09:58:18Z.


@PastiiJay I checked 5810d6b against the current beta at 6cce57e. The merge is clean as of that revision. For the beta baseline, the lock-scope fix protects the ordinary shadow refresh too, so the first run with lazy write-back and ReBAR off will still exercise it.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7215319934 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7215319934). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T09:58:18Z. --- @PastiiJay I checked `5810d6b` against the current `beta` at `6cce57e`. The merge is clean as of that revision. For the beta baseline, the lock-scope fix protects the ordinary shadow refresh too, so the first run with lazy write-back and ReBAR off will still exercise it.
Vladimir-Human commented 2026-11-27 10:44:19 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T10:44:19Z.


Thanks @PastiiJay and @TaynanGT! Confirmed 5810d6b merges cleanly against current beta (6cce57e), and I am ready to rebase whenever the next beta batch lands.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216245466 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7216245466). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T10:44:19Z. --- Thanks @PastiiJay and @TaynanGT! Confirmed `5810d6b` merges cleanly against current `beta` (`6cce57e`), and I am ready to rebase whenever the next beta batch lands.
PastiiJay commented 2026-11-27 10:50:22 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:50:22Z.


Thanks @Vladimir-Human, and @TaynanGT for the earlier testing. Lazy write-back is the riskiest of the batch, so we're reviewing it carefully and won't merge it in a rush. Could you post your GPU and driver with the VICTORY_LAZY_COPYBACK setting you used?

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216366335 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7216366335). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T10:50:22Z. --- Thanks @Vladimir-Human, and @TaynanGT for the earlier testing. Lazy write-back is the riskiest of the batch, so we're reviewing it carefully and won't merge it in a rush. Could you post your GPU and driver with the `VICTORY_LAZY_COPYBACK` setting you used?
TaynanGT commented 2026-11-27 10:51:38 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T10:51:38Z.


@Vladimir-Human I’ll keep 6cce57e as the verified beta reference and check the new beta head once the next batch lands.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216392074 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7216392074). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T10:51:38Z. --- @Vladimir-Human I’ll keep `6cce57e` as the verified beta reference and check the new beta head once the next batch lands.
PastiiJay commented 2026-11-27 10:52:02 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:52:02Z.


We'll take them onto the AMD line one at a time with an A/B bench. Thanks, the tests you added make that much easier.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216400476 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7216400476). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T10:52:02Z. --- We'll take them onto the AMD line one at a time with an A/B bench. Thanks, the tests you added make that much easier.
PastiiJay commented 2026-11-27 10:53:15 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:53:15Z.


We don't merge PRs directly, to keep the line safe. But we'll port the best of your work ourselves, one piece at a time with an A/B bench, and credit you by name. Thanks for the careful work across these PRs.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216425213 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7216425213). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T10:53:15Z. --- We don't merge PRs directly, to keep the line safe. But we'll port the best of your work ourselves, one piece at a time with an A/B bench, and credit you by name. Thanks for the careful work across these PRs.
TaynanGT commented 2026-11-27 10:58:56 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T10:58:56Z.


@PastiiJay The copy-lock change is isolated in Vice-Tay #192 if you want that piece first. It is a narrow starting point for the beta port and keeps the lazy write-back and pipeline library experiments separate.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216538203 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7216538203). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T10:58:56Z. --- @PastiiJay The copy-lock change is isolated in Vice-Tay #192 if you want that piece first. It is a narrow starting point for the beta port and keeps the lazy write-back and pipeline library experiments separate.
PastiiJay commented 2026-11-27 11:11:34 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T11:11:34Z.


checked it against our AMD line: our copy_stale already holds copied for the whole copy and card_dirty has no dirty/sent split, so that race isn't there. thanks for pointing at it, it was worth the check.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216787686 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7216787686). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T11:11:34Z. --- checked it against our AMD line: our copy_stale already holds `copied` for the whole copy and card_dirty has no dirty/sent split, so that race isn't there. thanks for pointing at it, it was worth the check.
TaynanGT commented 2026-11-27 11:16:48 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T11:16:48Z.


@PastiiJay Use the current AMD copy path as the baseline for the lazy write-back comparison. Your lock-scope check establishes the starting point for that port.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216889787 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7216889787). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T11:16:48Z. --- @PastiiJay Use the current AMD copy path as the baseline for the lazy write-back comparison. Your lock-scope check establishes the starting point for that port.
PastiiJay commented 2026-11-27 11:30:23 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T11:30:23Z.


Thanks @TaynanGT, that's a good idea. Our current AMD copy path will be the reference for the before/after bench when we pick up the lazy write-back.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7217152365 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7217152365). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T11:30:23Z. --- Thanks @TaynanGT, that's a good idea. Our current AMD copy path will be the reference for the before/after bench when we pick up the lazy write-back.
TaynanGT commented 2026-11-27 11:42:27 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T11:42:27Z.


@PastiiJay That AMD path is the reference I’d use. On the same frame window with ReBAR off in both runs, record transferred bytes and queue waits along with frame time. That will show whether lazy write-back changes traffic or just moves the wait.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7217382129 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7217382129). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T11:42:27Z. --- @PastiiJay That AMD path is the reference I’d use. On the same frame window with ReBAR off in both runs, record transferred bytes and queue waits along with frame time. That will show whether lazy write-back changes traffic or just moves the wait.
Vladimir-Human commented 2026-11-27 12:07:22 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T12:07:22Z.


Quick note for that A/B comparison @PastiiJay @TaynanGT: #59 (7311cab) now logs MB read back, explicit flushes, VEH read/write faults, and self-bypassed on the 5s line whenever VICTORY_LAZY_COPYBACK=1 (in both release and diagnostics builds, zero output when off). Happy to backport that same counter line into #51 too if you benchmark the combined branch.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7217865010 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7217865010). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T12:07:22Z. --- Quick note for that A/B comparison @PastiiJay @TaynanGT: `#59` (`7311cab`) now logs `MB read back`, `explicit flushes`, VEH read/write faults, and `self-bypassed` on the 5s line whenever `VICTORY_LAZY_COPYBACK=1` (in both release and diagnostics builds, zero output when off). Happy to backport that same counter line into `#51` too if you benchmark the combined branch.
TaynanGT commented 2026-11-27 12:13:38 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T12:13:38Z.


@Vladimir-Human The #59 counters give us useful detail for the lazy arm. Let’s use the same readback and queue-wait totals in both arms, then use the extra counters to explain the lazy run. The backport can stay separate until we compare the combined branch.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7217988366 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7217988366). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T12:13:38Z. --- @Vladimir-Human The #59 counters give us useful detail for the lazy arm. Let’s use the same readback and queue-wait totals in both arms, then use the extra counters to explain the lazy run. The backport can stay separate until we compare the combined branch.
Vladimir-Human commented 2026-11-28 18:42:25 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:42:25Z.


Closing rollup PR: cleanly split and ported onto origin/stable-amd (75022ba) across #180 (1/4), #184 (2/4), #185 (3/4), and #190 (4/4).

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7243994069 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7243994069). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:42:25Z. --- Closing rollup PR: cleanly split and ported onto `origin/stable-amd` (`75022ba`) across #180 (1/4), #184 (2/4), #185 (3/4), and #190 (4/4).
TaynanGT commented 2026-11-29 11:25:39 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-29T11:25:39Z.


Thanks for splitting the rollup onto stable-amd and preserving the individual changes. The separate PRs make it easier to evaluate lazy copyback, shadow bookkeeping and PSO changes independently.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7255104278 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/51#issuecomment-7255104278). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T11:25:39Z. --- Thanks for splitting the rollup onto stable-amd and preserving the individual changes. The separate PRs make it easier to evaluate lazy copyback, shadow bookkeeping and PSO changes independently.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
PastiiJay/klbf-lab!51
No description provided.