Keep no-wait texture refreshes coherent during page remaps #1156
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!1156
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1156"
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?
@BradRoland on GitHub · 2026-11-25 21:59 UTC · original
BradRoland:codex/defer-remapped-textures→main· +51473 −140 · 15 files · 18 commits · openWith
VICTORY_TEXTURE_NO_WAIT=1, a successful read could publish a texture from the middle of a multi-page remap. On9c184b3a synthetic 128 KiB texture stayed readable throughout the change. The staging buffer took the replacement first page (0x77) and the previous second page (0x11) and accepted that combination as its new contents.A fresh staging buffer now takes the normal mapping read lock. This matters for textures picked by heap index, whose first upload can also be their last. Once staging has a previous sample, a contended refresh keeps it, resets the guard checkpoint, and retries on a later submission. The frame log counts deferred refreshes. Repeated contention can delay an update, and first uploads can wait.
The regression uses two writable views of the same pagefile mapping and real D3D12 staging. It checks first use, both pages of the retained image while the writer holds the lock, and the complete replacement image after an alias write that produced no further guard notification.
cargo test --locked -p victory-gpu --features diagnostics -- --test-threads=1withVICTORY_D3D12_WARP=1passed all 202 enabled tests.Related to #1061. The synthetic case confirms a mixed-page read. Whether it caused the reported prologue-window artifact on the RX 7700 XT still needs a gameplay run. Comparing the same camera and switches from that issue would also show how often the new path defers.
@BradRoland on GitHub · 2026-11-26 00:06 UTC · original
Retested against upstream
dc4c0fcon Windows. Commit367d934runs the remap regression in separate processes withVICTORY_LIGHT_REFRESH=0and1. With both settings, the first upload waited, the contested refresh preserved the old 128 KiB image, the retry staged the complete replacement image, and the next unchanged refresh read zero bytes. All four combinations passed across WARP and a GeForce RTX 4080 (621.14). These runs used generated texture data.@grosterr on GitHub · 2026-11-26 08:20 UTC · original
A gameplay data point for the prologue-window question, from an RTX 3060 12 GB (Ryzen 7 5700X, 32 GB, Windows 11, Series X profile). In short: with this PR in our tree, the blocky outline around silhouettes in the cell's sunlight still appeared, so in our case it is not (or not only) the mixed-page read.
Before this PR: with
VICTORY_TEXTURE_NO_WAIT=1and our usual set, about one launch in six or seven showed a blocky outline around silhouettes in the sun from the cell window, or black patches on walls. Each switch alone and repeats of the full set came out clean (about 20 runs), so it looked random between launches. That made this PR a good candidate.With this PR: the tree was the #770 stack + main
6d20eed+ #1057, #1112, #1044, #1101, #1014, this PR (e06a814), #1150, #1023, #1032, #1136 and #1031. Switches:LEVELS_ON_DEMAND EARLY_TEXTURES_MS=40 TEXTURE_NO_WAIT WIDE_TEXTURES ASYNC_SUBMIT QUEUE2 INDIRECT_WINDOW COPY_PLAIN JOIN_PARTS BACK_OWN_VIEW INDIRECT_GATHER CARD_HASH_WIDE. One 10-minute run on the same save and route:One more thing, with a caveat: in that run the first three minutes (the cutscene and the way into the world) were far slower than without these PRs: a median of 1.8 s a frame, of which 0.85 s was "textures", against 0.27 s and 18 ms on the same machine without them. Your description says first uploads can now wait for the mapping lock, which would fit. But #1031 and #1023 were in the same tree and change the texture path too, and I did not split them. So I can't say which of the three it was. I also learned later that a small page file had slowed other runs, and free memory in this one was not recorded. The steady frame later was 207 ms against 179.
How the texture.rs conflict with the #770 stack (
05c5898and #768's motion tracking) was resolved, including one test expectation: #770AI-assisted (Claude Code); the runs and observations are mine.
@HLVM04 on GitHub · 2026-11-26 08:26 UTC · original
A gameplay data point for the first-upload case this PR names (textures picked by heap index), from an RTX 5070 Ti (Series S profile, fork main plus PRs and local changes). We have not run this PR's code.
VICTORY_TEXTURE_NO_WAIT=1, our main character's skin colour and normal textures (BC7 sRGB and BC5, 512x512, sampled from mip 3 down) sometimes came out black. In a black run, title memory held the right bytes while both host copies were 100% zero.So the "first upload can also be the last" case does occur in gameplay. This PR's lock on a fresh staging buffer looks like it should cover it as well, but that's untested here.
@tikD1337 on GitHub · 2026-11-26 13:38 UTC · original
I measured this PR on a machine where it makes the opening cutscene much slower. The cause appears to be the first-sample wait. Details below; tell me if I misread the intent.
Setup
main06702fewith this PR (367d934) merged. One conflict intexture.rs:mainhas since addedrefresh_aheadbesiderefresh_unlocked, which this PR removes. I keptrefresh_ahead.mainbuild I compare against has the same line, plus texture-check counters of mine.VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_TEXTURE_NO_WAIT=1 VICTORY_WIDE_REFRESH=1 VICTORY_JOIN_PARTS=1 VICTORY_BACK_OWN_VIEW=1.Measured: café cutscene (n = 1 run each)
main06702femain+ #1130 + this PR never reached the world in its 300 s run. It stayed in loading.Measured: where the time goes. The frame line "texture refreshes per frame, all threads" splits the time. In the heaviest cutscene readings with this PR it says, for example:
The heaviest readings wait 6.5 to 12.6 s a frame, summed over threads, for title memory to hold still. On
mainwith the same switches that part is 0.0 ms in every reading:TEXTURE_NO_WAITnever waits there.Code reading: why (line numbers in
367d934,crates/victory-gpu/src/texture.rs)if no_wait() && last.hash.is_some(), skips the wait only for a texture that has been sampled before. Every texture without a first sample (last.hash == None) goes to line 1082,waited(2, crate::watch::title_memory_reading), and blocks until the runtime has finished remapping. The doc comment at line 406 says so ("A fresh staging buffer still waits for its first sample").WIDE_REFRESH, several helper threads).last.asked = 0, so the next check reads the whole texture again even when nothing more was written. That adds to the MB.Suggestion
maindoes, sincemainnever shows it half read.askedinstead of 0. From code reading:watch::writes(writes_asinwatch.rs) keeps every write it found in its journal, with the number of the asking that found it, and answers from that journal. So a write consumed by the deferred check still carries a number above the previousasked, and the next check sees it and reads the texture. Only a texture that was not written skips the whole read. My branch does this behind a switch on top of this PR. That variant was slower still in the one run I made (406 MB, 2,108 ms a frame), because the first-sample wait above dominates.Not measured: whether the mixed-pages problem this PR fixes is visible on this machine with
main's kernel read. I did not look for it.AI-assisted (Claude Code). The measurements are from runs on the machine above. The cause is from the fork's own frame-line counters plus reading the code.
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.Merge
Merge the changes and update on Forgejo.