1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Embedding a shader the way a size-conscious program wants it: validated and
//! minified while this example is compiled, DEFLATE-compressed into it, and
//! inflated at run time only if something asks for the text.
//!
//! ```text
//! cargo run -p wgslender --features compress --example embed_compressed
//! ```
//!
//! What a real program does with the last line is hand it to the GPU —
//! `device.create_shader_module(wgpu::ShaderModuleDescriptor {
//! source: wgpu::ShaderSource::Wgsl(SHADER.as_str().into()), .. })` — which is
//! the first and only moment the text has to exist.
/// The bytes that actually land in the binary.
///
/// A `static`, because the constructor is `const`. Any path relative to your
/// own crate root works; this one points at the package's test fixture, that
/// being the shader this package ships.
static SHADER: CompressedWgsl =
include_wgsl_compressed!;
/// The same file unprocessed, so the example can show what the two compile-time
/// passes bought. A real program would not carry this.
const AS_WRITTEN: &str = include_str!;
/// `part` as a whole-number percentage of `whole`, in integers: a size report
/// is not worth a rounding argument.