GPU: only a shader that can store by address declares its title-memory copies written (12 GB/frame of CPU compare with ray tracing) #916

Open
github-bot wants to merge 2 commits from github-bot/gh-916 into main AGit
Owner

@⁠SpaghettiMaster545 on GitHub · 2026-11-25 12:41 UTC · original
SpaghettiMaster545:pr/raw-store-written → main · +79 −3 · 2 files · 2 commits · open

What was wrong

A shader that reads title memory by address declared every numbered copy of that memory written whenever it could store anything at all. Each of those copies was then snapshotted before its submission and compared on the CPU after. The programs that walk the ray-tracing structures read them by address but store their results through views, so every one of their dispatches declared all of the copies.

How it shows in game

With the structure builder running, that came to 12 GB snapshotted and compared per frame (3,030 ranges of 4 MiB). A frame took 3.5 s, 1.3 s of it copying back.

What the change does

Only a program that can store by address (a flat, global or scalar-memory store or atomic, or code that is not fully known) declares the title-memory copies it reads as written. Stores through root views are declared as before (stores_by_address in pipeline.rs, used by draw.rs).

How it was tested

  • cargo test --locked -p victory-gpu --lib passes on this branch (169 passed, 5 ignored). cargo clippy -p victory-gpu --all-targets --locked -- -D warnings shows only the errors that main already has (placed_filler_twins, sort_unstable_by_key, is_multiple_of, depth_written) and adds none.
  • Game runs with the same switches: in the world a frame went from 3.5 s to about 490 ms, and copying back from 1.3 s to 60 ms.
  • GPU and driver: NVIDIA GeForce RTX 5070 Ti, driver 621.40, Windows 11.

Developed with AI assistance (Claude Code).

