GPU: wait before overwriting an in-flight texture staging buffer under VICTORY_LATE_WAIT/RELAY #141
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!141
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-141"
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?
@adritoyalser on GitHub · 2026-11-24 21:49 UTC · original
adritoyalser:fix/late-staging-hazard→main· +183 −33 · 2 files · 1 commits · openProblem
Each title-written texture uses a single mapped
UPLOADheap staging buffer (Staging::buffer). UnderVICTORY_LATE_WAIT/VICTORY_RELAY,Host::submitcheckedlate_blocked(whether an earlier flight's shaders might write the texture's title memory), but did not check whether an earlier unfinished flight was still reading thatStaging::bufferon the GPU viaCopyTextureRegion.When two overlapping flights touch the same CPU-updated texture (such as subtitles, glyph atlases, or dynamic UI/video textures — see e.g. overlapping subtitles under
VICTORY_RELAY=2in #89),Staging::refresh→detilecould overwriteStaging::bufferon the CPU while the earlier flight's GPU copy was still reading it.Fix
Stagingbuffer (Staging::in_flightincrates/victory-gpu/src/texture.rs).Host::submit(crates/victory-gpu/src/host.rs), whenlateis enabled:runs, if anyStep::Texture(staging)hasstaging.in_flight() > FINISHED, wait until it lands (relay_waitunderVICTORY_RELAY=2,self.settleotherwise).staging.mark_in_flight(this_submission)when sending a late submission containingStep::Texture(staging).VICTORY_LATE_WAIT/VICTORY_RELAYare off, or when flights touch different textures.staging_in_flight_tracks_submission_completioninhost::late_tests.Verification
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings— cleancargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings— cleancargo test -p victory-gpu --locked— 111 passed, 0 failed, 1 ignored@tycosnh on GitHub · 2026-11-25 00:42 UTC · original
Test of
f909bf0against #168 on an RTX 4090: walls not restored, late modes about 50 ms/frame slowerI repeated #168's method on
4e17478(main) and on this PR's headf909bf0.Short answer: on this machine the PR does not bring the first room's walls back under
VICTORY_RELAY=2or the late-wait set. It costs about +48 ms/frame underRELAY=2and +52 ms/frame under the late-wait set, with no change on defaults. Here the walls also go missing in default runs, decided per run, so #168's split (walls in every default run, missing in every late run) did not reproduce.Setup
TdrDelay/TdrDdiDelayraised to 60 s (#168 used the default).cargo build --profile diag -p victory --features diagnostics --locked, toolchain 1.98.1, separate target dirs for the two commitscargo test --workspace --lockedon4e17478: 496 passed, 0 failed, 7 ignored (same as #168)Method
VICTORY_DATA_DIR) and loads to the player at the window of the first room, with the world showing about 56 s after launch.VICTORY_KEYS=10:Enter,15:Enter,20:Enter,25:Enterand nothing after that. Each run lasts 540 s and ends withWM_SYSCOMMAND/SC_CLOSE. All runs exited with code 0 within 5 s, none had to be killed.VICTORY_*ones. No network endpoints were open for the process at any check.indirect mesh dispatches: ... N groups asked per frameover the same window.VICTORY_CAPTURE_FRAMESand looked at locally (not attached).Results
4e174784e174784e17478VICTORY_RELAY=24e17478VICTORY_RELAY=24e17478f909bf0f909bf0VICTORY_RELAY=2f909bf0VICTORY_RELAY=2f909bf0¹
VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024None of them logged an
ERRORline or lost the device. Every run refused the same pipelines once at startup with 0x80070057: compute02384a60fda6f2d0,2cc4c197ee29e291,2da4beb386509b77and369cbe906ea72764, and meshf5e50eb2108c425bwith pixelce3f0432a08f1d35. The4e17478runs also refused compute6b82bc7d22016cb5.1. The walls are not restored, and here they are lost in default runs too
With one or two runs per arm and walls missing in default runs too, this can't show that the PR makes the walls worse. It does show it doesn't bring them back.
The grille follows the switches more closely than the walls. It is missing in all four
RELAY=2runs and in P-C1, and drawn in every default run and in C1. Skin is present in every run. No subtitles were on screen in any captured frame, so I couldn't check the overlapping subtitles from #89.2. The wait serializes the late submissions
The new wait is counted as "title memory read" in the settle lines. Compared with the same mode on
4e17478:4e17478f909bf0RELAY=2: settles per frameRELAY=2: waiting under "title memory read"All of the waiting in settles is now under that reason.
GPU time per frame goes up and the card is less busy. With the PR,
RELAY=2runs at 278 to 290 ms against 292 to 298 ms on defaults, so almost all of its speed-up is gone.The mesh group count also comes back to the default level, about 25,000 against 13,700 to 15,600 on
4e17478withRELAY=2. That fits #168's point that part of the relay's speed-up was geometry that wasn't drawn. Under the late-wait set it rises from 20,800 to 25,400.Test report written with Claude Code (Claude Opus 5.5), from real runs on the hardware named above. No game data attached.
@adritoyalser on GitHub · 2026-11-25 01:29 UTC · original
Thanks for the thorough RTX 4090 benchmark @tycosnh! The settle breakdown pinpointed the exact performance bug in
f909bf0:f909bf0markedin_flighton everyStep::Texture(even skipped uploads with noCopyTextureRegion) and waited eagerly at submission entry before checking whether the texture had changed, causing ~15–18 settles/frame on static textures.Pushed a fix that:
uploads: boolonStep::Textureand only marksin_flightwhentexture::uploadactually recorded aCopyTextureRegion.Staging::detile(), so unchanged textures never wait at all — only an actual detile into an in-flight staging buffer waits for that specific flight (relay_wait/settle).late_tests::staging_wait_only_runs_on_detile_and_real_uploadsto verify zero waits on unchanged refreshes,uploads = falseon skipped copies, and a wait on detile whenin_flightis set (clippy0 warnings).That should eliminate the +48–52 ms/frame overhead on static textures while keeping the data-hazard protection (and note that #272 is also exploring a similar per-upload fence approach).
@Revens2 on GitHub · 2026-11-25 05:13 UTC · original
Merging this PR on top of main
c96b4f2(plus #115) conflicts incrates/victory-gpu/src/texture.rs: main addedunreported_changeafterdetileon the partial-hash path, while this PR changesdetileto takewait_flight. Resolution:self.detile(read, wait_flight);followed by main'sunreportedblock. It builds. In a local combo of eight PRs it ran in the game 3 times with the outcome described on #115 (not attributable to this PR). Not verified alone.@adritoyalser on GitHub · 2026-11-25 06:32 UTC · original
Rebased cleanly onto current
main(8dd30ab), preserving the new on-demand levels path intexture.rs.staging_wait_only_runs_on_detile_and_real_uploadspasses.58ecb510c9toebb5c47ff8View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.