Skip to content

GPU: a shader cache that cannot keep an entry still gives its translation - #358

Closed
Dufftwt wants to merge 1 commit into
Marvisak:mainfrom
Dufftwt:fix/shader-cache-write-failure-keeps-translation
Closed

Dufftwt wants to merge 1 commit into
Marvisak:mainfrom
Dufftwt:fix/shader-cache-write-failure-keeps-translation

Conversation

@Dufftwt

@Dufftwt Dufftwt commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What's wrong

shader_cache::cached gets a console shader's translation through victory-pipeline's cache. On a miss, the cache runs the converter (our translator) and then writes the entry: it creates the shard folder, writes a temporary file and renames it into place.

If writing fails, get_or_convert returns an error, and cached passes it up with ? as if the shader had failed:

let path = cache.get_or_convert(&converter, &input).map_err(|e| format!("{e:#}"))?;

The translation, which worked, is thrown away. pipeline.rs stores the shader as not translating for the rest of the run, logs "shader does not translate", and every draw or dispatch that uses it is dropped.

Ways the write can fail on a user's machine:

  • a full disk;
  • a file where a shard folder should be;
  • an antivirus scanner holding the freshly written temporary file, so the rename fails.

The last one happens intermittently on Windows, so it would show up as random missing geometry in a run. The module's own documentation treats the cache as an optimisation ("an entry that does not read back is translated again"), not as something a shader depends on.

What the fix does

  • The converter (Translate) records that its translation worked.
  • When get_or_convert fails after a successful translation, cached logs a warning naming the cache error. It then leaves the cache loop and translates without the cache, the same path already used after two unreadable entries.
  • When the translation itself fails, the error is returned as before.

In this rare case the shader is translated twice. I kept it that way to leave the cache interface unchanged.

How it behaves after the fix

A shader that translates is used whether or not its cache entry could be written. A warning (shader cache entry not written, with the OS error) says the cache couldn't keep it. A shader that doesn't translate still fails with its own error.

Tests

The new test a_cache_that_cannot_keep_an_entry_still_gives_the_translation:

  • puts a file where each of the 256 shard folders would go, so no entry can be written;
  • checks that cached still returns the translation;
  • checks that a failing translation still returns its own error.

I ran cargo test --workspace on GitHub's windows-latest with Rust 1.98.1 from rust-toolchain.toml:

Not tested: a real disk-full or scanner case.

Related: #254 and #130 change cached too. #161 cleans up staging files after a failed write, but still returns the error.

…tion

host_shader goes through the shader cache, which translates on a miss
and then writes the entry. When the write failed (a full disk, a file
where the entry's folder goes, a scanner holding the new file during
the rename), the error came back as the shader's: a translation that
had worked was thrown away, the shader was marked as not translating
for the rest of the run, and every draw using it was dropped.

The converter now records that its translation worked; a cache error
after that is logged as such and the shader is translated without the
cache, as when there is none.
muhammed-aksoy pushed a commit to muhammed-aksoy/VIctory that referenced this pull request Nov 24, 2026
AntoninMichelq pushed a commit to AntoninMichelq/VIctory-forkAMD that referenced this pull request Nov 24, 2026
On top of integrate/shaders2. Conflicts:
- lower.rs: Marvisak#265's scratch() stays; flat() takes Marvisak#294's root SRV/UAV doc.
- valu_tests.rs: the shader side's test helpers (emit with a Target) stay;
  Marvisak#294's two root UAV tests are appended.
- shader_cache.rs: both new tests kept (Marvisak#320 wave-size key, Marvisak#358 cache
  that cannot keep an entry).
- HostShader initialisers in scratch_tests.rs and valu_tests.rs get
  root_uavs; emit() calls in tests get Target::ANY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@jeremygold02

Copy link
Copy Markdown
Contributor

Tested PR #358 at head 369dc3246931ec4d0d9a1e0aaec0dae2da717d1c (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at 369dc3246931ec4d0d9a1e0aaec0dae2da717d1c.

  • cargo test --locked -p victory-gpu a_cache_that_cannot_keep_an_entry_still_gives_the_translation — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 44 filtered out; finished in 0.14s ); cases: shader_cache::tests::a_cache_that_cannot_keep_an_entry_still_gives_the_translation.

