librashader/librashader-reflect/src/back/cross.rs

46 lines
1.4 KiB
Rust
Raw Normal View History

use crate::back::targets::{CompilerBackend, FromCompilation, GLSL, HLSL};
use crate::back::CompileShader;
2022-11-11 17:53:02 +11:00
use crate::error::ShaderReflectError;
use crate::front::shaderc::GlslangCompilation;
2022-11-11 18:26:57 +11:00
use crate::reflect::cross::{CompiledAst, CrossReflect, GlslReflect, HlslReflect};
2022-11-11 17:53:02 +11:00
use crate::reflect::ReflectShader;
pub type GlVersion = spirv_cross::glsl::Version;
2022-11-12 17:23:49 +11:00
pub struct GlslangGlslContext {
2022-11-11 18:26:57 +11:00
pub texture_fixups: Vec<u32>,
pub compiler: CompiledAst<spirv_cross::glsl::Target>
}
impl FromCompilation<GlslangCompilation> for GLSL {
type Target = GLSL;
type Options = GlVersion;
2022-11-12 17:23:49 +11:00
type Context = GlslangGlslContext;
fn from_compilation(
compile: GlslangCompilation,
) -> Result<
2022-11-11 18:26:57 +11:00
CompilerBackend<impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context> + ReflectShader>,
ShaderReflectError,
> {
Ok(CompilerBackend {
backend: GlslReflect::try_from(compile)?,
})
}
}
impl FromCompilation<GlslangCompilation> for HLSL {
type Target = HLSL;
type Options = Option<()>;
2022-11-11 18:26:57 +11:00
type Context = ();
fn from_compilation(
compile: GlslangCompilation,
) -> Result<
2022-11-11 18:26:57 +11:00
CompilerBackend<impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context> + ReflectShader>,
ShaderReflectError,
> {
Ok(CompilerBackend {
backend: HlslReflect::try_from(compile)?,
})
}
}