Merge remote-tracking branch 'pr/1901' into wave-6

This commit is contained in:
trustno1-coder
2026-11-28 19:33:07 -08:00

View File

@ -109,11 +109,7 @@ fn build() -> [u8; 32] {
// So are the switches that pick the form of a translation ([`KEYED`]).
for name in KEYED {
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);
append_setting_value(&mut bytes, std::env::var_os(name).as_deref());
}
// So is whether pixel programs keep the console's early depth test
// (`VICTORY_EARLY_DEPTH=1`): only while it is on, so that the
@ -148,6 +144,17 @@ fn build() -> [u8; 32] {
*hash.finalize().as_bytes()
}
/// Unset can select a built-in policy while an explicitly empty value opts out.
/// Encode presence separately. Environment values cannot contain a NUL.
fn append_setting_value(bytes: &mut Vec<u8>, value: Option<&std::ffi::OsStr>) {
bytes.push(b'=');
bytes.push(u8::from(value.is_some()));
if let Some(value) = value {
bytes.extend_from_slice(value.as_encoded_bytes());
}
bytes.push(0);
}
/// What tells one set of translations from another ([`build`]).
pub(crate) fn translation() -> [u8; 32] {
build()
@ -571,6 +578,28 @@ mod tests {
}
}
#[test]
fn unset_and_empty_settings_do_not_reuse_a_cached_translation() {
let dir = tempfile::tempdir().unwrap();
let cache = Cache::open(dir.path()).unwrap();
let runs = AtomicU64::new(0);
let mut outputs = Vec::new();
for setting in [Some(""), None, Some("skip-one"), None, Some("")] {
let mut input = b"setting".to_vec();
append_setting_value(&mut input, setting.map(std::ffi::OsStr::new));
let build = blake3::hash(&input);
let result = cached(&cache, build.as_bytes(), b"synthetic", |_| {
runs.fetch_add(1, Ordering::Relaxed);
let mut value = shader();
value.dxil.push(match setting { None => 0, Some("") => 1, _ => 2 });
Ok(value)
}).unwrap();
outputs.push(*result.dxil.last().unwrap());
}
assert_eq!(outputs, [1, 0, 2, 0, 1]);
assert_eq!(runs.load(Ordering::Relaxed), 3);
}
#[test]
fn translations_come_back_from_the_cache() {
let dir = tempfile::tempdir().unwrap();