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

Open
Skyfrye wants to merge 1 commit from upstream-pr/360 into main
Skyfrye commented 2026-11-26 13:05:40 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-26T13:05:40Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6627284889 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/360). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T13:05:40Z. --- ## 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)
LooperSalty commented 2026-11-26 14:34:12 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-26T14:34:12Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7195009090 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/360#issuecomment-7195009090). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T14:34:12Z. --- 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)
LooperSalty commented 2026-11-26 15:41:35 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-26T15:41:35Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7196620151 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/360#issuecomment-7196620151). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T15:41:35Z. --- 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)
Skyfrye commented 2026-11-26 16:02:28 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-26T16:02:28Z.


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.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7197098092 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/360#issuecomment-7197098092). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T16:02:28Z. --- 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.
LooperSalty commented 2026-11-26 17:26:25 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-26T17:26:25Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7199019225 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/360#issuecomment-7199019225). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T17:26:25Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/360:upstream-pr/360'
git switch 'upstream-pr/360'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/360'
git switch 'upstream-pr/360'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/360'
git switch 'upstream-pr/360'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/360'
git switch 'main'
git merge --squash 'upstream-pr/360'
git switch 'main'
git merge --ff-only 'upstream-pr/360'
git switch 'main'
git merge 'upstream-pr/360'
git push origin 'main'
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
LooperSalty/AnyXboxX!360
No description provided.