reflect: add FromCompilation<GlslangCompilation>
for SpirV
This commit is contained in:
parent
a8840829aa
commit
22f87aa7f8
4 changed files with 60 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
pub mod cross;
|
pub mod cross;
|
||||||
pub mod targets;
|
pub mod targets;
|
||||||
|
mod spirv;
|
||||||
|
|
||||||
use crate::back::targets::OutputTarget;
|
use crate::back::targets::OutputTarget;
|
||||||
use crate::error::{ShaderCompileError, ShaderReflectError};
|
use crate::error::{ShaderCompileError, ShaderReflectError};
|
||||||
|
|
56
librashader-reflect/src/back/spirv.rs
Normal file
56
librashader-reflect/src/back/spirv.rs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
use crate::back::{CompilerBackend, CompileShader, FromCompilation, ShaderCompilerOutput};
|
||||||
|
use crate::back::targets::SpirV;
|
||||||
|
use crate::error::{ShaderCompileError, ShaderReflectError};
|
||||||
|
use crate::front::shaderc::GlslangCompilation;
|
||||||
|
use crate::reflect::{ReflectShader, ShaderReflection};
|
||||||
|
use crate::reflect::cross::{GlslReflect};
|
||||||
|
use crate::reflect::semantics::ShaderSemantics;
|
||||||
|
|
||||||
|
struct WriteSpirV {
|
||||||
|
// rely on GLSL to provide out reflection but we don't actually need the AST.
|
||||||
|
reflect: GlslReflect,
|
||||||
|
vertex: Vec<u32>,
|
||||||
|
fragment: Vec<u32>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromCompilation<GlslangCompilation> for SpirV {
|
||||||
|
type Target = SpirV;
|
||||||
|
type Options = Option<()>;
|
||||||
|
type Context = ();
|
||||||
|
type Output = impl CompileShader<Self::Target, Options = Option<()>, Context = ()>
|
||||||
|
+ ReflectShader;
|
||||||
|
|
||||||
|
fn from_compilation(
|
||||||
|
compile: GlslangCompilation,
|
||||||
|
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
|
||||||
|
let vertex = compile.vertex.as_binary().to_vec();
|
||||||
|
let fragment = compile.vertex.as_binary().to_vec();
|
||||||
|
let reflect = GlslReflect::try_from(compile)?;
|
||||||
|
Ok(CompilerBackend {
|
||||||
|
backend: WriteSpirV {
|
||||||
|
reflect,
|
||||||
|
vertex,
|
||||||
|
fragment,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReflectShader for WriteSpirV {
|
||||||
|
fn reflect(&mut self, pass_number: usize, semantics: &ShaderSemantics) -> Result<ShaderReflection, ShaderReflectError> {
|
||||||
|
self.reflect.reflect(pass_number, semantics)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CompileShader<SpirV> for WriteSpirV {
|
||||||
|
type Options = Option<()>;
|
||||||
|
type Context = ();
|
||||||
|
|
||||||
|
fn compile(self, _options: Self::Options) -> Result<ShaderCompilerOutput<Vec<u32>, Self::Context>, ShaderCompileError> {
|
||||||
|
Ok(ShaderCompilerOutput {
|
||||||
|
vertex: self.vertex,
|
||||||
|
fragment: self.fragment,
|
||||||
|
context: (),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ pub struct GLSL;
|
||||||
/// Shader compiler target for HLSL.
|
/// Shader compiler target for HLSL.
|
||||||
pub struct HLSL;
|
pub struct HLSL;
|
||||||
/// Shader compiler target for SPIR-V.
|
/// Shader compiler target for SPIR-V.
|
||||||
pub struct SPIRV;
|
pub struct SpirV;
|
||||||
/// Shader compiler target for MSL
|
/// Shader compiler target for MSL
|
||||||
pub struct MSL;
|
pub struct MSL;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ impl OutputTarget for GLSL {
|
||||||
impl OutputTarget for HLSL {
|
impl OutputTarget for HLSL {
|
||||||
type Output = String;
|
type Output = String;
|
||||||
}
|
}
|
||||||
impl OutputTarget for SPIRV {
|
impl OutputTarget for SpirV {
|
||||||
type Output = Vec<u32>;
|
type Output = Vec<u32>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ pub mod reflect {
|
||||||
pub mod targets {
|
pub mod targets {
|
||||||
pub use librashader_reflect::back::targets::GLSL;
|
pub use librashader_reflect::back::targets::GLSL;
|
||||||
pub use librashader_reflect::back::targets::HLSL;
|
pub use librashader_reflect::back::targets::HLSL;
|
||||||
pub use librashader_reflect::back::targets::SPIRV;
|
pub use librashader_reflect::back::targets::SpirV;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use librashader_reflect::error::*;
|
pub use librashader_reflect::error::*;
|
||||||
|
|
Loading…
Add table
Reference in a new issue