reflect: simplify FromCompilation output signature

CompileShader<..> + ReflectShader and be simplified to CompileReflectShader since FromCompilation instances are unique for (Compilation, Reflector)
This commit is contained in:
chyyran 2024-09-15 01:14:32 -04:00 committed by Ronny Chan
parent c291d9d85f
commit 805854b94b
7 changed files with 37 additions and 19 deletions

View file

@ -1,11 +1,12 @@
use crate::back::spirv::WriteSpirV; use crate::back::spirv::WriteSpirV;
use crate::back::targets::{OutputTarget, DXIL}; use crate::back::targets::{OutputTarget, DXIL};
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput}; use crate::back::{
CompileReflectShader, CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput,
};
use crate::error::{ShaderCompileError, ShaderReflectError}; use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::front::SpirvCompilation; use crate::front::SpirvCompilation;
use crate::reflect::cross::glsl::GlslReflect; use crate::reflect::cross::glsl::GlslReflect;
use crate::reflect::cross::SpirvCross; use crate::reflect::cross::SpirvCross;
use crate::reflect::ReflectShader;
pub use spirv_to_dxil::DxilObject; pub use spirv_to_dxil::DxilObject;
pub use spirv_to_dxil::ShaderModel; pub use spirv_to_dxil::ShaderModel;
use spirv_to_dxil::{ use spirv_to_dxil::{
@ -20,8 +21,7 @@ impl FromCompilation<SpirvCompilation, SpirvCross> for DXIL {
type Target = DXIL; type Target = DXIL;
type Options = Option<ShaderModel>; type Options = Option<ShaderModel>;
type Context = (); type Context = ();
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context> type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross>;
+ ReflectShader;
fn from_compilation( fn from_compilation(
compile: SpirvCompilation, compile: SpirvCompilation,
@ -88,4 +88,11 @@ impl CompileShader<DXIL> for WriteSpirV {
context: (), context: (),
}) })
} }
fn compile_boxed(
self: Box<Self>,
options: Self::Options,
) -> Result<ShaderCompilerOutput<DxilObject, Self::Context>, ShaderCompileError> {
<WriteSpirV as CompileShader<DXIL>>::compile(*self, options)
}
} }

View file

