GPU: cache the error of a container that does not translate #1094
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1094
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1094/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?
@adamdotpy on GitHub · 2026-11-24 15:42 UTC · original
adamdotpy:gpu/cache-translation-failures→main· +260 −14 · 2 files · 5 commits · closed without mergingCarries @lines9686-rgb's commit from #1089, verified here; AI-assisted.
The change is
lines9686-rgb@1c2b2d6, pushed unchanged with its authorship, because external PR creation is still restricted and the issue proposes the branch for cherry-pick.What it does
shader_cachestored only successful translations, so every run re-translated every container that does not translate — measured in #1089 at ~400 programs per run, the large compute ones 2-3 s each, with the creation workers spending about 1.5 minutes after world entry failing the same programs again while their draws were dropped.Translate::convertnow stores a refusal as aVSF1entry (the error's text) under the same key instead of returningErr, so it is written like a translation.cachedreads either magic:VSH1gives the shader,VSF1gives the error back. A damagedVSF1entry is a miss, like a damaged shader entry, and is tried again.The key is
build(): the BLAKE3 of our executable plus the loop limit. A rebuilt translator, or anotherVICTORY_SHADER_LOOP_LIMIT, is a different key and tries again, so a fix is not hidden by a cached refusal. Translation itself is pure over the container, so the same key cannot succeed after failing.Verification here
Windows 11, Rust 1.98.1, on
ffe310ewith this commit applied:cargo test -p victory-gpu: 52 passed, 1 ignored (50 before; the two new tests arefailures_come_back_from_the_cache_tooandfailure_entries_round_trip_and_are_no_shader).cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: clean.cargo build --release -p victory: builds.rustfmt --edition 2024 --check crates/victory-gpu/src/shader_cache.rs: clean (the otherfmtdifferences in the tree are onmainalready).I read the change for the three things that could go wrong and all three hold: a refusal cannot become a stale success (the key holds the build), a truncated entry is retried rather than trusted (the decode returns
Noneand the file is removed), and nothing outsidehost_shaderreads the entry (onlypipeline.rsdoes, and it drops the draws as before).Two things worth knowing
queue.rs:270says "shaders from the cache and translated so far"; a cached refusal is counted in the first number now, so a run with many refusals shows a higher hit rate than it has translations. Not wrong, but the wording could say "from the cache (refusals included)".VICTORY_DUMP_FAILEDreview point: a refused container is translated once per build now, so the dump is written once per hash rather than per retry.Fixes #1089.
@DrDarkDK on GitHub · 2026-11-24 15:45 UTC · original
On
1c2b2d6, I populated a disposable cache with a synthetic translation refusal, then shortened the saved entry.VSF1by itself returned an empty error.VSF1followed by a valid UTF-8 prefix returned just that prefix. Both counted as cache hits and skipped translation. The short-marker and invalid-UTF-8 controls both retried and recovered the full error.I simulated truncation after the write completed. If truncated entries are meant to be cache misses, storing and checking the payload length would cover both cases.
AI-assisted with Codex.
@adamdotpy on GitHub · 2026-11-24 15:52 UTC · original
Good catch, and you are right about both cases: the entry was marker-then-text, so a file cut after the marker decoded as an empty reason and one cut inside the text decoded as the prefix that survived. Both are usually valid UTF-8, so both were served as hits — the refusal held, but its reason was empty or truncated, in the one place that reason is read.
Fixed in
0061ed8as you suggested: the entry carries the text's length (VSF1, 4 bytes little endian, then the text), and a decode whose text is not exactly that long is damage, so the container is translated again and the reason comes back whole. Your short-marker and prefix cases are now the testa_damaged_failure_entry_is_no_entry, which cuts a real entry at the marker, four bytes past it and one byte before its end, and also checks the marker followed by non-UTF-8 and a shader entry's magic with a reason after it.Verified on Windows 11, Rust 1.98.1:
cargo test -p victory-gpu53 passed / 1 ignored (51 before; the cache tests are 5),cargo clippy -p victory-gpu --all-targets --all-features -D warningsclean,cargo build --release -p victorybuilds, and the file isrustfmt-clean. Before the fix the new test failed exactly as your repro says (cut to 4 bytes:Some("")vsNone).@fuzeofficlal on GitHub · 2026-11-24 16:29 UTC · original
Tested the
VSF1disk failure entry format (with the 4-byte length prefix in0061ed8) on Windows across RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1). A few behavioral edge cases worth tightening here:HITS/MISSEScounter distortion: IncrementingMISSESon initial failure andHITSonVSF1hits causesqueue.rsto count refused shaders under"translated so far". Gating both counters onresult.is_ok()keeps the frame translation stats accurate.converter.ranstaystrueacross the 2-iteration corruption retry loop unless reset at the top of each iteration, andhost_shader()still re-runstranslate()when disk caching is disabled or unavailable unless backed by a small build-keyed in-memory negative map.Pendingpipeline stalls inpipeline/make.rs: Even once aShaderhas failed in memory (translated.get() == Some(None)), hundreds of siblingPendingPSOs sharing thatArc<Shader>still get pushed onto the worker channel inmake::readyand stall the render thread up to the 500 ms frame wait budget behind slow driver PSOs. Short-circuitingPending::readywhen any active stage shader has already failed avoids queueing and waiting altogether.Reference commit with synthetic unit tests covering all three points (feel free to cherry-pick or fold in any pieces):
github.com/fuzeofficlal/VIctory@46b28785d9@Zipettte on GitHub · 2026-11-24 16:29 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
1c2b2d6:cargo test -p victory-gpupasses, 52 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@TG0000 on GitHub · 2026-11-24 16:32 UTC · original
Measured
0061ed8, it does what it says. I replayed offline the shaders one warm launch asked for (1,918 of them, 8 threads, Ryzen 9 5900X), onmainplus a set of open shader PRs plus this one:In game, one warm launch on plain
mainspent 277 thread-seconds on 401 refusals. Load time and frame time were not measured.I had written the same thing separately and dropped it in favour of this PR. Two cases my tests had that fail here, for a follow-up or this one:
mainkeeps the reason. (My version had the same defect.) #358 and #389 edit the same function.A test that a different loop limit or exe makes a different key would also pin the retry.
AI-assisted (Claude Code).
@adamdotpy on GitHub · 2026-11-24 16:39 UTC · original
Both of your cases are fixed in
097a790on this branch, and each was reproduced here before the fix, with the failing assertion quoted in the commit message.1. Damage that keeps the length.
decode_failureonly compared lengths, so a torn write with the right length was served as a refusal with a wrong reason. The entry now carries the first four bytes of the text's BLAKE3 between the length and the text, and a mismatch is a miss. The marker movesVSF1→VSF2, so entries written by the previous revision are clean misses and get translated again rather than parsed with their text's first bytes as a checksum. Red test:a_damaged_failure_entry_is_no_entrynow flips one byte in the text with the length intact — without the checksum it returnsSome("aascalar memory read as data"), with itNone.2. Unwritable cache folder.
cachedpropagatedget_or_convert's error with?, so the answer became the OS error and the log lost the reason. A failed write now logsshader cache entry not written; translating without itand falls through to the translation itself, which returns the real reason. Red test:a_cache_that_cannot_be_written_still_says_whyblocks the entry's own path with a directory so the rename onto it fails — without the fix the result isErr("Access is denied. (os error 5)"), with itErr("a scalar memory read as data").Verified on Windows 11 / Rust 1.98.1:
cargo test -p victory-gpu54 passed / 1 ignored (6 inshader_cache, both new ones included),cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warningsclean,cargo build --release -p victorybuilds,rustfmt --edition 2024 --checkclean on the changed file. Pushed as a fast-forward togpu/cache-translation-failures, no force.Your third suggestion — a test that a different loop limit or exe makes a different key — is already covered by the existing
translations_come_back_from_the_cache("another build translates again") plusbuild()hashing the exe andVICTORY_SHADER_LOOP_LIMITtogether, so I did not add a duplicate.Thanks for the measurement table, by the way: 0.05 s against 10.3 s for 339 refusals is the number that justifies this whole branch.
@adamdotpy on GitHub · 2026-11-24 17:10 UTC · original
Point by point on the three edge cases, checked against this branch at
d03d93c(Windows 11 / Rust 1.98.1, isolated target dir):1. Counter distortion — real, fixed in
e090242. Reproduced first: the new testrefusals_are_not_counted_as_translatedsaw(hits, misses)move by(1, 1)for one fresh refusal plus one served from aVSF2entry — a cached refusal incrementedHITS, a fresh oneMISSES, both under the "shaders from the cache and translated so far" frame line. Now only a successful entry moves its counter (the refusal is still logged withok=false); the test passes with(0, 0)for the refusals and(0, 1)then(1, 0)for a shader that translates and is then cached. The cache tests now share a mutex so the process-wide counters can't race between them.2a.
ranacross the retry loop — not a defect, no reset needed.ranis only read after an entry decodes. In iteration 2 an entry can only be served if the file exists, and after a damaged entry the code removes it first — so eitherconvertre-ran in iteration 2 (rantrue, correctly a miss) or the removal failed and the file is iteration 1's ownconvertoutput (ranstill true, also correctly a miss: it was translated in this call). A pre-existing file would have been served in iteration 1, so a true hit never seesran == true.2b. No disk cache — main's behavior, not this PR's. The
None => translate(container)arm ofhost_shaderis byte-identical onmain(git show upstream/main:...shader_cache.rs), and the cache is on by default (run.rsalways callsuse_shader_cachewith the cache subdir;use_shader_cacheonly leavesCACHEunset when the folder can't be opened). So re-translating refusals with the cache off is exactly what main does. A build-keyed in-memory negative map for that path is a reasonable follow-up, but it's a new feature with a growth/keying decision, not a fix to this branch — happy to take it as its own PR if you want it.3. Sibling
Pendingstalls — real, fixed ind03d93c. Confirmed in code:ready()queued any not-yet-madePendingand waited within the 500 ms frame budget even whenHostPipeline::newcould only refuse it (s.translated()?per stage).ready()now answersNoneat once when any stage shader hastranslated == Some(None), and still records the refusal inmadeso the diagnostics path (missing) keeps naming the shader. Red first: the newa_refused_shader_skips_the_worker_queuefailed on "not sent to a worker"; nowreadyreturnsNonewithqueued == falseandmade == Some(None).Verification on
d03d93c:cargo test -p victory-gpu56 passed / 1 ignored (both new tests included),cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warningsclean,cargo build --release -p victorybuilds,rustfmt --edition 2024 --checkclean onshader_cache.rsand on the lines changed inmake.rs(its three remaining fmt hunks are pre-existing on main). Pushed as a fast-forward togpu/cache-translation-failures, no force.@Marvisak on GitHub · 2026-11-25 00:32 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Already in main: a container that does not translate is cached with its reason (shader_cache.rs REFUSED entries,
c47b5297), so it is not translated again every run.If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed