Port opt-in GPU byte-masked patch uploads (VICTORY_MASKED_PATCH) #269

Closed
github-bot wants to merge 552 commits from github-bot/gh-269 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 13:05 UTC · original
Vladimir-Human:perf/masked-patch-uploads → main · +47008 −4130 · 187 files · 552 commits · closed without merging

Summary

Ports opt-in VICTORY_MASKED_PATCH (off by default; adapted from fxceless/victory-fork commits 3221ac4, 0e006f0, and 50c79c3) into victory-gpu.

With VICTORY_MASKED_PATCH unset or 0 (default), baseline behavior is unchanged: the MASKED_PATCH compute pipeline is not compiled, card_patches() is a no-op, and pages exceeding the per-submission run cap settle flights as before. When opted in via VICTORY_MASKED_PATCH=1 (or alt for 20s alternating comparison, or VICTORY_AB under diagnostics), pages exceeding runs_left emit folded 12-byte (offset, mask, value) dword patches applied via a MASKED_PATCH compute pass sharing CARD_COMPARE's root signature instead of stalling the queue.

Key Changes

  • crates/victory-gpu/src/shadow.rs:
    • Adds PatchWord, Patch, Card::{patch, has_patch}, opt-in masked_patch_mode() (0 off by default, 1 on, alt 20s alternating, plus VICTORY_AB under diagnostics), PATCH_READY, masked_patch_now(), patch_words(), chronological folded() dword merging, exact-piece piece_spans(), and card_patches(sent_as).
    • Integrates PageMerge::{Dirty, Patched} into parallel merge_under_writes / merge_page_under_writes, restoring unspent left budget and emitting exact byte-masked words when a page exceeds the cap (with at + n <= u32::MAX - 3 bounds safety).
    • Maintains acyclic lock order (dirty -> patch -> sent), updates lock-free card_merge_relay and land_card fast paths (publishing has_sent before clearing has_patch), and includes pending masked-patch ranges in card_dirty_now.
  • crates/victory-gpu/src/host/masked_patch.rs & crates/victory-gpu/src/host.rs:
    • Compiles MASKED_PATCH (cs_5_1) sharing CARD_COMPARE's root signature only when opted in, and pools patch upload buffers (PATCH_POOL_MOST = 4).
    • Runs MASKED_PATCH in Host::card_before before card.dirty (send::Own / upq / direct copies) so newer dirty ranges always win over earlier patch words—including sub-dword byte overlaps within the same 32-bit dword—while preserving untouched sibling bytes written by in-flight shaders, with exact D3D12 state transitions (upcheck / dirty / before) and CARD_COMPARE piece rehashing over ranges.iter().chain(patched).
    • Logs per-frame masked-patch counts (pages, dwords, dispatches, submissions) alongside the wait/settle breakdown when enabled.
  • crates/victory-gpu/src/indirect.rs & crates/victory-gpu/src/host/masked_patch.rs tests:
    • Adds opt-in default tests (masked_patch_defaults_off_and_parses_opt_in_modes, baseline settle vs opt-in patch check in merge_under_writes_patches_past_run_cap_without_settling).
    • Adds D3D12 HW and WARP parity and sub-dword overlap ordering tests (hw_masked_patch_byte_mask_and_dirty_ordering, warp_masked_patch_byte_mask_and_dirty_ordering, and hw_host_card_before_applies_masked_patch_and_dirty_in_order running real Host::card_before in isolated VICTORY_MASKED_PATCH=1 subprocesses on HW and WARP with ID3D12InfoQueue 0-error assertions) covering all 3 within-dword overlap cases ([patch0, dirty1, dirty2, dirty3], [patch0, dirty1, dirty2, flight 0xEE], [dirty0, dirty1, patch2, patch3]), aligned 4-byte SCATTER dirty override, overlapping patches, and CARD_COMPARE rehash + mutation detection.

Verification (rustc 1.98.1 & 1.100.0, VICTORY_D3D12_DEBUG=1, --test-threads=1)

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default & --features diagnostics): 0 warnings
  • cargo run -p xtask --locked -- policy --staged (4 files ok), xtask policy (314 files ok), cargo test -p xtask --locked (11/11 passed)
  • victory-gpu PR A suite (masked_patch, piece_spans_preserve_exact_rehash_piece_set, lock_free_card_, merge_under_writes_patches_past_run_cap_without_settling, warp_card_compare_stores_the_hash_it_made_when_told): 11/11 HW default, 11/11 HW diagnostics, 11/11 WARP diagnostics (0 skips, 0 D3D12 debug errors).

