1#[cfg(doc)]
4use crate::{VertexAttribute, VertexBufferLayout, VertexFormat};
5
6#[macro_export]
45macro_rules! vertex_attr_array {
46 ($($location:expr => $format:ident),* $(,)?) => {
47 $crate::_vertex_attr_array_helper!([] ; 0; $($location => $format ,)*)
48 };
49}
50
51#[doc(hidden)]
52#[macro_export]
53macro_rules! _vertex_attr_array_helper {
54 ([$($t:expr,)*] ; $off:expr ;) => { [$($t,)*] };
55 ([$($t:expr,)*] ; $off:expr ; $location:expr => $format:ident, $($ll:expr => $ii:ident ,)*) => {
56 $crate::_vertex_attr_array_helper!(
57 [$($t,)*
58 $crate::VertexAttribute {
59 format: $crate::VertexFormat :: $format,
60 offset: $off,
61 shader_location: $location,
62 },];
63 $off + $crate::VertexFormat :: $format.size();
64 $($ll => $ii ,)*
65 )
66 };
67}
68
69#[test]
70fn test_vertex_attr_array() {
71 let attrs = vertex_attr_array![0 => Float32x2, 3 => Uint16x4];
72 assert_eq!(attrs.len(), 2);
74 assert_eq!(attrs[0].offset, 0);
75 assert_eq!(attrs[0].shader_location, 0);
76 assert_eq!(attrs[1].offset, size_of::<(f32, f32)>() as u64);
77 assert_eq!(attrs[1].shader_location, 3);
78}
79
80#[macro_export]
81#[doc(hidden)]
82macro_rules! include_spirv_source {
83 ($($token:tt)*) => {
84 {
85 const SPIRV_SOURCE: [
87 u8;
88 $crate::__macro_helpers::include_bytes!($($token)*).len()
89 ] = *$crate::__macro_helpers::include_bytes!($($token)*);
90 const SPIRV_LEN: usize = SPIRV_SOURCE.len() / 4;
91 const SPIRV_WORDS: [u32; SPIRV_LEN] = $crate::util::make_spirv_const(SPIRV_SOURCE);
92 &SPIRV_WORDS
93 }
94 }
95}
96
97#[test]
98fn make_spirv_le_pass() {
99 static SPIRV: &[u32] = include_spirv_source!("le-aligned.spv");
100 assert_eq!(SPIRV, &[0x07230203, 0x11223344]);
101}
102
103#[test]
104fn make_spirv_be_pass() {
105 static SPIRV: &[u32] = include_spirv_source!("be-aligned.spv");
106 assert_eq!(SPIRV, &[0x07230203, 0x11223344]);
107}
108
109#[macro_export]
115#[cfg(feature = "spirv")]
116macro_rules! include_spirv {
117 ($($token:tt)*) => {
118 {
119 $crate::ShaderModuleDescriptor {
120 label: Some($($token)*),
121 source: $crate::ShaderSource::SpirV(
122 $crate::__macro_helpers::Cow::Borrowed($crate::include_spirv_source!($($token)*))
123 ),
124 }
125 }
126 };
127}
128
129#[cfg(all(feature = "spirv", test))]
130#[expect(dead_code)]
131static SPIRV: crate::ShaderModuleDescriptor<'_> = include_spirv!("le-aligned.spv");
132
133#[macro_export]
139macro_rules! include_spirv_raw {
140 ($($token:tt)*) => {
141 {
142 $crate::ShaderModuleDescriptorPassthrough {
143 label: $crate::__macro_helpers::Some($($token)*),
144 spirv: Some($crate::__macro_helpers::Cow::Borrowed($crate::include_spirv_source!($($token)*))),
145 entry_point: $crate::__macro_helpers::String::new(),
146 num_workgroups: (0, 0, 0),
148 runtime_checks: $crate::ShaderRuntimeChecks::unchecked(),
149 dxil: None,
150 msl: None,
151 hlsl: None,
152 glsl: None,
153 wgsl: None,
154 }
155 }
156 };
157}
158
159#[cfg(test)]
160#[expect(dead_code)]
161static SPIRV_RAW: crate::ShaderModuleDescriptorPassthrough<'_> =
162 include_spirv_raw!("le-aligned.spv");
163
164#[macro_export]
175macro_rules! include_wgsl {
176 ($($token:tt)*) => {
177 {
178 $crate::ShaderModuleDescriptor {
179 label: $crate::__macro_helpers::Some($($token)*),
180 source: $crate::ShaderSource::Wgsl($crate::__macro_helpers::Cow::Borrowed($crate::__macro_helpers::include_str!($($token)*))),
181 }
182 }
183 };
184}
185
186#[macro_export]
194#[doc(hidden)]
195#[cfg(dx12)]
196macro_rules! hal_type_dx12 {
197 ($ty: literal) => {
198 concat!("- [`hal::api::Dx12`] uses [`hal::dx12::", $ty, "`]")
199 };
200}
201#[macro_export]
203#[doc(hidden)]
204#[cfg(not(dx12))]
205macro_rules! hal_type_dx12 {
206 ($ty: literal) => {
207 concat!("- `hal::api::Dx12` uses `hal::dx12::", $ty, "`")
208 };
209}
210
211#[macro_export]
213#[doc(hidden)]
214#[cfg(metal)]
215macro_rules! hal_type_metal {
216 ($ty: literal) => {
217 concat!("- [`hal::api::Metal`] uses [`hal::metal::", $ty, "`]")
218 };
219}
220#[macro_export]
222#[doc(hidden)]
223#[cfg(not(metal))]
224macro_rules! hal_type_metal {
225 ($ty: literal) => {
226 concat!("- `hal::api::Metal` uses `hal::metal::", $ty, "`")
227 };
228}
229
230#[macro_export]
232#[doc(hidden)]
233#[cfg(vulkan)]
234macro_rules! hal_type_vulkan {
235 ($ty: literal) => {
236 concat!("- [`hal::api::Vulkan`] uses [`hal::vulkan::", $ty, "`]")
237 };
238}
239#[macro_export]
241#[doc(hidden)]
242#[cfg(not(vulkan))]
243macro_rules! hal_type_vulkan {
244 ($ty: literal) => {
245 concat!("- `hal::api::Vulkan` uses `hal::vulkan::", $ty, "`")
246 };
247}
248
249#[macro_export]
251#[doc(hidden)]
252#[cfg(gles)]
253macro_rules! hal_type_gles {
254 ($ty: literal) => {
255 concat!("- [`hal::api::Gles`] uses [`hal::gles::", $ty, "`]")
256 };
257}
258#[macro_export]
260#[doc(hidden)]
261#[cfg(not(gles))]
262macro_rules! hal_type_gles {
263 ($ty: literal) => {
264 concat!("- `hal::api::Gles` uses `hal::gles::", $ty, "`")
265 };
266}
267
268#[doc(hidden)]
269pub mod helpers {
270 pub use alloc::{borrow::Cow, string::String};
271 pub use core::{include_bytes, include_str};
272 pub use Some;
273}