Behavior covered: Checks an uncacheable shader-cache entry still returns the translation to the caller.
Code: crates/victory-gpu/src/shader_cache.rs

Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…Marvisak#358 Marvisak#89 Marvisak#331 Marvisak#86 Marvisak#83 Marvisak#211 Marvisak#260 Marvisak#275)

Conflict in crates/victory-gpu/src/descriptor/host.rs: gpu-state (Marvisak#251)
moved the dynamic-slot search into free_table(); gpu-draw (Marvisak#86) bounds
the search by the heap's spare slots instead of DYNAMIC. free_table() works
over taken.len(), which is the spare count, so the helper is kept with
gpu-draw's spare-based cursor wrap. Both sides' tests kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sahajiscoding added a commit to sahajiscoding/VIctory that referenced this pull request Nov 24, 2026
… & shader ops

- Prefer high-performance discrete GPU via IDXGIFactory6::EnumAdapterByGpuPreference
  and VICTORY_ADAPTER (index or name substring) in victory-gpu and victory-shader (Marvisak#208/Marvisak#1132)
- Cap shader-visible sampler heaps at D3D12's 2,048 architectural limit instead of
  failing heap creation (Marvisak#100/Marvisak#86)
- Fall back to the in-memory translated shader if shader-cache disk write fails (Marvisak#358)
- Add F11 / Alt+Enter borderless fullscreen toggle and clean WM_CLOSE handling to
  both title windows (lifecycle.rs) and VIctory's fallback window (host.rs); clamp
  fit_into() dimensions to >= 1 (Marvisak#451)
- Enhance PC keyboard+mouse fallback gamepad with Space/LShift/R/LCtrl aliases,
  LMB/RMB/MMB triggers, and RMB/F9 mouse camera look; support null-device
  cross-device previous/next reading walk (Marvisak#361)
- Fall back to a no-op display deferral when PowerSetRequest returns ERROR_NOT_SUPPORTED
- Clamp short virtual-drive '..' paths at the virtual drive root (Marvisak#182)
- Wake and cancel sleeping delayed callbacks immediately on XTaskQueueTerminate (Marvisak#132)
- Cache XMA IMDCT rotation sin/cos tables across subframes (Marvisak#172)
- Lower additional RDNA2 VALU instructions (v_mul_hi_{u,i}32_{u,i}24, v_mad_{u,i}32_{u,i}16,
  v_lerp_u8, v_sad_u{8,16,32}, v_cvt_pk_{u,i}16_{u,i}32, v_dot{2,4}_{i,u}32_{i,u}{16,8})
  with DXIL validation and conditional INT64 feature flagging (Marvisak#157)
- Add portable victory.toml lookup next to victory.exe, interactive [S] Setup wizard
  and [K] Controls guide in victory.exe, and scripts/build-windows.ps1 release packager

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
The tester tree (upstream main ffe310e plus its PRs, update 8; see its
INTEGRATION.md) ran 11-25 minutes in the world on an RTX 5070 without a
device removal. Where both sides carry the same PR (the wave64 stack
#223/#233/#320 with #439 and #180, #454, #336, #259, #331 and others), the
tester tree's newer head is taken; our own work and the PRs only we
merged are kept.

Conflicts, file by file:

- descriptor/host.rs: the tester layout (`spare`, the guard slot after the
  dynamic slots, `free_table`, the capped sampler heap). A capped view
  heap keeps `capped_reserve()` dynamic slots, now 2^18 by default (the
  tester measurement, and our 91fed158), still `VICTORY_DYNAMIC_SLOTS` in
  diagnostics builds; uncapped hosts keep our 2^19. Our slot statistics
  (TAKEN/PEAK/SHORT), the bindless plan cache (`CommittedRegions`,
  `timed_valid_title_address`, `timed_find`, `title_bounds`) and the
  revision triple are kept beside the tester's `guard_slot`.
- Buffer states: the tester tree's buffer-state tracker (#334: every list
  moves host copies of title memory between GENERIC_READ and
  UNORDERED_ACCESS and back to common before it closes) and depth twins
  (#469) are taken. #40's enhanced/legacy indirect barriers (the indirect
  prelude, `use_indirect_buffers`, the title buffer handoff mirrored in
  `host_barrier`) cannot share buffers with that tracker and are dropped;
  #40's argument checks (`byte_len`, exact spans, overflow-safe clamp
  shader, aligned counts) stay. `indirect::bound` and #282's
  `rectangles` go through `buffer_state`, and `indirect::execute` (#334)
  replaces `done`. #178's DXC fallback compiles both of our passes.
  Our segments (#387: `close` ends the segment, `close_native` closes a
  native list) carry the tracker: each native list returns its buffers
  to common and its twins to their depth targets, and each prelude also
  holds our texture uploads.
- shadow.rs: our write flow (`queue_write`, one `snapshot` after the
  batch's refreshes, `finish_writes`, the unchanged-page cache) with
  #261's copy-back that also gives the snapshot the title's bytes; its
  tests run through our flow.
- pipeline/make.rs: #275's per-frame budget and per-pipeline wake pair,
  with our compute waits (a dispatch waits for its pipeline, up to 20 s).
- pipeline/library.rs: the tester version (#347, #275's saver thread);
  our concurrent-write test kept. shader_cache.rs: our byte-returning
  cache API with #358's "translated, only not kept".
- draw.rs: #493's root SRV tables; where no table can stand in, our
  drop of a draw whose root view is unset or outside title buffers. Our
  refusal of a table offset past the capped heap stays.
- resource.rs: `HostTexture` has both our `staged` generation and the
  depth twin.
- Shaders: the tester's lower.rs for the wave64 stack, #160's image
  sampling (it covers our #73 and #136 sample forms) and #453/#587; kept
  from our side: #136's preference for an image or buffer use of a
  descriptor read as data and its `s_buffer_` arm, #422's nearest-even
  narrowing (also for #169's d16 loads and #453's interpolation), #452's
  spin-wait limit, #391's LDS limit, #302's spilled root arguments (now in
  `NativeProgram::translation_ir`), #136's PSV0 interpolation beside the
  tester's row harmonisation. split_tests.rs, lane_read_loop_tests.rs and
  docs/wave64-on-wave32.md are the tester versions (the same PRs at newer
  heads).
- Tests: #483's heap guard dwords filled in our GPU tests of #200
  (v_div_scale) and #437 (scalar loads from a raw view), which read
  through the guard slot otherwise; #334's debug-layer test passes an
  offset to our `indirect::bound`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yourmomsbasement pushed a commit to yourmomsbasement/VIctory_Dev that referenced this pull request Nov 24, 2026
…ied together

Merges Marvisak#72 Marvisak#347 Marvisak#1000 Marvisak#358 Marvisak#352 Marvisak#626 Marvisak#1152 Marvisak#1129 Marvisak#1203 Marvisak#24 Marvisak#642 Marvisak#427 Marvisak#485
Marvisak#550 Marvisak#174 Marvisak#1279 onto main (ffe310e), each head unchanged, no conflicts.

One change of mine: three of the PRs each add a `mod tests` at the end of
pipeline/host.rs, so the merge defines `tests` three times (E0428). The
second and third are named `library_tests` and `blend_tests`; nothing else
changes.

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(367 passed, 6 ignored; main has 342 passed, 6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
MamaLeVrai added a commit to MamaLeVrai/VIctory that referenced this pull request Nov 24, 2026
…erlaps with the GPU bundles

Marvisak#189 (wave64 on 32-lane hosts) and the GPU bundles Marvisak#1426 and Marvisak#1439 overlap
in three places:

- host.rs, where the host is built: Marvisak#208 (Marvisak#1426) logs the capabilities
  summary, Marvisak#189 chooses the Wave64 mode. Both lines are kept.
- host.rs, after the device helpers: Marvisak#208's adapter and capability probe and
  Marvisak#189's recommended_wave64_mode are two new functions at the same spot.
  Both are kept.
- shader_cache.rs: Marvisak#189 prefixes the translation input with a mode byte
  (input[33..]), Marvisak#358 (Marvisak#1439) records that a translation ran
  (self.translated). Both are kept; the two tests of Marvisak#358 that call
  cached() pass Wave64Mode::Native, as Marvisak#189's own tests do.

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(725 passed, 11 ignored, two runs).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Marvisak Marvisak closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants