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_SUM_WGSL, COMPOSITE_WGSL, FULLSCREEN_TEXTURE_QUAD_WGSL,
8    LAYOUT_PACK_WGSL, READBACK_PACK_WGSL, RGB_TO_YUV420_WGSL, RGBA_PRESENT_WGSL, YUV_REPACK_WGSL,
9    YUV_TO_LINEAR_WGSL, 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, transition's and generator'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        ("composite-sum", COMPOSITE_SUM_WGSL),
31        ("layout-pack", LAYOUT_PACK_WGSL),
32        ("readback-pack", READBACK_PACK_WGSL),
33        ("rgba-present", RGBA_PRESENT_WGSL),
34        ("rgb-to-yuv420", RGB_TO_YUV420_WGSL),
35        ("yuv-repack", YUV_REPACK_WGSL),
36        ("yuv-to-linear", YUV_TO_LINEAR_WGSL),
37        ("yuv16-to-linear", YUV16_TO_LINEAR_WGSL),
38    ]
39    .map(|(label, source)| (label.to_owned(), source.to_owned()))
40    .to_vec();
41    modules.push(("vector".to_owned(), crate::vector::vector_wgsl()));
42    let mut definitions = crate::builtins::internal_effect_definitions();
43    definitions.extend(crate::builtin_effect_definitions());
44    definitions.extend(crate::builtin_transition_definitions());
45    definitions.extend(crate::builtin_generator_definitions());
46    modules.extend(
47        definitions
48            .iter()
49            .map(|definition| (definition.id.clone(), effect_wgsl(definition))),
50    );
51    modules
52}
53
54#[cfg(test)]
55#[path = "shader_inventory_tests.rs"]
56mod tests;