@ -1,9 +1,8 @@
use crate::back::targets::GLSL; use crate::back::targets::GLSL;
use crate::back::{CompileShader, CompilerBackend, FromCompilation}; use crate::back::{CompileReflectShader, CompilerBackend, FromCompilation};
use crate::error::ShaderReflectError; use crate::error::ShaderReflectError;
use crate::front::SpirvCompilation; use crate::front::SpirvCompilation;
use crate::reflect::cross::{CompiledProgram, SpirvCross}; use crate::reflect::cross::{CompiledProgram, SpirvCross};
use crate::reflect::ReflectShader;
/// The GLSL version to target. /// The GLSL version to target.
pub use spirv_cross2::compile::glsl::GlslVersion; pub use spirv_cross2::compile::glsl::GlslVersion;
@ -22,8 +21,7 @@ impl FromCompilation<SpirvCompilation, SpirvCross> for GLSL {
type Target = GLSL; type Target = GLSL;
type Options = GlslVersion; type Options = GlslVersion;
type Context = CrossGlslContext; type Context = CrossGlslContext;
type Output = impl CompileShader<Self::Target, Options = GlslVersion, Context = Self::Context> type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross>;
+ ReflectShader;
fn from_compilation( fn from_compilation(
compile: SpirvCompilation, compile: SpirvCompilation,

View file

@ -1,10 +1,9 @@
use crate::back::targets::HLSL; use crate::back::targets::HLSL;
use crate::back::{CompileShader, CompilerBackend, FromCompilation}; use crate::back::{CompileReflectShader, CompilerBackend, FromCompilation};
use crate::error::ShaderReflectError; use crate::error::ShaderReflectError;
use crate::front::SpirvCompilation; use crate::front::SpirvCompilation;
use crate::reflect::cross::hlsl::HlslReflect; use crate::reflect::cross::hlsl::HlslReflect;
use crate::reflect::cross::{CompiledProgram, SpirvCross}; use crate::reflect::cross::{CompiledProgram, SpirvCross};
use crate::reflect::ReflectShader;
/// The HLSL shader model version to target. /// The HLSL shader model version to target.
pub use spirv_cross2::compile::hlsl::HlslShaderModel; pub use spirv_cross2::compile::hlsl::HlslShaderModel;
@ -108,8 +107,7 @@ impl FromCompilation<SpirvCompilation, SpirvCross> for HLSL {
type Target = HLSL; type Target = HLSL;
type Options = Option<HlslShaderModel>; type Options = Option<HlslShaderModel>;
type Context = CrossHlslContext; type Context = CrossHlslContext;
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context> type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross>;
+ ReflectShader;
fn from_compilation( fn from_compilation(
compile: SpirvCompilation, compile: SpirvCompilation,

View file

@ -1,5 +1,5 @@
use crate::back::targets::MSL; use crate::back::targets::MSL;
use crate::back::{CompileShader, CompilerBackend, FromCompilation}; use crate::back::{CompileReflectShader, CompileShader, CompilerBackend, FromCompilation};
use crate::error::ShaderReflectError; use crate::error::ShaderReflectError;
use crate::front::SpirvCompilation; use crate::front::SpirvCompilation;
use crate::reflect::cross::msl::MslReflect; use crate::reflect::cross::msl::MslReflect;
@ -57,8 +57,7 @@ impl FromCompilation<SpirvCompilation, Naga> for MSL {
type Target = MSL; type Target = MSL;
type Options = Option<self::MslVersion>; type Options = Option<self::MslVersion>;
type Context = NagaMslContext; type Context = NagaMslContext;
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context> type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, Naga>;
+ ReflectShader;
fn from_compilation( fn from_compilation(
compile: SpirvCompilation, compile: SpirvCompilation,

View file

@ -63,6 +63,17 @@ impl CompileShader<SPIRV> for WriteSpirV {
context: (), context: (),
}) })
} }
fn compile_boxed(
self: Box<Self>,
_options: Self::Options,
) -> Result<ShaderCompilerOutput<Vec<u32>, Self::Context>, ShaderCompileError> {
Ok(ShaderCompilerOutput {
vertex: self.vertex,
fragment: self.fragment,
context: (),
})
}
} }
/// The context for a SPIRV compilation via Naga /// The context for a SPIRV compilation via Naga

View file

@ -1,9 +1,8 @@
use crate::back::targets::WGSL; use crate::back::targets::WGSL;
use crate::back::{CompileShader, CompilerBackend, FromCompilation}; use crate::back::{CompileReflectShader, CompilerBackend, FromCompilation};
use crate::error::ShaderReflectError; use crate::error::ShaderReflectError;
use crate::front::SpirvCompilation; use crate::front::SpirvCompilation;
use crate::reflect::naga::{Naga, NagaLoweringOptions, NagaReflect}; use crate::reflect::naga::{Naga, NagaLoweringOptions, NagaReflect};
use crate::reflect::ReflectShader;
use naga::Module; use naga::Module;
/// The context for a WGSL compilation via Naga /// The context for a WGSL compilation via Naga
@ -16,8 +15,7 @@ impl FromCompilation<SpirvCompilation, Naga> for WGSL {
type Target = WGSL; type Target = WGSL;
type Options = NagaLoweringOptions; type Options = NagaLoweringOptions;
type Context = NagaWgslContext; type Context = NagaWgslContext;
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context> type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, Naga>;
+ ReflectShader;
fn from_compilation( fn from_compilation(
compile: SpirvCompilation, compile: SpirvCompilation,

View file

@ -101,6 +101,13 @@ impl CompileShader<MSL> for CrossReflect<targets::Msl> {
}, },
}) })
} }
fn compile_boxed(
self: Box<Self>,
options: Self::Options,
) -> Result<ShaderCompilerOutput<String, Self::Context>, ShaderCompileError> {
<CrossReflect<targets::Msl> as CompileShader<MSL>>::compile(*self, options)
}
} }
#[cfg(test)] #[cfg(test)]