2022-11-22 08:53:36 +11:00
|
|
|
use crate::back::targets::{GLSL, HLSL};
|
|
|
|
use crate::back::{CompilerBackend, CompileShader, FromCompilation};
|
2022-11-11 17:53:02 +11:00
|
|
|
use crate::error::ShaderReflectError;
|
2022-11-11 17:44:41 +11:00
|
|
|
use crate::front::shaderc::GlslangCompilation;
|
2022-11-22 08:21:50 +11:00
|
|
|
use crate::reflect::cross::{CompiledAst, GlslReflect, HlslReflect};
|
2022-11-11 17:53:02 +11:00
|
|
|
use crate::reflect::ReflectShader;
|
2022-11-11 17:44:41 +11:00
|
|
|
|
|
|
|
pub type GlVersion = spirv_cross::glsl::Version;
|
2022-11-12 17:23:49 +11:00
|
|
|
pub struct GlslangGlslContext {
|
2022-11-20 14:03:58 +11:00
|
|
|
pub sampler_bindings: Vec<u32>,
|
2022-11-22 08:21:50 +11:00
|
|
|
pub compiler: CompiledAst<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;
|
|
|
|
type Options = GlVersion;
|
2022-11-12 17:23:49 +11:00
|
|
|
type Context = GlslangGlslContext;
|
2022-11-22 10:19:43 +11:00
|
|
|
type Output = impl CompileShader<Self::Target, Options = GlVersion, Context = GlslangGlslContext> + ReflectShader;
|
2022-11-11 17:44:41 +11:00
|
|
|
|
|
|
|
fn from_compilation(
|
|
|
|
compile: GlslangCompilation,
|
|
|
|
) -> Result<
|
2022-11-22 10:19:43 +11:00
|
|
|
CompilerBackend<Self::Output>,
|
2022-11-11 17:44:41 +11:00
|
|
|
ShaderReflectError,
|
|
|
|
> {
|
|
|
|
Ok(CompilerBackend {
|
|
|
|
backend: GlslReflect::try_from(compile)?,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 17:37:16 +11:00
|
|
|
pub struct GlslangHlslContext {
|
|
|
|
pub compiler: CompiledAst<spirv_cross::hlsl::Target>,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-11 17:44:41 +11:00
|
|
|
impl FromCompilation<GlslangCompilation> for HLSL {
|
|
|
|
type Target = HLSL;
|
|
|
|
type Options = Option<()>;
|
2022-11-24 17:37:16 +11:00
|
|
|
type Context = GlslangHlslContext;
|
2022-11-22 10:19:43 +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,
|
|
|
|
) -> Result<
|
2022-11-22 10:19:43 +11:00
|
|
|
CompilerBackend<Self::Output>,
|
2022-11-11 17:44:41 +11:00
|
|
|
ShaderReflectError,
|
|
|
|
> {
|
|
|
|
Ok(CompilerBackend {
|
|
|
|
backend: HlslReflect::try_from(compile)?,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|