librashader_reflect/back/
glsl.rs

1use crate::back::targets::GLSL;
2use crate::back::{CompileReflectShader, CompilerBackend, FromCompilation};
3use crate::error::ShaderReflectError;
4use crate::front::SpirvCompilation;
5use crate::reflect::cross::{CompiledProgram, SpirvCross};
6
7/// The GLSL version to target.
8pub use spirv_cross2::compile::glsl::GlslVersion;
9
10use crate::reflect::cross::glsl::GlslReflect;
11
12/// The context for a GLSL compilation via spirv-cross.
13pub struct CrossGlslContext {
14    /// A map of bindings of sampler names to binding locations.
15    pub sampler_bindings: Vec<(String, u32)>,
16    /// The compiled program artifact after compilation.
17    pub artifact: CompiledProgram<spirv_cross2::targets::Glsl>,
18}
19
20#[cfg(not(feature = "stable"))]
21impl FromCompilation<SpirvCompilation, SpirvCross> for GLSL {
22    type Target = GLSL;
23    type Options = GlslVersion;
24    type Context = CrossGlslContext;
25    type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross>;
26
27    fn from_compilation(
28        compile: SpirvCompilation,
29    ) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
30        Ok(CompilerBackend {
31            backend: GlslReflect::try_from(&compile)?,
32        })
33    }
34}
35
36#[cfg(feature = "stable")]
37impl FromCompilation<SpirvCompilation, SpirvCross> for GLSL {
38    type Target = GLSL;
39    type Options = GlslVersion;
40    type Context = CrossGlslContext;
41    type Output = Box<dyn CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross> + Send>;
42
43    fn from_compilation(
44        compile: SpirvCompilation,
45    ) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
46        Ok(CompilerBackend {
47            backend: Box::new(GlslReflect::try_from(&compile)?),
48        })
49    }
50}