gpu/shadow: opt-in ReBAR GPU_UPLOAD heap with VRAM guard & WC streaming (3/4 of #51) #58

Closed
Vladimir-Human wants to merge 86 commits from upstream-pr/58 into main
Vladimir-Human commented 2026-11-26 00:43:59 +00:00 (Migrated from github.com)

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


Split 3/4 of #51 cleanly on top of beta (independent of #56, #57, and Part 4 Lazy Copy-Back).

Summary of Changes (crates/victory-gpu/src/shadow.rs)

  • Opt-in mod rebar (VICTORY_REBAR=1|2, default OFF): allocates host shadow buffers/windows in D3D12_HEAP_TYPE_GPU_UPLOAD after querying live adapter support and checking VRAM budget (1 for windows only, 2 for windows + buffers, keeping VICTORY_CARD_BUFFERS VRAM copies preferred when carded).
  • Concurrent headroom guard & OOM-safe accounting: tracks placed + in-flight ReBAR reservations atomically and rolls back CARD_BYTES / WINDOW_CARD_BYTES if shared_buffer staging allocation fails.
  • AVX2 VMOVNTDQA WC streaming helpers + _mm_sfence() ordering: adds copy_from_wc, slices_equal_wc, merge_gpu_into_title_runs, wc_sfence(), and TLS SCRATCH_WC so reads from write-combined ReBAR mappings avoid slow uncached byte reads while keeping sequential WC writes ordered.
  • Worker serialization for WC reads: routes WC snapshot/diff scans through serialized jobs (copy_jobs_wc / find_pieces_wc) and single-threaded differing to avoid thrashing PCIe read queues.
  • Unit & live-GPU tests + opt-in benchmark: rebar_tests::{rebar_wc_write_read_compare_roundtrip, simd_wc_and_gpu_merge_helpers_match_scalar_oracles} and #[ignore] bench_rebar (plus rebar::tests::rebar_decisions_and_concurrent_headroom_hold).

Verification (VICTORY_D3D12_DEBUG=1)

  • cargo test -p victory-gpu -> passed
  • cargo test -p victory-gpu --all-features -> passed
  • cargo run -p xtask -- policy --staged -> asset policy: 1 files ok (shadow.rs = 224,768 B)

Related: #51, #56, #57

<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5501800912 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/58). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T00:43:59Z. --- Split 3/4 of #51 cleanly on top of `beta` (independent of #56, #57, and Part 4 Lazy Copy-Back). ### Summary of Changes (`crates/victory-gpu/src/shadow.rs`) - **Opt-in `mod rebar` (`VICTORY_REBAR=1|2`, default OFF)**: allocates host shadow buffers/windows in `D3D12_HEAP_TYPE_GPU_UPLOAD` after querying live adapter support and checking VRAM budget (`1` for windows only, `2` for windows + buffers, keeping `VICTORY_CARD_BUFFERS` VRAM copies preferred when carded). - **Concurrent headroom guard & OOM-safe accounting**: tracks placed + in-flight ReBAR reservations atomically and rolls back `CARD_BYTES` / `WINDOW_CARD_BYTES` if `shared_buffer` staging allocation fails. - **AVX2 `VMOVNTDQA` WC streaming helpers + `_mm_sfence()` ordering**: adds `copy_from_wc`, `slices_equal_wc`, `merge_gpu_into_title_runs`, `wc_sfence()`, and TLS `SCRATCH_WC` so reads from write-combined ReBAR mappings avoid slow uncached byte reads while keeping sequential WC writes ordered. - **Worker serialization for WC reads**: routes WC snapshot/diff scans through serialized jobs (`copy_jobs_wc` / `find_pieces_wc`) and single-threaded `differing` to avoid thrashing PCIe read queues. - **Unit & live-GPU tests + opt-in benchmark**: `rebar_tests::{rebar_wc_write_read_compare_roundtrip, simd_wc_and_gpu_merge_helpers_match_scalar_oracles}` and `#[ignore] bench_rebar` (plus `rebar::tests::rebar_decisions_and_concurrent_headroom_hold`). ### Verification (`VICTORY_D3D12_DEBUG=1`) - `cargo test -p victory-gpu` -> passed - `cargo test -p victory-gpu --all-features` -> passed - `cargo run -p xtask -- policy --staged` -> `asset policy: 1 files ok` (`shadow.rs` = 224,768 B) Related: #51, #56, #57
HandshakeHackin commented 2026-11-26 02:58:59 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-26T02:58:59Z.


On hosted native Windows I forced the diagnostics software adapter and VICTORY_REBAR=2 at d29505a. WARP reported GPU-upload heap support, allocated and mapped the 256 KiB buffer, and completed the write/read/compare round trip, including detecting the altered byte. The verification wrapper required an initialized device and an explicit support or fallback marker, since the original live test can return early. This verifies buffer contents on WARP. The physical RX 9070 XT run is still needed for PCIe behavior and timings. Windows test and result

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7181290057 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/58#issuecomment-7181290057). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-26T02:58:59Z. --- On hosted native Windows I forced the diagnostics software adapter and `VICTORY_REBAR=2` at `d29505a`. WARP reported GPU-upload heap support, allocated and mapped the 256 KiB buffer, and completed the write/read/compare round trip, including detecting the altered byte. The verification wrapper required an initialized device and an explicit support or fallback marker, since the original live test can return early. This verifies buffer contents on WARP. The physical RX 9070 XT run is still needed for PCIe behavior and timings. [Windows test and result](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45745588363/job/139660707514)
PastiiJay commented 2026-11-26 10:42:11 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T10:42:11Z.


Thanks @HandshakeHackin for the GPU-upload round trip on WARP. The ReBAR path still needs a real-card run on our side, we'll do that next.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7189719259 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/58#issuecomment-7189719259). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T10:42:11Z. --- Thanks @HandshakeHackin for the GPU-upload round trip on WARP. The ReBAR path still needs a real-card run on our side, we'll do that next.
Vladimir-Human commented 2026-11-28 18:26:44 +00:00 (Migrated from github.com)

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


Superseded by https://github.com/PastiiJay/klbf-lab/pull/185 cleanly ported onto origin/stable-amd (75022ba).

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7243795139 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/58#issuecomment-7243795139). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:26:44Z. --- Superseded by https://github.com/PastiiJay/klbf-lab/pull/185 cleanly ported onto `origin/stable-amd` (`75022ba`).

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!58
No description provided.