2023-01-13 23:59:16 -05:00
|
|
|
use crate::back::targets::SPIRV;
|
2022-12-21 21:39:31 -05:00
|
|
|
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
|
2022-12-05 23:09:59 -05:00
|
|
|
use crate::error::{ShaderCompileError, ShaderReflectError};
|
2023-01-19 01:06:17 -05:00
|
|
|
use crate::front::GlslangCompilation;
|
2022-12-21 21:39:31 -05:00
|
|
|
use crate::reflect::cross::GlslReflect;
|
2022-12-05 23:09:59 -05:00
|
|
|
use crate::reflect::semantics::ShaderSemantics;
|
2022-12-21 21:39:31 -05:00
|
|
|
use crate::reflect::{ReflectShader, ShaderReflection};
|
2022-12-05 23:09:59 -05:00
|
|
|
|
2023-02-04 17:53:51 -05:00
|
|
|
pub(crate) struct WriteSpirV {
|
2022-12-05 23:09:59 -05:00
|
|
|
// rely on GLSL to provide out reflection but we don't actually need the AST.
|
2023-02-04 17:53:51 -05:00
|
|
|
pub(crate) reflect: GlslReflect,
|
|
|
|
pub(crate) vertex: Vec<u32>,
|
|
|
|
pub(crate) fragment: Vec<u32>,
|
2022-12-05 23:09:59 -05:00
|
|
|
}
|
|
|
|
|
2023-01-13 23:59:16 -05:00
|
|
|
impl FromCompilation<GlslangCompilation> for SPIRV {
|
|
|
|
type Target = SPIRV;
|
2022-12-05 23:09:59 -05:00
|
|
|
type Options = Option<()>;
|
|
|
|
type Context = ();
|
2023-01-16 19:35:23 -05:00
|
|
|
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context>
|
|
|
|
+ ReflectShader;
|
2022-12-05 23:09:59 -05:00
|
|
|
|
|
|
|
fn from_compilation(
|
|
|
|
compile: GlslangCompilation,
|
|
|
|
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
|
2023-02-05 19:48:24 -05:00
|
|
|
let reflect = GlslReflect::try_from(&compile)?;
|
|
|
|
let vertex = compile.vertex;
|
|
|
|
let fragment = compile.fragment;
|
2022-12-05 23:09:59 -05:00
|
|
|
Ok(CompilerBackend {
|
|
|
|
backend: WriteSpirV {
|
|
|
|
reflect,
|
|
|
|
vertex,
|
|
|
|
fragment,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ReflectShader for WriteSpirV {
|
2022-12-21 21:39:31 -05:00
|
|
|
fn reflect(
|
|
|
|
&mut self,
|
|
|
|
pass_number: usize,
|
|
|
|
semantics: &ShaderSemantics,
|
|
|
|
) -> Result<ShaderReflection, ShaderReflectError> {
|
2022-12-05 23:09:59 -05:00
|
|
|
self.reflect.reflect(pass_number, semantics)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 23:59:16 -05:00
|
|
|
impl CompileShader<SPIRV> for WriteSpirV {
|
2022-12-05 23:09:59 -05:00
|
|
|
type Options = Option<()>;
|
|
|
|
type Context = ();
|
|
|
|
|
2022-12-21 21:39:31 -05:00
|
|
|
fn compile(
|
|
|
|
self,
|
|
|
|
_options: Self::Options,
|
|
|
|
) -> Result<ShaderCompilerOutput<Vec<u32>, Self::Context>, ShaderCompileError> {
|
2022-12-05 23:09:59 -05:00
|
|
|
Ok(ShaderCompilerOutput {
|
|
|
|
vertex: self.vertex,
|
|
|
|
fragment: self.fragment,
|
|
|
|
context: (),
|
|
|
|
})
|
|
|
|
}
|
2022-12-21 21:39:31 -05:00
|
|
|
}
|