Shader packs: read pack sources as Iris's JCPP does; legalise what naga refuses

Preprocessor (GLSL and shaders.properties), as JCPP does:
- a #define replaces an earlier macro (Bloop, Steadfast: DefineRedefined);
- in #if, a float counts as its integer part (Steadfast's
  shaders.properties float token), and a macro always defined empty counts
  as 0 (Iris's MC_GL_VENDOR_OTHER, Bloop's TAA_USE_YCOCG);
- an #if may run to the end of the input (Bloop's taa.fsh);
- #error "..." lexes in skipped blocks (Photon);
- shaders.properties keeps its empty lines and hides backslashes from the
  preprocessor (IRIS_PASSTHROUGHBACKSLASH), so a continued value no longer
  swallows the next directive or line (Photon, Bliss, Steadfast's custom
  uniforms; Complementary's isCold uniform is now complete).

Legaliser: % through overloads (naga won't take ivec2 % int: Noble),
sqrt of a negative constant left to the GPU (Bloop's NaN), constants naga
can't fold (?:, mix: Bliss) become globals set in main, and 16/8-bit types
(u16vec2 & co., Noble on NVIDIA) become their 32-bit ones.

horizon-client: real_packs_load runs the game's own load over the packs in
HORIZON_TEST_SHADERPACKS (the compatibility table's source).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-22 02:45:32 +02:00
parent 5aff29807a
commit 21998a7e6a
6 changed files with 629 additions and 14 deletions
+39
View File
@@ -179,4 +179,43 @@ mod tests {
);
assert_eq!(vendor_name(0, "Apple M4 Pro"), "Apple");
}
/// The packs in `HORIZON_TEST_SHADERPACKS` (folders or zips) load as the
/// game loads them, with their default options: the compatibility table
/// of docs/shader-packs.md. Skipped when the variable isn't set.
#[test]
fn real_packs_load() {
let Some(dir) = std::env::var_os("HORIZON_TEST_SHADERPACKS") else {
return;
};
let mut entries: Vec<_> = std::fs::read_dir(dir)
.unwrap()
.flatten()
.map(|e| e.path())
.filter(|p| is_java_pack(p))
.collect();
entries.sort();
let mut failures = Vec::new();
for path in entries {
let name = path.file_name().unwrap().to_string_lossy().into_owned();
match load(&path, &BTreeMap::new(), "Apple", "Apple M4 Pro") {
Ok(pack) => {
let folders: Vec<String> = pack
.folders
.iter()
.map(|f| {
let n = f.passes.len() + usize::from(f.final_pass.is_some());
format!("{} {n} passes", f.folder)
})
.collect();
println!("{name}: loads ({})", folders.join(", "));
}
Err(e) => {
println!("{name}: {e}");
failures.push(name);
}
}
}
assert!(failures.is_empty(), "{failures:?}");
}
}