Streaming, copy queue, texture pools and a shader cache that survives rebuilds

Textures and staging cut from 64 MB blocks; a kept view per page section and
page lists read again until the title has filled them in; the GPU side told
when streamed bytes land; results fetched over the copy queue
(VICTORY_RELAY_COPY=1); the write-watch journal behind a reader-writer lock;
the shader cache keyed by the translator's sources and `victory shaders`;
helper lanes as in upstream 1733 (VICTORY_HELPER_OWN).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 18:55:40 -06:00
1 parent 7f166af4f3
commit 9fea7434cd
20 files changed
+1629 -232

No files matched your search

+56 -45
View File
@@ -1,7 +1,7 @@
//! Translated shaders kept on disk (decision 0003): under the configured
//! cache folder, keyed by the container's content and by the VIctory build
//! that translated it (the BLAKE3 of our executable), so a rebuilt
//! translator never serves an old translation. Entries go through
//! cache folder, keyed by the container's content and by the translator
//! (the BLAKE3 of its sources) and its settings, so a changed translator
//! never serves an old translation. Entries go through
//! `victory-pipeline`'s content-addressed cache, which writes them
//! atomically; an entry that does not read back is translated again.
//!
@@ -37,13 +37,13 @@ pub(crate) fn counts() -> (u64, u64) {
(HITS.load(Ordering::Relaxed), MISSES.load(Ordering::Relaxed))
}
/// What identifies this build: the BLAKE3 of our executable file and of
/// the translation settings it runs with (the loop limit, which a
/// diagnostics build can change at run time).
fn build() -> &'static [u8; 32] {
static BUILD: OnceLock<[u8; 32]> = OnceLock::new();
BUILD.get_or_init(|| {
let exe = std::env::current_exe().and_then(std::fs::read);
/// What identifies a translation beside its container: the translator
/// (the BLAKE3 of its sources, `build.rs`), the settings it runs with, and
/// what it was told of the host. Not our executable: a rebuild of anything
/// else used to translate every shader again.
fn build() -> [u8; 32] {
static FIXED: OnceLock<Vec<u8>> = OnceLock::new();
let fixed = FIXED.get_or_init(|| {
let limit = victory_shader::emit::loop_limit();
if limit != victory_shader::emit::DEFAULT_LOOP_LIMIT {
tracing::warn!(
@@ -51,42 +51,53 @@ fn build() -> &'static [u8; 32] {
"VICTORY_SHADER_LOOP_LIMIT: translated loops stop sooner"
);
}
match exe {
Ok(mut bytes) => {
bytes.extend_from_slice(&limit.to_le_bytes());
// Which group barriers wait is part of the translation too.
bytes.push(victory_shader::emit::group_sync());
// So are the switches that pick the form of a wave64 program:
// without them here a run with `VICTORY_WAVE_WIDE=0` was
// served the translations an earlier run of the same
// executable had cached with the switch unset.
for name in [
"VICTORY_WAVE_WIDE",
"VICTORY_WAVE_DEEP_SKIPS",
"VICTORY_WAVE_OWN_BITS",
"VICTORY_F16_NEAREST",
] {
bytes.extend_from_slice(name.as_bytes());
bytes.push(b'=');
if let Some(value) = std::env::var_os(name) {
bytes.extend_from_slice(value.as_encoded_bytes());
}
bytes.push(0);
}
// And which clean-up passes ran over the translated code.
bytes.extend_from_slice(&victory_shader::emit::shader_opt().to_le_bytes());
*blake3::hash(&bytes).as_bytes()
}
Err(e) => {
// Without it no entry can be trusted: a fresh key per run.
tracing::warn!(error = %e, "cannot read our executable; shader cache unused");
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default();
*blake3::hash(&now.as_nanos().to_le_bytes()).as_bytes()
let mut bytes = env!("VICTORY_TRANSLATOR").as_bytes().to_vec();
bytes.extend_from_slice(&limit.to_le_bytes());
// Which group barriers wait is part of the translation too.
bytes.push(victory_shader::emit::group_sync());
// So are the switches that pick the form of a wave64 program:
// without them here a run with `VICTORY_WAVE_WIDE=0` was
// served the translations an earlier run of the same
// executable had cached with the switch unset.
for name in [
"VICTORY_WAVE_WIDE",
"VICTORY_WAVE_DEEP_SKIPS",
"VICTORY_WAVE_OWN_BITS",
"VICTORY_WAVE_LOCAL",
"VICTORY_F16_NEAREST",
"VICTORY_HELPER_OWN",
"VICTORY_STRICT_JOINS",
"VICTORY_MESH_OUTPUT_STRICT",
] {
bytes.extend_from_slice(name.as_bytes());
bytes.push(b'=');
if let Some(value) = std::env::var_os(name) {
bytes.extend_from_slice(value.as_encoded_bytes());
}
bytes.push(0);
}
})
// And which clean-up passes ran over the translated code.
bytes.extend_from_slice(&victory_shader::emit::shader_opt().to_le_bytes());
bytes
});
let mut hash = blake3::Hasher::new();
hash.update(fixed);
for value in victory_shader::emit::host_settings() {
hash.update(&value.to_le_bytes());
}
*hash.finalize().as_bytes()
}
/// Puts the translation of `container` into the cache before any title asks
/// for it (`victory shaders`): whether it was there already, or why it does
/// not translate. The host is opened first, as a run does: what the card
/// can do decides the form of some programs.
pub fn precompile(container: &[u8]) -> Result<bool, String> {
let _ = crate::host::host();
let misses = MISSES.load(Ordering::Relaxed);
host_shader(container)?;
// (Counts other threads' misses too: the caller only adds them up.)
Ok(MISSES.load(Ordering::Relaxed) == misses)
}
/// The translation of a console shader container, from the cache when
@@ -94,7 +105,7 @@ fn build() -> &'static [u8; 32] {
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() {
Some(cache) => cached(cache, build(), container, translate),
Some(cache) => cached(cache, &build(), container, translate),
None => translate(container),
}
}