Shader cache: HOST_MAX_WAVE is not part of the cache key #1844

Open
opened 2026-11-26 04:46:23 +00:00 by github-bot · 6 comments
Owner

@⁠Melow-code on GitHub · 2026-11-24 23:17 UTC · original

What happens

The shader cache identifies a compiled shader by its ISA code hash, the host GPU's vendor and device, and the translator version. It does not include the host's maximum wave size (HOST_MAX_WAVE).

A cache built on an AMD GPU (64-lane waves) serves DXIL compiled for wave64. When the same cache is used on an NVIDIA GPU (32-lane waves), the wave64 DXIL is loaded and passed to the NVIDIA driver, which refuses it or produces wrong results.

How to reproduce

  1. Build the shader cache on an AMD GPU with VICTORY_WAVE_WIDE=1.
  2. Copy the cache directory to a machine with an NVIDIA GPU.
  3. Run the same title. The cached shaders are loaded without recompilation.
  4. The NVIDIA driver either refuses the PSO (wave64 not supported) or the shader runs with wrong lane semantics.

Suggested fix

Add HOST_MAX_WAVE (or the effective wave size used during compilation) to the cache key. A cache miss on a different host wave size triggers recompilation.

This also affects the reverse direction: a cache from NVIDIA wave32 on AMD wave64 would miss the upper-half lowering.

**@⁠Melow-code** on GitHub · 2026-11-24 23:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/1844) ## What happens The shader cache identifies a compiled shader by its ISA code hash, the host GPU's vendor and device, and the translator version. It does not include the host's maximum wave size (`HOST_MAX_WAVE`). A cache built on an AMD GPU (64-lane waves) serves DXIL compiled for wave64. When the same cache is used on an NVIDIA GPU (32-lane waves), the wave64 DXIL is loaded and passed to the NVIDIA driver, which refuses it or produces wrong results. ## How to reproduce 1. Build the shader cache on an AMD GPU with `VICTORY_WAVE_WIDE=1`. 2. Copy the cache directory to a machine with an NVIDIA GPU. 3. Run the same title. The cached shaders are loaded without recompilation. 4. The NVIDIA driver either refuses the PSO (wave64 not supported) or the shader runs with wrong lane semantics. ## Suggested fix Add `HOST_MAX_WAVE` (or the effective wave size used during compilation) to the cache key. A cache miss on a different host wave size triggers recompilation. This also affects the reverse direction: a cache from NVIDIA wave32 on AMD wave64 would miss the upper-half lowering.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:46:23 +00:00
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-24 23:22 UTC · original

On main 70564ae I can't find HOST_MAX_WAVE or VICTORY_WAVE_WIDE (git grep over crates/ and apps/ finds neither). emit::translate(container) takes no host input: it emits the console's own WaveSize and leaves the host to accept or refuse the pipeline. So on main a translation is the same on every GPU. The cache key (shader_cache.rs key(): translator source hash, entry encoding, loop limit) is complete for it, and it has no vendor or device in it either.

