librashader_reflect/front/
mod.rs

1use crate::error::ShaderCompileError;
2use librashader_preprocess::ShaderSource;
3pub(crate) mod spirv_passes;
4
5mod glslang;
6
7/// The output of a shader compiler that is reflectable.
8pub trait ShaderReflectObject: Sized {
9    /// The compiler that produces this reflect object.
10    type Compiler;
11}
12
13pub use crate::front::glslang::Glslang;
14
15/// Trait for types that can compile shader sources into a compilation unit.
16pub trait ShaderInputCompiler<O: ShaderReflectObject>: Sized {
17    /// Compile the input shader source file into a compilation unit.
18    fn compile(source: &ShaderSource) -> Result<O, ShaderCompileError>;
19}
20
21/// Marker trait for types that are the reflectable outputs of a shader compilation.
22impl ShaderReflectObject for SpirvCompilation {
23    type Compiler = Glslang;
24}
25
26/// A reflectable shader compilation via glslang.
27#[derive(Debug, Clone)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29pub struct SpirvCompilation {
30    pub(crate) vertex: Vec<u32>,
31    pub(crate) fragment: Vec<u32>,
32}
33
34impl TryFrom<&ShaderSource> for SpirvCompilation {
35    type Error = ShaderCompileError;
36
37    /// Tries to compile SPIR-V from the provided shader source.
38    fn try_from(source: &ShaderSource) -> Result<Self, Self::Error> {
39        Glslang::compile(source)
40    }
41}