cart_tmp_wgpu/util/
mod.rs

1//! Utility structures and functions.
2
3mod belt;
4
5#[cfg(all(not(target_arch = "wasm32"), feature = "subscriber"))]
6pub use wgc::logging::subscriber::{initialize_default_subscriber, ChromeTracingLayer};
7
8pub use belt::StagingBelt;
9
10/// Wrapper aligning contents to at least 4.
11#[repr(align(4))]
12pub struct WordAligned<Bytes: ?Sized>(pub Bytes);
13
14/// Treat the given byte slice as a SPIR-V module.
15///
16/// # Panic
17///
18/// This function panics if:
19///
20/// - Input isn't aligned to 4 bytes
21/// - Input length isn't multiple of 4
22/// - Input is longer than [`usize::max_value`]
23/// - SPIR-V magic number is missing from beginning of stream
24pub fn make_spirv<'a>(data: &'a [u8]) -> super::ShaderModuleSource<'a> {
25    const MAGIC_NUMBER: u32 = 0x0723_0203;
26
27    let (pre, words, post) = unsafe { data.align_to::<u32>() };
28    assert_eq!(pre, &[], "data offset is not aligned to words!");
29    assert_eq!(post, &[], "data size is not aligned to words!");
30    assert_eq!(
31        words[0], MAGIC_NUMBER,
32        "wrong magic word {:x}. Make sure you are using a binary SPIRV file.",
33        words[0]
34    );
35    super::ShaderModuleSource::SpirV(words)
36}