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

Open
Xeltax wants to merge 1 commit from upstream-pr/842 into main
Xeltax commented 2026-11-25 10:17:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Xeltax on 2026-11-25T10:17:47Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6602205445 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/842). Originally posted by [Xeltax](https://github.com/Xeltax) on 2026-11-25T10:17:47Z. --- **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)
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/842:upstream-pr/842'
git switch 'upstream-pr/842'

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