Skip to main content

librashader_reflect/front/
mod.rs

1use crate::error::ShaderCompileError;
2use librashader_preprocess::ShaderSource;
3pub(crate) mod spirv_passes;
4
5#[cfg(feature = "glslang-in")]
6mod glslang;
7
8#[cfg(feature = "glslang-in")]
9pub use crate::front::glslang::Glslang;
10
11use crate::reflect::semantics::ShaderSemantics;
12
13#[cfg(feature = "naga-in")]
14mod naga;
15
16#[cfg(feature = "naga-in")]
17pub use crate::front::naga::NagaWgsl;
18
19/// The output of a shader compiler that is reflectable.
20pub trait ShaderReflectObject: Sized {
21    /// The compiler that produces this reflect object.
22    type Compiler;
23}
24
25/// Trait for types that can compile shader sources into a compilation unit.
26pub trait ShaderInputCompiler<O: ShaderReflectObject>: Sized {
27    /// Compile the input shader source file into a compilation unit.
28    fn compile(source: &ShaderSource) -> Result<O, ShaderCompileError>;
29
30    /// Apply the mangled semantics if needed for the outputs
31    fn apply_mangled_semantics(_semantics: &mut ShaderSemantics) {}
32}
33
34/// A reflectable shader compilation via glslang.
35#[derive(Debug, Clone)]
36#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
37pub struct SpirvCompilation {
38    pub(crate) vertex: Vec<u32>,
39    pub(crate) fragment: Vec<u32>,
40}
41
42/// A reflectable shader compilation via naga, where the input is WGSL, and not GLSL.
43///
44/// This is only used for .wgsl.slangpacks when running in `wasm32-unknown-unknown`.
45#[derive(Debug, Clone)]
46#[cfg(feature = "naga-in")]
47#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48pub struct WgslCompilation {
49    pub(crate) vertex: ::naga::Module,
50    pub(crate) fragment: ::naga::Module,
51}