Skip to main content

bevy_render_macros/
lib.rs

1#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4mod as_bind_group;
5mod specializer;
6
7use bevy_macro_utils::{derive_label, BevyManifest};
8use proc_macro::TokenStream;
9use quote::format_ident;
10use syn::{parse_macro_input, DeriveInput};
11
12pub(crate) fn bevy_render_path() -> syn::Path {
13    BevyManifest::shared(|manifest| manifest.get_path("bevy_render"))
14}
15
16pub(crate) fn bevy_ecs_path() -> syn::Path {
17    BevyManifest::shared(|manifest| manifest.get_path("bevy_ecs"))
18}
19
20#[proc_macro_derive(
21    AsBindGroup,
22    attributes(
23        uniform,
24        storage_texture,
25        texture,
26        sampler,
27        bind_group_data,
28        storage,
29        bindless,
30        data
31    )
32)]
33pub fn derive_as_bind_group(input: TokenStream) -> TokenStream {
34    let input = parse_macro_input!(input as DeriveInput);
35
36    as_bind_group::derive_as_bind_group(input).unwrap_or_else(|err| err.to_compile_error().into())
37}
38
39/// Derive macro generating an impl of the trait `RenderLabel`.
40///
41/// This does not work for unions.
42#[proc_macro_derive(RenderLabel)]
43pub fn derive_render_label(input: TokenStream) -> TokenStream {
44    let input = parse_macro_input!(input as DeriveInput);
45    let mut trait_path = bevy_render_path();
46    trait_path
47        .segments
48        .push(format_ident!("render_graph").into());
49    trait_path
50        .segments
51        .push(format_ident!("RenderLabel").into());
52    derive_label(input, "RenderLabel", &trait_path)
53}
54
55/// Derive macro generating an impl of the trait `Specializer`
56///
57/// This only works for structs whose members all implement `Specializer`
58#[proc_macro_derive(Specializer, attributes(specialize, key, base_descriptor))]
59pub fn derive_specialize(input: TokenStream) -> TokenStream {
60    specializer::impl_specializer(input)
61}
62
63/// Derive macro generating the most common impl of the trait `SpecializerKey`
64#[proc_macro_derive(SpecializerKey)]
65pub fn derive_specializer_key(input: TokenStream) -> TokenStream {
66    specializer::impl_specializer_key(input)
67}