perf: refreshes that precede a shader write run on the wide threads #362

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

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


Change

When a list's shaders write a range of a host copy (Step::GpuWrite), the copy's pending refresh used to run first, synchronously on the submitting thread (Batch::flush_one, then Shadow::writing). That bypassed the threads that run the other refreshes of a submission (VICTORY_WIDE_REFRESH=1, which the launcher sets). In a frame of the world those refreshes are 2.6 to 3.1 ms of the submitting thread, over some 5,200 declarations.

Now the batch keeps an ordered list of steps per copy (ShadowStep):

  • Refresh: refreshes with nothing between them, merged as before.
  • Write: the first declaration of a range in the submission, which keeps its bytes.
  • Barrier: a repeated declaration, which does nothing itself but keeps the refreshes before it apart from those after it.

Batch::flush runs each copy's list as one job on the wide threads (with 4 copies or more), or serially otherwise, inside the flush's one write-watch asking. A repeated declaration of the same range is skipped, as writing and Flights::declare already did (once per submission).

card_before and the copy-back still take the submission's declared ranges from #383's declared_in / declared_writes, as on main (by an index with VICTORY_STEP_INDEX). The batch only keeps a set of (copy, range) to tell a range's first declaration from a repeat.

Order kept:

  • Per copy, Refresh → Write → later Refreshes, as flush_one-then-writing did.
  • Title copies and Step::Run still flush everything, pending writes included, before they write title memory.
  • One job per copy per wave, so a copy's CPU side has one writer at a time. Workers call the same writing/update as before, so the lock order matches what the relay thread already does concurrently.

Texture refreshes are left as on main. With #383's VICTORY_PARALLEL_REFRESH (on by default since #386), Batch::flush runs check_textures() first, then the copies' steps: no texture check runs beside a copy's work.

A note on #383, not checked by me: watch::writes resets the kernel's write-watch notes and then records them, which is not atomic across threads. Two texture checks side by side over the same pages, not asked ahead, could miss a write for a submission. This was the reason the original commit's parallel texture refreshes were left out of this PR.

Linked issue: none.

Verification

Rebased on 2026-11-26 onto upstream main at f9f1181, over #383. The conflicts were in card_before's declared ranges and in Batch::flush: #383's code is kept in both, and this PR's own declared-range list is dropped. Checks were run on 8473267; nothing in third_party/victory changed from there to f9f1181.

Windows 11 26300, Rust 1.98.1 (MSVC), from third_party/victory:

cargo build --locked --release -p victory                                    -> Finished; the 2 warnings main has, no new one
cargo check -p victory-gpu --lib --features diagnostics                       -> OK
cargo test --locked -p victory-gpu --lib batch::                               -> 7 passed, 1 ignored (the existing benchmark)
VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib   -> 239 passed, 3 failed (with VICTORY_STEP_INDEX, VICTORY_CARD_SYNC_BATCH, VICTORY_PARALLEL_REFRESH and VICTORY_WIDE_REFRESH set)

The 3 failures are those of main: spans_say_the_next_start_and_the_lowest_level_viewed, warp_card_fetch_copies_flagged_pieces_to_their_slots, warp_card_patch_writes_the_masked_bytes_and_no_others.

New tests in host::batch. They do not build without the change.

  • refreshes_merge_up_to_the_next_step_between_them
  • a_copys_refreshes_and_shader_writes_keep_their_order: interleavings over two copies, a repeated declaration, a copy with only shader writes, and what follows a flush.
  • a_range_given_again_keeps_no_bytes_across_flushes: each (copy, range) gives one Write, in the flush where it was first given.

