test: add test for shader preprocess

This commit is contained in:
chyyran 2023-02-08 03:37:21 -05:00
parent 2128945c06
commit 44b2a797b4
4 changed files with 23 additions and 10 deletions

View file

@ -5,7 +5,7 @@ The following shaders are known to be broken due to various issues.
This list is updated as of [slang-shaders@`356678e`](https://github.com/libretro/slang-shaders/commit/356678ec53ca940a53fa509eff0b65bb63a403bb) This list is updated as of [slang-shaders@`356678e`](https://github.com/libretro/slang-shaders/commit/356678ec53ca940a53fa509eff0b65bb63a403bb)
## Parsing errors ## Broken due to parsing errors
librashader's preset parser is somewhat stricter than RetroArch in what it accepts. All shaders and textures in a preset must librashader's preset parser is somewhat stricter than RetroArch in what it accepts. All shaders and textures in a preset must
resolve to a fully canonical path to properly parse. The following shaders have broken paths. resolve to a fully canonical path to properly parse. The following shaders have broken paths.
@ -40,3 +40,9 @@ librashader's parser is fuzzed with slang-shaders and will accept invalid keys l
to account for shader presets that use these invalid constructs. No known shader presets fail to parse due to syntax errors to account for shader presets that use these invalid constructs. No known shader presets fail to parse due to syntax errors
that haven't already been accounted for. that haven't already been accounted for.
## Broken due to preprocessing errors
The preprocessor resolves `#include` pragmas in each `.slang` shader and recursively flattens files into a single compute unit.
* `misc/shaders/glass.slang`: Missing `misc/include/img/param_floats.h`.
* Looks like this was moved too deep, it references `../include/img/param_floats.h`, but the shader lives in the `misc/shaders/` folder.

1
Cargo.lock generated
View file

@ -793,6 +793,7 @@ dependencies = [
"librashader-common", "librashader-common",
"librashader-presets", "librashader-presets",
"nom", "nom",
"rayon",
"rustc-hash", "rustc-hash",
"thiserror", "thiserror",
] ]

View file

@ -24,4 +24,5 @@ line_directives = []
[dev-dependencies] [dev-dependencies]
glob = "0.3.1" glob = "0.3.1"
librashader-presets = { version = "0.1.0-beta.16", path = "../librashader-presets"} librashader-presets = { version = "0.1.0-beta.16", path = "../librashader-presets"}
rayon = "1.6.1"

View file

@ -1,18 +1,23 @@
use glob::glob; use glob::glob;
use librashader_preprocess::{PreprocessError, ShaderSource}; use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderPreset; use librashader_presets::ShaderPreset;
use rayon::prelude::*;
#[test] #[test]
fn preprocess_all_slang_presets_parsed() { fn preprocess_all_slang_presets_parsed() {
for entry in glob("../test/slang-shaders/**/*.slangp").unwrap() { for entry in glob("../test/slang-shaders/**/*.slangp").unwrap() {
if let Ok(path) = entry { if let Ok(path) = entry {
if let Ok(preset) = ShaderPreset::try_parse(&path) { if let Ok(preset) = ShaderPreset::try_parse(&path) {
for shader in preset.shaders { preset.shaders.into_par_iter().for_each(|shader| {
ShaderSource::load(&shader.name).expect(&format!( if let Err(e) = ShaderSource::load(&shader.name) {
"Failed to preprocess shader {} from preset {}", println!(
shader.name.display(), "Failed to preprocess shader {} from preset {}: {:?}",
path.display() shader.name.display(),
)); path.display(),
} e
);
}
})
} }
} }
} }