Write InitHeaders' stores into title memory from a record of them (0.5 → 2.2 fps on RX 7900 XTX) #153

Open
SyberMaik wants to merge 2 commits from upstream-pr/153 into main
SyberMaik commented 2026-11-28 13:15:33 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by SyberMaik on 2026-11-28T13:15:33Z.


What

InitHeaders takes its destinations from a table in title memory, so nothing bound to it says where it stores. Until now, every visible raw-memory copy was declared written after each dispatch. With --rt-write-stats it was the only broad raw writer left: 6–19 GB of write declarations per frame-rate sample in the opening, each declared range snapshotted, compared and copied back.

The existing store trace (--rt-store-trace) shows what InitHeaders really writes: at most 96 stores per dispatch, 1,408 bytes, in 16-byte pieces. Most of them land outside the acceleration-structure headers the host knows from live views, so no static declaration can cover them.

This PR turns the store trace into the publication mechanism for InitHeaders:

  • InitHeaders is translated with the trace in every build, and each trace entry now also holds the dwords the store wrote (event stride 5 → 9 dwords).
  • After each dispatch, the record is copied to a read-back buffer and its count reset. Once the list has run, the host writes the recorded bytes into title memory in record order, with guards opened as for the copy-back.
  • The raw writes of InitHeaders are declared as none.

Safeguards

  • If the shader also changes title memory through raw-address atomics (not recorded), translation reports it and its writes stay declared broadly.
  • If a record overflows (4,096 stores), this is logged once and the writes are declared broadly from then on.
  • Indirect dispatches keep the broad declaration; their record is still read and reset so nothing carries over.
  • VICTORY_RECORDED_WRITES=0 restores the previous behaviour.

Measured

Ryzen 7 5800X3D, 32 GB, RX 7900 XTX, Series X with ray tracing (--rt --console series-x --local-gpu-memory --sparse-textures --no-upload-ahead --capture-readbacks --rt-write-stats). Same save, same scene, 6 minutes each, median of about 45 frame-rate samples in the world:

before recorded
FPS 0.5 2.2
ms per frame 2,063 456
copying back 764 ms 99 ms
on the GPU 750 ms 19 ms
preparing 1,272 ms 398 ms
broad raw write declaration samples 124 0
draws per frame (avg) ~2,540 ~2,690

Over 1,000 InitHeaders dispatches were applied from their record with no overflow, no atomics warning and no crash. Builder, activation, traversal and resolve were on in both runs.

Not verified yet: a frame-by-frame visual comparison of the two runs. My capture run did not save frames. I would appreciate a check on your scene, or I can follow up with captures.

A second small commit makes the capture folder when it does not exist. Without that, every frame was logged "frame not saved" (os error 3).

Generated with Claude Code

<!-- greyfinch-sync:DexNom/VIctory:issue:5540495590 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/153). Originally posted by [SyberMaik](https://github.com/SyberMaik) on 2026-11-28T13:15:33Z. --- ## What InitHeaders takes its destinations from a table in title memory, so nothing bound to it says where it stores. Until now, every visible raw-memory copy was declared written after each dispatch. With `--rt-write-stats` it was the **only** broad raw writer left: 6–19 GB of write declarations per frame-rate sample in the opening, each declared range snapshotted, compared and copied back. The existing store trace (`--rt-store-trace`) shows what InitHeaders really writes: at most 96 stores per dispatch, 1,408 bytes, in 16-byte pieces. Most of them land outside the acceleration-structure headers the host knows from live views, so no static declaration can cover them. This PR turns the store trace into the publication mechanism for InitHeaders: - InitHeaders is translated with the trace in every build, and each trace entry now also holds the dwords the store wrote (event stride 5 → 9 dwords). - After each dispatch, the record is copied to a read-back buffer and its count reset. Once the list has run, the host writes the recorded bytes into title memory in record order, with guards opened as for the copy-back. - The raw writes of InitHeaders are declared as none. ## Safeguards - If the shader also changes title memory through raw-address atomics (not recorded), translation reports it and its writes stay declared broadly. - If a record overflows (4,096 stores), this is logged once and the writes are declared broadly from then on. - Indirect dispatches keep the broad declaration; their record is still read and reset so nothing carries over. - `VICTORY_RECORDED_WRITES=0` restores the previous behaviour. ## Measured Ryzen 7 5800X3D, 32 GB, RX 7900 XTX, Series X with ray tracing (`--rt --console series-x --local-gpu-memory --sparse-textures --no-upload-ahead --capture-readbacks --rt-write-stats`). Same save, same scene, 6 minutes each, median of about 45 frame-rate samples in the world: | | before | recorded | | --- | ---: | ---: | | FPS | 0.5 | **2.2** | | ms per frame | 2,063 | **456** | | copying back | 764 ms | **99 ms** | | on the GPU | 750 ms | **19 ms** | | preparing | 1,272 ms | **398 ms** | | broad raw write declaration samples | 124 | **0** | | draws per frame (avg) | ~2,540 | ~2,690 | Over 1,000 InitHeaders dispatches were applied from their record with no overflow, no atomics warning and no crash. Builder, activation, traversal and resolve were on in both runs. **Not verified yet:** a frame-by-frame visual comparison of the two runs. My capture run did not save frames. I would appreciate a check on your scene, or I can follow up with captures. A second small commit makes the capture folder when it does not exist. Without that, every frame was logged "frame not saved" (os error 3). 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/153:upstream-pr/153'
git switch 'upstream-pr/153'

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