spirv_cross2/
targets.rs

1use crate::compile;
2use crate::compile::CompilableTarget;
3use crate::sealed::Sealed;
4use spirv_cross_sys::CompilerBackend;
5
6/// Reflection only backend, no compilation features
7/// enabled.
8pub struct None;
9
10/// Compile SPIR-V to GLSL.
11#[cfg(feature = "glsl")]
12#[cfg_attr(docsrs, doc(cfg(feature = "glsl")))]
13pub struct Glsl;
14
15/// Compile SPIR-V to Metal Shading Language (MSL).
16#[cfg(feature = "msl")]
17#[cfg_attr(docsrs, doc(cfg(feature = "msl")))]
18pub struct Msl;
19
20/// Compile SPIR-V to HLSL.
21#[cfg(feature = "hlsl")]
22#[cfg_attr(docsrs, doc(cfg(feature = "hlsl")))]
23pub struct Hlsl;
24
25/// Compile SPIR-V to debuggable C++.
26///
27/// This backend is deprecated but is included here for completion.
28/// See the [SPIRV-Cross docs](https://github.com/KhronosGroup/SPIRV-Cross?tab=readme-ov-file#using-shaders-generated-from-c-backend)
29/// for how to debug shaders generated from the C++ backend
30#[deprecated = "This backend is deprecated in SPIRV-Cross."]
31#[cfg(feature = "cpp")]
32#[cfg_attr(docsrs, doc(cfg(feature = "cpp")))]
33pub struct Cpp;
34
35/// Compile SPIR-V to a JSON reflection format
36#[cfg(feature = "json")]
37#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
38pub struct Json;
39
40impl Sealed for None {}
41impl Target for None {
42    const BACKEND: CompilerBackend = CompilerBackend::None;
43}
44
45#[cfg(feature = "glsl")]
46#[cfg_attr(docsrs, doc(cfg(feature = "glsl")))]
47mod glsl {
48    use super::*;
49    impl CompilableTarget for Glsl {
50        type Options = compile::glsl::CompilerOptions;
51    }
52    impl Sealed for Glsl {}
53    impl Target for Glsl {
54        const BACKEND: CompilerBackend = CompilerBackend::Glsl;
55    }
56}
57
58#[cfg(feature = "hlsl")]
59#[cfg_attr(docsrs, doc(cfg(feature = "hlsl")))]
60mod hlsl {
61    use super::*;
62    impl CompilableTarget for Hlsl {
63        type Options = compile::hlsl::CompilerOptions;
64    }
65    impl Sealed for Hlsl {}
66    impl Target for Hlsl {
67        const BACKEND: CompilerBackend = CompilerBackend::Hlsl;
68    }
69}
70
71#[cfg(feature = "msl")]
72#[cfg_attr(docsrs, doc(cfg(feature = "msl")))]
73mod msl {
74    use super::*;
75    impl CompilableTarget for Msl {
76        type Options = compile::msl::CompilerOptions;
77    }
78    impl Sealed for Msl {}
79    impl Target for Msl {
80        const BACKEND: CompilerBackend = CompilerBackend::Msl;
81    }
82}
83
84#[cfg(feature = "json")]
85#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
86mod json {
87    use super::*;
88    impl CompilableTarget for Json {
89        type Options = compile::NoOptions;
90    }
91    impl Sealed for Json {}
92    impl Target for Json {
93        const BACKEND: CompilerBackend = CompilerBackend::Json;
94    }
95}
96
97#[cfg(feature = "cpp")]
98#[cfg_attr(docsrs, doc(cfg(feature = "cpp")))]
99mod cpp {
100    use super::*;
101    #[allow(deprecated)]
102    impl CompilableTarget for Cpp {
103        type Options = compile::NoOptions;
104    }
105
106    #[allow(deprecated)]
107    impl Sealed for Cpp {}
108
109    #[allow(deprecated)]
110    impl Target for Cpp {
111        const BACKEND: CompilerBackend = CompilerBackend::Cpp;
112    }
113}
114
115/// Marker trait for a compiler backend target.
116pub trait Target: Sealed {
117    #[doc(hidden)]
118    const BACKEND: CompilerBackend;
119}