shader cache: victory shaders and translate --warm report shaders as cached when there is no cache #291

Open
opened 2026-11-26 19:22:35 +00:00 by github-bot · 1 comment
Owner

@⁠itsonewi on GitHub · 2026-11-26 19:16 UTC · original

What happens

crates/victory-gpu/src/shader_cache.rs:161-171 answers "this translation was already in the cache" with a counter that only moves when a cache exists:

pub fn precompile(container: &[u8]) -> Result<bool, String> {
    let _ = crate::host::host();
    let misses = MISSES.load(Ordering::Relaxed);
    ...
    match CACHE.get() {
        Some(cache) => cached(cache, &build(), container, translate, true)?,
        None => translate(container)?,                      // :167
    };
    Ok(MISSES.load(Ordering::Relaxed) == misses)            // :170
}

MISSES is bumped only inside cached_by, on a real miss (:262-274). In the None arm (:167) the container is translated, but MISSES is left alone, so :170 returns Ok(true) — "it was there already" — for a translation that just happened.

That arm is reachable in ordinary use: use_shader_cache (:61-67) swallows a failed Cache::open with tracing::warn!("no shader cache") and runs on with CACHE empty (cache folder on a read-only or full volume, a path that is a file, a locked or undeletable folder...). Both callers of precompile then report success for work that was thrown away:

  • victory shaders — apps/victory/src/translate.rs:436-440 counts every Ok(_) towards done and prints "{done} shaders in the cache" (:468).
  • victory translate --warm — crates/victory-hle/src/modules/d3d12x.rs:71-74 turns the answer inside out (|was_there| !was_there, so Ok(false) means "in the cache already"), and apps/victory/src/translate.rs:227/:231 print it as "{translated} translated now, {there} in the cache already".

So with no usable cache folder, both commands finish with a clean summary — "N shaders in the cache", or "0 translated now, N in the cache already" — while nothing was written and the next run translates every one of them again. The only hint is one warn! line from use_shader_cache, far from the summary that contradicts it.

Why it matters

The whole point of victory shaders and --warm is that the run after them finds its shaders translated. A run that says it filled the cache and did not costs the user the same warm-up twice (minutes to tens of minutes), with the tool's own output as the reason to believe it worked.

Suggested fix

Count the translation in the None arm as well, or return Ok(false) there, so that "was there already" means exactly that. A shader translated without a cache should show up as "translated now" (and victory shaders should not count it as in the cache). Reporting a Cache::open failure once at the end of the run, next to the counts, would make the cause visible.

AI use

Found by reading crates/victory-gpu/src/shader_cache.rs, crates/victory-hle/src/modules/d3d12x.rs and apps/victory/src/translate.rs. Nothing was built or run (no Windows build or GPU here), so the no-cache path was traced in the source, not reproduced.

**@⁠itsonewi** on GitHub · 2026-11-26 19:16 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/291) ## What happens `crates/victory-gpu/src/shader_cache.rs:161-171` answers "this translation was already in the cache" with a counter that only moves when a cache exists: ```rust pub fn precompile(container: &[u8]) -> Result<bool, String> { let _ = crate::host::host(); let misses = MISSES.load(Ordering::Relaxed); ... match CACHE.get() { Some(cache) => cached(cache, &build(), container, translate, true)?, None => translate(container)?, // :167 }; Ok(MISSES.load(Ordering::Relaxed) == misses) // :170 } ``` `MISSES` is bumped only inside `cached_by`, on a real miss (`:262-274`). In the `None` arm (`:167`) the container *is* translated, but `MISSES` is left alone, so `:170` returns `Ok(true)` — "it was there already" — for a translation that just happened. That arm is reachable in ordinary use: `use_shader_cache` (`:61-67`) swallows a failed `Cache::open` with `tracing::warn!("no shader cache")` and runs on with `CACHE` empty (cache folder on a read-only or full volume, a path that is a file, a locked or undeletable folder...). Both callers of `precompile` then report success for work that was thrown away: * `victory shaders` — `apps/victory/src/translate.rs:436-440` counts every `Ok(_)` towards `done` and prints `"{done} shaders in the cache"` (`:468`). * `victory translate --warm` — `crates/victory-hle/src/modules/d3d12x.rs:71-74` turns the answer inside out (`|was_there| !was_there`, so `Ok(false)` means "in the cache already"), and `apps/victory/src/translate.rs:227`/`:231` print it as "{translated} translated now, {there} in the cache already". So with no usable cache folder, both commands finish with a clean summary — "N shaders in the cache", or "0 translated now, N in the cache already" — while nothing was written and the next run translates every one of them again. The only hint is one `warn!` line from `use_shader_cache`, far from the summary that contradicts it. ## Why it matters The whole point of `victory shaders` and `--warm` is that the run after them finds its shaders translated. A run that says it filled the cache and did not costs the user the same warm-up twice (minutes to tens of minutes), with the tool's own output as the reason to believe it worked. ## Suggested fix Count the translation in the `None` arm as well, or return `Ok(false)` there, so that "was there already" means exactly that. A shader translated without a cache should show up as "translated now" (and `victory shaders` should not count it as in the cache). Reporting a `Cache::open` failure once at the end of the run, next to the counts, would make the cause visible. ## AI use Found by reading `crates/victory-gpu/src/shader_cache.rs`, `crates/victory-hle/src/modules/d3d12x.rs` and `apps/victory/src/translate.rs`. Nothing was built or run (no Windows build or GPU here), so the no-cache path was traced in the source, not reproduced.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:22:35 +00:00
Author
Owner

