GPU: VICTORY_BACK_JOIN writes nearby runs of shader writes back as one kernel call (opt-in) #842

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

@⁠Xeltax on GitHub · 2026-11-25 10:17 UTC · original
Xeltax:vicky/back-join → main · +108 −6 · 1 files · 1 commits · open

What. copy_back_with puts the GPU's bytes back into title memory one run at a time, with one NtWriteVirtualMemory per run (#2009: only the GPU's bytes are written).

With the ray-tracing structure builder on, the runs are tiny and countless: the builder changes a few bytes here and there in each node. Per frame on an RTX 4080:

  • about 350 pieces were put back, holding 780,000–910,000 runs (about 2,400 a 64 KiB piece);
  • putting back what shaders wrote took 248 ms a frame (0.73 ms a piece, against 0.23 ms with the builder off).

This PR adds an opt-in switch, VICTORY_BACK_JOIN=<bytes>. Runs of GPU bytes no more than that many bytes apart are written with one call, the gap included. The gap holds the title's bytes as back_piece read them just before. Unset or 0: each run alone, exactly as now.

It also adds one frame-rate line, putting shader writes back, per frame:

  • pieces, runs and kernel writes;
  • milliseconds reading and merging, opening guards (watch::writing) and writing.

Measured. RTX 4080, Series X profile, VICTORY_BVH_BUILDER=1 without quarantine, same shot, single runs. The base is VIcky's rt branch: 8dd30ab + #36, #646, #579, #213, #188, #346 and three opt-in VIcky switches (see #346's thread). It is not plain main: on main the builder's frames are dominated by #346's problem.

per frame VICTORY_BACK_JOIN unset VICTORY_BACK_JOIN=256
kernel writes when putting back ~850,000 1,300
writing (most of 248 ms) 1.8 ms
copying back 264–354 ms 58–65 ms
frame 652–916 ms 502–583 ms (1.7–2.0 fps)

With the builder off I have not measured it; the runs there are far fewer.

The shortcut (written in the switch's doc). A title write that lands in a gap between the read and the write (microseconds) is overwritten with the byte read before it. The gaps are at most VICTORY_BACK_JOIN bytes and lie only between bytes the GPU wrote. That is narrower than what the relay's merge (relay_merge) already does: it writes the whole stretch. It is off by default for that reason.

Tests

  • joined_runs (the joining alone): three tests, for no join, joins of 1, 3 and 96 bytes, and no runs.
  • cargo test -p victory-gpu --lib: 147 (3 new) passed. -p victory-shader --lib: 215 passed. -p victory-hle --lib: 98 passed.
  • cargo xtask policy: ok.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠Xeltax** on GitHub · 2026-11-25 10:17 UTC · [original](https://github.com/fxceless/victory-fork/pull/842) `Xeltax:vicky/back-join` → `main` · +108 −6 · 1 files · 1 commits · open **What.** `copy_back_with` puts the GPU's bytes back into title memory one run at a time, with one `NtWriteVirtualMemory` per run (#2009: only the GPU's bytes are written). With the ray-tracing structure builder on, the runs are tiny and countless: the builder changes a few bytes here and there in each node. Per frame on an RTX 4080: - about 350 pieces were put back, holding **780,000–910,000 runs** (about 2,400 a 64 KiB piece); - putting back what shaders wrote took 248 ms a frame (0.73 ms a piece, against 0.23 ms with the builder off). This PR adds an opt-in switch, `VICTORY_BACK_JOIN=<bytes>`. Runs of GPU bytes no more than that many bytes apart are written with one call, the gap included. The gap holds the title's bytes as `back_piece` read them just before. Unset or 0: each run alone, exactly as now. It also adds one frame-rate line, `putting shader writes back, per frame`: - pieces, runs and kernel writes; - milliseconds reading and merging, opening guards (`watch::writing`) and writing. **Measured.** RTX 4080, Series X profile, `VICTORY_BVH_BUILDER=1` without quarantine, same shot, single runs. The base is VIcky's `rt` branch: `8dd30ab` + #36, #646, #579, #213, #188, #346 and three opt-in VIcky switches (see #346's thread). It is not plain `main`: on `main` the builder's frames are dominated by #346's problem. | per frame | `VICTORY_BACK_JOIN` unset | `VICTORY_BACK_JOIN=256` | |---|---|---| | kernel writes when putting back | ~850,000 | 1,300 | | writing | (most of 248 ms) | 1.8 ms | | copying back | 264–354 ms | 58–65 ms | | frame | 652–916 ms | 502–583 ms (1.7–2.0 fps) | With the builder off I have not measured it; the runs there are far fewer. **The shortcut** (written in the switch's doc). A title write that lands in a gap between the read and the write (microseconds) is overwritten with the byte read before it. The gaps are at most `VICTORY_BACK_JOIN` bytes and lie only between bytes the GPU wrote. That is narrower than what the relay's merge (`relay_merge`) already does: it writes the whole stretch. It is off by default for that reason. **Tests** - `joined_runs` (the joining alone): three tests, for no join, joins of 1, 3 and 96 bytes, and no runs. - `cargo test -p victory-gpu --lib`: 147 (3 new) passed. `-p victory-shader --lib`: 215 passed. `-p victory-hle --lib`: 98 passed. - `cargo xtask policy`: ok. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
copy_back_with puts the GPU's bytes back one run at a time, one
NtWriteVirtualMemory each (#2009). With the ray-tracing structure builder
on, a frame put back about 350 pieces holding 780,000-910,000 runs, 248 ms
a frame on an RTX 4080. VICTORY_BACK_JOIN=<n> writes runs no more than n
bytes apart as one call, the gap included (title bytes back_piece read just
before): with 256, 1,300 calls and 1.8 ms of writing; copying back went
from 264-354 ms to 58-65 ms a frame. Unset or 0: as before.

Also a frame-rate line of the copy-back's pieces, runs, kernel writes and
the time reading and merging, opening guards and writing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01A4bpLmErkufJL3LGgfR561
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:22 +00:00
This pull request has changes conflicting with the target branch.
  • 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/842/head:github-bot/gh-842'
git switch 'github-bot/gh-842'

Merge

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