1#![cfg_attr(not(wgpu_core), expect(unused_macros, unused_imports))]
3
4#[cfg(doc)]
5use crate::{VertexAttribute, VertexBufferLayout, VertexFormat};
6
7#[macro_export]
46macro_rules! vertex_attr_array {
47 ($($location:expr => $format:ident),* $(,)?) => {
48 $crate::_vertex_attr_array_helper!([] ; 0; $($location => $format ,)*)
49 };
50}
51
52#[doc(hidden)]
53#[macro_export]
54macro_rules! _vertex_attr_array_helper {
55 ([$($t:expr,)*] ; $off:expr ;) => { [$($t,)*] };
56 ([$($t:expr,)*] ; $off:expr ; $location:expr => $format:ident, $($ll:expr => $ii:ident ,)*) => {
57 $crate::_vertex_attr_array_helper!(
58 [$($t,)*
59 $crate::VertexAttribute {
60 format: $crate::VertexFormat :: $format,
61 offset: $off,
62 shader_location: $location,
63 },];
64 $off + $crate::VertexFormat :: $format.size();
65 $($ll => $ii ,)*
66 )
67 };
68}
69
70#[test]
71fn test_vertex_attr_array() {
72 let attrs = vertex_attr_array![0 => Float32x2, 3 => Uint16x4];
73 assert_eq!(attrs.len(), 2);
75 assert_eq!(attrs[0].offset, 0);
76 assert_eq!(attrs[0].shader_location, 0);
77 assert_eq!(attrs[1].offset, size_of::<(f32, f32)>() as u64);
78 assert_eq!(attrs[1].shader_location, 3);
79}
80
81#[macro_export]
82#[doc(hidden)]
83macro_rules! include_spirv_source {
84 ($($token:tt)*) => {
85 {
86 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_points: $crate::__macro_helpers::Cow::Borrowed(&[$crate::PassthroughShaderEntryPoint {
146 name: $crate::__macro_helpers::Cow::Borrowed("main"),
147 workgroup_size: (0, 0, 0),
149 }]),
150 dxil: None,
151 metallib: None,
152 msl: None,
153 hlsl: None,
154 glsl: None,
155 wgsl: None,
156 }
157 }
158 };
159}
160
161#[cfg(test)]
162#[expect(dead_code)]
163static SPIRV_RAW: crate::ShaderModuleDescriptorPassthrough<'_> =
164 include_spirv_raw!("le-aligned.spv");
165
166#[macro_export]
177macro_rules! include_wgsl {
178 ($($token:tt)*) => {
179 {
180 $crate::ShaderModuleDescriptor {
181 label: $crate::__macro_helpers::Some($($token)*),
182 source: $crate::ShaderSource::Wgsl($crate::__macro_helpers::Cow::Borrowed($crate::__macro_helpers::include_str!($($token)*))),
183 }
184 }
185 };
186}
187
188#[cfg(dx12)]
196macro_rules! hal_type_dx12 {
197 ($ty: literal) => {
198 concat!("- [`hal::api::Dx12`] uses [`hal::dx12::", $ty, "`]")
199 };
200}
201#[cfg(not(dx12))]
203macro_rules! hal_type_dx12 {
204 ($ty: literal) => {
205 concat!("- `hal::api::Dx12` uses `hal::dx12::", $ty, "`")
206 };
207}
208pub(crate) use hal_type_dx12;
209
210#[cfg(metal)]
212macro_rules! hal_type_metal {
213 ($ty: literal) => {
214 concat!("- [`hal::api::Metal`] uses [`hal::metal::", $ty, "`]")
215 };
216}
217#[cfg(not(metal))]
219macro_rules! hal_type_metal {
220 ($ty: literal) => {
221 concat!("- `hal::api::Metal` uses `hal::metal::", $ty, "`")
222 };
223}
224pub(crate) use hal_type_metal;
225
226#[cfg(vulkan)]
228macro_rules! hal_type_vulkan {
229 ($ty: literal) => {
230 concat!("- [`hal::api::Vulkan`] uses [`hal::vulkan::", $ty, "`]")
231 };
232}
233#[cfg(not(vulkan))]
235macro_rules! hal_type_vulkan {
236 ($ty: literal) => {
237 concat!("- `hal::api::Vulkan` uses `hal::vulkan::", $ty, "`")
238 };
239}
240pub(crate) use hal_type_vulkan;
241
242#[cfg(gles)]
244macro_rules! hal_type_gles {
245 ($ty: literal) => {
246 concat!("- [`hal::api::Gles`] uses [`hal::gles::", $ty, "`]")
247 };
248}
249#[cfg(not(gles))]
251macro_rules! hal_type_gles {
252 ($ty: literal) => {
253 concat!("- `hal::api::Gles` uses `hal::gles::", $ty, "`")
254 };
255}
256pub(crate) use hal_type_gles;
257
258#[doc(hidden)]
259pub mod helpers {
260 pub use alloc::{borrow::Cow, string::String};
261 pub use core::{include_bytes, include_str};
262 pub use Some;
263}