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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! Translates WGSL shader code to Rust embedded in your crate via macros.
//!
//! This does not necessarily mean you can run your compute or render pipelines in Rust
//! on your CPU unchanged; this is *not* a full “software renderer”. Rather, the primary goal
//! of the library is to allow you to share simple functions between CPU and GPU code, so
//! that the two parts of your code can agree on definitions.
//!
//! If you need additional control over the translation or to use a different source language,
//! use the [`naga_rust_back`] library directly instead.
//!
//! # Example
//!
// TODO: Make this example more obviously an example of WGSL and not Rust.
//! ```
//! naga_rust_embed::wgsl!(r"
//! fn add_one(x: i32) -> i32 {
//! return x + 1;
//! }
//! ");
//!
//! assert_eq!(add_one(10), 11);
//! ```
//!
//! This library is in an early stage of development and many features do not work yet.
//! Expect compilation failures and to have to tweak your code to fit.
//! Broadly, simple mathematical functions will work, and bindings, textures, atomics,
//! derivatives, and workgroup operations will not.
//!
//! [`naga_rust_back`]: https://docs.rs/naga-rust-back
/// Takes the pathname of a WGSL source file, as a string literal, and embeds its Rust translation.
///
/// The pathname must be relative to [`CARGO_MANIFEST_DIR`].
/// (If and when Rust proc-macros gain the ability to access files relative to the current
/// source file, a new `include_wgsl!` macro will be provided and this `include_wgsl_mr!` will be
/// deprecated.)
///
/// This macro should be used in a position where items are allowed
/// (e.g. inside a crate, module, function body, or block).
///
/// ```
/// # use naga_rust_embed::include_wgsl_mr;
/// include_wgsl_mr!("src/example.wgsl");
/// ```
///
/// If any configuration is needed, write it attribute-style before the source code literal:
///
/// ```
/// # use naga_rust_embed::include_wgsl_mr;
/// include_wgsl_mr!(
/// global_struct = Globals,
/// "src/example.wgsl",
/// );
/// ```
///
///
/// [`CARGO_MANIFEST_DIR`]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
pub use include_wgsl_mr;
/// Converts the provided WGSL string literal to Rust.
///
/// The macro should be given a single string literal containing the source code,
/// and used in a position where items are allowed
/// (e.g. inside a crate, module, function body, or block).
///
/// ```
/// # use naga_rust_embed::wgsl;
/// wgsl!("fn wgsl_hello_world() {}");
///
/// fn main() {
/// wgsl_hello_world();
/// }
/// ```
///
/// If any configuration is needed, write it attribute-style before the source code literal:
///
/// ```
/// # use naga_rust_embed::wgsl;
/// wgsl!(
/// global_struct = Globals,
/// "var<private> foo: i32 = 10;",
/// );
///
/// assert_eq!(Globals::default().foo, 10);
/// ```
///
pub use wgsl;
/// Support library for the generated Rust code.
/// Do not use this directly; its contents are not guaranteed to be stable.
pub use naga_rust_rt as rt;