perf: card_before splits ranges into flat masks, packs block masks by word and joins piece runs as they come #360

Open
github-bot wants to merge 1 commit from github-bot/gh-360 into main AGit
Owner

@⁠Skyfrye on GitHub · 2026-11-26 13:05 UTC · original
Skyfrye:nep/card-masks-flat → main · +154 −41 · 2 files · 1 commits · open

Change

In Host::card_before, which runs on the submitting thread once per submission for copies in the card's memory:

  • masked_blocks made a Vec for every 4 KiB block it sends by mask; the blocks now index one flat list of ranges (MaskedSplit).
  • block_mask set a mask's bits one byte at a time; it now fills 64-bit words. The bytes out are the same, and a test compares them with the old form.
  • With rehash_runs or many runs under shader writes, a copy's ranges became a Vec of piece runs that joined_piece_runs then sorted and joined (tens of thousands of two-byte runs in the world). They are now joined as they come (joined_piece_runs_iter), since they arrive in order. Out-of-order input falls back to the old join. joined and joined_piece_runs skip the sort when their input is already in order.

The output is the same for every input. Only the allocations and the work on the submitting thread change.

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), on upstream main at 8ed1109, from third_party/victory:

cargo build --locked --release -p victory                 -> Finished; the 2 warnings main has, no new one
cargo test --locked -p victory-gpu --lib mask_tests        -> 1 passed
cargo test --locked -p victory-gpu --lib card_tests        -> 7 passed

The tests:

  • crowded_blocks_go_up_by_mask_and_the_rest_as_copies checks the flat split for both least paths, including ranges cut at block edges. It also checks the word-packed mask against the old byte-by-byte form at the block's edges and at 63/64-bit boundaries.
  • piece_runs_join_without_losing_or_adding_pieces checks that the streaming join, fed sorted and unsorted input, equals the old join.

These tests do not build without the change.