**@⁠SpaghettiMaster545** on GitHub · 2026-11-25 12:41 UTC · [original](https://github.com/fxceless/victory-fork/pull/916) `SpaghettiMaster545:pr/raw-store-written` → `main` · +79 −3 · 2 files · 2 commits · open ## What was wrong A shader that reads title memory by address declared every numbered copy of that memory written whenever it could store anything at all. Each of those copies was then snapshotted before its submission and compared on the CPU after. The programs that walk the ray-tracing structures read them by address but store their results through views, so every one of their dispatches declared all of the copies. ## How it shows in game With the structure builder running, that came to 12 GB snapshotted and compared per frame (3,030 ranges of 4 MiB). A frame took 3.5 s, 1.3 s of it copying back. ## What the change does Only a program that can store by address (a flat, global or scalar-memory store or atomic, or code that is not fully known) declares the title-memory copies it reads as written. Stores through root views are declared as before (`stores_by_address` in `pipeline.rs`, used by `draw.rs`). ## How it was tested - `cargo test --locked -p victory-gpu --lib` passes on this branch (169 passed, 5 ignored). `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` shows only the errors that `main` already has (`placed_filler_twins`, `sort_unstable_by_key`, `is_multiple_of`, `depth_written`) and adds none. - Game runs with the same switches: in the world a frame went from 3.5 s to about 490 ms, and copying back from 1.3 s to 60 ms. - GPU and driver: NVIDIA GeForce RTX 5070 Ti, driver 621.40, Windows 11. Developed with AI assistance (Claude Code).
A shader that reads title memory by address had every numbered copy of
that memory declared written whenever it could store anything at all:
snapshotted before its submission and compared on the CPU after. The
programs that walk the ray-tracing structures read them by address and
store their results through views, so each of their dispatches declared
all of the copies. With the structure builder running (quarantined) that
was 12 GB snapshotted and compared a frame, 3030 ranges of 4 MiB, and a
frame took 3.5 s (1.3 s of it copying back; run rt-4).

Now only a program that can store by address (a flat, global or
scalar-memory store or atomic, or code not all known) declares them;
stores through root views are declared as before. Run rt-5, same
switches: about 490 ms a frame in the world, 60 ms copying back.

(cherry picked from commit 30ee710008c9bda3ce5b32f360cc0c61c32792fd)
A vector store through a buffer descriptor does not; flat, global and
scalar-memory stores do, the scalar buffer forms too (kept
conservative). Pins the classification a review checked by hand.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:47 +00:00
Author
Owner

@⁠ArturoWolff on GitHub · 2026-11-25 12:52 UTC · original

I checked the store classification independently on Linux at 417592b, using the branch's actual victory-shader decoder and both predicates extracted unchanged from pipeline.rs. Each synthetic stream starts with an s_load_dword by address. Ten cases passed their decode-name and predicate checks.

Following instruction Existing stores New stores_by_address
buffer_store_dword, tbuffer_store_format_x true false
flat_store_dword, global_atomic_add, s_store_dword true true
s_buffer_store_dword, s_buffer_atomic_add true true
another s_load_dword false false
s_setpc_b64, unnamed FLAT opcode 0x7f true true

The scalar-buffer row is worth pinning in a regression test: the new predicate distinguishes the vector descriptor stores, but deliberately or not, still classifies the scalar-buffer forms as possible address writes. That's conservative, not evidence of lost writes. I'd keep it conservative unless the lowering and aliased views are proved separately. This checks the decision behind the reported Windows improvement; it does not measure copy-back volume, VRAM residency or frame time under Proton. No game or GPU run.

AI disclosure: Hermes Agent built and ran the fixtures and wrote this report on ArturoWolff's behalf.

**@⁠ArturoWolff** on GitHub · 2026-11-25 12:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/916#issuecomment-7162983607) I checked the store classification independently on Linux at `417592b`, using the branch's actual `victory-shader` decoder and both predicates extracted unchanged from `pipeline.rs`. Each synthetic stream starts with an `s_load_dword` by address. Ten cases passed their decode-name and predicate checks. | Following instruction | Existing `stores` | New `stores_by_address` | |---|---|---| | `buffer_store_dword`, `tbuffer_store_format_x` | true | false | | `flat_store_dword`, `global_atomic_add`, `s_store_dword` | true | true | | `s_buffer_store_dword`, `s_buffer_atomic_add` | true | true | | another `s_load_dword` | false | false | | `s_setpc_b64`, unnamed FLAT opcode `0x7f` | true | true | The scalar-buffer row is worth pinning in a regression test: the new predicate distinguishes the vector descriptor stores, but deliberately or not, still classifies the scalar-buffer forms as possible address writes. That's conservative, not evidence of lost writes. I'd keep it conservative unless the lowering and aliased views are proved separately. This checks the decision behind the reported Windows improvement; it does not measure copy-back volume, VRAM residency or frame time under Proton. No game or GPU run. AI disclosure: Hermes Agent built and ran the fixtures and wrote this report on ArturoWolff's behalf.
Author
Owner

@⁠SpaghettiMaster545 on GitHub · 2026-11-25 15:36 UTC · original

Thanks for checking. I agree it should stay conservative. A scalar buffer store's descriptor can point anywhere, title memory included, and proving otherwise would need the aliasing proof you describe. I pinned the classification in a test (only_stores_that_can_take_an_address_count_as_address_stores, in f9c0ddc): buffer_store_dword does not count, s_store_dword, s_buffer_store_dword and global_store_dword do, and a plain s_load_dword does not. It passes on Windows (RTX 5070 Ti, NVIDIA 621.40).

**@⁠SpaghettiMaster545** on GitHub · 2026-11-25 15:36 UTC · [original](https://github.com/fxceless/victory-fork/pull/916#issuecomment-7167107076) Thanks for checking. I agree it should stay conservative. A scalar buffer store's descriptor can point anywhere, title memory included, and proving otherwise would need the aliasing proof you describe. I pinned the classification in a test (`only_stores_that_can_take_an_address_count_as_address_stores`, in `f9c0ddc`): `buffer_store_dword` does not count, `s_store_dword`, `s_buffer_store_dword` and `global_store_dword` do, and a plain `s_load_dword` does not. It passes on Windows (RTX 5070 Ti, NVIDIA 621.40).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/pipeline.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/916/head:github-bot/gh-916'
git switch 'github-bot/gh-916'

Merge

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