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: [
86 u8;
87 $crate::__macro_helpers::include_bytes!($($token)*).len()
88 ] = *$crate::__macro_helpers::include_bytes!($($token)*);
89 const SPIRV_LEN: usize = SPIRV_SOURCE.len() / 4;
90 const SPIRV_WORDS: [u32; SPIRV_LEN] = $crate::util::make_spirv_const(SPIRV_SOURCE);
91 &SPIRV_WORDS
92 }
93 }
94}
95
96#[test]
97fn make_spirv_le_pass() {
98 static SPIRV: &[u32] = include_spirv_source!(concat!(env!("OUT_DIR"), "/le-aligned.spv"));
99 assert_eq!(SPIRV, &[0x07230203, 0x11223344]);
100}
101
102#[test]
103fn make_spirv_be_pass() {
104 static SPIRV: &[u32] = include_spirv_source!(concat!(env!("OUT_DIR"), "/be-aligned.spv"));
105 assert_eq!(SPIRV, &[0x07230203, 0x11223344]);
106}
107
108#[macro_export]
114#[cfg(feature = "spirv")]
115macro_rules! include_spirv {
116 ($($token:tt)*) => {
117 {
118 $crate::ShaderModuleDescriptor {
119 label: Some($($token)*),
120 source: $crate::ShaderSource::SpirV(
121 $crate::__macro_helpers::Cow::Borrowed($crate::include_spirv_source!($($token)*))
122 ),
123 }
124 }
125 };
126}
127
128#[cfg(all(feature = "spirv", test))]
129#[expect(dead_code)]
130static SPIRV: crate::ShaderModuleDescriptor<'_> =
131 include_spirv!(concat!(env!("OUT_DIR"), "/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 num_workgroups: (0, 0, 0),
147 dxil: None,
148 metallib: None,
149 msl: None,
150 hlsl: None,
151 glsl: None,
152 wgsl: None,
153 }
154 }
155 };
156}
157
158#[cfg(test)]
159#[expect(dead_code)]
160static SPIRV_RAW: crate::ShaderModuleDescriptorPassthrough<'_> =
161 include_spirv_raw!(concat!(env!("OUT_DIR"), "/le-aligned.spv"));
162
163#[macro_export]
174macro_rules! include_wgsl {
175 ($($token:tt)*) => {
176 {
177 $crate::ShaderModuleDescriptor {
178 label: $crate::__macro_helpers::Some($($token)*),
179 source: $crate::ShaderSource::Wgsl($crate::__macro_helpers::Cow::Borrowed($crate::__macro_helpers::include_str!($($token)*))),
180 }
181 }
182 };
183}
184
185#[cfg(dx12)]
193macro_rules! hal_type_dx12 {
194 ($ty: literal) => {
195 concat!("- [`hal::api::Dx12`] uses [`hal::dx12::", $ty, "`]")
196 };
197}
198#[cfg(not(dx12))]
200macro_rules! hal_type_dx12 {
201 ($ty: literal) => {
202 concat!("- `hal::api::Dx12` uses `hal::dx12::", $ty, "`")
203 };
204}
205pub(crate) use hal_type_dx12;
206
207#[cfg(metal)]
209macro_rules! hal_type_metal {
210 ($ty: literal) => {
211 concat!("- [`hal::api::Metal`] uses [`hal::metal::", $ty, "`]")
212 };
213}
214#[cfg(not(metal))]
216macro_rules! hal_type_metal {
217 ($ty: literal) => {
218 concat!("- `hal::api::Metal` uses `hal::metal::", $ty, "`")
219 };
220}
221pub(crate) use hal_type_metal;
222
223#[cfg(vulkan)]
225macro_rules! hal_type_vulkan {
226 ($ty: literal) => {
227 concat!("- [`hal::api::Vulkan`] uses [`hal::vulkan::", $ty, "`]")
228 };
229}
230#[cfg(not(vulkan))]
232macro_rules! hal_type_vulkan {
233 ($ty: literal) => {
234 concat!("- `hal::api::Vulkan` uses `hal::vulkan::", $ty, "`")
235 };
236}
237pub(crate) use hal_type_vulkan;
238
239#[cfg(gles)]
241macro_rules! hal_type_gles {
242 ($ty: literal) => {
243 concat!("- [`hal::api::Gles`] uses [`hal::gles::", $ty, "`]")
244 };
245}
246#[cfg(not(gles))]
248macro_rules! hal_type_gles {
249 ($ty: literal) => {
250 concat!("- `hal::api::Gles` uses `hal::gles::", $ty, "`")
251 };
252}
253pub(crate) use hal_type_gles;
254
255#[doc(hidden)]
256pub mod helpers {
257 pub use Some;
258 pub use alloc::{borrow::Cow, string::String};
259 pub use core::{include_bytes, include_str};
260}