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

59 lines
1.9 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::GlslangCompilation;
use crate::reflect::cross::{CompiledProgram, GlslReflect, HlslReflect};
2022-11-11 17:53:02 +11:00
use crate::reflect::ReflectShader;
/// The GLSL version to use.
pub type GlslVersion = spirv_cross::glsl::Version;
2023-02-02 10:58:21 +11:00
/// The HLSL shader model version to use
pub type HlslVersion = spirv_cross::hlsl::ShaderModel;
/// The context for a GLSL compilation via spirv-cross.
pub struct CrossGlslContext {
/// A map of bindings of sampler names to binding locations.
pub sampler_bindings: Vec<(String, u32)>,
/// The compiled program artifact after compilation.
pub artifact: CompiledProgram<spirv_cross::glsl::Target>,
2022-11-11 18:26:57 +11:00
}
impl FromCompilation<GlslangCompilation> for GLSL {
type Target = GLSL;
type Options = GlslVersion;
type Context = CrossGlslContext;
2023-01-17 11:35:23 +11:00
type Output = impl CompileShader<Self::Target, Options = GlslVersion, Context = Self::Context>
2022-11-30 17:38:05 +11:00
+ 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)?,
})
}
}
/// The context for a HLSL compilation via spirv-cross.
pub struct CrossHlslContext {
2023-01-17 11:35:23 +11:00
/// The compiled HLSL program.
pub artifact: CompiledProgram<spirv_cross::hlsl::Target>,
}
impl FromCompilation<GlslangCompilation> for HLSL {
type Target = HLSL;
2023-02-02 10:58:21 +11:00
type Options = Option<HlslVersion>;
type Context = CrossHlslContext;
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)?,
})
}
}