bevy_render_macros/
lib.rs1#![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 extract_component;
6mod extract_resource;
7mod specializer;
8
9use bevy_macro_utils::{derive_label, BevyManifest};
10use proc_macro::TokenStream;
11use quote::format_ident;
12use syn::{parse_macro_input, DeriveInput};
13
14pub(crate) fn bevy_render_path() -> syn::Path {
15 BevyManifest::shared().get_path("bevy_render")
16}
17
18pub(crate) fn bevy_ecs_path() -> syn::Path {
19 BevyManifest::shared().get_path("bevy_ecs")
20}
21
22#[proc_macro_derive(ExtractResource)]
23pub fn derive_extract_resource(input: TokenStream) -> TokenStream {
24 extract_resource::derive_extract_resource(input)
25}
26
27#[proc_macro_derive(ExtractComponent, attributes(extract_component_filter))]
55pub fn derive_extract_component(input: TokenStream) -> TokenStream {
56 extract_component::derive_extract_component(input)
57}
58
59#[proc_macro_derive(
60 AsBindGroup,
61 attributes(
62 uniform,
63 storage_texture,
64 texture,
65 sampler,
66 bind_group_data,
67 storage,
68 bindless,
69 data
70 )
71)]
72pub fn derive_as_bind_group(input: TokenStream) -> TokenStream {
73 let input = parse_macro_input!(input as DeriveInput);
74
75 as_bind_group::derive_as_bind_group(input).unwrap_or_else(|err| err.to_compile_error().into())
76}
77
78#[proc_macro_derive(RenderLabel)]
82pub fn derive_render_label(input: TokenStream) -> TokenStream {
83 let input = parse_macro_input!(input as DeriveInput);
84 let mut trait_path = bevy_render_path();
85 trait_path
86 .segments
87 .push(format_ident!("render_graph").into());
88 trait_path
89 .segments
90 .push(format_ident!("RenderLabel").into());
91 derive_label(input, "RenderLabel", &trait_path)
92}
93
94#[proc_macro_derive(RenderSubGraph)]
98pub fn derive_render_sub_graph(input: TokenStream) -> TokenStream {
99 let input = parse_macro_input!(input as DeriveInput);
100 let mut trait_path = bevy_render_path();
101 trait_path
102 .segments
103 .push(format_ident!("render_graph").into());
104 trait_path
105 .segments
106 .push(format_ident!("RenderSubGraph").into());
107 derive_label(input, "RenderSubGraph", &trait_path)
108}
109
110#[proc_macro_derive(Specializer, attributes(specialize, key, base_descriptor))]
114pub fn derive_specialize(input: TokenStream) -> TokenStream {
115 specializer::impl_specializer(input)
116}
117
118#[proc_macro_derive(SpecializerKey)]
120pub fn derive_specializer_key(input: TokenStream) -> TokenStream {
121 specializer::impl_specializer_key(input)
122}
123
124#[proc_macro_derive(ShaderLabel)]
125pub fn derive_shader_label(input: TokenStream) -> TokenStream {
126 let input = parse_macro_input!(input as DeriveInput);
127 let mut trait_path = bevy_render_path();
128 trait_path
129 .segments
130 .push(format_ident!("render_phase").into());
131 trait_path
132 .segments
133 .push(format_ident!("ShaderLabel").into());
134 derive_label(input, "ShaderLabel", &trait_path)
135}
136
137#[proc_macro_derive(DrawFunctionLabel)]
138pub fn derive_draw_function_label(input: TokenStream) -> TokenStream {
139 let input = parse_macro_input!(input as DeriveInput);
140 let mut trait_path = bevy_render_path();
141 trait_path
142 .segments
143 .push(format_ident!("render_phase").into());
144 trait_path
145 .segments
146 .push(format_ident!("DrawFunctionLabel").into());
147 derive_label(input, "DrawFunctionLabel", &trait_path)
148}