GPU and shaders: stores through title memory by address mark their copy, and only marked copies are taken for written (#284) #346
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!346
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/346/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ghost on GitHub · 2026-11-24 23:44 UTC · original
gpu/memory-store-marks→main· +368 −38 · 7 files · 2 commits · closed without mergingCloses #284.
What
A list whose shaders could store through title memory by address declared every numbered copy written. Declaring a copy written costs a snapshot of its bytes before the submission and a compare after it (
shadow.rs). In the prologue with the structure builder on, 1,023 copies are numbered (the limit), 4.3 GB, and three to four lists a frame declared all of them: a frame took 3.2-3.4 s, of which about 2.8 s were those snapshots and compares. The module's comment already named the remedy ("a dirty-page mask written by the shader would bound both").This PR does the copy-granular form of it:
Shader (
Lower::memory): every store and atomic through a copy also sets that copy's mark, dwordMEMORY_FAULTS + nof the buffer the fault notes already live in (MEMORY_MARKS = 1024dwords after them). A plain store of 1, so no atomic; lanes that do not run write the sink. Loads do not mark.Host (
memory.rs): the marks are read and cleared once a frame, with the faults. A list that can store declares written onlyEach copy at most once per list.
mapandnamereturn the copy's index for this.No new root parameter, no change to
draw.rs, the pipeline code or the shader interface beyond the longer buffer. The translation changes, so cached translations of these programs are redone (the build fingerprint does that).The shortcut it takes
The first store to a copy that none of the three rules holds is not copied back to title memory: its mark brings the copy in from the next frame the marks are read in. That is the loss a page without a copy already has, for a frame or two. The host logs how many copies that happened to (
shaders stored to copies no list had declared written), 50 lines at most.Measured
RTX 5080 16 GB (32-lane waves), Windows 11, diag build, Series X profile,
VICTORY_SHADER_LOOP_LIMIT=256, warm caches, scripted Enter, 300 s runs. The builder numbers are with #156 merged locally, because on a 32-lane card the builder does not start without it; this branch itself is onmain(2119b0e) and does not need #156.Builder on (
VICTORY_BVH_BUILDER=1 VICTORY_BVH_QUARANTINE=1), per frame, from each run's last reports:The marks named 38 of the 1,023 copies in the first frame they were read, then 1 to 5 new ones a frame.
Builder off (defaults), this branch on
mainagainstmain: 375-418 ms a frame against 416-422 ms, no device loss and no title crash in 300 s either way. So nothing moves in a normal run.Tested
cargo test --release -p victory-shader -p victory-gpu: 110 + 210 passed, 0 failed, on this branch and with #156 merged.cargo clippy --release -p victory-shader -p victory-gpu: no warnings. The files this touches are rustfmt-clean where this touches them (the tree as a whole is not, so I did not run it over the crates).What I could not test
VICTORY_BVH_BUILDER=1and no quarantine the title crashes about 5-7 s after the builder starts, at the same addresses with and without this change (+0x27c195d,+0x2bd385b,+0x4f38ba5,+0x4e335b4,+0x8f92a): the crash of #16. Until that is fixed, a store this PR's shortcut drops for a frame cannot be told from the builder's own trouble.VICTORY_RELAY/VICTORY_LATE_WAITthe marks are read while earlier submissions may still run. A mark set after the read is found the next frame, and the 8-frame window is there for that; I did not run those modes.Relation to other PRs
pub uselist overlaps and merges by hand); the measurements above need it.readytracks, per list, which copies it refreshed and declared. This PR replaces thefirst_writerule that #205 reworks with a per-copy key, so the two conflict in that loop. I am glad to rebase onto #205 if it goes in first.Not in this PR: the limit of 1,023 copies (the log says
no number left for another copy; its pages read zerosin the prologue), the washed-out picture with the builder on, and #16.AI-assisted (Claude Code). No game data: counts, timings and log lines only.
🤖 Generated with Claude Code
https://claude.ai/code/session_01TydV9AGmPCiUTkG8rHubBQ
@ghost on GitHub · 2026-11-25 00:31 UTC · original
AI-assisted (Claude Code).
A clarification of one line in the description, from a measurement made after opening this: with the builder off (defaults) the memory-by-address path numbers no copies at all on this card (0 numbered, 0 loads, 0 stores over a 300 s run). So "nothing moves in a normal run" holds because nothing uses the path then, which is a simpler reason than the frame times I gave. The change only matters once something numbers copies, today the structure builder.
The counts behind this, and what they say about the 1,023-copy limit, are in #284.
@ghost on GitHub · 2026-11-25 02:31 UTC · original
AI-assisted (Claude Code).
Pushed
ac36155: the test the description listed as missing.emit/memory_tests.rsruns a small compute program on the card (hardware adapter and WARP) in which 24 of 32 threads store through an address held in a register pair. It checks that each value lands in the copy the directory names for the page, that this copy's mark is set and no other, that the masked threads store and mark nothing, and that with no copy for the page the stores are dropped, the page is noted as a fault and no copy is marked.Mutation check: with the mark removed from
Lower::memorythe test fails on "copy 1 is marked".The test host gains
Root::Written(n), a root UAV over the n-th writable heap buffer, so the fault notes and marks can be bound at their root slot and read back.cargo test --release -p victory-shader -p victory-gpu: 110 + 211 passed, 0 failed. Clippy clean with--tests.@Xeltax on GitHub · 2026-11-25 10:10 UTC · original
AI-assisted (Claude Code). Numbers and log lines only; no game data.
Tested on an RTX 4080: with the builder on, 4.5 s a frame becomes 0.85–0.9 s (1.1–1.2 fps).
Setup
8dd30ab+ #36, #646, #579, #213, #188, then this PR merged (one conflict, in theemitexports).VICTORY_SHADER_OPT=0.VICTORY_BVH_BUILDER=1without quarantine. No title crash in 540 s.What the marks do here. A per-frame tally added locally in
readygives the copies declared written in a frame:All 1,023 copies (21.5 GB) are still refreshed, by 5 lists a frame.
What remains.
copy_back_with(measured below).Pitfall for anyone testing this PR. If you copy a
targetfolder from another worktree to save build time,victory-shader's build script does not rerun and the shader cache key does not change. The run then uses the old translations without marks. Two tells:translate --warm) right after the merge says "0 translated now";A
cargo clean -p victory-shaderfixes it. It cost me one invalid run.Follow-ups on top of this PR. All are opt-in, on VIcky's
rtbranch (https://github.com/Xeltax/VIcky/tree/rt,VICKY-RT.md). Same card, single runs, same shot:VICTORY_BACK_JOIN=256: the biggest part.copy_back_withwrites each run of GPU bytes with its ownNtWriteVirtualMemory. With the builder on, a frame put back about 350 pieces holding 780,000–910,000 runs, about 2,400 a piece.VICTORY_MEMORY_REFRESH=touched.VICTORY_MEMORY_NAMED_WRITES=0: a copy only named by a constant and never marked stops being snapshotted after 3 frames.If any of these would be useful here or in a separate PR, say so and I'll open it against
main.Pull request closed