rendy_util/
features.rs

1/// Resolve into input AST if empty backend is enabled.
2#[macro_export]
3#[cfg(feature = "gfx-backend-empty")]
4macro_rules! rendy_with_empty_backend {
5    ($($tt:tt)*) => { $($tt)* };
6}
7
8/// Resolve into input AST if empty backend is enabled.
9#[macro_export]
10#[cfg(not(feature = "gfx-backend-empty"))]
11macro_rules! rendy_with_empty_backend {
12    ($($tt:tt)*) => {};
13}
14
15/// Resolve into input AST if empty backend is disabled.
16#[macro_export]
17#[cfg(not(feature = "gfx-backend-empty"))]
18macro_rules! rendy_without_empty_backend {
19    ($($tt:tt)*) => { $($tt)* };
20}
21
22/// Resolve into input AST if empty backend is disabled.
23#[macro_export]
24#[cfg(feature = "gfx-backend-empty")]
25macro_rules! rendy_without_empty_backend {
26    ($($tt:tt)*) => {};
27}
28
29/// Resolve into input AST if dx12 backend is enabled.
30#[macro_export]
31#[cfg(feature = "gfx-backend-dx12")]
32macro_rules! rendy_with_dx12_backend {
33    ($($tt:tt)*) => { $($tt)* };
34}
35
36/// Resolve into input AST if dx12 backend is enabled.
37#[macro_export]
38#[cfg(not(feature = "gfx-backend-dx12"))]
39macro_rules! rendy_with_dx12_backend {
40    ($($tt:tt)*) => {};
41}
42
43/// Resolve into input AST if dx12 backend is disabled.
44#[macro_export]
45#[cfg(not(feature = "gfx-backend-dx12"))]
46macro_rules! rendy_without_dx12_backend {
47    ($($tt:tt)*) => { $($tt)* };
48}
49
50/// Resolve into input AST if dx12 backend is disabled.
51#[macro_export]
52#[cfg(feature = "gfx-backend-dx12")]
53macro_rules! rendy_without_dx12_backend {
54    ($($tt:tt)*) => {};
55}
56
57/// Resolve into input AST if metal backend is enabled.
58#[macro_export]
59#[cfg(feature = "gfx-backend-metal")]
60macro_rules! rendy_with_metal_backend {
61    ($($tt:tt)*) => { $($tt)* };
62}
63
64/// Resolve into input AST if metal backend is enabled.
65#[macro_export]
66#[cfg(not(feature = "gfx-backend-metal"))]
67macro_rules! rendy_with_metal_backend {
68    ($($tt:tt)*) => {};
69}
70
71/// Resolve into input AST if metal backend is disabled.
72#[macro_export]
73#[cfg(not(feature = "gfx-backend-metal"))]
74macro_rules! rendy_without_metal_backend {
75    ($($tt:tt)*) => { $($tt)* };
76}
77
78/// Resolve into input AST if metal backend is disabled.
79#[macro_export]
80#[cfg(feature = "gfx-backend-metal")]
81macro_rules! rendy_without_metal_backend {
82    ($($tt:tt)*) => {};
83}
84
85/// Resolve into input AST if vulkan backend is enabled.
86#[macro_export]
87#[cfg(feature = "gfx-backend-vulkan")]
88macro_rules! rendy_with_vulkan_backend {
89    ($($tt:tt)*) => { $($tt)* };
90}
91
92/// Resolve into input AST if vulkan backend is enabled.
93#[macro_export]
94#[cfg(not(feature = "gfx-backend-vulkan"))]
95macro_rules! rendy_with_vulkan_backend {
96    ($($tt:tt)*) => {};
97}
98
99/// Resolve into input AST if vulkan backend is disabled.
100#[macro_export]
101#[cfg(not(feature = "gfx-backend-vulkan"))]
102macro_rules! rendy_without_vulkan_backend {
103    ($($tt:tt)*) => { $($tt)* };
104}
105
106/// Resolve into input AST if vulkan backend is disabled.
107#[macro_export]
108#[cfg(feature = "gfx-backend-vulkan")]
109macro_rules! rendy_without_vulkan_backend {
110    ($($tt:tt)*) => {};
111}
112
113/// Resolve into input AST if rendy is requested to not perform slow safety checks.
114#[macro_export]
115#[cfg(feature = "no-slow-safety-checks")]
116macro_rules! rendy_without_slow_safety_checks {
117    ($($tt:tt)*) => { $($tt)* };
118}
119
120/// Resolve into input AST if rendy is requested to not perform slow safety checks.
121#[macro_export]
122#[cfg(not(feature = "no-slow-safety-checks"))]
123macro_rules! rendy_without_slow_safety_checks {
124    ($($tt:tt)*) => {};
125}
126
127/// Resolve into input AST if rendy is requested to perform slow safety checks.
128#[macro_export]
129#[cfg(not(feature = "no-slow-safety-checks"))]
130macro_rules! rendy_with_slow_safety_checks {
131    ($($tt:tt)*) => { $($tt)* };
132}
133
134/// Resolve into input AST if rendy is requested to perform slow safety checks.
135#[macro_export]
136#[cfg(feature = "no-slow-safety-checks")]
137macro_rules! rendy_with_slow_safety_checks {
138    ($($tt:tt)*) => {};
139}
140
141/// Execute arm with matching backend.
142/// If particular backend is disabled
143/// then its arm is stripped from compilation altogether.
144#[macro_export]
145macro_rules! rendy_backend_match {
146    ($target:path {
147        $(empty => $empty_code:block)?
148        $(dx12 => $dx12_code:block)?
149        $(metal => $metal_code:block)?
150        $(vulkan => $vulkan_code:block)?
151    }) => {{
152        $($crate::rendy_with_empty_backend!(if std::any::TypeId::of::<$target>() == std::any::TypeId::of::<$crate::empty::Backend>() { return $empty_code; }))?;
153        $($crate::rendy_with_dx12_backend!(if std::any::TypeId::of::<$target>() == std::any::TypeId::of::<$crate::dx12::Backend>() { return $dx12_code; }))?;
154        $($crate::rendy_with_metal_backend!(if std::any::TypeId::of::<$target>() == std::any::TypeId::of::<$crate::metal::Backend>() { return $metal_code; }))?;
155        $($crate::rendy_with_vulkan_backend!(if std::any::TypeId::of::<$target>() == std::any::TypeId::of::<$crate::vulkan::Backend>() { return $vulkan_code; }))?;
156
157        panic!("
158            Undefined backend requested.
159            Make sure feature for required backend is enabled.
160            Try to add `--features=vulkan` or if on macos `--features=metal`.
161        ")
162    }};
163
164    ($target:path as $back:ident => $code:block) => {{
165        $crate::rendy_backend_match!($target {
166            empty => { use $crate::empty as $back; $code }
167            dx12 => { use $crate::dx12 as $back; $code }
168            metal => { use $crate::metal as $back; $code }
169            vulkan => { use $crate::vulkan as $back; $code }
170        });
171    }};
172}