The problem you describe would appear with a change that lowers wave64 programs differently on 32-lane hosts (the wave64-on-32 work in #189, #439 or #734, say). Whichever of those lands should put the host's wave size into key(), next to the loop limit. Which branch has HOST_MAX_WAVE? That's the one to raise it on.

**@⁠BastienRodz** on GitHub · 2026-11-24 23:22 UTC · [original](https://github.com/Marvisak/VIctory/issues/1844#issuecomment-7147326811) On `main` `70564ae` I can't find `HOST_MAX_WAVE` or `VICTORY_WAVE_WIDE` (`git grep` over `crates/` and `apps/` finds neither). `emit::translate(container)` takes no host input: it emits the console's own `WaveSize` and leaves the host to accept or refuse the pipeline. So on `main` a translation is the same on every GPU. The cache key (`shader_cache.rs` `key()`: translator source hash, entry encoding, loop limit) is complete for it, and it has no vendor or device in it either. The problem you describe would appear with a change that lowers wave64 programs differently on 32-lane hosts (the wave64-on-32 work in #189, #439 or #734, say). Whichever of those lands should put the host's wave size into `key()`, next to the loop limit. Which branch has `HOST_MAX_WAVE`? That's the one to raise it on.
Author
Owner

@⁠fiestorra on GitHub · 2026-11-24 23:24 UTC · original

Checked against main: the premise does not hold, and here is what the key actually is

I went looking for the two symbols before believing the report, and on main at 70564ae neither exists:

git grep -l HOST_MAX_WAVE    -- crates apps   →  0 files
git grep -l VICTORY_WAVE_WIDE -- crates apps  →  0 files

That matches what BastienRodz said in the thread, and it is worth pinning down, because the cache key is not missing anything: it is built from three things, and no host property is among them.

crates/victory-gpu/src/shader_cache.rs:

fn key(translator: &str, encoding: &[u8], limit: u32) -> [u8; 32] {
    let mut h = blake3::Hasher::new();
    h.update(translator.as_bytes());          // victory_shader::SOURCE_HASH
    h.update(blake3::hash(encoding).as_bytes()); // this file, whose encode/decode define entries
    h.update(&limit.to_le_bytes());           // VICTORY_SHADER_LOOP_LIMIT
    *h.finalize().as_bytes()
}

Three inputs: the translator's own source hash, the cache file's encoding (so a format change invalidates entries), and the loop limit. Nothing about the adapter, the vendor, or a wave size — because the translation does not depend on any of them. emit::translate(container) emits the console's own WaveSize and leaves the host to accept or refuse the pipeline; that accept-or-refuse is not a cache of translations.

So the scenario in the report — a cache built on AMD serving wave64 DXIL to an NVIDIA card — is not what happens: the same DXIL is produced on both, byte for byte, which is exactly why one cache folder can serve both. What is per adapter is the pipeline cache beside it, and that one does have the guard:

//! … the host refuses a library of another adapter or driver, and an entry
//! whose description differs, so neither is ever used.

(crates/victory-gpu/src/pipeline/library.rs, and the refusal is why a library copied between machines costs a recompile rather than a wrong pipeline).

Two things worth doing with this, neither of which is "add HOST_MAX_WAVE to the key":

  1. If a wave-size switch appears later, the right place for it is a new input on the translation side — it would have to change the emitted DXIL, so it would belong in build() next to the loop limit, not bolted onto the adapter.
  2. If the reporter saw a wrong shader on a copied cache, the interesting question is the pipeline library's guard or the shader cache's read-back check, not the key's inputs; both are testable without the title.

I can also settle the AMD-to-NVIDIA half on one machine, since this one has both an integrated AMD and an RTX 4090: translate into one cache folder with one adapter and run with the other, and the shader cache should hit while the pipeline library recompiles. I will post those numbers if nobody has by the time I get to it.

No game data is involved: a key, two greps and a comment.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 23:24 UTC · [original](https://github.com/Marvisak/VIctory/issues/1844#issuecomment-7147373487) **Checked against `main`: the premise does not hold, and here is what the key actually is** I went looking for the two symbols before believing the report, and on `main` at `70564ae` neither exists: ``` git grep -l HOST_MAX_WAVE -- crates apps → 0 files git grep -l VICTORY_WAVE_WIDE -- crates apps → 0 files ``` That matches what BastienRodz said in the thread, and it is worth pinning down, because the cache key is not missing anything: **it is built from three things, and no host property is among them.** `crates/victory-gpu/src/shader_cache.rs`: ```rust fn key(translator: &str, encoding: &[u8], limit: u32) -> [u8; 32] { let mut h = blake3::Hasher::new(); h.update(translator.as_bytes()); // victory_shader::SOURCE_HASH h.update(blake3::hash(encoding).as_bytes()); // this file, whose encode/decode define entries h.update(&limit.to_le_bytes()); // VICTORY_SHADER_LOOP_LIMIT *h.finalize().as_bytes() } ``` Three inputs: the translator's own source hash, the cache file's encoding (so a format change invalidates entries), and the loop limit. Nothing about the adapter, the vendor, or a wave size — **because the translation does not depend on any of them**. `emit::translate(container)` emits the console's own `WaveSize` and leaves the host to accept or refuse the pipeline; that accept-or-refuse is not a cache of translations. So the scenario in the report — a cache built on AMD serving wave64 DXIL to an NVIDIA card — is not what happens: the *same* DXIL is produced on both, byte for byte, which is exactly why one cache folder can serve both. What is per adapter is the **pipeline** cache beside it, and that one does have the guard: ``` //! … the host refuses a library of another adapter or driver, and an entry //! whose description differs, so neither is ever used. ``` (`crates/victory-gpu/src/pipeline/library.rs`, and the refusal is why a library copied between machines costs a recompile rather than a wrong pipeline). Two things worth doing with this, neither of which is "add `HOST_MAX_WAVE` to the key": 1. **If a wave-size switch appears later**, the right place for it is a new input on the translation side — it would have to change the emitted DXIL, so it would belong in `build()` next to the loop limit, not bolted onto the adapter. 2. **If the reporter saw a wrong shader on a copied cache**, the interesting question is the pipeline library's guard or the shader cache's read-back check, not the key's inputs; both are testable without the title. I can also settle the AMD-to-NVIDIA half on one machine, since this one has both an integrated AMD and an RTX 4090: translate into one cache folder with one adapter and run with the other, and the shader cache should hit while the pipeline library recompiles. I will post those numbers if nobody has by the time I get to it. No game data is involved: a key, two greps and a comment. Written with an AI assistant.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-24 23:29 UTC · original

I found the host-dependent path in fxceless/victory-fork at 2119b0e. Its D3D12 host sets HOST_MAX_WAVE, the emitter uses it to choose a wave64 lowering, and the shader-cache key omits that value. This agrees with the checks above on Marvisak's 70564ae, where the emitter is host-neutral.

8aa94c7 is one commit directly on 2119b0e44c53aa9648307b0c5c73590290305b1f. Its disk-cache regression feeds the same synthetic input with wave limits 32, 64 and unknown, then repeats them. Before the change all six lookups returned the first entry (32). After it, each limit returned its own entry and the three repeats came from disk. All three shader-cache tests, strict GPU Clippy and asset policy passed.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-24 23:29 UTC · [original](https://github.com/Marvisak/VIctory/issues/1844#issuecomment-7147459272) I found the host-dependent path in [fxceless/victory-fork at `2119b0e`](https://github.com/fxceless/victory-fork/commit/2119b0e44c53aa9648307b0c5c73590290305b1f). Its D3D12 host sets `HOST_MAX_WAVE`, the emitter uses it to choose a wave64 lowering, and the shader-cache key omits that value. This agrees with the checks above on Marvisak's `70564ae`, where the emitter is host-neutral. [8aa94c7](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/8aa94c718dc0565ec6b61500e31d63fccb652368) is one commit directly on `2119b0e44c53aa9648307b0c5c73590290305b1f`. Its disk-cache regression feeds the same synthetic input with wave limits 32, 64 and unknown, then repeats them. Before the change all six lookups returned the first entry (32). After it, each limit returned its own entry and the three repeats came from disk. All three shader-cache tests, strict GPU Clippy and asset policy passed.
Author
Owner

@⁠Melow-code on GitHub · 2026-11-25 00:33 UTC · original

Fixed on the fxceless fork, where HOST_MAX_WAVE exists and the lowering reads it: fxceless/victory-gta6#379 makes the shader cache key carry the host max wave (with its own accessor in victory-shader's emit, next to the loop limit), so a cache built on a 64-lane GPU never serves its wave64 translations to a 32-lane GPU, in either direction. The fork's cache had merged the view-heap clamp in the meantime; the PR is rebased on that and its key_bytes carries both.

Upstream has no host-max-wave split yet (the translator requires the device to support the wave size), so the bug as written does not apply to this tree the same way; if the split lands here later, the same key part will be needed.

Written with DeepSeek V4 Pro (OpenCode), reported by Claude Code.

**@⁠Melow-code** on GitHub · 2026-11-25 00:33 UTC · [original](https://github.com/Marvisak/VIctory/issues/1844#issuecomment-7148626232) Fixed on the fxceless fork, where HOST_MAX_WAVE exists and the lowering reads it: fxceless/victory-gta6#379 makes the shader cache key carry the host max wave (with its own accessor in victory-shader's emit, next to the loop limit), so a cache built on a 64-lane GPU never serves its wave64 translations to a 32-lane GPU, in either direction. The fork's cache had merged the view-heap clamp in the meantime; the PR is rebased on that and its key_bytes carries both. Upstream has no host-max-wave split yet (the translator requires the device to support the wave size), so the bug as written does not apply to this tree the same way; if the split lands here later, the same key part will be needed. Written with DeepSeek V4 Pro (OpenCode), reported by Claude Code.
Author
Owner

@⁠StExpeditus on GitHub · 2026-11-25 08:57 UTC · original

Checked against main 940d32f6: the described scenario no longer seems reachable.

  • The translation has no host input. Options (crates/victory-shader/src/emit/mod.rs) has only view_marks: bool; translate_with takes a container and those options, never a device or a wave size. Wave64/wave32 handling reads the native program's flag (native.rs: +0x14 u32 flags: bit 5 wave32 (else wave64)), so the emitted DXIL is identical for a given container on any host GPU.
  • The shader cache key (victory-gpu/src/shader_cache.rs key()) covers every input the translation has: victory_shader::SOURCE_HASH (translator sources, manifest, lock file and compiler), the entry encoding (the file's own text) and the loop limit.
  • The compiled-PSO layer (pipeline/library.rs) is additionally guarded per adapter/driver: the host refuses a library of another adapter or driver.

So a cache entry built on an AMD GPU is byte-identical to one built on NVIDIA for the same container, and the driver-side artifacts can't cross adapters either. Unless a host wave-size input is added to the translation (e.g. wave-size-specialised lowering), there is nothing for HOST_MAX_WAVE to key. Suggest closing as outdated, or keeping it open as a marker for that future input.

**@⁠StExpeditus** on GitHub · 2026-11-25 08:57 UTC · [original](https://github.com/Marvisak/VIctory/issues/1844#issuecomment-7157685993) Checked against main `940d32f6`: the described scenario no longer seems reachable. - The translation has no host input. `Options` (`crates/victory-shader/src/emit/mod.rs`) has only `view_marks: bool`; `translate_with` takes a container and those options, never a device or a wave size. Wave64/wave32 handling reads the **native program's** flag (`native.rs`: `+0x14 u32 flags: bit 5 wave32 (else wave64)`), so the emitted DXIL is identical for a given container on any host GPU. - The shader cache key (`victory-gpu/src/shader_cache.rs` `key()`) covers every input the translation has: `victory_shader::SOURCE_HASH` (translator sources, manifest, lock file and compiler), the entry encoding (the file's own text) and the loop limit. - The compiled-PSO layer (`pipeline/library.rs`) is additionally guarded per adapter/driver: the host refuses a library of another adapter or driver. So a cache entry built on an AMD GPU is byte-identical to one built on NVIDIA for the same container, and the driver-side artifacts can't cross adapters either. Unless a host wave-size input is added to the translation (e.g. wave-size-specialised lowering), there is nothing for `HOST_MAX_WAVE` to key. Suggest closing as outdated, or keeping it open as a marker for that future input.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 12:48 UTC · original

Automated triage for the maintainers.

On main (940d32f) neither HOST_MAX_WAVE nor VICTORY_WAVE_WIDE exists; they come from a fork, as the reporter confirms above. Here the translation takes no host input, and key in crates/victory-gpu/src/shader_cache.rs hashes the translator source hash, the entry encoding and the loop limit, which is everything the translation depends on. So a translation cached on an AMD GPU is the same as one made on NVIDIA. Compiled pipelines are kept per adapter and driver (crates/victory-gpu/src/pipeline/library.rs), and a library from another adapter or driver is refused.

The point stands for later: if a host-dependent wave lowering lands upstream, the host's wave size must join the key. Open PR #2369 adds that key part.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 12:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/1844#issuecomment-7162892352) <!-- victory-issue-triage v1 verdict=answered seen=2026-11-25T08:57:23Z at=2026-11-25T12:48:37Z --> Automated triage for the maintainers. On `main` (`940d32f`) neither `HOST_MAX_WAVE` nor `VICTORY_WAVE_WIDE` exists; they come from a fork, as the reporter confirms above. Here the translation takes no host input, and `key` in `crates/victory-gpu/src/shader_cache.rs` hashes the translator source hash, the entry encoding and the loop limit, which is everything the translation depends on. So a translation cached on an AMD GPU is the same as one made on NVIDIA. Compiled pipelines are kept per adapter and driver (`crates/victory-gpu/src/pipeline/library.rs`), and a library from another adapter or driver is refused. The point stands for later: if a host-dependent wave lowering lands upstream, the host's wave size must join the key. Open PR #2369 adds that key part. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#1844
No description provided.