librashader_reflect/back/
msl.rs1use crate::back::targets::MSL;
2use crate::back::{CompileReflectShader, CompilerBackend, FromCompilation};
3use crate::error::ShaderReflectError;
4use crate::front::SpirvCompilation;
5use crate::reflect::cross::msl::MslReflect;
6use crate::reflect::cross::{CompiledProgram, SpirvCross};
7use crate::reflect::naga::{Naga, NagaReflect};
8use naga::back::msl::TranslationInfo;
9use naga::Module;
10
11pub use spirv_cross2::compile::msl::MslVersion;
13
14#[derive(Debug, Default, Clone)]
16pub struct MslNagaCompileOptions {
17 pub sampler_bind_group: u32,
19}
20
21pub struct CrossMslContext {
23 pub artifact: CompiledProgram<spirv_cross2::targets::Msl>,
25}
26
27#[cfg(not(feature = "stable"))]
28impl FromCompilation<SpirvCompilation, SpirvCross> for MSL {
29 type Target = MSL;
30 type Options = Option<self::MslVersion>;
31 type Context = CrossMslContext;
32 type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross>;
33
34 fn from_compilation(
35 compile: SpirvCompilation,
36 ) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
37 Ok(CompilerBackend {
38 backend: MslReflect::try_from(&compile)?,
39 })
40 }
41}
42
43#[cfg(feature = "stable")]
44impl FromCompilation<SpirvCompilation, SpirvCross> for MSL {
45 type Target = MSL;
46 type Options = Option<self::MslVersion>;
47 type Context = CrossMslContext;
48 type Output = Box<dyn CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross> + Send>;
49
50 fn from_compilation(
51 compile: SpirvCompilation,
52 ) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
53 Ok(CompilerBackend {
54 backend: Box::new(MslReflect::try_from(&compile)?),
55 })
56 }
57}
58
59pub struct NagaMslModule {
61 pub translation_info: TranslationInfo,
62 pub module: Module,
63}
64
65pub struct NagaMslContext {
66 pub vertex: NagaMslModule,
67 pub fragment: NagaMslModule,
68 pub next_free_binding: u32,
69}
70
71#[cfg(not(feature = "stable"))]
72impl FromCompilation<SpirvCompilation, Naga> for MSL {
73 type Target = MSL;
74 type Options = Option<self::MslVersion>;
75 type Context = NagaMslContext;
76 type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, Naga>;
77
78 fn from_compilation(
79 compile: SpirvCompilation,
80 ) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
81 Ok(CompilerBackend {
82 backend: NagaReflect::try_from(&compile)?,
83 })
84 }
85}
86
87#[cfg(feature = "stable")]
88impl FromCompilation<SpirvCompilation, Naga> for MSL {
89 type Target = MSL;
90 type Options = Option<self::MslVersion>;
91 type Context = NagaMslContext;
92 type Output = Box<dyn CompileReflectShader<Self::Target, SpirvCompilation, Naga> + Send>;
93
94 fn from_compilation(
95 compile: SpirvCompilation,
96 ) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
97 Ok(CompilerBackend {
98 backend: Box::new(NagaReflect::try_from(&compile)?),
99 })
100 }
101}