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;
|
2023-01-19 17:06:17 +11:00
|
|
|
use crate::front::GlslangCompilation;
|
2022-11-28 15:47:41 +11:00
|
|
|
use crate::reflect::cross::{CompiledProgram, GlslReflect, HlslReflect};
|
2022-11-11 17:53:02 +11:00
|
|
|
use crate::reflect::ReflectShader;
|
2022-11-11 17:44:41 +11:00
|
|
|
|
2023-02-08 10:50:26 +11:00
|
|
|
/// The GLSL version to target.
|
|
|
|
pub use spirv_cross::glsl::Version as GlslVersion;
|
2022-12-01 17:50:16 +11:00
|
|
|
|
2023-02-08 10:50:26 +11:00
|
|
|
/// The HLSL shader model version to target.
|
|
|
|
pub use spirv_cross::hlsl::ShaderModel as HlslShaderModel;
|
2023-02-02 10:58:21 +11:00
|
|
|
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The context for a GLSL compilation via spirv-cross.
|
|
|
|
pub struct CrossGlslContext {
|
|
|
|
/// A map of bindings of sampler names to binding locations.
|
2022-11-24 18:08:58 +11:00
|
|
|
pub sampler_bindings: Vec<(String, u32)>,
|
2022-12-01 17:50:16 +11:00
|
|
|
/// The compiled program artifact after compilation.
|
|
|
|
pub artifact: CompiledProgram<spirv_cross::glsl::Target>,
|
2022-11-11 18:26:57 +11:00
|
|
|
}
|
2022-11-22 08:28:28 +11:00
|
|
|
|
2022-11-11 17:44:41 +11:00
|
|
|
impl FromCompilation<GlslangCompilation> for GLSL {
|
|
|
|
type Target = GLSL;
|
2022-12-01 17:50:16 +11:00
|
|
|
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;
|
2022-11-11 17:44:41 +11:00
|
|
|
|
|
|
|
fn from_compilation(
|
|
|
|
compile: GlslangCompilation,
|
2022-11-30 17:38:05 +11:00
|
|
|
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
|
2022-11-11 17:44:41 +11:00
|
|
|
Ok(CompilerBackend {
|
2023-02-06 11:48:24 +11:00
|
|
|
backend: GlslReflect::try_from(&compile)?,
|
2022-11-11 17:44:41 +11:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 17:50:16 +11:00
|
|
|
/// 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>,
|
2022-11-24 17:37:16 +11:00
|
|
|
}
|
|
|
|
|
2022-11-11 17:44:41 +11:00
|
|
|
impl FromCompilation<GlslangCompilation> for HLSL {
|
|
|
|
type Target = HLSL;
|
2023-02-08 10:50:26 +11:00
|
|
|
type Options = Option<HlslShaderModel>;
|
2022-12-01 17:50:16 +11:00
|
|
|
type Context = CrossHlslContext;
|
2022-11-30 17:38:05 +11:00
|
|
|
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context>
|
|
|
|
+ ReflectShader;
|
2022-11-11 17:44:41 +11:00
|
|
|
|
|
|
|
fn from_compilation(
|
|
|
|
compile: GlslangCompilation,
|
2022-11-30 17:38:05 +11:00
|
|
|
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
|
2022-11-11 17:44:41 +11:00
|
|
|
Ok(CompilerBackend {
|
2023-02-06 11:48:24 +11:00
|
|
|
backend: HlslReflect::try_from(&compile)?,
|
2022-11-11 17:44:41 +11:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|