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

Closed
github-bot wants to merge 1 commit from gh-pr/358/head into gh-pr/358/base
Owner

@⁠Dufftwt on GitHub · 2026-11-24 02:34 UTC · original
Dufftwt:fix/shader-cache-write-failure-keeps-translation → main · +32 −3 · 1 files · 1 commits · closed without merging

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:

  • This PR: everything passes. victory-gpu has 44 passed (1 ignored), the other crates have 0 failed.
  • The new test alone on main: it fails because the good translation comes back as Err("Cannot create a file when that file already exists. (os error 183)").
  • I ran with --test-threads=1. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (#181, #244).

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.

**@⁠Dufftwt** on GitHub · 2026-11-24 02:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/358) `Dufftwt:fix/shader-cache-write-failure-keeps-translation` → `main` · +32 −3 · 1 files · 1 commits · closed without merging ## 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: ```rust 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`: - **This PR:** everything passes. `victory-gpu` has 44 passed (1 ignored), the other crates have 0 failed. - **The new test alone on `main`:** it fails because the good translation comes back as `Err("Cannot create a file when that file already exists. (os error 183)")`. - I ran with `--test-threads=1`. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (#181, #244). **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.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:00:40 +00:00
github-bot closed this pull request 2026-11-26 04:00:40 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:26 UTC · original

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

**@⁠jeremygold02** on GitHub · 2026-11-24 04:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/358#issuecomment-7122028823) 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](https://github.com/Marvisak/VIctory/blob/369dc3246931ec4d0d9a1e0aaec0dae2da717d1c/crates/victory-gpu/src/shader_cache.rs)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!358
No description provided.