texture: capture picked textures ahead of submission (VICTORY_PICK_REFRESH_AHEAD) #555
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/lobomfz--VIctory-xmem!555
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-555"
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?
@just-another-dude84 on GitHub · 2026-12-05 03:24 UTC · original
just-another-dude84:pick-refresh-ahead→main· +341 −10 · 6 files · 1 commits · openProblem
On camera turns the title streams in hundreds of textures a frame. On this machine, heavy turns average about 350 uploads a frame. Each upload's staging is captured (read, hashed, detiled) at its first
refresh(), which is the submitting thread's front refresh (Batch::refresh_front→refresh_spans→shadow::wide_each). The submitting thread takes jobs of its own there, then waits for the wide workers.On turns with 250 or more uploads a frame, that join took 6.6–6.9 ms per frame, 4.9–5.1 ms of it the submitting thread's own share of the refreshes. The card sat idle for 13–16 ms per frame on those turns, waiting for submissions.
About 85% of those stagings are made by the texture pass (
heap_textures). The pass picks them on a list-recording thread, well before the list is submitted. So the capture can start there.Change
With
VICTORY_PICK_REFRESH_AHEAD=1(off by default):upload_fromwithPICKINGset, aoncestaging not captured yet), the staging goes to a pool of 3 threads of its own ("victory-pick-refresh-N", fast cores).catch_unwind. A job that panics clears the staging's hash, so the submission captures it again.lastlock.refresh_timedsees the pending ahead capture and settles it, still underlast:watch::writes(.., false)) is asked from the pool. Guards are never installed from it.Uploads still land in the same submission as before, so nothing is shown later than it was.
The per-second line
pick refresh ahead per framecounts what happened (diagnostics builds only).Measured (same save, same rotation route, diag build,
VICTORY_TEXTURE_COSTS=1 VICTORY_CARD_SPANS=1)Seconds with 250 or more texture uploads a frame:
On this setup every pick-ahead capture settled as "not watched". The textures are read through pool windows, so the submitting thread still reads and hashes them, but no longer detiles them: 254 a frame, 253 with the same hash. The gain is the detile moved off the submitting thread. If writes into pool windows were noted for the kernel watch, the read and hash could be skipped too.
No visual difference while turning: no stale, late or flickering textures.
Test PC: RX 6800 16 GB, i7-12700K, RADV, Arch (zen kernel), X11, Proton Experimental, Series S, RT on, 720p → 1080p.
Cost
refresh_timed's body moved intocaptureunchanged.Smoke test
Same save, clean branch build: 251–336 captures a frame on heavy turns, none dropped, no panics, no device errors.
🤖 Generated with Claude Code
@Kal0s-design on GitHub · 2026-12-05 03:53 UTC · original
Checked
9003f4aon native Windows (one NVIDIA desktop card plus WARP, didn't run the game).victory-gpu lib tests (4 threads, skipping descriptor::tests::views_die_with_their_resource) give 353 passed and 4 failed on both this branch and main
b581f7e. The 4 are the same on both, the two indirect host_list_* and the two pipeline::host library loads that already fail on main. Same result with VICTORY_PICK_REFRESH_AHEAD=1 set, though no existing test reaches the pick path, so that run only shows nothing else changed. clippy on victory-gpu with --all-targets has no new warnings, and clippy with --features diagnostics is clean for the new code. cargo check -p victory passes and the victory-core tests pass (35).With the switch off I read it as the same behaviour as main. enabled() is the first operand in upload_from (texture.rs:1279) so the try_lock and the send never happen, ahead_pending is never set so the early return at the top of refresh_timed is as before, and capture() only adds two stores to last.unwatched and the
!force &&check, with force always false on that path.To test the staleness question I wrote a throwaway test (not pushed) that builds a Staging over title memory with an upload buffer on WARP. It runs refresh_ahead, lets the title write, then calls the submission's refresh and compares the staging bytes with a fresh detile of the memory as it is now. I ran it on write-watched memory, plain memory and partly mapped memory, with a full rewrite, a one-byte change in the last row, zeroing, and no write at all. A stress version does 3600 captures with the ahead read racing a writer thread on 6 textures at once, and another goes through pick_refresh::send so the real pool races the submission's refresh. No stale uploads in 5 runs out of 5. On write-watched memory the clean case really skips the read (refresh_now returns 0) and a write makes it read again (returns the size), so the trust path works on real watched memory. That's worth knowing since the body says every capture in the game run settled as not watched, so this path never ran there. With the clean check forced to always pass, the stress test reports 1060 stale out of 3600, so the test does catch it.
I found one stale case. If
oncegoes false between the job and the submission, refresh_timed skips the ahead_pending block and goes straight to capture(.., false) (the check at texture.rs:1945 only applies when alone). For partly mapped memory the job already stamped last.partial, so the 30 frame throttle in capture (theframe < at + 30return at texture.rs:2074) returns 0 and the first upload carries the pick-time bytes. My test flipsonceafter refresh_ahead, writes the committed part, then refreshes. Watched and plain memory come out fresh and partly mapped comes out stale. On main the first refresh of that staging reads, since partial is still None. upload_from clearsoncewhen a draw samples the texture through a table (texture.rs:1263), so a texture that's picked by the pass and also sampled by a draw in the same frame can hit this. It's bounded by the throttle, but main only lets later mips arrive late, not the first upload. Adding this right before theif alone && last.hash.is_some()check fixed it in my test, and the other cases still pass.There's also a small window on the panic path, from reading the code (I didn't trigger it). capture() sets last.hash before it detiles (texture.rs:2138 then detile), and ahead_pending is only set after capture returns. If the detile panics, the unwind drops the
lastguard, and only then does refresh_ahead_failed (pick_refresh.rs:73) lock it again to clear the hash. A submission refresh that takeslastin that gap sees a hash with nothing pending, returns 0, and finish_refresh uploads a half detiled buffer because detile already setdirty. The staging isonce, so nothing reads it again. A panic in detile should be rare, but clearing the hash inside the locked scope would close it, for example by catching the unwind in the ahead branch of refresh_timed before the guard drops, or by setting the hash only after the detile.Things I checked that look fine.
Smaller things.
unsafe impl Send for Staging(texture.rs:146) says the mapping is written only at submission. It's still under last's lock but now also from the pool.What I didn't test is the game, any timing, the diagnostics line output, AMD or Intel cards, whether keep_on_fast_cores does anything useful on a hybrid CPU, and the panic window above.
AI-assisted: yes
@luisaugustz on GitHub · 2026-12-05 13:30 UTC · original
Measured on RX 9070 XT + Ryzen 7 5800X (RADV, 4K output, FSR 4 Performance, ray tracing on), on the
downtownroute from #554:VICTORY_PICK_REFRESH_AHEAD=1preparing_msdropped a little in one run (12.0 → 11.5), but the frame rate didn't follow. On this machine the city seems bound by the card's ray tracing rather than by the texture captures.Details are in #591.
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.