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

49 lines
1.6 KiB
Rust
Raw Normal View History

2022-11-22 08:53:36 +11:00
use crate::back::targets::{GLSL, HLSL};
2022-11-30 17:38:05 +11:00
use crate::back::{CompileShader, CompilerBackend, FromCompilation};
2022-11-11 17:53:02 +11:00
use crate::error::ShaderReflectError;
use crate::front::shaderc::GlslangCompilation;
use crate::reflect::cross::{CompiledProgram, 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 {
pub sampler_bindings: Vec<(String, u32)>,
pub compiler: CompiledProgram<spirv_cross::glsl::Target>,
2022-11-11 18:26:57 +11:00
}
impl FromCompilation<GlslangCompilation> for GLSL {
type Target = GLSL;
type Options = GlVersion;
2022-11-12 17:23:49 +11:00
type Context = GlslangGlslContext;
2022-11-30 17:38:05 +11:00
type Output = impl CompileShader<Self::Target, Options = GlVersion, Context = GlslangGlslContext>
+ ReflectShader;
fn from_compilation(
compile: GlslangCompilation,
2022-11-30 17:38:05 +11:00
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
Ok(CompilerBackend {
backend: GlslReflect::try_from(compile)?,
})
}
}
pub struct GlslangHlslContext {
pub compiler: CompiledProgram<spirv_cross::hlsl::Target>,
}
impl FromCompilation<GlslangCompilation> for HLSL {
type Target = HLSL;
type Options = Option<()>;
type Context = GlslangHlslContext;
2022-11-30 17:38:05 +11:00
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context>
+ ReflectShader;
fn from_compilation(
compile: GlslangCompilation,
2022-11-30 17:38:05 +11:00
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
Ok(CompilerBackend {
backend: HlslReflect::try_from(compile)?,
})
}
}