Merge pull request #4 from jeremygold02/codex/paired-wave32

feat(diagnostics): load matching paired Wave32 shaders
This commit is contained in:
trustno1-coder authored and GitHub committed 2026-11-26 07:33:10 -08:00
commit 0ef2b99370
2 files changed
+43 -1

No files matched your search

+42 -1
View File
@@ -121,10 +121,51 @@ pub fn precompile(container: &[u8]) -> Result<bool, String> {
/// there is one.
pub(crate) fn host_shader(container: &[u8]) -> Result<HostShader, String> {
let translate = |c: &[u8]| victory_shader::emit::translate(c).map_err(|e| e.to_string());
match CACHE.get() {
let shader = match CACHE.get() {
Some(cache) => cached(cache, &build(), container, translate),
None => translate(container),
}?;
#[cfg(feature = "diagnostics")]
let shader = paired_override(container, shader);
Ok(shader)
}
/// Try cache entries made by the paired-wave translator for the 32-lane,
/// one-million-descriptor host. The normal translation remains our source
/// of binding metadata and remains in the translation cache.
#[cfg(feature = "diagnostics")]
fn paired_override(container: &[u8], mut shader: HostShader) -> HostShader {
static DIR: OnceLock<Option<PathBuf>> = OnceLock::new();
let Some(dir) = DIR.get_or_init(|| std::env::var_os("VICTORY_PAIRED_SHADER_DIR").map(PathBuf::from)) else {
return shader;
};
if shader.stage != HwStage::Cs || victory_shader::emit::host_settings() != [32, 999_999, 0, 0] {
return shader;
}
let digest = blake3::hash(container).to_hex();
let hash = &digest[..16];
let path = dir.join(format!("{hash}.vsh"));
let mut bytes = match std::fs::read(&path) {
Ok(bytes) => bytes,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return shader,
Err(e) => {
tracing::warn!(hash, error = %e, "could not read paired shader");
return shader;
}
};
// Paired VSH1 entries predate the half-view list. These programs have
// none. The equality check includes the list on our side.
bytes.extend_from_slice(&0u32.to_le_bytes());
if let Some(mut paired) = decode(&bytes) {
let dxil = std::mem::replace(&mut paired.dxil, shader.dxil.clone());
if paired == shader && dxil.starts_with(b"DXBC") {
shader.dxil = dxil;
tracing::info!(hash, "using paired Wave32 bytecode with matching shader bindings");
return shader;
}
}
tracing::warn!(hash, "paired shader entry did not match the translated shader bindings");
shader
}
/// The cache entry's converter: the build and the container in, the
+1
View File
@@ -316,6 +316,7 @@ The on/off switches below (`...=1`) are off when unset or set to `0`.
| `VICTORY_CRASH_SAVE=<rva>:<len>,...` | saves title memory to the cache folder on a crash |
| `VICTORY_CAPTURE=<dir>` | saves presented frames (powers of two, or `VICTORY_CAPTURE_FRAMES=<list>`) |
| `VICTORY_DUMP_TARGETS=1` | with the two above, saves every render target of those frames |
| `VICTORY_PAIRED_SHADER_DIR=<dir>` | opt-in local paired-translator VSH1 compute shaders for 32-lane hosts with a 1,000,000-slot view heap. Loads `<16-digit-shader-hash>.vsh` only when its bindings match the normal translation. Missing or incompatible entries use the normal translation. With `play-nvidia.ps1`, pass the directory through `-More @{VICTORY_PAIRED_SHADER_DIR = 'C:\path\to\paired'}`. |
| `VICTORY_D3D12_DEBUG=1` | host debug layer |
| `VICTORY_D3D12_GBV=1` | with the above, GPU-based validation (bad descriptor use reported, not faulted; slow) |
| `VICTORY_D3D12_DRED=1` | on a GPU failure, the allocation hit and the commands in flight |