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

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

@⁠Skyfrye on GitHub · 2026-11-26 13:05 UTC · original
Skyfrye:nep/wide-prewrite-refresh → main · +290 −64 · 1 files · 1 commits · open

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

**@⁠Skyfrye** on GitHub · 2026-11-26 13:05 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/362) `Skyfrye:nep/wide-prewrite-refresh` → `main` · +290 −64 · 1 files · 1 commits · open ## 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)
At submission, a range given to shaders (`Step::GpuWrite`) first brought
that copy's pending refresh up to date (`Batch::flush_one`: a
`Shadow::update` on the submitting thread, outside the flush's one
write-watch asking), then kept the range's bytes (`Shadow::writing`).
With VICTORY_WIDE_REFRESH=1, which the launcher sets, only the other
copies' refreshes went to the victory-wide threads, at the flush.

Now the batch keeps, per host copy, what to do in the order of the
submission's steps (`CopyOps`, `ShadowStep`): refreshes merged where
nothing comes between them, the bytes of a range given to shaders kept,
and a barrier where a range is given again. At the flush each copy's
list is one piece of work for the wide threads (`ShadowBatch::run`),
inside the flush's write-watch asking:
- per copy the order is the old one (refresh, the range's bytes kept,
  later refreshes), and one thread at a time works on a copy;
- title memory copies and title work run at submission still flush
  everything, the kept bytes too, before they write title memory;
- a range given again in the same submission is skipped:
  `Shadow::writing` did nothing more for it (the flights count it once
  per submission, and it is pending already);
- the refreshes ask the kernel no earlier than before, so they see no
  fewer of the title's writes.

Texture refreshes stay on the submitting thread at their step, as
before: the write-watch journal's asking with reset is not atomic across
threads, and two textures, or a texture and a copy, over the same pages
could miss a write for a submission.

The batch also notes the declared ranges once per submission (per copy
in the order first declared, each range once in the order declared),
which `card_before` (filtered to copies in the card's memory, not
transient) and the copy-back take in place of two scans of every list's
steps (`declared_writes` and card_before's own). The sync list of the
copies in the card's memory still goes to the queue on its own, as
before.

Tests (pure CPU): refreshes merge up to the next step between them; a
copy's refreshes and shader writes keep their order when two copies'
steps interleave; the declared ranges are each once, in the order
declared, as the scan gave them.

Code from Antigravity (gemini-4-neon-medium) in commit 22d77e4 of the
same branch family, reduced to this change and ported to main by
Claude Opus 5.5 (subagent).

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:10 +00:00
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/362#issuecomment-7196619085) 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-362 from e251559c3a to 6fae0faa47 2026-11-26 16:06:36 +00:00 Compare
Author
Owner

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

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

**@⁠LooperSalty** on GitHub · 2026-11-26 17:26 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/362#issuecomment-7199018141) 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 has changes conflicting with the target branch.
  • third_party/victory/crates/victory-gpu/src/host.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/362/head:github-bot/gh-362'
git switch 'github-bot/gh-362'

Merge

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