Credit: adapted from fxceless/victory-fork (3221ac4, 0e006f0, 50c79c3).

**@⁠Vladimir-Human** on GitHub · 2026-11-27 13:05 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/269) `Vladimir-Human:perf/masked-patch-uploads` → `main` · +47008 −4130 · 187 files · 552 commits · closed without merging ## Summary Ports opt-in `VICTORY_MASKED_PATCH` (off by default; adapted from `fxceless/victory-fork` commits `3221ac4`, `0e006f0`, and `50c79c3`) into `victory-gpu`. With `VICTORY_MASKED_PATCH` unset or `0` (default), baseline behavior is unchanged: the `MASKED_PATCH` compute pipeline is not compiled, `card_patches()` is a no-op, and pages exceeding the per-submission run cap settle flights as before. When opted in via `VICTORY_MASKED_PATCH=1` (or `alt` for 20s alternating comparison, or `VICTORY_AB` under `diagnostics`), pages exceeding `runs_left` emit folded 12-byte `(offset, mask, value)` dword patches applied via a `MASKED_PATCH` compute pass sharing `CARD_COMPARE`'s root signature instead of stalling the queue. ### Key Changes - **`crates/victory-gpu/src/shadow.rs`:** - Adds `PatchWord`, `Patch`, `Card::{patch, has_patch}`, opt-in `masked_patch_mode()` (`0` off by default, `1` on, `alt` 20s alternating, plus `VICTORY_AB` under `diagnostics`), `PATCH_READY`, `masked_patch_now()`, `patch_words()`, chronological `folded()` dword merging, exact-piece `piece_spans()`, and `card_patches(sent_as)`. - Integrates `PageMerge::{Dirty, Patched}` into parallel `merge_under_writes` / `merge_page_under_writes`, restoring unspent `left` budget and emitting exact byte-masked words when a page exceeds the cap (with `at + n <= u32::MAX - 3` bounds safety). - Maintains acyclic lock order (`dirty -> patch -> sent`), updates lock-free `card_merge_relay` and `land_card` fast paths (publishing `has_sent` before clearing `has_patch`), and includes pending masked-patch ranges in `card_dirty_now`. - **`crates/victory-gpu/src/host/masked_patch.rs` & `crates/victory-gpu/src/host.rs`:** - Compiles `MASKED_PATCH` (`cs_5_1`) sharing `CARD_COMPARE`'s root signature only when opted in, and pools patch upload buffers (`PATCH_POOL_MOST = 4`). - Runs `MASKED_PATCH` in `Host::card_before` **before** `card.dirty` (`send::Own` / `upq` / direct copies) so newer dirty ranges always win over earlier patch words—including sub-dword byte overlaps within the same 32-bit dword—while preserving untouched sibling bytes written by in-flight shaders, with exact D3D12 state transitions (`upcheck` / `dirty` / `before`) and `CARD_COMPARE` piece rehashing over `ranges.iter().chain(patched)`. - Logs per-frame masked-patch counts (`pages`, `dwords`, `dispatches`, `submissions`) alongside the wait/settle breakdown when enabled. - **`crates/victory-gpu/src/indirect.rs` & `crates/victory-gpu/src/host/masked_patch.rs` tests:** - Adds opt-in default tests (`masked_patch_defaults_off_and_parses_opt_in_modes`, baseline settle vs opt-in patch check in `merge_under_writes_patches_past_run_cap_without_settling`). - Adds D3D12 HW and WARP parity and sub-dword overlap ordering tests (`hw_masked_patch_byte_mask_and_dirty_ordering`, `warp_masked_patch_byte_mask_and_dirty_ordering`, and `hw_host_card_before_applies_masked_patch_and_dirty_in_order` running real `Host::card_before` in isolated `VICTORY_MASKED_PATCH=1` subprocesses on HW and WARP with `ID3D12InfoQueue` 0-error assertions) covering all 3 within-dword overlap cases (`[patch0, dirty1, dirty2, dirty3]`, `[patch0, dirty1, dirty2, flight 0xEE]`, `[dirty0, dirty1, patch2, patch3]`), aligned 4-byte `SCATTER` dirty override, overlapping patches, and `CARD_COMPARE` rehash + mutation detection. ### Verification (`rustc 1.98.1` & `1.100.0`, `VICTORY_D3D12_DEBUG=1`, `--test-threads=1`) - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default & `--features diagnostics`): **0 warnings** - `cargo run -p xtask --locked -- policy --staged` (`4 files ok`), `xtask policy` (`314 files ok`), `cargo test -p xtask --locked` (**11/11 passed**) - `victory-gpu` PR A suite (`masked_patch`, `piece_spans_preserve_exact_rehash_piece_set`, `lock_free_card_`, `merge_under_writes_patches_past_run_cap_without_settling`, `warp_card_compare_stores_the_hash_it_made_when_told`): **11/11 HW default**, **11/11 HW `diagnostics`**, **11/11 WARP `diagnostics`** (0 skips, **0 D3D12 debug errors**). Credit: adapted from `fxceless/victory-fork` (`3221ac4`, `0e006f0`, `50c79c3`).
When title memory changes under in-flight GPU shader writes past the per-page
merge cap, emit folded 12-byte `(offset, mask, value)` dword patches and apply
them on the GPU via `MASKED_PATCH` compute dispatches (sharing `CARD_COMPARE`'s
root signature) instead of stalling the queue to settle flights.