In the world, my copy of the game, Series X, VICTORY_INDIRECT_RAW=3, the launcher's switches (VICTORY_WIDE_REFRESH=1 among them): one run of 300 s with this PR stacked with the other parts of the same split (#360, #361, #362) and #278, #279, #291, #292, #307, on main at 8ed1109.

  • The picture: checked by screen captures every 15 s. The prison cutscene, the cell and the corridor are drawn as on main. There was no exception and no device lost.
  • Frame rate: a median of 13.2 fps over the last 3 minutes, against 12.6 to 12.8 in earlier runs of main-like builds. That run got further into the story (the corridor, about 6,300 draws a frame), and the machine was about 60 % loaded by other work, so the difference is within what separates two runs here.
  • An earlier build with all of commit 22d77e4 (texture refreshes on the wide threads too, which this split leaves out; see #362) ran at 15.5 fps against 12.6 to 12.8.
  • No separate run per PR. These parts take CPU time off the submitting thread. I did not measure each on its own.

Oracle and test data

No game file.

Checklist

  • The PR covers a single reviewable behaviour: the same card-side ranges, masks and piece runs, computed with fewer allocations.
  • A test fails without this change and passes with it (the tests do not build without it).
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Nothing unimplemented here.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: run counts only; no title code.
  • Code taken from another project: none. The code comes from a commit made with Antigravity in this fork's work (see below).

AI assistance: the code was written with Antigravity (Google's AI IDE, model gemini-4-neon-medium) in commit 22d77e4 of a local branch. Claude Opus 5.5, in Claude Code, reduced it to this change, ported it to main, reviewed it (with a separate Claude Opus 5.5 review of the whole commit), ran the checks and the game, and wrote this description.

🤖 Generated with Claude Code

**@⁠Skyfrye** on GitHub · 2026-11-26 13:05 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/360) `Skyfrye:nep/card-masks-flat` → `main` · +154 −41 · 2 files · 1 commits · open ## Change In `Host::card_before`, which runs on the submitting thread once per submission for copies in the card's memory: - `masked_blocks` made a `Vec` for every 4 KiB block it sends by mask; the blocks now index one flat list of ranges (`MaskedSplit`). - `block_mask` set a mask's bits one byte at a time; it now fills 64-bit words. The bytes out are the same, and a test compares them with the old form. - With `rehash_runs` or many runs under shader writes, a copy's ranges became a `Vec` of piece runs that `joined_piece_runs` then sorted and joined (tens of thousands of two-byte runs in the world). They are now joined as they come (`joined_piece_runs_iter`), since they arrive in order. Out-of-order input falls back to the old join. `joined` and `joined_piece_runs` skip the sort when their input is already in order. The output is the same for every input. Only the allocations and the work on the submitting thread change. Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), on upstream `main` at `8ed1109`, from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished; the 2 warnings main has, no new one cargo test --locked -p victory-gpu --lib mask_tests -> 1 passed cargo test --locked -p victory-gpu --lib card_tests -> 7 passed ``` The tests: - `crowded_blocks_go_up_by_mask_and_the_rest_as_copies` checks the flat split for both `least` paths, including ranges cut at block edges. It also checks the word-packed mask against the old byte-by-byte form at the block's edges and at 63/64-bit boundaries. - `piece_runs_join_without_losing_or_adding_pieces` checks that the streaming join, fed sorted and unsorted input, equals the old join. These tests do not build without the change. In the world, my copy of the game, Series X, `VICTORY_INDIRECT_RAW=3`, the launcher's switches (`VICTORY_WIDE_REFRESH=1` among them): one run of 300 s with this PR stacked with the other parts of the same split (#360, #361, #362) and #278, #279, #291, #292, #307, on `main` at `8ed1109`. - **The picture:** checked by screen captures every 15 s. The prison cutscene, the cell and the corridor are drawn as on `main`. There was no exception and no device lost. - **Frame rate:** a median of 13.2 fps over the last 3 minutes, against 12.6 to 12.8 in earlier runs of main-like builds. That run got further into the story (the corridor, about 6,300 draws a frame), and the machine was about 60 % loaded by other work, so the difference is within what separates two runs here. - **An earlier build** with all of commit 22d77e4 (texture refreshes on the wide threads too, which this split leaves out; see #362) ran at 15.5 fps against 12.6 to 12.8. - **No separate run per PR.** These parts take CPU time off the submitting thread. I did not measure each on its own. ## Oracle and test data No game file. ## Checklist - [x] The PR covers a single reviewable behaviour: the same card-side ranges, masks and piece runs, computed with fewer allocations. - [x] A test fails without this change and passes with it (the tests do not build without it). - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Nothing unimplemented here.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: run counts only; no title code. - [x] Code taken from another project: none. The code comes from a commit made with Antigravity in this fork's work (see below). AI assistance: the code was written with Antigravity (Google's AI IDE, model gemini-4-neon-medium) in commit 22d77e4 of a local branch. Claude Opus 5.5, in Claude Code, reduced it to this change, ported it to `main`, reviewed it (with a separate Claude Opus 5.5 review of the whole commit), ran the checks and the game, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
For copies in the card's memory, `card_before` runs on the submitting
thread once per submission:
- `masked_blocks` made a `Vec` per 4 KiB block it sent by mask; the
  blocks now index one flat list of ranges (`MaskedSplit`).
- `block_mask` set the mask's bits one byte at a time; it now fills
  64-bit words, with the same bytes out (checked against the old
  version in the tests).
- With `rehash_runs` or many runs under shader writes, the copy's ranges
  became a `Vec` of piece runs that `joined_piece_runs` then sorted and
  joined: tens of thousands of two-byte runs in the world. They are now
  joined as they come (`joined_piece_runs_iter`), in order already;
  out-of-order input falls back to the old join. `joined` and
  `joined_piece_runs` skip the sort when their input is in order.

Same output for every input; tests compare the new against the old forms.

Code from Antigravity (gemini-4-neon-medium), commit 22d77e4 of the
perf/submit-deferred-card branch, reduced to this change and ported to
main by Claude Opus 5.5.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:10:06 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 14:34 UTC · original

Diff read, nothing run. This PR changes the card_before range and block-mask code in victory-gpu/src/host.rs and shadow.rs but adds no test (rule 5 of AGENTS.md: a new behaviour comes with a test that fails without it). Please add a unit test that checks the flat masks, the word packing and the piece-run joining against the previous implementation on the same ranges, then CI can run on the updated branch.

🤖 Generated with Claude Code

**@⁠LooperSalty** on GitHub · 2026-11-26 14:34 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/360#issuecomment-7195009090) Diff read, nothing run. This PR changes the card_before range and block-mask code in `victory-gpu/src/host.rs` and `shadow.rs` but adds no test (rule 5 of AGENTS.md: a new behaviour comes with a test that fails without it). Please add a unit test that checks the flat masks, the word packing and the piece-run joining against the previous implementation on the same ranges, then CI can run on the updated branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 15:41 UTC · original

This PR now conflicts with main in third_party/victory/crates/victory-gpu/src/host.rs (main moved with #358, #377 and #386). Please rebase on main, re-run the victory-gpu tests and force-push your branch.

🤖 Generated with Claude Code

**@⁠LooperSalty** on GitHub · 2026-11-26 15:41 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/360#issuecomment-7196620151) This PR now conflicts with main in `third_party/victory/crates/victory-gpu/src/host.rs` (main moved with #358, #377 and #386). Please rebase on main, re-run the victory-gpu tests and force-push your branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot force-pushed github-bot/gh-360 from 8f7374fc12 to 12c9f291ad 2026-11-26 16:06:37 +00:00 Compare
Author
Owner

@⁠Skyfrye on GitHub · 2026-11-26 16:02 UTC · original

Rebased onto main at f9f1181, over #383. #383 moved the hash passes into its hash_passes closure; this PR's streaming join of piece runs (joined_piece_runs_iter) now runs inside that closure. So it applies with VICTORY_CARD_SYNC_BATCH on (as #386 sets it) and off. The flat masks, the word-packed block masks and the sort skip in shadow.rs applied as they were, and #383's declared_in in card_before is untouched. Checks on 8473267 (nothing in third_party/victory changed from there to f9f1181): release build with only main's 2 warnings; mask_tests card_tests 8 passed under WARP. The ignored two_dirty_card_buffers_reach_readback_in_the_same_submission passed with VICTORY_CARD_SYNC_BATCH=0 and =1. The full lib suite with #383's switches on gave 236 passed and 3 failed (the 3 that fail on main). The in-game figures in the description are from before the rebase. Rebase done by a Claude Opus 5.5 subagent, checked by Claude Opus 5.5.

**@⁠Skyfrye** on GitHub · 2026-11-26 16:02 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/360#issuecomment-7197098092) Rebased onto `main` at `f9f1181`, over #383. #383 moved the hash passes into its `hash_passes` closure; this PR's streaming join of piece runs (`joined_piece_runs_iter`) now runs inside that closure. So it applies with `VICTORY_CARD_SYNC_BATCH` on (as #386 sets it) and off. The flat masks, the word-packed block masks and the sort skip in `shadow.rs` applied as they were, and #383's `declared_in` in `card_before` is untouched. Checks on `8473267` (nothing in `third_party/victory` changed from there to `f9f1181`): release build with only main's 2 warnings; `mask_tests card_tests` 8 passed under WARP. The ignored `two_dirty_card_buffers_reach_readback_in_the_same_submission` passed with `VICTORY_CARD_SYNC_BATCH=0` and `=1`. The full lib suite with #383's switches on gave 236 passed and 3 failed (the 3 that fail on main). The in-game figures in the description are from before the rebase. Rebase done by a Claude Opus 5.5 subagent, checked by Claude Opus 5.5.
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 17:26 UTC · original

Nit: block_mask now clamps with saturating_sub and min. A range outside its block no longer fails: it sets bits from the block's start, where the old form panicked on underflow. masked_blocks guarantees the containment, so a debug_assert! that each range lies in [base, base + 4096) would keep a violation loud in debug builds.

🤖 Generated with Claude Code

**@⁠LooperSalty** on GitHub · 2026-11-26 17:26 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/360#issuecomment-7199019225) Nit: `block_mask` now clamps with `saturating_sub` and `min`. A range outside its block no longer fails: it sets bits from the block's start, where the old form panicked on underflow. `masked_blocks` guarantees the containment, so a `debug_assert!` that each range lies in `[base, base + 4096)` would keep a violation loud in debug builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request has changes conflicting with the target branch.
  • third_party/victory/crates/victory-gpu/src/host.rs
  • third_party/victory/crates/victory-gpu/src/shadow.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/360/head:github-bot/gh-360'
git switch 'github-bot/gh-360'

Merge

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