@⁠TinkerBell-90 on GitHub · 2026-11-26 21:03 UTC · original

I tried this on a-publier at cd8dfc0 and could not get the summary described here: the None arm of precompile is not reached from victory shaders or translate --warm.

Both commands call cfg.cache_subdir("shaders")? before use_shader_cache (apps/victory/src/translate.rs:180 and :413), and subdir (crates/victory-core/src/config.rs:134) does the same two steps as Cache::open (crates/victory-pipeline/src/cache.rs:37) on the same directory: ensure_outside_repo, then create_dir_all. Whatever would make Cache::open fail has already failed in cache_subdir, and the command stops there with that error. So CACHE is set whenever these two commands get to translate, unless the folder changes between the two calls.

Run on Linux: the app built for x86_64-pc-windows-gnu, under Wine 10 + vkd3d-proton on an RX 9070 XT (RADV). Not Windows. The input is one container made with the test helpers of native.rs (a pixel shader that is only s_endpgm); no game files, nothing run in game.

cache folder victory shaders victory translate --warm all
new 1 shaders in the cache, exit 0 1 translated now, 0 in the cache already, exit 0; on the folder victory shaders filled: 0 translated now, 1 in the cache already
VICTORY_CACHE_DIR is a file Error: creating ...\shaders (os error 183), exit 1 same, exit 1
shaders exists, read-only 0 shaders in the cache, 1 do not translate, reason Access denied. (os error 5), exit 0 0 translated now, 0 in the cache already, 1 do not translate, exit 0

No run claims a shader is in the cache when it is not. Ok(false) in the None arm would still be right for a future caller, but it changes nothing these two commands print today.

What does mislead is the last row. The shader translated, the write failed, and both commands count it under "do not translate". victory shaders at least shows the reason; --warm drops it (Err(_) => 2, translate.rs:218), so all the user sees is "1 do not translate" and exit 0. If anything here needs a fix, it is that: keep the reason in --warm as victory shaders does, or tell a cache write error apart from a translation refusal.

AI-assisted.

**@⁠TinkerBell-90** on GitHub · 2026-11-26 21:03 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/291#issuecomment-7203349667) I tried this on `a-publier` at `cd8dfc0` and could not get the summary described here: the `None` arm of `precompile` is not reached from `victory shaders` or `translate --warm`. Both commands call `cfg.cache_subdir("shaders")?` before `use_shader_cache` (`apps/victory/src/translate.rs:180` and `:413`), and `subdir` (`crates/victory-core/src/config.rs:134`) does the same two steps as `Cache::open` (`crates/victory-pipeline/src/cache.rs:37`) on the same directory: `ensure_outside_repo`, then `create_dir_all`. Whatever would make `Cache::open` fail has already failed in `cache_subdir`, and the command stops there with that error. So `CACHE` is set whenever these two commands get to translate, unless the folder changes between the two calls. Run on Linux: the app built for `x86_64-pc-windows-gnu`, under Wine 10 + vkd3d-proton on an RX 9070 XT (RADV). Not Windows. The input is one container made with the test helpers of `native.rs` (a pixel shader that is only `s_endpgm`); no game files, nothing run in game. | cache folder | `victory shaders` | `victory translate --warm all` | |---|---|---| | new | `1 shaders in the cache`, exit 0 | `1 translated now, 0 in the cache already`, exit 0; on the folder `victory shaders` filled: `0 translated now, 1 in the cache already` | | `VICTORY_CACHE_DIR` is a file | `Error: creating ...\shaders` (`os error 183`), exit 1 | same, exit 1 | | `shaders` exists, read-only | `0 shaders in the cache, 1 do not translate`, reason `Access denied. (os error 5)`, exit 0 | `0 translated now, 0 in the cache already, 1 do not translate`, exit 0 | No run claims a shader is in the cache when it is not. `Ok(false)` in the `None` arm would still be right for a future caller, but it changes nothing these two commands print today. What does mislead is the last row. The shader translated, the write failed, and both commands count it under "do not translate". `victory shaders` at least shows the reason; `--warm` drops it (`Err(_) => 2`, `translate.rs:218`), so all the user sees is "1 do not translate" and exit 0. If anything here needs a fix, it is that: keep the reason in `--warm` as `victory shaders` does, or tell a cache write error apart from a translation refusal. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.