Runs masked patches before `card.dirty` uploads (`send::Own` / `upq` / direct
copies) so newer dirty ranges cleanly override older patch words while
untouched sibling bytes written by in-flight shaders are preserved, rehashes
the exact patched 64 KiB piece set, protects lock-free `card_merge_relay` /
`land_card` fast paths and `card_dirty_now`, pools patch upload buffers, and
supports `VICTORY_MASKED_PATCH=1|0|alt` (default ON). Includes unit tests plus
D3D12 HW and WARP byte-mask and `card.dirty` ordering parity tests.

Adapted from fxceless/victory-fork (`3221ac4`, `0e006f0`, `50c79c3`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:14:41 +00:00
Author
Owner

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

@⁠Vladimir-Human Keep masked patches opt-in for the first comparison. A newer dirty copy must still win over an earlier patch, including a byte overlap within one dword. That ordering test and a same-route wait measurement will tell us more than enabling it by default.

**@⁠TaynanGT** on GitHub · 2026-11-27 13:09 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/269#issuecomment-7219125813) @⁠Vladimir-Human Keep masked patches opt-in for the first comparison. A newer dirty copy must still win over an earlier patch, including a byte overlap within one dword. That ordering test and a same-route wait measurement will tell us more than enabling it by default.
github-bot changed title from Port GPU byte-masked patch uploads (VICTORY_MASKED_PATCH) to Port opt-in GPU byte-masked patch uploads (VICTORY_MASKED_PATCH) 2026-11-27 13:48:12 +00:00
github-bot force-pushed github-bot/gh-269 from 5d31b8e485 to cfddee33a7 2026-11-27 13:48:13 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 13:47 UTC · original

@⁠TaynanGT Updated in cfddee33 to address both points:

  1. Opt-in by default (VICTORY_MASKED_PATCH=0 / unset):

    • shadow::masked_patch_mode() now defaults to 0 (off). When unset or 0, Host::make_card_work skips compiling the MASKED_PATCH PSO (PATCH_READY stays false), card_patches() returns immediately, and merge_under_writes settles flights as baseline.
    • Explicit VICTORY_MASKED_PATCH=1, VICTORY_MASKED_PATCH=alt (20s alternating), or VICTORY_AB (under diagnostics) opts in and logs per-frame masked-patch counts (pages, dwords, dispatches, submissions) alongside the existing wait/settle breakdown for same-route comparisons.
    • Added unit coverage in shadow::copied_and_take_tests::masked_patch_defaults_off_and_parses_opt_in_modes and updated merge_under_writes_patches_past_run_cap_without_settling to verify both default-off baseline settling and opt-in masked patching.
  2. D3D12 HW + WARP sub-dword overlap ordering tests (VICTORY_D3D12_DEBUG=1):

    • Confirmed Host::card_before orders MASKED_PATCH -> transition barrier -> card.dirty (send::Own CopyBufferRegion/SCATTER, upq, or direct copy) -> CARD_COMPARE rehash, with self.data updated synchronously when each patch or dirty run is recorded.
    • Added explicit within-dword sub-byte overlap checks to both indirect::tests::{hw,warp}_masked_patch_byte_mask_and_dirty_ordering (dwords 128..140) and host::masked_patch::tests::hw_host_card_before_applies_masked_patch_and_dirty_in_order (dwords 16..28, running the real Host::card_before path in isolated VICTORY_MASKED_PATCH=1 subprocesses on HW and, under diagnostics, WARP with ID3D12InfoQueue 0-error assertions):
      • earlier masked patch on bytes 0..=1 + newer dirty copy on bytes 1..=3 -> [patch0, dirty1, dirty2, dirty3]
      • earlier masked patch on bytes 0..=1 + newer dirty copy on bytes 1..=2 + untouched flight byte 3 (0xEE) -> [patch0, dirty1, dirty2, 0xEE]
      • earlier masked patch on bytes 1..=3 + newer dirty copy on bytes 0..=1 -> [dirty0, dirty1, patch2, patch3]
      • plus aligned 4-byte SCATTER dirty override over an earlier masked patch.

Re-verified locally (VICTORY_D3D12_DEBUG=1, --test-threads=1): clippy --all-targets --locked -- -D warnings (default & diagnostics) 0 warnings, xtask policy (314 files ok) & xtask tests 11/11, and the PR test suite 11/11 HW default, 11/11 HW diagnostics, and 11/11 WARP diagnostics (0 D3D12 debug errors).

**@⁠Vladimir-Human** on GitHub · 2026-11-27 13:47 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/269#issuecomment-7219949438) @⁠TaynanGT Updated in `cfddee33` to address both points: 1. **Opt-in by default (`VICTORY_MASKED_PATCH=0` / unset):** - `shadow::masked_patch_mode()` now defaults to `0` (off). When unset or `0`, `Host::make_card_work` skips compiling the `MASKED_PATCH` PSO (`PATCH_READY` stays `false`), `card_patches()` returns immediately, and `merge_under_writes` settles flights as baseline. - Explicit `VICTORY_MASKED_PATCH=1`, `VICTORY_MASKED_PATCH=alt` (20s alternating), or `VICTORY_AB` (under `diagnostics`) opts in and logs per-frame masked-patch counts (`pages`, `dwords`, `dispatches`, `submissions`) alongside the existing wait/settle breakdown for same-route comparisons. - Added unit coverage in `shadow::copied_and_take_tests::masked_patch_defaults_off_and_parses_opt_in_modes` and updated `merge_under_writes_patches_past_run_cap_without_settling` to verify both default-off baseline settling and opt-in masked patching. 2. **D3D12 HW + WARP sub-dword overlap ordering tests (`VICTORY_D3D12_DEBUG=1`):** - Confirmed `Host::card_before` orders `MASKED_PATCH` -> transition barrier -> `card.dirty` (`send::Own` `CopyBufferRegion`/`SCATTER`, `upq`, or direct copy) -> `CARD_COMPARE` rehash, with `self.data` updated synchronously when each patch or dirty run is recorded. - Added explicit within-dword sub-byte overlap checks to both `indirect::tests::{hw,warp}_masked_patch_byte_mask_and_dirty_ordering` (dwords `128..140`) and `host::masked_patch::tests::hw_host_card_before_applies_masked_patch_and_dirty_in_order` (dwords `16..28`, running the real `Host::card_before` path in isolated `VICTORY_MASKED_PATCH=1` subprocesses on HW and, under `diagnostics`, WARP with `ID3D12InfoQueue` 0-error assertions): - earlier masked patch on bytes `0..=1` + newer dirty copy on bytes `1..=3` -> `[patch0, dirty1, dirty2, dirty3]` - earlier masked patch on bytes `0..=1` + newer dirty copy on bytes `1..=2` + untouched flight byte `3` (`0xEE`) -> `[patch0, dirty1, dirty2, 0xEE]` - earlier masked patch on bytes `1..=3` + newer dirty copy on bytes `0..=1` -> `[dirty0, dirty1, patch2, patch3]` - plus aligned 4-byte `SCATTER` dirty override over an earlier masked patch. Re-verified locally (`VICTORY_D3D12_DEBUG=1`, `--test-threads=1`): `clippy --all-targets --locked -- -D warnings` (default & `diagnostics`) **0 warnings**, `xtask policy` (`314 files ok`) & `xtask` tests **11/11**, and the PR test suite **11/11 HW default**, **11/11 HW `diagnostics`**, and **11/11 WARP `diagnostics`** (0 D3D12 debug errors).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 13:51 UTC · original

@⁠Vladimir-Human The default-off path and the overlapping-byte checks are the controls we needed. Keep the later dirty write winning and the untouched byte stable in the full path. The matched run can now compare settle time and the masked-patch counters separately.

**@⁠TaynanGT** on GitHub · 2026-11-27 13:51 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/269#issuecomment-7220036004) @⁠Vladimir-Human The default-off path and the overlapping-byte checks are the controls we needed. Keep the later dirty write winning and the untouched byte stable in the full path. The matched run can now compare settle time and the masked-patch counters separately.
github-bot referenced this pull request from a commit 2026-11-30 15:24:03 +00:00
github-bot closed this pull request 2026-11-30 17:15:07 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-30 17:13 UTC · original

main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

**@⁠TaynanGT** on GitHub · 2026-11-30 17:13 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/269#issuecomment-7285931094) `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.