In the world, before the rebase (not repeated since), 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: refreshes that precede a shader write run with the submission's other refreshes, on the wide threads, in the same per-copy order.
  • 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: step counts and timings; 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 comes from commit 22d77e4 of a local branch, written with Antigravity (Google's AI IDE, model gemini-4-neon-medium).
  • A Claude Opus 5.5 subagent in Claude Code reduced it to this change and ported it to main. It also kept texture refreshes serial and kept card_before's own submission, after a separate Claude Opus 5.5 review of 22d77e4 found a race and a resource-state bug there.
  • A Claude Opus 5.5 subagent rebased it over #383.
  • Claude Opus 5.5 (coordinating) checked the port, ran the game and wrote this description.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6627286784 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/362). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T13:05:46Z. --- ## Change When a list's shaders write a range of a host copy (`Step::GpuWrite`), the copy's pending refresh used to run first, synchronously on the submitting thread (`Batch::flush_one`, then `Shadow::writing`). That bypassed the threads that run the other refreshes of a submission (`VICTORY_WIDE_REFRESH=1`, which the launcher sets). In a frame of the world those refreshes are 2.6 to 3.1 ms of the submitting thread, over some 5,200 declarations. Now the batch keeps an ordered list of steps per copy (`ShadowStep`): - **Refresh:** refreshes with nothing between them, merged as before. - **Write:** the first declaration of a range in the submission, which keeps its bytes. - **Barrier:** a repeated declaration, which does nothing itself but keeps the refreshes before it apart from those after it. `Batch::flush` runs each copy's list as one job on the wide threads (with 4 copies or more), or serially otherwise, inside the flush's one write-watch asking. A repeated declaration of the same range is skipped, as `writing` and `Flights::declare` already did (once per submission). `card_before` and the copy-back still take the submission's declared ranges from #383's `declared_in` / `declared_writes`, as on `main` (by an index with `VICTORY_STEP_INDEX`). The batch only keeps a set of (copy, range) to tell a range's first declaration from a repeat. Order kept: - Per copy, Refresh → Write → later Refreshes, as `flush_one`-then-`writing` did. - Title copies and `Step::Run` still flush everything, pending writes included, before they write title memory. - One job per copy per wave, so a copy's CPU side has one writer at a time. Workers call the same `writing`/`update` as before, so the lock order matches what the relay thread already does concurrently. Texture refreshes are left as on `main`. With #383's `VICTORY_PARALLEL_REFRESH` (on by default since #386), `Batch::flush` runs `check_textures()` first, then the copies' steps: no texture check runs beside a copy's work. A note on #383, not checked by me: `watch::writes` resets the kernel's write-watch notes and then records them, which is not atomic across threads. Two texture checks side by side over the same pages, not asked ahead, could miss a write for a submission. This was the reason the original commit's parallel texture refreshes were left out of this PR. Linked issue: none. ## Verification Rebased on 2026-11-26 onto upstream `main` at `f9f1181`, over #383. The conflicts were in `card_before`'s declared ranges and in `Batch::flush`: #383's code is kept in both, and this PR's own declared-range list is dropped. Checks were run on `8473267`; nothing in `third_party/victory` changed from there to `f9f1181`. Windows 11 26300, Rust 1.98.1 (MSVC), from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished; the 2 warnings main has, no new one cargo check -p victory-gpu --lib --features diagnostics -> OK cargo test --locked -p victory-gpu --lib batch:: -> 7 passed, 1 ignored (the existing benchmark) VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib -> 239 passed, 3 failed (with VICTORY_STEP_INDEX, VICTORY_CARD_SYNC_BATCH, VICTORY_PARALLEL_REFRESH and VICTORY_WIDE_REFRESH set) ``` The 3 failures are those of `main`: `spans_say_the_next_start_and_the_lowest_level_viewed`, `warp_card_fetch_copies_flagged_pieces_to_their_slots`, `warp_card_patch_writes_the_masked_bytes_and_no_others`. New tests in `host::batch`. They do not build without the change. - `refreshes_merge_up_to_the_next_step_between_them` - `a_copys_refreshes_and_shader_writes_keep_their_order`: interleavings over two copies, a repeated declaration, a copy with only shader writes, and what follows a flush. - `a_range_given_again_keeps_no_bytes_across_flushes`: each (copy, range) gives one `Write`, in the flush where it was first given. In the world, before the rebase (not repeated since), 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: refreshes that precede a shader write run with the submission's other refreshes, on the wide threads, in the same per-copy order. - [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: step counts and timings; 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 comes from commit 22d77e4 of a local branch, written with Antigravity (Google's AI IDE, model gemini-4-neon-medium). - A Claude Opus 5.5 subagent in Claude Code reduced it to this change and ported it to `main`. It also kept texture refreshes serial and kept `card_before`'s own submission, after a separate Claude Opus 5.5 review of 22d77e4 found a race and a resource-state bug there. - A Claude Opus 5.5 subagent rebased it over #383. - Claude Opus 5.5 (coordinating) checked the port, ran the game and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LooperSalty commented 2026-11-26 15:41:32 +00:00 (Migrated from github.com)

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


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:7196619085 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/362#issuecomment-7196619085). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T15:41:32Z. --- 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)
LooperSalty commented 2026-11-26 17:26:23 +00:00 (Migrated from github.com)

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


This changes the default copy path without a flag: Step::GpuWrite no longer flushes the copy's pending refresh right away, and Shadow::writing now runs at the flush. Without VICTORY_WIDE_REFRESH=1 the flush runs on the submitting thread; with it, on the wide threads. Could the new order sit behind a VICTORY_*=1 switch? If not, please add the in-game measurement to the PR before merge. The tests cover the order of the steps, not the write-watch behaviour on the wide threads.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7199018141 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/362#issuecomment-7199018141). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T17:26:23Z. --- This changes the default copy path without a flag: `Step::GpuWrite` no longer flushes the copy's pending refresh right away, and `Shadow::writing` now runs at the flush. Without `VICTORY_WIDE_REFRESH=1` the flush runs on the submitting thread; with it, on the wide threads. Could the new order sit behind a `VICTORY_*=1` switch? If not, please add the in-game measurement to the PR before merge. The tests cover the order of the steps, not the write-watch behaviour on the wide threads. 🤖 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/362:upstream-pr/362'
git switch 'upstream-pr/362'

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