Skip to main content

alpha2_render/
shader_inventory.rs

1//! All WGSL the renderer gives the GPU, for checking with compilers other than naga.
2//!
3//! naga skips the fragment-stage uniformity rule that Tint and `WebKit` enforce, so a shader
4//! naga accepts can still fail in a browser.
5
6use alpha2_shaders::{
7    CANVAS_PRESENT_WGSL, COMPOSITE_WGSL, FULLSCREEN_TEXTURE_QUAD_WGSL, READBACK_PACK_WGSL,
8    RGB_TO_YUV420_WGSL, RGBA_PRESENT_WGSL, YUV_REPACK_WGSL, YUV_TO_LINEAR_WGSL,
9    YUV16_TO_LINEAR_WGSL,
10};
11
12use crate::EffectDef;
13use crate::registry::build_shader;
14
15/// The full module compiled for `definition`: generated preamble plus body.
16#[must_use]
17pub fn effect_wgsl(definition: &EffectDef) -> String {
18    build_shader(definition)
19}
20
21/// Every labelled WGSL module the renderer can create: built-in pipelines plus each built-in
22/// effect's and transition's generated module.
23#[must_use]
24pub fn builtin_wgsl_modules() -> Vec<(String, String)> {
25    let mut modules = [
26        // Runs only in a browser, so only browser compilers check it.
27        ("canvas-present", CANVAS_PRESENT_WGSL),
28        ("fullscreen-quad", FULLSCREEN_TEXTURE_QUAD_WGSL),
29        ("composite", COMPOSITE_WGSL),
30        ("readback-pack", READBACK_PACK_WGSL),
31        ("rgba-present", RGBA_PRESENT_WGSL),
32        ("rgb-to-yuv420", RGB_TO_YUV420_WGSL),
33        ("yuv-repack", YUV_REPACK_WGSL),
34        ("yuv-to-linear", YUV_TO_LINEAR_WGSL),
35        ("yuv16-to-linear", YUV16_TO_LINEAR_WGSL),
36    ]
37    .map(|(label, source)| (label.to_owned(), source.to_owned()))
38    .to_vec();
39    modules.push(("vector".to_owned(), crate::vector::vector_wgsl()));
40    let mut definitions = crate::builtins::internal_effect_definitions();
41    definitions.extend(crate::builtin_effect_definitions());
42    definitions.extend(crate::builtin_transition_definitions());
43    modules.extend(
44        definitions
45            .iter()
46            .map(|definition| (definition.id.clone(), effect_wgsl(definition))),
47    );
48    modules
49}
50
51#[cfg(test)]
52#[path = "shader_inventory_tests.rs"]
53mod tests;