From 751031749f80b67bd2f31870d2ac4e5da6838330 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Wed, 27 May 2026 18:09:46 +0800 Subject: [PATCH 01/15] Add Default to AppLabel's --- crates/bevy_app/src/app.rs | 2 +- crates/bevy_app/src/sub_app.rs | 2 +- crates/bevy_render/src/pipelined_rendering.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index bd6bba5dea23c..64d817a7a8ff6 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -1954,7 +1954,7 @@ mod tests { fn test_extract_sees_changes() { use super::AppLabel; - #[derive(AppLabel, Clone, Copy, Hash, PartialEq, Eq, Debug)] + #[derive(AppLabel, Clone, Copy, Hash, PartialEq, Eq, Debug, Default)] struct MySubApp; #[derive(Resource)] diff --git a/crates/bevy_app/src/sub_app.rs b/crates/bevy_app/src/sub_app.rs index c7194135535ef..347f87986fd16 100644 --- a/crates/bevy_app/src/sub_app.rs +++ b/crates/bevy_app/src/sub_app.rs @@ -34,7 +34,7 @@ type ExtractFn = Box; /// #[derive(Resource, Default)] /// struct Val(pub i32); /// -/// #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, AppLabel)] +/// #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, AppLabel, Default)] /// struct ExampleApp; /// /// // Create an app with a certain resource. diff --git a/crates/bevy_render/src/pipelined_rendering.rs b/crates/bevy_render/src/pipelined_rendering.rs index 9806ff45015cd..6f0b2b1fa6b83 100644 --- a/crates/bevy_render/src/pipelined_rendering.rs +++ b/crates/bevy_render/src/pipelined_rendering.rs @@ -14,7 +14,7 @@ use crate::RenderApp; /// /// The Main schedule of this app can be used to run logic after the render schedule starts, but /// before I/O processing. This can be useful for something like frame pacing. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, AppLabel)] +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, AppLabel, Default)] pub struct RenderExtractApp; /// Channels used by the main app to send and receive the render app. From ff2fd568579995cb1dbb7c7062d026fccffa58af Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Wed, 27 May 2026 21:56:17 +0800 Subject: [PATCH 02/15] Generalise SyncToRenderWorld and RenderEntity --- crates/bevy_render/src/sync_world.rs | 40 +++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/crates/bevy_render/src/sync_world.rs b/crates/bevy_render/src/sync_world.rs index 76e98ec266592..8a73bab794c0f 100644 --- a/crates/bevy_render/src/sync_world.rs +++ b/crates/bevy_render/src/sync_world.rs @@ -111,7 +111,8 @@ impl Plugin for SyncWorldPlugin { ); } } -/// Marker component that indicates that its entity needs to be synchronized to the render world. + +/// Marker component that indicates that its entity needs to be synchronized to the sub world. /// /// This component is automatically added as a required component by [`ExtractComponentPlugin`] and [`SyncComponentPlugin`]. /// For more information see [`SyncWorldPlugin`]. @@ -124,36 +125,41 @@ impl Plugin for SyncWorldPlugin { #[derive(Component, Copy, Clone, Debug, Default, Reflect)] #[reflect(Component, Default, Clone)] #[component(storage = "SparseSet")] -pub struct SyncToRenderWorld; +pub struct SyncToSubWorld(PhantomData); + +pub type SyncToRenderWorld = SyncToSubWorld; -/// Component added on the main world entities that are synced to the Render World in order to keep track of the corresponding render world entity. +/// Component added on the main world entities that are synced to the Sub World in order to keep track of the corresponding sub world entity. /// -/// Can also be used as a newtype wrapper for render world entities. +/// Can also be used as a newtype wrapper for sub world entities. #[derive(Component, Deref, Copy, Clone, Debug, Eq, Hash, PartialEq, Reflect)] #[component(clone_behavior = Ignore)] #[reflect(Component, Clone)] -pub struct RenderEntity(Entity); -impl RenderEntity { +pub struct SubEntity(#[deref] Entity, PhantomData); + +pub type RenderEntity = SubEntity; + +impl SubEntity { #[inline] pub fn id(&self) -> Entity { self.0 } } -impl From for RenderEntity { +impl From for SubEntity { fn from(entity: Entity) -> Self { - RenderEntity(entity) + SubEntity(entity, PhantomData) } } -impl ContainsEntity for RenderEntity { +impl ContainsEntity for SubEntity { fn entity(&self) -> Entity { self.id() } } -// SAFETY: RenderEntity is a newtype around Entity that derives its comparison traits. -unsafe impl EntityEquivalent for RenderEntity {} +// SAFETY: SubEntity is a newtype around Entity that derives its comparison traits. +unsafe impl EntityEquivalent for SubEntity {} /// Component added on the render world entities to keep track of the corresponding main world entity. /// @@ -180,7 +186,7 @@ impl ContainsEntity for MainEntity { } } -// SAFETY: RenderEntity is a newtype around Entity that derives its comparison traits. +// SAFETY: MainEntity is a newtype around Entity that derives its comparison traits. unsafe impl EntityEquivalent for MainEntity {} /// A [`HashMap`] pre-configured to use [`EntityHash`] hashing with a [`MainEntity`]. @@ -236,7 +242,7 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl bevy_ecs::world::ComponentEntry::Vacant(entry) => { let id = render_world.spawn(MainEntity(e)).id(); - entry.insert(RenderEntity(id)); + entry.insert(SubEntity::(id, PhantomData)); } }; } @@ -540,6 +546,8 @@ mod render_entities_world_query_impls { #[cfg(test)] mod tests { + use core::marker::PhantomData; + use bevy_ecs::{ component::Component, entity::Entity, @@ -550,9 +558,11 @@ mod tests { world::World, }; + use crate::RenderApp; + use super::{ entity_sync_system, EntityRecord, MainEntity, PendingSyncEntity, RenderEntity, - SyncToRenderWorld, + SyncToRenderWorld, SyncToSubWorld, }; #[derive(Component)] @@ -588,7 +598,7 @@ mod tests { let main_entity = main_world .spawn(RenderDataComponent) // indicates that its entity needs to be synchronized to the render world - .insert(SyncToRenderWorld) + .insert(SyncToSubWorld::(PhantomData)) .id(); entity_sync_system(&mut main_world, &mut render_world); From 8d7d5a4f70492e3287b47ef97046690bbfafa31f Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Wed, 27 May 2026 22:47:56 +0800 Subject: [PATCH 03/15] Entity sync --- crates/bevy_render/src/extract_plugin.rs | 2 +- crates/bevy_render/src/sync_component.rs | 2 +- crates/bevy_render/src/sync_world.rs | 164 ++++++++++++----------- 3 files changed, 89 insertions(+), 79 deletions(-) diff --git a/crates/bevy_render/src/extract_plugin.rs b/crates/bevy_render/src/extract_plugin.rs index a5c478f81f5a9..b177ffb465268 100644 --- a/crates/bevy_render/src/extract_plugin.rs +++ b/crates/bevy_render/src/extract_plugin.rs @@ -65,7 +65,7 @@ impl Plugin for ExtractPlugin { { #[cfg(feature = "trace")] let _stage_span = bevy_log::info_span!("entity_sync").entered(); - entity_sync_system(main_world, render_world); + entity_sync_system::(main_world, render_world); } // run extract schedule diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs index 5ec00b2ffc896..339c3fc8632a7 100644 --- a/crates/bevy_render/src/sync_component.rs +++ b/crates/bevy_render/src/sync_component.rs @@ -57,7 +57,7 @@ impl, F: Send + Sync + 'static> Plugin app.world_mut() .register_component_hooks::() .on_remove(|mut world, context| { - let mut pending = world.resource_mut::(); + let mut pending = world.resource_mut::>(); pending.push(EntityRecord::ComponentRemoved( context.entity, |mut entity| { diff --git a/crates/bevy_render/src/sync_world.rs b/crates/bevy_render/src/sync_world.rs index 8a73bab794c0f..2d13d4bae5c63 100644 --- a/crates/bevy_render/src/sync_world.rs +++ b/crates/bevy_render/src/sync_world.rs @@ -94,15 +94,15 @@ pub struct SyncWorldPlugin; impl Plugin for SyncWorldPlugin { fn build(&self, app: &mut bevy_app::App) { - app.init_resource::(); + app.init_resource::>(); app.add_observer( - |add: On, mut pending: ResMut| { + |add: On, mut pending: ResMut>| { pending.push(EntityRecord::Added(add.entity)); }, ); app.add_observer( |remove: On, - mut pending: ResMut, + mut pending: ResMut>, query: Query<&RenderEntity>| { if let Ok(e) = query.get(remove.entity) { pending.push(EntityRecord::Removed(*e)); @@ -161,7 +161,7 @@ impl ContainsEntity for SubEntity { // SAFETY: SubEntity is a newtype around Entity that derives its comparison traits. unsafe impl EntityEquivalent for SubEntity {} -/// Component added on the render world entities to keep track of the corresponding main world entity. +/// Component added on the sub world entities to keep track of the corresponding main world entity. /// /// Can also be used as a newtype wrapper for main world entities. #[derive(Component, Deref, Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Reflect)] @@ -208,56 +208,61 @@ pub struct TemporaryEntity(PhantomDat pub type TemporaryRenderEntity = TemporaryEntity; -/// A record enum to what entities with [`SyncToRenderWorld`] have been added or removed. +/// A record enum to what entities with [`SyncToSubWorld`] have been added or removed. #[derive(Debug)] -pub(crate) enum EntityRecord { - /// When an entity is spawned on the main world, notify the render world so that it can spawn a corresponding +pub(crate) enum EntityRecord { + /// When an entity is spawned on the main world, notify the sub world so that it can spawn a corresponding /// entity. This contains the main world entity. Added(Entity), - /// When an entity is despawned on the main world, notify the render world so that the corresponding entity can be - /// despawned. This contains the render world entity. - Removed(RenderEntity), - /// When a component is removed from an entity, notify the render world so that the corresponding component can be + /// When an entity is despawned on the main world, notify the sub world so that the corresponding entity can be + /// despawned. This contains the sub world entity. + Removed(SubEntity), + /// When a component is removed from an entity, notify the sub world so that the corresponding component can be /// removed. This contains the main world entity. ComponentRemoved(Entity, fn(EntityWorldMut<'_>)), } // Entity Record in MainWorld pending to Sync #[derive(Resource, Default, Deref, DerefMut)] -pub(crate) struct PendingSyncEntity { - records: Vec, +pub(crate) struct PendingSyncEntity { + #[deref] + records: Vec>, + marker: PhantomData, } -pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut World) { - main_world.resource_scope(|world, mut pending: Mut| { +pub(crate) fn entity_sync_system( + main_world: &mut World, + sub_world: &mut World, +) { + main_world.resource_scope(|world, mut pending: Mut>| { // TODO : batching record for record in pending.drain(..) { match record { EntityRecord::Added(e) => { if let Ok(mut main_entity) = world.get_entity_mut(e) { - match main_entity.entry::() { + match main_entity.entry::>() { bevy_ecs::world::ComponentEntry::Occupied(_) => { panic!("Attempting to synchronize an entity that has already been synchronized!"); } bevy_ecs::world::ComponentEntry::Vacant(entry) => { - let id = render_world.spawn(MainEntity(e)).id(); + let id = sub_world.spawn(MainEntity(e)).id(); - entry.insert(SubEntity::(id, PhantomData)); + entry.insert(SubEntity::(id, PhantomData)); } }; } } - EntityRecord::Removed(render_entity) => { - if let Ok(ec) = render_world.get_entity_mut(render_entity.id()) { + EntityRecord::Removed(sub_entity) => { + if let Ok(ec) = sub_world.get_entity_mut(sub_entity.id()) { ec.despawn(); }; } EntityRecord::ComponentRemoved(main_entity, removal_function) => { - let Some(render_entity) = world.get::(main_entity) else { + let Some(sub_entity) = world.get::>(main_entity) else { continue; }; - if let Ok(render_world_entity) = render_world.get_entity_mut(render_entity.id()) { - removal_function(render_world_entity); + if let Ok(sub_world_entity) = sub_world.get_entity_mut(sub_entity.id()) { + removal_function(sub_world_entity); } }, } @@ -283,11 +288,12 @@ pub(crate) fn despawn_temporary_entities( /// This module exists to keep the complex unsafe code out of the main module. /// -/// The implementations for both [`MainEntity`] and [`RenderEntity`] should stay in sync, +/// The implementations for both [`MainEntity`] and [`SubEntity`] should stay in sync, /// and are based off of the `&T` implementation in `bevy_ecs`. -mod render_entities_world_query_impls { - use super::{MainEntity, RenderEntity}; +mod sub_entities_world_query_impls { + use super::{MainEntity, SubEntity}; + use bevy_app::AppLabel; use bevy_ecs::{ archetype::Archetype, change_detection::Tick, @@ -301,11 +307,11 @@ mod render_entities_world_query_impls { world::{unsafe_world_cell::UnsafeWorldCell, World}, }; - // SAFETY: defers completely to `&RenderEntity` implementation, + // SAFETY: defers completely to `&SubEntity` implementation, // and then only modifies the output safely. - unsafe impl WorldQuery for RenderEntity { - type Fetch<'w> = <&'static RenderEntity as WorldQuery>::Fetch<'w>; - type State = <&'static RenderEntity as WorldQuery>::State; + unsafe impl WorldQuery for SubEntity { + type Fetch<'w> = <&'static SubEntity as WorldQuery>::Fetch<'w>; + type State = <&'static SubEntity as WorldQuery>::State; fn shrink_fetch<'wlong: 'wshort, 'wshort>( fetch: Self::Fetch<'wlong>, @@ -320,13 +326,13 @@ mod render_entities_world_query_impls { last_run: Tick, this_run: Tick, ) -> Self::Fetch<'w> { - // SAFETY: defers to the `&T` implementation, with T set to `RenderEntity`. + // SAFETY: defers to the `&T` implementation, with T set to `SubEntity`. unsafe { - <&RenderEntity as WorldQuery>::init_fetch(world, component_id, last_run, this_run) + <&SubEntity as WorldQuery>::init_fetch(world, component_id, last_run, this_run) } } - const IS_DENSE: bool = <&'static RenderEntity as WorldQuery>::IS_DENSE; + const IS_DENSE: bool = <&'static SubEntity as WorldQuery>::IS_DENSE; #[inline] unsafe fn set_archetype<'w, 's>( @@ -335,9 +341,9 @@ mod render_entities_world_query_impls { archetype: &'w Archetype, table: &'w Table, ) { - // SAFETY: defers to the `&T` implementation, with T set to `RenderEntity`. + // SAFETY: defers to the `&T` implementation, with T set to `SubEntity`. unsafe { - <&RenderEntity as WorldQuery>::set_archetype(fetch, component_id, archetype, table); + <&SubEntity as WorldQuery>::set_archetype(fetch, component_id, archetype, table); } } @@ -347,36 +353,36 @@ mod render_entities_world_query_impls { &component_id: &'s ComponentId, table: &'w Table, ) { - // SAFETY: defers to the `&T` implementation, with T set to `RenderEntity`. - unsafe { <&RenderEntity as WorldQuery>::set_table(fetch, &component_id, table) } + // SAFETY: defers to the `&T` implementation, with T set to `SubEntity`. + unsafe { <&SubEntity as WorldQuery>::set_table(fetch, &component_id, table) } } fn update_component_access(&component_id: &ComponentId, access: &mut FilteredAccess) { - <&RenderEntity as WorldQuery>::update_component_access(&component_id, access); + <&SubEntity as WorldQuery>::update_component_access(&component_id, access); } fn init_state(world: &mut World) -> ComponentId { - <&RenderEntity as WorldQuery>::init_state(world) + <&SubEntity as WorldQuery>::init_state(world) } fn get_state(components: &Components) -> Option { - <&RenderEntity as WorldQuery>::get_state(components) + <&SubEntity as WorldQuery>::get_state(components) } fn matches_component_set( &state: &ComponentId, set_contains_id: &impl Fn(ComponentId) -> bool, ) -> bool { - <&RenderEntity as WorldQuery>::matches_component_set(&state, set_contains_id) + <&SubEntity as WorldQuery>::matches_component_set(&state, set_contains_id) } } // SAFETY: Component access of Self::ReadOnly is a subset of Self. // Self::ReadOnly matches exactly the same archetypes/tables as Self. - unsafe impl QueryData for RenderEntity { + unsafe impl QueryData for SubEntity { const IS_READ_ONLY: bool = true; const IS_ARCHETYPAL: bool = <&MainEntity as QueryData>::IS_ARCHETYPAL; - type ReadOnly = RenderEntity; + type ReadOnly = SubEntity; type Item<'w, 's> = Entity; fn shrink<'wlong: 'wshort, 'wshort, 's>( @@ -392,37 +398,37 @@ mod render_entities_world_query_impls { entity: Entity, table_row: TableRow, ) -> Option> { - // SAFETY: defers to the `&T` implementation, with T set to `RenderEntity`. + // SAFETY: defers to the `&T` implementation, with T set to `SubEntity`. let component = - unsafe { <&RenderEntity as QueryData>::fetch(state, fetch, entity, table_row) }; - component.map(RenderEntity::id) + unsafe { <&SubEntity as QueryData>::fetch(state, fetch, entity, table_row) }; + component.map(SubEntity::id) } fn iter_access( state: &Self::State, ) -> impl Iterator> { - <&RenderEntity as QueryData>::iter_access(state) + <&SubEntity as QueryData>::iter_access(state) } } /// SAFETY: access is read only and only on the current entity - unsafe impl IterQueryData for RenderEntity {} + unsafe impl IterQueryData for SubEntity {} /// SAFETY: access is read only - unsafe impl ReadOnlyQueryData for RenderEntity {} + unsafe impl ReadOnlyQueryData for SubEntity {} /// SAFETY: access is only on the current entity - unsafe impl SingleEntityQueryData for RenderEntity {} + unsafe impl SingleEntityQueryData for SubEntity {} - impl ArchetypeQueryData for RenderEntity {} + impl ArchetypeQueryData for SubEntity {} - impl ReleaseStateQueryData for RenderEntity { + impl ReleaseStateQueryData for SubEntity { fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> { item } } - // SAFETY: defers completely to `&RenderEntity` implementation, + // SAFETY: defers completely to `&SubEntity` implementation, // and then only modifies the output safely. unsafe impl WorldQuery for MainEntity { type Fetch<'w> = <&'static MainEntity as WorldQuery>::Fetch<'w>; @@ -548,6 +554,7 @@ mod render_entities_world_query_impls { mod tests { use core::marker::PhantomData; + use bevy_app::AppLabel; use bevy_ecs::{ component::Component, entity::Entity, @@ -558,31 +565,32 @@ mod tests { world::World, }; - use crate::RenderApp; - use super::{ - entity_sync_system, EntityRecord, MainEntity, PendingSyncEntity, RenderEntity, - SyncToRenderWorld, SyncToSubWorld, + entity_sync_system, EntityRecord, MainEntity, PendingSyncEntity, SubEntity, SyncToSubWorld, }; #[derive(Component)] - struct RenderDataComponent; + struct SubDataComponent; + + #[derive(Debug, Default, Clone, Copy, Hash, PartialEq, Eq, AppLabel)] + struct ExtractApp; #[test] fn sync_world() { let mut main_world = World::new(); - let mut render_world = World::new(); - main_world.init_resource::(); + let mut sub_world = World::new(); + main_world.init_resource::>(); main_world.add_observer( - |add: On, mut pending: ResMut| { + |add: On>, + mut pending: ResMut>| { pending.push(EntityRecord::Added(add.entity)); }, ); main_world.add_observer( - |remove: On, - mut pending: ResMut, - query: Query<&RenderEntity>| { + |remove: On>, + mut pending: ResMut>, + query: Query<&SubEntity>| { if let Ok(e) = query.get(remove.entity) { pending.push(EntityRecord::Removed(*e)); }; @@ -596,25 +604,27 @@ mod tests { // spawn let main_entity = main_world - .spawn(RenderDataComponent) - // indicates that its entity needs to be synchronized to the render world - .insert(SyncToSubWorld::(PhantomData)) + .spawn(SubDataComponent) + // indicates that its entity needs to be synchronized to the sub world + .insert(SyncToSubWorld::(PhantomData)) .id(); - entity_sync_system(&mut main_world, &mut render_world); + entity_sync_system::(&mut main_world, &mut sub_world); - let mut q = render_world.query_filtered::>(); + let mut q = sub_world.query_filtered::>(); // Only one synchronized entity - assert!(q.iter(&render_world).count() == 1); + assert!(q.iter(&sub_world).count() == 1); - let render_entity = q.single(&render_world).unwrap(); - let render_entity_component = main_world.get::(main_entity).unwrap(); + let sub_entity = q.single(&sub_world).unwrap(); + let sub_entity_component = main_world + .get::>(main_entity) + .unwrap(); - assert!(render_entity_component.id() == render_entity); + assert!(sub_entity_component.id() == sub_entity); - let main_entity_component = render_world - .get::(render_entity_component.id()) + let main_entity_component = sub_world + .get::(sub_entity_component.id()) .unwrap(); assert!(main_entity_component.id() == main_entity); @@ -622,9 +632,9 @@ mod tests { // despawn main_world.despawn(main_entity); - entity_sync_system(&mut main_world, &mut render_world); + entity_sync_system::(&mut main_world, &mut sub_world); // Only one synchronized entity - assert!(q.iter(&render_world).count() == 0); + assert!(q.iter(&sub_world).count() == 0); } } From c7052bdd50f0813240497560980ed4498faf601d Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Wed, 27 May 2026 22:51:30 +0800 Subject: [PATCH 04/15] Extract instances --- .../src/light_probe/environment_map.rs | 3 +- crates/bevy_pbr/src/light_probe/mod.rs | 2 +- crates/bevy_render/src/extract_instances.rs | 75 ++++++++++--------- crates/bevy_render/src/sync_world.rs | 3 +- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/crates/bevy_pbr/src/light_probe/environment_map.rs b/crates/bevy_pbr/src/light_probe/environment_map.rs index 3ba44e3247fb4..329cdbb3c5bc6 100644 --- a/crates/bevy_pbr/src/light_probe/environment_map.rs +++ b/crates/bevy_pbr/src/light_probe/environment_map.rs @@ -61,6 +61,7 @@ use bevy_render::{ }, renderer::{RenderAdapter, RenderDevice}, texture::{FallbackImage, GpuImage}, + RenderApp, }; use core::{num::NonZero, ops::Deref}; @@ -139,7 +140,7 @@ pub struct EnvironmentMapViewLightProbeInfo { pub(crate) rotation: Quat, } -impl ExtractInstance for EnvironmentMapIds { +impl ExtractInstance for EnvironmentMapIds { type QueryData = Read; type QueryFilter = (); diff --git a/crates/bevy_pbr/src/light_probe/mod.rs b/crates/bevy_pbr/src/light_probe/mod.rs index dd300f5b3f4d8..1a39e93810792 100644 --- a/crates/bevy_pbr/src/light_probe/mod.rs +++ b/crates/bevy_pbr/src/light_probe/mod.rs @@ -378,7 +378,7 @@ impl Plugin for LightProbePlugin { app.add_plugins(( EnvironmentMapGenerationPlugin, - ExtractInstancesPlugin::::new(), + ExtractInstancesPlugin::::new(), )); let Some(render_app) = app.get_sub_app_mut(RenderApp) else { diff --git a/crates/bevy_render/src/extract_instances.rs b/crates/bevy_render/src/extract_instances.rs index d85f8fa646b34..a259492f3ef02 100644 --- a/crates/bevy_render/src/extract_instances.rs +++ b/crates/bevy_render/src/extract_instances.rs @@ -1,12 +1,12 @@ //! Convenience logic for turning components from the main world into extracted -//! instances in the render world. +//! instances in the sub world. //! //! This is essentially the same as the `extract_component` module, but //! higher-performance because it avoids the ECS overhead. use core::marker::PhantomData; -use bevy_app::{App, Plugin}; +use bevy_app::{App, AppLabel, Plugin}; use bevy_camera::visibility::ViewVisibility; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ @@ -17,62 +17,66 @@ use bevy_ecs::{ }; use crate::sync_world::MainEntityHashMap; -use crate::{Extract, ExtractSchedule, RenderApp}; +use crate::{Extract, ExtractSchedule}; -/// Describes how to extract data needed for rendering from a component or +/// Describes how to extract data needed for processing from a component or /// components. /// -/// Before rendering, any applicable components will be transferred from the -/// main world to the render world in the [`ExtractSchedule`] step. +/// Before processing, any applicable components will be transferred from the +/// main world to the sub world in the [`ExtractSchedule`] step. /// /// This is essentially the same as /// [`ExtractComponent`](crate::extract_component::ExtractComponent), but /// higher-performance because it avoids the ECS overhead. -pub trait ExtractInstance: Send + Sync + Sized + 'static { +pub trait ExtractInstance: Send + Sync + Sized + 'static { /// ECS [`ReadOnlyQueryData`] to fetch the components to extract. type QueryData: ReadOnlyQueryData; /// Filters the entities with additional constraints. type QueryFilter: QueryFilter; - /// Defines how the component is transferred into the "render world". + /// Defines how the component is transferred into the "sub world". fn extract(item: QueryItem<'_, '_, Self::QueryData>) -> Option; } -/// This plugin extracts one or more components into the "render world" as +/// This plugin extracts one or more components into the "sub world" as /// extracted instances. /// /// Therefore it sets up the [`ExtractSchedule`] step for the specified /// [`ExtractedInstances`]. #[derive(Default)] -pub struct ExtractInstancesPlugin +pub struct ExtractInstancesPlugin where - EI: ExtractInstance, + L: AppLabel, + EI: ExtractInstance, { only_extract_visible: bool, - marker: PhantomData EI>, + marker: PhantomData (L, EI)>, } -/// Stores all extract instances of a type in the render world. +/// Stores all extract instances of a type in the sub world. #[derive(Resource, Deref, DerefMut)] -pub struct ExtractedInstances(MainEntityHashMap) +pub struct ExtractedInstances(#[deref] MainEntityHashMap, PhantomData) where - EI: ExtractInstance; + L: AppLabel, + EI: ExtractInstance; -impl Default for ExtractedInstances +impl Default for ExtractedInstances where - EI: ExtractInstance, + L: AppLabel, + EI: ExtractInstance, { fn default() -> Self { - Self(Default::default()) + Self(Default::default(), PhantomData) } } -impl ExtractInstancesPlugin +impl ExtractInstancesPlugin where - EI: ExtractInstance, + L: AppLabel, + EI: ExtractInstance, { /// Creates a new [`ExtractInstancesPlugin`] that unconditionally extracts to - /// the render world, whether the entity is visible or not. + /// the sub world, whether the entity is visible or not. pub fn new() -> Self { Self { only_extract_visible: false, @@ -80,7 +84,7 @@ where } } - /// Creates a new [`ExtractInstancesPlugin`] that extracts to the render world + /// Creates a new [`ExtractInstancesPlugin`] that extracts to the sub world /// if and only if the entity it's attached to is visible. pub fn extract_visible() -> Self { Self { @@ -90,27 +94,29 @@ where } } -impl Plugin for ExtractInstancesPlugin +impl Plugin for ExtractInstancesPlugin where - EI: ExtractInstance, + L: AppLabel + Default, + EI: ExtractInstance, { fn build(&self, app: &mut App) { - if let Some(render_app) = app.get_sub_app_mut(RenderApp) { - render_app.init_resource::>(); + if let Some(sub_app) = app.get_sub_app_mut(L::default()) { + sub_app.init_resource::>(); if self.only_extract_visible { - render_app.add_systems(ExtractSchedule, extract_visible::); + sub_app.add_systems(ExtractSchedule, extract_visible::); } else { - render_app.add_systems(ExtractSchedule, extract_all::); + sub_app.add_systems(ExtractSchedule, extract_all::); } } } } -fn extract_all( - mut extracted_instances: ResMut>, +fn extract_all( + mut extracted_instances: ResMut>, query: Extract>, ) where - EI: ExtractInstance, + L: AppLabel, + EI: ExtractInstance, { extracted_instances.clear(); for (entity, other) in &query { @@ -120,11 +126,12 @@ fn extract_all( } } -fn extract_visible( - mut extracted_instances: ResMut>, +fn extract_visible( + mut extracted_instances: ResMut>, query: Extract>, ) where - EI: ExtractInstance, + L: AppLabel, + EI: ExtractInstance, { extracted_instances.clear(); for (entity, view_visibility, other) in &query { diff --git a/crates/bevy_render/src/sync_world.rs b/crates/bevy_render/src/sync_world.rs index 2d13d4bae5c63..66c2fa21884aa 100644 --- a/crates/bevy_render/src/sync_world.rs +++ b/crates/bevy_render/src/sync_world.rs @@ -96,7 +96,8 @@ impl Plugin for SyncWorldPlugin { fn build(&self, app: &mut bevy_app::App) { app.init_resource::>(); app.add_observer( - |add: On, mut pending: ResMut>| { + |add: On, + mut pending: ResMut>| { pending.push(EntityRecord::Added(add.entity)); }, ); From 1816340fae4444f6af844ef318d562a06213ac99 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Wed, 27 May 2026 23:11:05 +0800 Subject: [PATCH 05/15] Plugins --- .../bevy_render/extract_render_asset.rs | 14 ++- crates/bevy_render/src/camera.rs | 3 +- crates/bevy_render/src/extract_component.rs | 37 ++++---- crates/bevy_render/src/extract_plugin.rs | 95 ++++++++++++++----- crates/bevy_render/src/extract_resource.rs | 21 ++-- crates/bevy_render/src/lib.rs | 11 ++- crates/bevy_render/src/pipelined_rendering.rs | 3 +- crates/bevy_render/src/sync_component.rs | 23 +++-- crates/bevy_render/src/sync_world.rs | 37 ++++---- 9 files changed, 163 insertions(+), 81 deletions(-) diff --git a/benches/benches/bevy_render/extract_render_asset.rs b/benches/benches/bevy_render/extract_render_asset.rs index 350de956b4e75..8c55844271836 100644 --- a/benches/benches/bevy_render/extract_render_asset.rs +++ b/benches/benches/bevy_render/extract_render_asset.rs @@ -1,11 +1,11 @@ use bevy_app::{App, AppLabel}; use bevy_asset::{Asset, AssetApp, AssetEvent, AssetId, Assets, RenderAssetUsages}; -use bevy_ecs::prelude::*; +use bevy_ecs::{prelude::*, schedule::ScheduleLabel}; use bevy_reflect::TypePath; use bevy_render::{ extract_plugin::ExtractPlugin, render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin}, - RenderApp, + Render, RenderApp, RenderSystems, }; use criterion::{criterion_group, BenchmarkId, Criterion, Throughput}; use std::time::{Duration, Instant}; @@ -33,6 +33,8 @@ impl RenderAsset for DummyRenderAsset { } } +pub(crate) fn pre_extract(_main_world: &mut World, _render_world: &mut World) {} + fn extract_render_asset_bench(c: &mut Criterion) { let mut group = c.benchmark_group("extract_render_asset"); @@ -45,7 +47,13 @@ fn extract_render_asset_bench(c: &mut Criterion) { app.add_plugins(bevy_asset::AssetPlugin::default()); app.init_asset::(); - app.add_plugins(ExtractPlugin::default()); + app.add_plugins(ExtractPlugin::::new( + pre_extract, + Render::base_schedule, + Render.intern(), + RenderSystems::ExtractCommands.intern(), + RenderSystems::PostCleanup.intern(), + )); app.add_plugins(RenderAssetPlugin::::default()); app.finish(); diff --git a/crates/bevy_render/src/camera.rs b/crates/bevy_render/src/camera.rs index 572ecfaecffe1..8ac5e672dabe8 100644 --- a/crates/bevy_render/src/camera.rs +++ b/crates/bevy_render/src/camera.rs @@ -102,7 +102,8 @@ impl Plugin for CameraPlugin { .add_systems( ExtractSchedule, ( - extract_cameras.after(extract_resource::), + extract_cameras + .after(extract_resource::), clear_dirty_specializations.in_set(DirtySpecializationSystems::Clear), clear_dirty_wireframe_specializations .in_set(DirtySpecializationSystems::Clear), diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_render/src/extract_component.rs index 1603f91219b38..bb540abcad2a3 100644 --- a/crates/bevy_render/src/extract_component.rs +++ b/crates/bevy_render/src/extract_component.rs @@ -1,6 +1,6 @@ use crate::{ sync_component::{SyncComponent, SyncComponentPlugin}, - sync_world::RenderEntity, + sync_world::SubEntity, Extract, ExtractSchedule, RenderApp, }; use bevy_app::{App, AppLabel, Plugin}; @@ -51,18 +51,20 @@ pub trait ExtractComponent: SyncComponent { /// entities. To do so, it sets up the [`ExtractSchedule`] step for the /// specified [`ExtractComponent`]. /// -/// It also registers [`SyncComponentPlugin`] to ensure the extracted components +/// It also registers [`SyncComponentPlugin`](`crate::sync_component::SyncComponentPlugin`) to ensure the extracted components /// are deleted if the main world components are removed. /// /// The marker type `F` is only used as a way to bypass the orphan rules. To /// implement the trait for a foreign type you can use a local type as the /// marker, e.g. the type of the plugin that calls [`ExtractComponentPlugin`]. -pub struct ExtractComponentPlugin { +pub struct ExtractComponentPlugin { only_extract_visible: bool, - marker: PhantomData (C, F)>, + marker: PhantomData (L, C, F)>, } -impl Default for ExtractComponentPlugin { +// pub type ExtractComponentPlugin = ExtractComponentPlugin; + +impl Default for ExtractComponentPlugin { fn default() -> Self { Self { only_extract_visible: false, @@ -71,7 +73,7 @@ impl Default for ExtractComponentPlugin { } } -impl ExtractComponentPlugin { +impl ExtractComponentPlugin { pub fn extract_visible() -> Self { Self { only_extract_visible: true, @@ -80,27 +82,30 @@ impl ExtractComponentPlugin { } } -impl, F: 'static + Send + Sync> Plugin - for ExtractComponentPlugin +impl< + L: AppLabel + Default + Clone + Copy + Eq, + C: ExtractComponent, + F: 'static + Send + Sync, + > Plugin for ExtractComponentPlugin { fn build(&self, app: &mut App) { - app.add_plugins(SyncComponentPlugin::::default()); + app.add_plugins(SyncComponentPlugin::::default()); - if let Some(render_app) = app.get_sub_app_mut(RenderApp) { + if let Some(render_app) = app.get_sub_app_mut(L::default()) { if self.only_extract_visible { - render_app.add_systems(ExtractSchedule, extract_visible_components::); + render_app.add_systems(ExtractSchedule, extract_visible_components::); } else { - render_app.add_systems(ExtractSchedule, extract_components::); + render_app.add_systems(ExtractSchedule, extract_components::); } } } } /// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`crate::sync_world::SyncToRenderWorld`]. -fn extract_components, F>( +fn extract_components, F>( mut commands: Commands, mut previous_len: Local, - query: Extract>, + query: Extract, C::QueryData), C::QueryFilter>>, ) { let mut values = Vec::with_capacity(*previous_len); for (entity, query_item) in &query { @@ -115,10 +120,10 @@ fn extract_components, F>( } /// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are visible and synced via [`crate::sync_world::SyncToRenderWorld`]. -fn extract_visible_components, F>( +fn extract_visible_components, F>( mut commands: Commands, mut previous_len: Local, - query: Extract>, + query: Extract, &ViewVisibility, C::QueryData), C::QueryFilter>>, ) { let mut values = Vec::with_capacity(*previous_len); for (entity, view_visibility, query_item) in &query { diff --git a/crates/bevy_render/src/extract_plugin.rs b/crates/bevy_render/src/extract_plugin.rs index b177ffb465268..aa2b332968304 100644 --- a/crates/bevy_render/src/extract_plugin.rs +++ b/crates/bevy_render/src/extract_plugin.rs @@ -1,36 +1,57 @@ -use crate::{ - sync_world::{despawn_temporary_entities, entity_sync_system, SyncWorldPlugin}, - Render, RenderApp, RenderSystems, -}; -use bevy_app::{App, Plugin, SubApp}; +use core::marker::PhantomData; + +use crate::sync_world::{despawn_temporary_entities, entity_sync_system, SyncWorldPlugin}; +use bevy_app::{App, AppLabel, Plugin, SubApp}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ resource::Resource, - schedule::{IntoScheduleConfigs, Schedule, ScheduleBuildSettings, ScheduleLabel, Schedules}, + schedule::{ + InternedScheduleLabel, InternedSystemSet, IntoScheduleConfigs, Schedule, + ScheduleBuildSettings, ScheduleLabel, Schedules, + }, world::{Mut, World}, }; use bevy_utils::default; -/// Plugin that sets up the [`RenderApp`] and handles extracting data from the +/// Plugin that sets up the [`RenderApp`](`crate::RenderApp`) and handles extracting data from the /// main world to the render world. -pub struct ExtractPlugin { +pub struct ExtractPlugin { /// Function that gets run at the beginning of each extraction. /// /// Gets the main world and render world as arguments (in that order). pub pre_extract: fn(&mut World, &mut World), + + marker: PhantomData, + + pub base_schedule: fn() -> Schedule, + pub schedule_label: InternedScheduleLabel, + + pub extract_set: InternedSystemSet, + pub despawn_set: InternedSystemSet, } -impl Default for ExtractPlugin { - fn default() -> Self { +impl ExtractPlugin { + pub fn new( + pre_extract: fn(&mut World, &mut World), + base_schedule: fn() -> Schedule, + schedule_label: InternedScheduleLabel, + extract_set: InternedSystemSet, + despawn_set: InternedSystemSet, + ) -> Self { Self { - pre_extract: |_, _| {}, + pre_extract, + marker: PhantomData, + base_schedule, + schedule_label, + extract_set, + despawn_set, } } } -impl Plugin for ExtractPlugin { +impl Plugin for ExtractPlugin { fn build(&self, app: &mut App) { - app.add_plugins(SyncWorldPlugin); + app.add_plugins(SyncWorldPlugin::::default()); app.init_resource::(); let mut render_app = SubApp::new(); @@ -45,16 +66,16 @@ impl Plugin for ExtractPlugin { extract_schedule.set_apply_final_deferred(false); render_app - .add_schedule(Render::base_schedule()) + .add_schedule((self.base_schedule)()) .add_schedule(extract_schedule) .allow_ambiguous_resource::() .add_systems( - Render, + self.schedule_label, ( // This set applies the commands from the extract schedule while the render schedule // is running in parallel with the main app. - apply_extract_commands.in_set(RenderSystems::ExtractCommands), - despawn_temporary_entities::.in_set(RenderSystems::PostCleanup), + apply_extract_commands.in_set(self.extract_set), + despawn_temporary_entities::.in_set(self.despawn_set), ), ); @@ -65,14 +86,14 @@ impl Plugin for ExtractPlugin { { #[cfg(feature = "trace")] let _stage_span = bevy_log::info_span!("entity_sync").entered(); - entity_sync_system::(main_world, render_world); + entity_sync_system::(main_world, render_world); } // run extract schedule extract(main_world, render_world); }); - app.insert_sub_app(RenderApp, render_app); + app.insert_sub_app(L::default(), render_app); } } @@ -135,9 +156,33 @@ mod test { extract_plugin::ExtractPlugin, sync_component::SyncComponent, sync_world::MainEntity, - Render, RenderApp, + RenderApp, }; + #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] + pub enum MyScheduleSystems { + ExtractCommands, + PostCleanup, + } + + #[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone, Default)] + pub struct MySchedule; + + impl MySchedule { + /// Sets up the base structure of the rendering [`Schedule`]. + /// + /// The sets defined in this enum are configured to run in order. + pub fn base_schedule() -> Schedule { + use MyScheduleSystems::*; + + let mut schedule = Schedule::new(Self); + + schedule.configure_sets((ExtractCommands, PostCleanup).chain()); + + schedule + } + } + #[derive(Component, Clone, Debug)] struct RenderComponent; @@ -171,7 +216,13 @@ mod test { fn extraction_works() { let mut app = App::new(); - app.add_plugins(ExtractPlugin::default()); + app.add_plugins(ExtractPlugin::::new( + |_, _| {}, + MySchedule::base_schedule, + MySchedule.intern(), + MyScheduleSystems::ExtractCommands.intern(), + MyScheduleSystems::PostCleanup.intern(), + )); app.add_plugins(ExtractComponentPlugin::::default()); app.add_plugins(ExtractComponentPlugin::::default()); app.add_systems(Startup, |mut commands: Commands| { @@ -182,7 +233,7 @@ mod test { // Normally RenderPlugin sets the RenderRecovery schedule as update, but for // testing we just use the Render schedule directly. - render_app.update_schedule = Some(Render.intern()); + render_app.update_schedule = Some(MySchedule.intern()); render_app.world_mut().add_observer( |event: On, mut commands: Commands| { diff --git a/crates/bevy_render/src/extract_resource.rs b/crates/bevy_render/src/extract_resource.rs index ca7556587c494..46079fcff3b8f 100644 --- a/crates/bevy_render/src/extract_resource.rs +++ b/crates/bevy_render/src/extract_resource.rs @@ -30,20 +30,27 @@ pub trait ExtractResource: Resource { /// The marker type `F` is only used as a way to bypass the orphan rules. To /// implement the trait for a foreign type you can use a local type as the /// marker, e.g. the type of the plugin that calls [`ExtractResourcePlugin`]. -pub struct ExtractResourcePlugin, F = ()>(PhantomData<(R, F)>); +pub struct ExtractResourcePlugin, F = (), L: AppLabel = RenderApp>( + PhantomData<(L, R, F)>, +); -impl, F> Default for ExtractResourcePlugin { +// pub type ExtractResourcePlugin = ExtractResourcePlugin; + +impl, F> Default for ExtractResourcePlugin { fn default() -> Self { Self(PhantomData) } } -impl, F: 'static + Send + Sync> Plugin - for ExtractResourcePlugin +impl< + L: AppLabel + Default, + R: ExtractResource, + F: 'static + Send + Sync, + > Plugin for ExtractResourcePlugin { fn build(&self, app: &mut App) { - if let Some(render_app) = app.get_sub_app_mut(RenderApp) { - render_app.add_systems(ExtractSchedule, extract_resource::); + if let Some(render_app) = app.get_sub_app_mut(L::default()) { + render_app.add_systems(ExtractSchedule, extract_resource::); } else { once!(bevy_log::error!( "Render app did not exist when trying to add `extract_resource` for <{}>.", @@ -54,7 +61,7 @@ impl, F: 'static + Send + } /// This system extracts the resource of the corresponding [`Resource`] type -pub fn extract_resource, F>( +pub fn extract_resource, F>( mut commands: Commands, main_resource: Extract>>, target_resource: Option>, diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 63e2da2bb5a89..b6a6de1c9cdee 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -76,7 +76,6 @@ pub mod prelude { view::Msaa, ExtractSchedule, }; } - pub use extract_param::Extract; pub use extract_plugin::{ExtractSchedule, MainWorld}; @@ -358,9 +357,13 @@ impl Plugin for RenderPlugin { if insert_future_resources(&self.render_creation, app.world_mut()) { // We only create the render world and set up extraction if we // have a rendering backend available. - app.add_plugins(ExtractPlugin { - pre_extract: error_handler::update_state, - }); + app.add_plugins(ExtractPlugin::::new( + error_handler::update_state, + Render::base_schedule, + Render.intern(), + RenderSystems::ExtractCommands.intern(), + RenderSystems::PostCleanup.intern(), + )); }; app.add_plugins(( diff --git a/crates/bevy_render/src/pipelined_rendering.rs b/crates/bevy_render/src/pipelined_rendering.rs index 6f0b2b1fa6b83..4440503bf7718 100644 --- a/crates/bevy_render/src/pipelined_rendering.rs +++ b/crates/bevy_render/src/pipelined_rendering.rs @@ -1,6 +1,7 @@ use async_channel::{Receiver, Sender}; -use bevy_app::{App, AppExit, AppLabel, Plugin, SubApp}; +use bevy_app::{App, AppExit, Plugin, SubApp}; +use bevy_derive::AppLabel; use bevy_ecs::{ resource::Resource, schedule::MainThreadExecutor, diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs index 339c3fc8632a7..d50899425300c 100644 --- a/crates/bevy_render/src/sync_component.rs +++ b/crates/bevy_render/src/sync_component.rs @@ -7,7 +7,7 @@ use bevy_ecs::{ }; use crate::{ - sync_world::{EntityRecord, PendingSyncEntity, SyncToRenderWorld}, + sync_world::{EntityRecord, PendingSyncEntity, SyncToSubWorld}, RenderApp, }; @@ -21,14 +21,16 @@ use crate::{ /// /// # Implementation details /// -/// It adds [`SyncToRenderWorld`] as a required component to make the [`SyncWorldPlugin`] aware of the component, and +/// It adds [`SyncToSubWorld`] as a required component to make the [`SyncWorldPlugin`] aware of the component, and /// handles cleanup of the component in the render world when it is removed from an entity. /// /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin /// [`SyncWorldPlugin`]: crate::sync_world::SyncWorldPlugin -pub struct SyncComponentPlugin(PhantomData<(C, F)>); +pub struct SyncComponentPlugin(PhantomData<(L, C, F)>); -impl, F> Default for SyncComponentPlugin { +// pub type SyncComponentPlugin = SyncComponentPlugin; + +impl, F> Default for SyncComponentPlugin { fn default() -> Self { Self(PhantomData) } @@ -40,6 +42,8 @@ impl, F> Default for SyncComponentPlugin { /// The marker type `F` is only used as a way to bypass the orphan rules. To /// implement the trait for a foreign type you can use a local type as the /// marker, e.g. the type of the plugin that calls [`SyncComponentPlugin`]. +/// +/// [`ExtractComponent`]: crate::extract_component::ExtractComponent pub trait SyncComponent: Component { /// Describes what components should be removed from the render world if the /// implementing component is removed. @@ -48,16 +52,19 @@ pub trait SyncComponent: Component { // type Target: Bundle = Self; } -impl, F: Send + Sync + 'static> Plugin - for SyncComponentPlugin +impl< + L: AppLabel + Default + Clone + Copy + Eq, + C: SyncComponent, + F: Send + Sync + 'static, + > Plugin for SyncComponentPlugin { fn build(&self, app: &mut App) { - app.register_required_components::(); + app.register_required_components::>(); app.world_mut() .register_component_hooks::() .on_remove(|mut world, context| { - let mut pending = world.resource_mut::>(); + let mut pending = world.resource_mut::>(); pending.push(EntityRecord::ComponentRemoved( context.entity, |mut entity| { diff --git a/crates/bevy_render/src/sync_world.rs b/crates/bevy_render/src/sync_world.rs index 66c2fa21884aa..dcb18fd3a2998 100644 --- a/crates/bevy_render/src/sync_world.rs +++ b/crates/bevy_render/src/sync_world.rs @@ -17,9 +17,9 @@ use bevy_ecs::{ }; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; -/// A plugin that synchronizes entities with [`SyncToRenderWorld`] between the main world and the render world. +/// A plugin that synchronizes entities with [`SyncToSubWorld`] between the main world and the render world. /// -/// All entities with the [`SyncToRenderWorld`] component are kept in sync. It +/// All entities with the [`SyncToSubWorld`] component are kept in sync. It /// is automatically added as a required component by [`ExtractComponentPlugin`] /// and [`SyncComponentPlugin`], so it doesn't need to be added manually when /// spawning or as a required component when either of these plugins are used. @@ -33,13 +33,13 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// [`SyncWorldPlugin`] is the first thing that runs every frame and it maintains an entity-to-entity mapping /// between the main world and the render world. /// It does so by spawning and despawning entities in the render world, to match spawned and despawned entities in the main world. -/// The link between synced entities is maintained by the [`RenderEntity`] and [`MainEntity`] components. +/// The link between synced entities is maintained by the [`SubEntity`] and [`MainEntity`] components. /// -/// The [`RenderEntity`] contains the corresponding render world entity of a main world entity, while [`MainEntity`] contains +/// The [`SubEntity`] contains the corresponding render world entity of a main world entity, while [`MainEntity`] contains /// the corresponding main world entity of a render world entity. /// For convenience, [`QueryData`](bevy_ecs::query::QueryData) implementations are provided for both components: /// adding [`MainEntity`] to a query (without a `&`) will return the corresponding main world [`Entity`], -/// and adding [`RenderEntity`] will return the corresponding render world [`Entity`]. +/// and adding [`SubEntity`] will return the corresponding render world [`Entity`]. /// If you have access to the component itself, the underlying entities can be accessed by calling `.id()`. /// /// Synchronization is necessary preparation for extraction ([`ExtractSchedule`](crate::ExtractSchedule)), which copies over component data from the main @@ -59,8 +59,8 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// |---------------------------Main World------------------------------| /// | Entity | Component | /// |-------------------------------------------------------------------| -/// | ID: 1v1 | PointLight | RenderEntity(ID: 3V1) | SyncToRenderWorld | -/// | ID: 18v1 | PointLight | RenderEntity(ID: 5V1) | SyncToRenderWorld | +/// | ID: 1v1 | PointLight | SubEntity(ID: 3V1) | SyncToSubWorld | +/// | ID: 18v1 | PointLight | SubEntity(ID: 5V1) | SyncToSubWorld | /// |-------------------------------------------------------------------| /// /// |----------Render World-----------| @@ -73,8 +73,8 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// ``` /// /// Note that this effectively establishes a link between the main world entity and the render world entity. -/// Not every entity needs to be synchronized, however; only entities with the [`SyncToRenderWorld`] component are synced. -/// Adding [`SyncToRenderWorld`] to a main world component will establish such a link. +/// Not every entity needs to be synchronized, however; only entities with the [`SyncToSubWorld`] component are synced. +/// Adding [`SyncToSubWorld`] to a main world component will establish such a link. /// Once a synchronized main entity is despawned, its corresponding render entity will be automatically /// despawned in the next `sync`. /// @@ -90,23 +90,22 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin /// [`SyncComponentPlugin`]: crate::sync_component::SyncComponentPlugin #[derive(Default)] -pub struct SyncWorldPlugin; +pub struct SyncWorldPlugin(PhantomData); -impl Plugin for SyncWorldPlugin { +impl Plugin for SyncWorldPlugin { fn build(&self, app: &mut bevy_app::App) { - app.init_resource::>(); + app.init_resource::>(); app.add_observer( - |add: On, - mut pending: ResMut>| { - pending.push(EntityRecord::Added(add.entity)); + |add: On>, mut pending: ResMut>| { + pending.push(EntityRecord::::Added(add.entity)); }, ); app.add_observer( - |remove: On, - mut pending: ResMut>, - query: Query<&RenderEntity>| { + |remove: On>, + mut pending: ResMut>, + query: Query<&SubEntity>| { if let Ok(e) = query.get(remove.entity) { - pending.push(EntityRecord::Removed(*e)); + pending.push(EntityRecord::::Removed(*e)); }; }, ); From fabe19de6e8abc1b57cb513fdd0e067365940fe6 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Fri, 29 May 2026 17:16:22 +0800 Subject: [PATCH 06/15] change hook to observer --- crates/bevy_render/src/sync_component.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs index d50899425300c..6a6781ec6b0d1 100644 --- a/crates/bevy_render/src/sync_component.rs +++ b/crates/bevy_render/src/sync_component.rs @@ -4,6 +4,9 @@ use bevy_app::{App, AppLabel, Plugin}; use bevy_ecs::{ bundle::{Bundle, NoBundleEffect}, component::Component, + lifecycle::Remove, + observer::On, + system::ResMut, }; use crate::{ @@ -61,16 +64,15 @@ impl< fn build(&self, app: &mut App) { app.register_required_components::>(); - app.world_mut() - .register_component_hooks::() - .on_remove(|mut world, context| { - let mut pending = world.resource_mut::>(); - pending.push(EntityRecord::ComponentRemoved( - context.entity, + app.add_observer( + |remove: On, mut pending: ResMut>| { + pending.push(EntityRecord::::ComponentRemoved( + remove.entity, |mut entity| { entity.remove::(); }, )); - }); + }, + ); } } From 899ee25caa44b85a1c650abe1468ef3f157ef78c Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Fri, 29 May 2026 17:01:46 +0800 Subject: [PATCH 07/15] Dual extraction --- crates/bevy_render/src/extract_plugin.rs | 224 +++++++++++++++++++++++ 1 file changed, 224 insertions(+) diff --git a/crates/bevy_render/src/extract_plugin.rs b/crates/bevy_render/src/extract_plugin.rs index aa2b332968304..8e25fb449fe44 100644 --- a/crates/bevy_render/src/extract_plugin.rs +++ b/crates/bevy_render/src/extract_plugin.rs @@ -303,4 +303,228 @@ mod test { .unwrap(); } } + + #[derive(AppLabel, Debug, Hash, PartialEq, Eq, Clone, Default, Copy)] + pub struct ExtractAppA; + + #[derive(AppLabel, Debug, Hash, PartialEq, Eq, Clone, Default, Copy)] + pub struct ExtractAppB; + + #[derive(Component, Clone, Debug)] + struct RenderComponentSeparateA; + + #[derive(Component, Clone, Debug)] + struct RenderComponentSeparateB; + + #[derive(Component, Clone, Debug)] + struct RenderComponentSeparateBoth; + + impl SyncComponent for RenderComponentSeparateA { + type Target = RenderComponentSeparateA; + } + + impl ExtractComponent for RenderComponentSeparateA { + type QueryData = &'static Self; + type QueryFilter = (); + type Out = Self; + + fn extract_component( + _item: bevy_ecs::query::QueryItem<'_, '_, Self::QueryData>, + ) -> Option { + Some(RenderComponentSeparateA) + } + } + + impl SyncComponent for RenderComponentSeparateB { + type Target = RenderComponentSeparateB; + } + + impl ExtractComponent for RenderComponentSeparateB { + type QueryData = &'static Self; + type QueryFilter = (); + type Out = Self; + + fn extract_component( + _item: bevy_ecs::query::QueryItem<'_, '_, Self::QueryData>, + ) -> Option { + Some(RenderComponentSeparateB) + } + } + + impl SyncComponent for RenderComponentSeparateBoth { + type Target = RenderComponentSeparateBoth; + } + + impl ExtractComponent for RenderComponentSeparateBoth { + type QueryData = &'static Self; + type QueryFilter = (); + type Out = Self; + + fn extract_component( + _item: bevy_ecs::query::QueryItem<'_, '_, Self::QueryData>, + ) -> Option { + Some(RenderComponentSeparateBoth) + } + } + + impl SyncComponent for RenderComponentSeparateBoth { + type Target = RenderComponentSeparateBoth; + } + + impl ExtractComponent for RenderComponentSeparateBoth { + type QueryData = &'static Self; + type QueryFilter = (); + type Out = Self; + + fn extract_component( + _item: bevy_ecs::query::QueryItem<'_, '_, Self::QueryData>, + ) -> Option { + Some(RenderComponentSeparateBoth) + } + } + + #[test] + fn dual_extraction_works() { + let mut app = App::new(); + + app.add_plugins(ExtractPlugin::::new( + |_, _| {}, + MySchedule::base_schedule, + MySchedule.intern(), + MyScheduleSystems::ExtractCommands.intern(), + MyScheduleSystems::PostCleanup.intern(), + )); + app.add_plugins(ExtractPlugin::::new( + |_, _| {}, + MySchedule::base_schedule, + MySchedule.intern(), + MyScheduleSystems::ExtractCommands.intern(), + MyScheduleSystems::PostCleanup.intern(), + )); + + app.add_plugins(ExtractComponentPlugin::< + ExtractAppA, + RenderComponentSeparateA, + >::default()); + app.add_plugins(ExtractComponentPlugin::< + ExtractAppB, + RenderComponentSeparateB, + >::default()); + app.add_plugins(ExtractComponentPlugin::< + ExtractAppA, + RenderComponentSeparateBoth, + >::default()); + app.add_plugins(ExtractComponentPlugin::< + ExtractAppB, + RenderComponentSeparateBoth, + >::default()); + + app.add_systems(Startup, |mut commands: Commands| { + commands.spawn(( + RenderComponent, + RenderComponentSeparateA, + RenderComponentSeparateB, + RenderComponentSeparateBoth, + )); + }); + + let sub_app_a = app.get_sub_app_mut(ExtractAppA).unwrap(); + sub_app_a.update_schedule = Some(MySchedule.intern()); + + let sub_app_b = app.get_sub_app_mut(ExtractAppB).unwrap(); + sub_app_b.update_schedule = Some(MySchedule.intern()); + + app.update(); + + // Check that all components have been extracted + { + let sub_app_a = app.get_sub_app_mut(ExtractAppA).unwrap(); + sub_app_a + .world_mut() + .run_system_cached( + |entity: Single<( + &MainEntity, + Option<&RenderComponentSeparateA>, + Option<&RenderComponentSeparateB>, + Option<&RenderComponentSeparateBoth>, + )>| { + assert!(entity.1.is_some()); + assert!(entity.2.is_none()); + assert!(entity.3.is_some()); + }, + ) + .unwrap(); + } + + { + let sub_app_b = app.get_sub_app_mut(ExtractAppB).unwrap(); + sub_app_b + .world_mut() + .run_system_cached( + |entity: Single<( + &MainEntity, + Option<&RenderComponentSeparateA>, + Option<&RenderComponentSeparateB>, + Option<&RenderComponentSeparateBoth>, + )>| { + assert!(entity.1.is_none()); + assert!(entity.2.is_some()); + assert!(entity.3.is_some()); + }, + ) + .unwrap(); + } + + // Remove RenderComponentSeparateA + app.world_mut() + .run_system_cached( + |mut commands: Commands, query: Query>| { + for entity in query { + commands.entity(entity).remove::(); + } + }, + ) + .unwrap(); + + app.update(); + + // Check that the extracted components have been removed + { + let sub_app_a = app.get_sub_app_mut(ExtractAppA).unwrap(); + sub_app_a + .world_mut() + .run_system_cached( + |entity: Single<( + &MainEntity, + Option<&RenderComponentSeparateA>, + Option<&RenderComponentSeparateB>, + Option<&RenderComponentSeparateBoth>, + )>| { + assert!(entity.1.is_none()); + assert!(entity.2.is_none()); + assert!(entity.3.is_some()); + }, + ) + .unwrap(); + } + + { + let sub_app_b = app.get_sub_app_mut(ExtractAppB).unwrap(); + sub_app_b + .world_mut() + .run_system_cached( + |entity: Single<( + &MainEntity, + Option<&RenderComponentSeparateA>, + Option<&RenderComponentSeparateB>, + Option<&RenderComponentSeparateBoth>, + )>| { + assert!(entity.1.is_none()); + assert!(entity.2.is_some()); + assert!(entity.3.is_some()); + }, + ) + .unwrap(); + } + } } From fdca1f24e9bdee1d0e8370ad64c1463ffc3967fb Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Fri, 29 May 2026 15:50:52 +0800 Subject: [PATCH 08/15] Support #[extract_app(AppA,AppB)] in derive(ExtractComponent) --- .../macros/src/extract_component.rs | 73 ++++++++++++++----- crates/bevy_render/src/extract_plugin.rs | 15 ++++ 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/crates/bevy_render/macros/src/extract_component.rs b/crates/bevy_render/macros/src/extract_component.rs index 9577f8c954d5b..ec802fea534a0 100644 --- a/crates/bevy_render/macros/src/extract_component.rs +++ b/crates/bevy_render/macros/src/extract_component.rs @@ -1,7 +1,10 @@ use bevy_macro_utils::fq_std::{FQClone, FQOption}; use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, parse_quote, DeriveInput, Path}; +use syn::{ + parse_macro_input, parse_quote, punctuated::Punctuated, DeriveInput, MacroDelimiter, Meta, + MetaList, Path, +}; pub fn derive_extract_component(input: TokenStream) -> TokenStream { let mut ast = parse_macro_input!(input as DeriveInput); @@ -20,15 +23,35 @@ pub fn derive_extract_component(input: TokenStream) -> TokenStream { let struct_name = &ast.ident; let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl(); - let app_label = match ast.attrs.iter().find(|a| a.path().is_ident("extract_app")) { - Some(attr) => match attr.parse_args::() { - Ok(label) => label, - Err(e) => return e.to_compile_error().into(), - }, + let app_labels: Vec = match ast.attrs.iter().find(|a| a.path().is_ident("extract_app")) { + Some(attr) => { + if let Meta::List(meta_list) = &attr.meta { + if let MacroDelimiter::Paren(_) = meta_list.delimiter { + match parse_to_paths(meta_list) { + Ok(labels) => labels, + Err(e) => return e.into(), + } + } else { + return syn::Error::new_spanned( + &ast.ident, + "ExtractComponent requires #[extract_app(MyAppLabelA,MyAppLabelB)] to specify the target sub-app(s) in (parentheses)", + ) + .to_compile_error() + .into(); + } + } else { + return syn::Error::new_spanned( + &ast.ident, + "ExtractComponent requires #[extract_app(MyAppLabelA,MyAppLabelB)] to specify the target sub-app(s) as a list", + ) + .to_compile_error() + .into(); + } + } None => { return syn::Error::new_spanned( &ast.ident, - "ExtractComponent requires #[extract_app(MyAppLabel)] to specify the target sub-app", + "ExtractComponent requires #[extract_app(MyAppLabelA,MyAppLabelB)] to specify the target sub-app(s)", ) .to_compile_error() .into(); @@ -73,20 +96,32 @@ pub fn derive_extract_component(input: TokenStream) -> TokenStream { } }; - TokenStream::from(quote! { - impl #impl_generics #bevy_render_path::sync_component::SyncComponent<#app_label> for #struct_name #type_generics #where_clause { - type Target = #sync_target; - } + app_labels.iter().map(|app_label| + TokenStream::from(quote! { + impl #impl_generics #bevy_render_path::sync_component::SyncComponent<#app_label> for #struct_name #type_generics #where_clause { + type Target = #sync_target; + } - impl #impl_generics #bevy_render_path::extract_component::ExtractComponent<#app_label> for #struct_name #type_generics #where_clause { - type QueryData = &'static Self; + impl #impl_generics #bevy_render_path::extract_component::ExtractComponent<#app_label> for #struct_name #type_generics #where_clause { + type QueryData = &'static Self; - type QueryFilter = #filter; - type Out = Self; + type QueryFilter = #filter; + type Out = Self; - fn extract_component(item: #bevy_ecs_path::query::QueryItem<'_, '_, Self::QueryData>) -> #FQOption { - #FQOption::Some(item.clone()) + fn extract_component(item: #bevy_ecs_path::query::QueryItem<'_, '_, Self::QueryData>) -> #FQOption { + #FQOption::Some(item.clone()) + } } - } - }) + }) + ).collect() +} + +fn parse_to_paths(meta_list: &MetaList) -> Result, proc_macro2::TokenStream> { + meta_list + .parse_args_with(|input: syn::parse::ParseStream| { + let result = Punctuated::::parse_terminated(input); + + result.map(|paths| paths.iter().cloned().collect::>()) + }) + .map_err(|e| e.to_compile_error()) } diff --git a/crates/bevy_render/src/extract_plugin.rs b/crates/bevy_render/src/extract_plugin.rs index 8e25fb449fe44..fff658eec51f5 100644 --- a/crates/bevy_render/src/extract_plugin.rs +++ b/crates/bevy_render/src/extract_plugin.rs @@ -319,6 +319,10 @@ mod test { #[derive(Component, Clone, Debug)] struct RenderComponentSeparateBoth; + #[derive(Component, Clone, Debug, ExtractComponent)] + #[extract_app(ExtractAppA, ExtractAppB)] + struct RenderComponentDual; + impl SyncComponent for RenderComponentSeparateA { type Target = RenderComponentSeparateA; } @@ -418,6 +422,8 @@ mod test { ExtractAppB, RenderComponentSeparateBoth, >::default()); + app.add_plugins(ExtractComponentPlugin::::default()); + app.add_plugins(ExtractComponentPlugin::::default()); app.add_systems(Startup, |mut commands: Commands| { commands.spawn(( @@ -425,6 +431,7 @@ mod test { RenderComponentSeparateA, RenderComponentSeparateB, RenderComponentSeparateBoth, + RenderComponentDual, )); }); @@ -447,10 +454,12 @@ mod test { Option<&RenderComponentSeparateA>, Option<&RenderComponentSeparateB>, Option<&RenderComponentSeparateBoth>, + Option<&RenderComponentDual>, )>| { assert!(entity.1.is_some()); assert!(entity.2.is_none()); assert!(entity.3.is_some()); + assert!(entity.4.is_some()); }, ) .unwrap(); @@ -466,10 +475,12 @@ mod test { Option<&RenderComponentSeparateA>, Option<&RenderComponentSeparateB>, Option<&RenderComponentSeparateBoth>, + Option<&RenderComponentDual>, )>| { assert!(entity.1.is_none()); assert!(entity.2.is_some()); assert!(entity.3.is_some()); + assert!(entity.4.is_some()); }, ) .unwrap(); @@ -499,10 +510,12 @@ mod test { Option<&RenderComponentSeparateA>, Option<&RenderComponentSeparateB>, Option<&RenderComponentSeparateBoth>, + Option<&RenderComponentDual>, )>| { assert!(entity.1.is_none()); assert!(entity.2.is_none()); assert!(entity.3.is_some()); + assert!(entity.4.is_some()); }, ) .unwrap(); @@ -518,10 +531,12 @@ mod test { Option<&RenderComponentSeparateA>, Option<&RenderComponentSeparateB>, Option<&RenderComponentSeparateBoth>, + Option<&RenderComponentDual>, )>| { assert!(entity.1.is_none()); assert!(entity.2.is_some()); assert!(entity.3.is_some()); + assert!(entity.4.is_some()); }, ) .unwrap(); From 2a68d73ba131aa57abf95b7f7f67b9bb8f8f4123 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Tue, 7 Jul 2026 14:19:36 +0800 Subject: [PATCH 09/15] Merge migration guides --- .../migration-guides/extract-extract-a.md | 10 ---------- .../{extract-extract-b.md => extract-extract.md} | 13 ++++++++++--- 2 files changed, 10 insertions(+), 13 deletions(-) delete mode 100644 _release-content/migration-guides/extract-extract-a.md rename _release-content/migration-guides/{extract-extract-b.md => extract-extract.md} (63%) diff --git a/_release-content/migration-guides/extract-extract-a.md b/_release-content/migration-guides/extract-extract-a.md deleted file mode 100644 index c8a818d2f4a7c..0000000000000 --- a/_release-content/migration-guides/extract-extract-a.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: Extract Extract -pull_requests: [] ---- - -Extraction used to be specific of Main World to Render World, but will now be generic - -- Use `TemporaryRenderEntity::default()` instead of `TemporaryRenderEntity` - -NOTE: more to come diff --git a/_release-content/migration-guides/extract-extract-b.md b/_release-content/migration-guides/extract-extract.md similarity index 63% rename from _release-content/migration-guides/extract-extract-b.md rename to _release-content/migration-guides/extract-extract.md index 3542421912a61..9dc7ff5a003dc 100644 --- a/_release-content/migration-guides/extract-extract-b.md +++ b/_release-content/migration-guides/extract-extract.md @@ -1,10 +1,11 @@ --- title: Extract Extract -pull_requests: [24420] +pull_requests: [24419, 24420, 24423] --- Extraction used to be specific of Main World to Render World, but will now be generic +- Use `TemporaryRenderEntity::default()` instead of `TemporaryRenderEntity` - When using extraction related traits e.g. `SyncComponent`, `ExtractComponent` and `ExtractResource`, you must specify the `AppLabel` for the target world. @@ -14,7 +15,6 @@ Before: impl SyncComponent for TemporalAntiAliasing { ... } #[derive(Component, ExtractComponent)] -#[extract_app(RenderApp)] pub struct Foo { ... } ``` @@ -28,4 +28,11 @@ impl SyncComponent for TemporalAntiAliasing { ... } pub struct Foo { ... } ``` -NOTE: more to come + +You can also extract a component from the main subapp to the render subapp, and to the audio subapp + +```rust,ignore +#[derive(Component, Clone, Debug, ExtractComponent)] +#[extract_app(RenderApp, AudioApp)] +struct SomeComponent; +``` From 7ccab50f1233ee77dce36c1986f63a86252018f9 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Sun, 24 May 2026 22:57:48 +0800 Subject: [PATCH 10/15] bevy_extract skeleton Placeholder More skeleton Rm extract placeholders squash skeleton squash skeleton squash skeleton --- Cargo.toml | 4 + .../migration-guides/extract-extract-e.md | 12 ++ benches/Cargo.toml | 1 + crates/bevy_anti_alias/Cargo.toml | 1 + crates/bevy_core_pipeline/Cargo.toml | 1 + crates/bevy_dev_tools/Cargo.toml | 1 + crates/bevy_extract/Cargo.toml | 39 ++++ crates/bevy_extract/LICENSE-APACHE | 176 ++++++++++++++++++ crates/bevy_extract/LICENSE-MIT | 19 ++ crates/bevy_extract/README.md | 9 + crates/bevy_extract/macros/Cargo.toml | 26 +++ crates/bevy_extract/macros/LICENSE-APACHE | 176 ++++++++++++++++++ crates/bevy_extract/macros/LICENSE-MIT | 19 ++ crates/bevy_extract/macros/src/lib.rs | 12 ++ crates/bevy_extract/src/lib.rs | 42 +++++ crates/bevy_gizmos_render/Cargo.toml | 1 + crates/bevy_internal/Cargo.toml | 4 + crates/bevy_pbr/Cargo.toml | 1 + crates/bevy_post_process/Cargo.toml | 1 + crates/bevy_render/Cargo.toml | 2 + crates/bevy_render/macros/Cargo.toml | 1 + crates/bevy_sprite_render/Cargo.toml | 1 + crates/bevy_ui_render/Cargo.toml | 1 + docs/cargo_features.md | 1 + 24 files changed, 551 insertions(+) create mode 100644 _release-content/migration-guides/extract-extract-e.md create mode 100644 crates/bevy_extract/Cargo.toml create mode 100644 crates/bevy_extract/LICENSE-APACHE create mode 100644 crates/bevy_extract/LICENSE-MIT create mode 100644 crates/bevy_extract/README.md create mode 100644 crates/bevy_extract/macros/Cargo.toml create mode 100644 crates/bevy_extract/macros/LICENSE-APACHE create mode 100644 crates/bevy_extract/macros/LICENSE-MIT create mode 100644 crates/bevy_extract/macros/src/lib.rs create mode 100644 crates/bevy_extract/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 4f0bd79fb1b43..be20263a32aff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -305,6 +305,9 @@ bevy_post_process = ["bevy_internal/bevy_post_process"] # Provides various anti-aliasing solutions bevy_anti_alias = ["bevy_internal/bevy_anti_alias"] +# Adds extract +bevy_extract = ["bevy_internal/bevy_extract"] + # Adds gamepad support bevy_gilrs = ["gamepad", "bevy_internal/bevy_gilrs"] @@ -759,6 +762,7 @@ bytemuck = "1" bevy_animation = { path = "crates/bevy_animation", version = "0.20.0-dev", default-features = false } bevy_asset = { path = "crates/bevy_asset", version = "0.20.0-dev", default-features = false } bevy_ecs = { path = "crates/bevy_ecs", version = "0.20.0-dev", default-features = false } +bevy_extract = { path = "crates/bevy_extract", version = "0.20.0-dev", default-features = false } bevy_gizmos = { path = "crates/bevy_gizmos", version = "0.20.0-dev", default-features = false } bevy_image = { path = "crates/bevy_image", version = "0.20.0-dev", default-features = false } bevy_reflect = { path = "crates/bevy_reflect", version = "0.20.0-dev", default-features = false } diff --git a/_release-content/migration-guides/extract-extract-e.md b/_release-content/migration-guides/extract-extract-e.md new file mode 100644 index 0000000000000..5c6672340c02a --- /dev/null +++ b/_release-content/migration-guides/extract-extract-e.md @@ -0,0 +1,12 @@ +--- +title: Extract Extract +pull_requests: [] +--- + +Extraction used to be specific of Main World to Render World, but will now be generic + +All above has moved to new crate `bevy_extract`. + +Most extraction parts are re-exported by `bevy_render` , but some migrations are needed + +NOTE: more to come diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 13b9d229fabac..7618e25a5280c 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -17,6 +17,7 @@ seq-macro = "0.3.6" # Bevy crates bevy_app = { path = "../crates/bevy_app" } bevy_ecs = { path = "../crates/bevy_ecs", features = ["multi_threaded"] } +bevy_extract = { path = "../crates/bevy_extract" } bevy_math = { path = "../crates/bevy_math" } bevy_picking = { path = "../crates/bevy_picking", features = ["mesh_picking"] } bevy_reflect = { path = "../crates/bevy_reflect", features = ["functions"] } diff --git a/crates/bevy_anti_alias/Cargo.toml b/crates/bevy_anti_alias/Cargo.toml index 27cca95bcc95d..edd71c731af33 100644 --- a/crates/bevy_anti_alias/Cargo.toml +++ b/crates/bevy_anti_alias/Cargo.toml @@ -29,6 +29,7 @@ bevy_image = { path = "../bevy_image", version = "0.20.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.20.0-dev" } bevy_shader = { path = "../bevy_shader", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.20.0-dev" } bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.20.0-dev" } diff --git a/crates/bevy_core_pipeline/Cargo.toml b/crates/bevy_core_pipeline/Cargo.toml index 0f9e1f64a0153..48a2c52536d65 100644 --- a/crates/bevy_core_pipeline/Cargo.toml +++ b/crates/bevy_core_pipeline/Cargo.toml @@ -22,6 +22,7 @@ bevy_color = { path = "../bevy_color", version = "0.20.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.20.0-dev" } bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_image = { path = "../bevy_image", version = "0.20.0-dev" } bevy_log = { path = "../bevy_log", version = "0.20.0-dev" } bevy_light = { path = "../bevy_light", version = "0.20.0-dev" } diff --git a/crates/bevy_dev_tools/Cargo.toml b/crates/bevy_dev_tools/Cargo.toml index 4a4f0f0e7294c..5cc980185e6d0 100644 --- a/crates/bevy_dev_tools/Cargo.toml +++ b/crates/bevy_dev_tools/Cargo.toml @@ -30,6 +30,7 @@ bevy_color = { path = "../bevy_color", version = "0.20.0-dev" } bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.20.0-dev" } bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_image = { path = "../bevy_image", version = "0.20.0-dev" } bevy_input = { path = "../bevy_input", version = "0.20.0-dev" } bevy_log = { path = "../bevy_log", version = "0.20.0-dev" } diff --git a/crates/bevy_extract/Cargo.toml b/crates/bevy_extract/Cargo.toml new file mode 100644 index 0000000000000..6a8eafe2fb0c5 --- /dev/null +++ b/crates/bevy_extract/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "bevy_extract" +version = "0.19.0-dev" +edition = "2024" +description = "Provides extract functionality for Bevy Engine" +homepage = "https://bevy.org" +repository = "https://github.com/bevyengine/bevy" +license = "MIT OR Apache-2.0" +keywords = ["bevy"] + +[features] +default = [] +trace = [] + +[dependencies] +# bevy +bevy_app = { path = "../bevy_app", version = "0.19.0-dev" } +bevy_camera = { path = "../bevy_camera", version = "0.19.0-dev" } +bevy_derive = { path = "../bevy_derive", version = "0.19.0-dev" } +bevy_ecs = { path = "../bevy_ecs", version = "0.19.0-dev" } +bevy_extract_macros = { path = "../bevy_extract/macros", version = "0.19.0-dev" } +bevy_log = { path = "../bevy_log", version = "0.19.0-dev" } +bevy_platform = { path = "../bevy_platform", version = "0.19.0-dev" } +bevy_reflect = { path = "../bevy_reflect", version = "0.19.0-dev" } +bevy_time = { path = "../bevy_time", version = "0.19.0-dev" } +bevy_utils = { path = "../bevy_utils", version = "0.19.0-dev" } + +# other +# downcast-rs = { version = "2", default-features = false } + +[dev-dependencies] +# crossbeam-channel = "0.5.0" + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"] +all-features = true diff --git a/crates/bevy_extract/LICENSE-APACHE b/crates/bevy_extract/LICENSE-APACHE new file mode 100644 index 0000000000000..d9a10c0d8e868 --- /dev/null +++ b/crates/bevy_extract/LICENSE-APACHE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/crates/bevy_extract/LICENSE-MIT b/crates/bevy_extract/LICENSE-MIT new file mode 100644 index 0000000000000..9cf106272ac3b --- /dev/null +++ b/crates/bevy_extract/LICENSE-MIT @@ -0,0 +1,19 @@ +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crates/bevy_extract/README.md b/crates/bevy_extract/README.md new file mode 100644 index 0000000000000..53c782c8d241f --- /dev/null +++ b/crates/bevy_extract/README.md @@ -0,0 +1,9 @@ +# Bevy App + +[![License](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/bevyengine/bevy#license) +[![Crates.io](https://img.shields.io/crates/v/bevy.svg)](https://crates.io/crates/bevy_extract) +[![Downloads](https://img.shields.io/crates/d/bevy_extract.svg)](https://crates.io/crates/bevy_extract) +[![Docs](https://docs.rs/bevy_extract/badge.svg)](https://docs.rs/bevy_extract/latest/bevy_extract/) +[![Discord](https://img.shields.io/discord/691052431525675048.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/bevy) + +This crate makes it easy to copy out main world state to a sub app's world. diff --git a/crates/bevy_extract/macros/Cargo.toml b/crates/bevy_extract/macros/Cargo.toml new file mode 100644 index 0000000000000..8fdb02d6bd117 --- /dev/null +++ b/crates/bevy_extract/macros/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "bevy_extract_macros" +version = "0.19.0-dev" +edition = "2024" +description = "Derive implementations for bevy_extract" +homepage = "https://bevy.org" +repository = "https://github.com/bevyengine/bevy" +license = "MIT OR Apache-2.0" +keywords = ["bevy"] + +[lib] +proc-macro = true + +[dependencies] +bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.19.0-dev" } + +syn = { version = "2.0", features = ["full"] } +proc-macro2 = "1.0" +quote = "1.0" + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"] +all-features = true diff --git a/crates/bevy_extract/macros/LICENSE-APACHE b/crates/bevy_extract/macros/LICENSE-APACHE new file mode 100644 index 0000000000000..d9a10c0d8e868 --- /dev/null +++ b/crates/bevy_extract/macros/LICENSE-APACHE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/crates/bevy_extract/macros/LICENSE-MIT b/crates/bevy_extract/macros/LICENSE-MIT new file mode 100644 index 0000000000000..9cf106272ac3b --- /dev/null +++ b/crates/bevy_extract/macros/LICENSE-MIT @@ -0,0 +1,19 @@ +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crates/bevy_extract/macros/src/lib.rs b/crates/bevy_extract/macros/src/lib.rs new file mode 100644 index 0000000000000..c58e6951655a1 --- /dev/null +++ b/crates/bevy_extract/macros/src/lib.rs @@ -0,0 +1,12 @@ +#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")] +#![cfg_attr(docsrs, feature(doc_cfg))] + +mod extract_component; +mod extract_resource; + +use bevy_macro_utils::BevyManifest; +// use proc_macro::TokenStream; + +pub(crate) fn _bevy_extract_path() -> syn::Path { + BevyManifest::shared(|manifest| manifest.get_path("bevy_extract")) +} diff --git a/crates/bevy_extract/src/lib.rs b/crates/bevy_extract/src/lib.rs new file mode 100644 index 0000000000000..c2923e88f6717 --- /dev/null +++ b/crates/bevy_extract/src/lib.rs @@ -0,0 +1,42 @@ +#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")] +#![cfg_attr( + any(docsrs, docsrs_dep), + expect( + internal_features, + reason = "rustdoc_internals is needed for fake_variadic" + ) +)] +#![cfg_attr(any(docsrs, docsrs_dep), feature(doc_cfg, rustdoc_internals))] +#![doc( + html_logo_url = "https://bevy.org/assets/icon.png", + html_favicon_url = "https://bevy.org/assets/icon.png" +)] +// #![expect(unsafe_code, reason = "Unsafe code is used to improve performance.")] + +//! This crate is about everything concerning extract. + +extern crate alloc; + +pub mod extract_component; +pub mod extract_instances; +mod extract_param; +pub mod extract_plugin; +pub mod extract_resource; +pub mod sync_component; +pub mod sync_world; + +// pub use extract_param::Extract; +// pub use extract_plugin::*; +// pub use extract_plugin::{ExtractSchedule, MainWorld}; +// pub use sync_world::*; + +// Required to make proc macros work in bevy itself. +extern crate self as bevy_extract; + +/// The extract prelude. +/// +/// This includes the most common types in this crate, re-exported for your convenience. +pub mod prelude { + // #[doc(hidden)] + // pub use crate::{ExtractPlugin, ExtractSchedule}; +} diff --git a/crates/bevy_gizmos_render/Cargo.toml b/crates/bevy_gizmos_render/Cargo.toml index 12c0e103446b6..b40a88d80a934 100644 --- a/crates/bevy_gizmos_render/Cargo.toml +++ b/crates/bevy_gizmos_render/Cargo.toml @@ -20,6 +20,7 @@ bevy_app = { path = "../bevy_app", version = "0.20.0-dev" } bevy_gizmos = { path = "../bevy_gizmos", version = "0.20.0-dev" } bevy_camera = { path = "../bevy_camera", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_image = { path = "../bevy_image", version = "0.20.0-dev" } bevy_mesh = { path = "../bevy_mesh", version = "0.20.0-dev" } bevy_math = { path = "../bevy_math", version = "0.20.0-dev" } diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 70b9bc34bad59..5a527b03f9981 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -16,6 +16,7 @@ trace = [ "bevy_core_pipeline?/trace", "bevy_anti_alias?/trace", "bevy_ecs/trace", + "bevy_extract/trace", "bevy_log/trace", "bevy_pbr?/trace", "bevy_render?/trace", @@ -231,6 +232,7 @@ morph = ["bevy_mesh?/morph", "bevy_render?/morph"] # Enables bevy_mesh and bevy_animation morph weight support morph_animation = ["morph", "bevy_animation?/bevy_mesh"] +bevy_extract = ["dep:bevy_extract"] bevy_shader = ["dep:bevy_shader"] bevy_image = ["dep:bevy_image", "bevy_color", "bevy_asset"] bevy_sprite = ["dep:bevy_sprite", "bevy_camera"] @@ -253,6 +255,7 @@ bevy_light = ["dep:bevy_light", "bevy_camera"] bevy_render = [ "dep:bevy_render", "bevy_camera", + "bevy_extract", "bevy_shader", "bevy_color/wgpu-types", "bevy_color/encase", @@ -542,6 +545,7 @@ bevy_post_process = { path = "../bevy_post_process", optional = true, version = bevy_ui_widgets = { path = "../bevy_ui_widgets", optional = true, version = "0.20.0-dev" } bevy_anti_alias = { path = "../bevy_anti_alias", optional = true, version = "0.20.0-dev" } bevy_dev_tools = { path = "../bevy_dev_tools", optional = true, version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.20.0-dev" } bevy_gizmos = { path = "../bevy_gizmos", optional = true, version = "0.20.0-dev", default-features = false } bevy_gizmos_render = { path = "../bevy_gizmos_render", optional = true, version = "0.20.0-dev", default-features = false } diff --git a/crates/bevy_pbr/Cargo.toml b/crates/bevy_pbr/Cargo.toml index 88c97062321ab..5f4491dd7bf97 100644 --- a/crates/bevy_pbr/Cargo.toml +++ b/crates/bevy_pbr/Cargo.toml @@ -45,6 +45,7 @@ bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.20.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.20.0-dev" } bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_gltf = { path = "../bevy_gltf", version = "0.20.0-dev", optional = true } bevy_light = { path = "../bevy_light", version = "0.20.0-dev" } bevy_log = { path = "../bevy_log", version = "0.20.0-dev" } diff --git a/crates/bevy_post_process/Cargo.toml b/crates/bevy_post_process/Cargo.toml index 48b76de3acdb2..0ba981e438e09 100644 --- a/crates/bevy_post_process/Cargo.toml +++ b/crates/bevy_post_process/Cargo.toml @@ -21,6 +21,7 @@ bevy_color = { path = "../bevy_color", version = "0.20.0-dev" } bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.20.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_image = { path = "../bevy_image", version = "0.20.0-dev" } bevy_camera = { path = "../bevy_camera", version = "0.20.0-dev" } bevy_reflect = { path = "../bevy_reflect", version = "0.20.0-dev" } diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 177cd762a022d..f84ba14afbcb5 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -67,6 +67,8 @@ bevy_derive = { path = "../bevy_derive", version = "0.20.0-dev" } bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } bevy_encase_derive = { path = "../bevy_encase_derive", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } +bevy_extract_macros = { path = "../bevy_extract/macros", version = "0.20.0-dev" } bevy_math = { path = "../bevy_math", version = "0.20.0-dev" } bevy_material = { path = "../bevy_material", version = "0.20.0-dev" } bevy_reflect = { path = "../bevy_reflect", version = "0.20.0-dev" } diff --git a/crates/bevy_render/macros/Cargo.toml b/crates/bevy_render/macros/Cargo.toml index f4af598044443..724d9759746ca 100644 --- a/crates/bevy_render/macros/Cargo.toml +++ b/crates/bevy_render/macros/Cargo.toml @@ -13,6 +13,7 @@ proc-macro = true [dependencies] bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.20.0-dev" } +bevy_extract_macros = { path = "../../bevy_extract/macros", version = "0.20.0-dev" } syn = { version = "2.0", features = ["full"] } proc-macro2 = "1.0" diff --git a/crates/bevy_sprite_render/Cargo.toml b/crates/bevy_sprite_render/Cargo.toml index 3427bf488e7ed..4a91871086f8f 100644 --- a/crates/bevy_sprite_render/Cargo.toml +++ b/crates/bevy_sprite_render/Cargo.toml @@ -20,6 +20,7 @@ bevy_asset = { path = "../bevy_asset", version = "0.20.0-dev" } bevy_color = { path = "../bevy_color", version = "0.20.0-dev" } bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_image = { path = "../bevy_image", version = "0.20.0-dev" } bevy_camera = { path = "../bevy_camera", version = "0.20.0-dev" } bevy_mesh = { path = "../bevy_mesh", version = "0.20.0-dev" } diff --git a/crates/bevy_ui_render/Cargo.toml b/crates/bevy_ui_render/Cargo.toml index 6486d73f0f109..4b8d0ba5eaf14 100644 --- a/crates/bevy_ui_render/Cargo.toml +++ b/crates/bevy_ui_render/Cargo.toml @@ -17,6 +17,7 @@ bevy_color = { path = "../bevy_color", version = "0.20.0-dev" } bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.20.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.20.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" } +bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" } bevy_image = { path = "../bevy_image", version = "0.20.0-dev" } bevy_input_focus = { path = "../bevy_input_focus", version = "0.20.0-dev" } bevy_math = { path = "../bevy_math", version = "0.20.0-dev" } diff --git a/docs/cargo_features.md b/docs/cargo_features.md index 949c02a34cfc9..904cef2b6e4ef 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -79,6 +79,7 @@ This is the complete `bevy` cargo feature list, without "profiles" or "collectio |bevy_core_pipeline|Provides cameras and other basic render pipeline features| |bevy_debug_stepping|Enable stepping-based debugging of Bevy systems| |bevy_dev_tools|Provides a collection of developer tools| +|bevy_extract|Adds extract| |bevy_feathers|Feathers widget collection.| |bevy_gilrs|Adds gamepad support| |bevy_gizmos|Adds support for gizmos| From 7a6c67aba2f1b828ac6bdb9349f0e4c132d194c0 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Wed, 27 May 2026 23:32:33 +0800 Subject: [PATCH 11/15] Move to bevy_extract --- .../{bevy_render => bevy_extract}/macros/src/extract_component.rs | 0 .../{bevy_render => bevy_extract}/macros/src/extract_resource.rs | 0 crates/{bevy_render => bevy_extract}/src/extract_component.rs | 0 crates/{bevy_render => bevy_extract}/src/extract_instances.rs | 0 crates/{bevy_render => bevy_extract}/src/extract_param.rs | 0 crates/{bevy_render => bevy_extract}/src/extract_plugin.rs | 0 crates/{bevy_render => bevy_extract}/src/extract_resource.rs | 0 crates/{bevy_render => bevy_extract}/src/sync_component.rs | 0 crates/{bevy_render => bevy_extract}/src/sync_world.rs | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename crates/{bevy_render => bevy_extract}/macros/src/extract_component.rs (100%) rename crates/{bevy_render => bevy_extract}/macros/src/extract_resource.rs (100%) rename crates/{bevy_render => bevy_extract}/src/extract_component.rs (100%) rename crates/{bevy_render => bevy_extract}/src/extract_instances.rs (100%) rename crates/{bevy_render => bevy_extract}/src/extract_param.rs (100%) rename crates/{bevy_render => bevy_extract}/src/extract_plugin.rs (100%) rename crates/{bevy_render => bevy_extract}/src/extract_resource.rs (100%) rename crates/{bevy_render => bevy_extract}/src/sync_component.rs (100%) rename crates/{bevy_render => bevy_extract}/src/sync_world.rs (100%) diff --git a/crates/bevy_render/macros/src/extract_component.rs b/crates/bevy_extract/macros/src/extract_component.rs similarity index 100% rename from crates/bevy_render/macros/src/extract_component.rs rename to crates/bevy_extract/macros/src/extract_component.rs diff --git a/crates/bevy_render/macros/src/extract_resource.rs b/crates/bevy_extract/macros/src/extract_resource.rs similarity index 100% rename from crates/bevy_render/macros/src/extract_resource.rs rename to crates/bevy_extract/macros/src/extract_resource.rs diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_extract/src/extract_component.rs similarity index 100% rename from crates/bevy_render/src/extract_component.rs rename to crates/bevy_extract/src/extract_component.rs diff --git a/crates/bevy_render/src/extract_instances.rs b/crates/bevy_extract/src/extract_instances.rs similarity index 100% rename from crates/bevy_render/src/extract_instances.rs rename to crates/bevy_extract/src/extract_instances.rs diff --git a/crates/bevy_render/src/extract_param.rs b/crates/bevy_extract/src/extract_param.rs similarity index 100% rename from crates/bevy_render/src/extract_param.rs rename to crates/bevy_extract/src/extract_param.rs diff --git a/crates/bevy_render/src/extract_plugin.rs b/crates/bevy_extract/src/extract_plugin.rs similarity index 100% rename from crates/bevy_render/src/extract_plugin.rs rename to crates/bevy_extract/src/extract_plugin.rs diff --git a/crates/bevy_render/src/extract_resource.rs b/crates/bevy_extract/src/extract_resource.rs similarity index 100% rename from crates/bevy_render/src/extract_resource.rs rename to crates/bevy_extract/src/extract_resource.rs diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_extract/src/sync_component.rs similarity index 100% rename from crates/bevy_render/src/sync_component.rs rename to crates/bevy_extract/src/sync_component.rs diff --git a/crates/bevy_render/src/sync_world.rs b/crates/bevy_extract/src/sync_world.rs similarity index 100% rename from crates/bevy_render/src/sync_world.rs rename to crates/bevy_extract/src/sync_world.rs From a56821a1546263320fedf9f4e418d353df37466a Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Wed, 27 May 2026 23:32:46 +0800 Subject: [PATCH 12/15] Move macro lib --- crates/bevy_extract/macros/src/lib.rs | 42 +++++++++++++++++++++++++++ crates/bevy_render/macros/src/lib.rs | 42 --------------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/crates/bevy_extract/macros/src/lib.rs b/crates/bevy_extract/macros/src/lib.rs index c58e6951655a1..a97d8d338bed6 100644 --- a/crates/bevy_extract/macros/src/lib.rs +++ b/crates/bevy_extract/macros/src/lib.rs @@ -10,3 +10,45 @@ use bevy_macro_utils::BevyManifest; pub(crate) fn _bevy_extract_path() -> syn::Path { BevyManifest::shared(|manifest| manifest.get_path("bevy_extract")) } + +#[proc_macro_derive(ExtractResource, attributes(extract_app))] +pub fn derive_extract_resource(input: TokenStream) -> TokenStream { + extract_resource::derive_extract_resource(input) +} + +/// Implements `ExtractComponent` trait for a component. +/// +/// The component must implement [`Clone`]. +/// The component will be extracted into the render world via cloning. +/// Note that this only enables extraction of the component, it does not execute the extraction. +/// See `ExtractComponentPlugin` to actually perform the extraction. +/// +/// If you only want to extract a component conditionally, you may use the `extract_component_filter` attribute. +/// To specify `SyncComponent::Target`, you can use the `extract_component_sync_target` attribute. +/// +/// # Example +/// +/// ```no_compile +/// use bevy_ecs::component::Component; +/// use bevy_render_macros::ExtractComponent; +/// +/// #[derive(Component, Clone, ExtractComponent)] +/// #[extract_component_filter(With)] +/// #[extract_component_sync_target((Self, OtherNeedsCleanup))] +/// pub struct Foo { +/// pub should_foo: bool, +/// } +/// +/// // Without a filter (unconditional). +/// #[derive(Component, Clone, ExtractComponent)] +/// pub struct Bar { +/// pub should_bar: bool, +/// } +/// ``` +#[proc_macro_derive( + ExtractComponent, + attributes(extract_component_filter, extract_component_sync_target, extract_app) +)] +pub fn derive_extract_component(input: TokenStream) -> TokenStream { + extract_component::derive_extract_component(input) +} diff --git a/crates/bevy_render/macros/src/lib.rs b/crates/bevy_render/macros/src/lib.rs index aa858cc5b1280..57165b90eea18 100644 --- a/crates/bevy_render/macros/src/lib.rs +++ b/crates/bevy_render/macros/src/lib.rs @@ -19,48 +19,6 @@ pub(crate) fn bevy_ecs_path() -> syn::Path { BevyManifest::shared(|manifest| manifest.get_path("bevy_ecs")) } -#[proc_macro_derive(ExtractResource, attributes(extract_app))] -pub fn derive_extract_resource(input: TokenStream) -> TokenStream { - extract_resource::derive_extract_resource(input) -} - -/// Implements `ExtractComponent` trait for a component. -/// -/// The component must implement [`Clone`]. -/// The component will be extracted into the render world via cloning. -/// Note that this only enables extraction of the component, it does not execute the extraction. -/// See `ExtractComponentPlugin` to actually perform the extraction. -/// -/// If you only want to extract a component conditionally, you may use the `extract_component_filter` attribute. -/// To specify `SyncComponent::Target`, you can use the `extract_component_sync_target` attribute. -/// -/// # Example -/// -/// ```no_compile -/// use bevy_ecs::component::Component; -/// use bevy_render_macros::ExtractComponent; -/// -/// #[derive(Component, Clone, ExtractComponent)] -/// #[extract_component_filter(With)] -/// #[extract_component_sync_target((Self, OtherNeedsCleanup))] -/// pub struct Foo { -/// pub should_foo: bool, -/// } -/// -/// // Without a filter (unconditional). -/// #[derive(Component, Clone, ExtractComponent)] -/// pub struct Bar { -/// pub should_bar: bool, -/// } -/// ``` -#[proc_macro_derive( - ExtractComponent, - attributes(extract_component_filter, extract_component_sync_target, extract_app) -)] -pub fn derive_extract_component(input: TokenStream) -> TokenStream { - extract_component::derive_extract_component(input) -} - #[proc_macro_derive( AsBindGroup, attributes( From 3d9dbe7099c368191aa73b08b79e97f6ddab01fe Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Fri, 29 May 2026 16:56:49 +0800 Subject: [PATCH 13/15] Migrate squash migrate fixes squash migrate fixes --- .../bevy_render/extract_render_asset.rs | 2 +- .../macros/src/extract_component.rs | 6 +-- .../macros/src/extract_resource.rs | 4 +- crates/bevy_extract/macros/src/lib.rs | 6 +-- crates/bevy_extract/src/extract_component.rs | 18 +++---- crates/bevy_extract/src/extract_param.rs | 9 ++-- crates/bevy_extract/src/extract_plugin.rs | 23 +++++---- crates/bevy_extract/src/extract_resource.rs | 12 ++--- crates/bevy_extract/src/lib.rs | 12 ++--- crates/bevy_extract/src/sync_component.rs | 13 ++--- crates/bevy_extract/src/sync_world.rs | 8 +-- .../src/light_probe/environment_map.rs | 2 +- crates/bevy_pbr/src/light_probe/mod.rs | 2 +- crates/bevy_pbr/src/material.rs | 1 - crates/bevy_pbr/src/wireframe.rs | 4 +- crates/bevy_render/macros/src/lib.rs | 2 - crates/bevy_render/src/gpu_readback.rs | 2 +- crates/bevy_render/src/lib.rs | 49 +++++++++++++++---- .../src/texture/manual_texture_view.rs | 2 +- crates/bevy_render/src/view/mod.rs | 2 +- .../src/mesh2d/wireframe2d.rs | 4 +- 21 files changed, 99 insertions(+), 84 deletions(-) diff --git a/benches/benches/bevy_render/extract_render_asset.rs b/benches/benches/bevy_render/extract_render_asset.rs index 8c55844271836..fdb6c92359b33 100644 --- a/benches/benches/bevy_render/extract_render_asset.rs +++ b/benches/benches/bevy_render/extract_render_asset.rs @@ -88,7 +88,7 @@ fn extract_render_asset_bench(c: &mut Criterion) { // Measuring the extract call let start = Instant::now(); - bevy_render::extract_plugin::extract(main.world_mut(), render_world); + bevy_extract::extract_plugin::extract(main.world_mut(), render_world); total += Instant::now().duration_since(start); // Run a standard app update to allow Bevy's internal systems to flush/clear the message queues. diff --git a/crates/bevy_extract/macros/src/extract_component.rs b/crates/bevy_extract/macros/src/extract_component.rs index ec802fea534a0..bb09c2149de5e 100644 --- a/crates/bevy_extract/macros/src/extract_component.rs +++ b/crates/bevy_extract/macros/src/extract_component.rs @@ -8,7 +8,7 @@ use syn::{ pub fn derive_extract_component(input: TokenStream) -> TokenStream { let mut ast = parse_macro_input!(input as DeriveInput); - let bevy_render_path: Path = crate::bevy_render_path(); + let bevy_extract_path: Path = crate::bevy_extract_path(); let bevy_ecs_path: Path = bevy_macro_utils::BevyManifest::shared(|manifest| { manifest .maybe_get_path("bevy_ecs") @@ -98,11 +98,11 @@ pub fn derive_extract_component(input: TokenStream) -> TokenStream { app_labels.iter().map(|app_label| TokenStream::from(quote! { - impl #impl_generics #bevy_render_path::sync_component::SyncComponent<#app_label> for #struct_name #type_generics #where_clause { + impl #impl_generics #bevy_extract_path::sync_component::SyncComponent<#app_label> for #struct_name #type_generics #where_clause { type Target = #sync_target; } - impl #impl_generics #bevy_render_path::extract_component::ExtractComponent<#app_label> for #struct_name #type_generics #where_clause { + impl #impl_generics #bevy_extract_path::extract_component::ExtractComponent<#app_label> for #struct_name #type_generics #where_clause { type QueryData = &'static Self; type QueryFilter = #filter; diff --git a/crates/bevy_extract/macros/src/extract_resource.rs b/crates/bevy_extract/macros/src/extract_resource.rs index 2f05734ad7f3d..7fe1b886e5200 100644 --- a/crates/bevy_extract/macros/src/extract_resource.rs +++ b/crates/bevy_extract/macros/src/extract_resource.rs @@ -5,7 +5,7 @@ use syn::{parse_macro_input, parse_quote, DeriveInput, Path}; pub fn derive_extract_resource(input: TokenStream) -> TokenStream { let mut ast = parse_macro_input!(input as DeriveInput); - let bevy_render_path: Path = crate::bevy_render_path(); + let bevy_extract_path: Path = crate::bevy_extract_path(); ast.generics .make_where_clause() @@ -31,7 +31,7 @@ pub fn derive_extract_resource(input: TokenStream) -> TokenStream { }; TokenStream::from(quote! { - impl #impl_generics #bevy_render_path::extract_resource::ExtractResource<#app_label> for #struct_name #type_generics #where_clause { + impl #impl_generics #bevy_extract_path::extract_resource::ExtractResource<#app_label> for #struct_name #type_generics #where_clause { type Source = Self; fn extract_resource(source: &Self::Source) -> Self { diff --git a/crates/bevy_extract/macros/src/lib.rs b/crates/bevy_extract/macros/src/lib.rs index a97d8d338bed6..618038b362a1f 100644 --- a/crates/bevy_extract/macros/src/lib.rs +++ b/crates/bevy_extract/macros/src/lib.rs @@ -5,9 +5,9 @@ mod extract_component; mod extract_resource; use bevy_macro_utils::BevyManifest; -// use proc_macro::TokenStream; +use proc_macro::TokenStream; -pub(crate) fn _bevy_extract_path() -> syn::Path { +pub(crate) fn bevy_extract_path() -> syn::Path { BevyManifest::shared(|manifest| manifest.get_path("bevy_extract")) } @@ -30,7 +30,7 @@ pub fn derive_extract_resource(input: TokenStream) -> TokenStream { /// /// ```no_compile /// use bevy_ecs::component::Component; -/// use bevy_render_macros::ExtractComponent; +/// use bevy_extract_macros::ExtractComponent; /// /// #[derive(Component, Clone, ExtractComponent)] /// #[extract_component_filter(With)] diff --git a/crates/bevy_extract/src/extract_component.rs b/crates/bevy_extract/src/extract_component.rs index bb540abcad2a3..7104d239c28c1 100644 --- a/crates/bevy_extract/src/extract_component.rs +++ b/crates/bevy_extract/src/extract_component.rs @@ -1,7 +1,7 @@ use crate::{ sync_component::{SyncComponent, SyncComponentPlugin}, sync_world::SubEntity, - Extract, ExtractSchedule, RenderApp, + Extract, ExtractSchedule, }; use bevy_app::{App, AppLabel, Plugin}; use bevy_camera::visibility::ViewVisibility; @@ -12,9 +12,7 @@ use bevy_ecs::{ }; use core::marker::PhantomData; -pub use crate::uniform::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin}; - -pub use bevy_render_macros::ExtractComponent; +pub use bevy_extract_macros::ExtractComponent; /// Describes how a component gets extracted for rendering. /// @@ -57,14 +55,12 @@ pub trait ExtractComponent: SyncComponent { /// The marker type `F` is only used as a way to bypass the orphan rules. To /// implement the trait for a foreign type you can use a local type as the /// marker, e.g. the type of the plugin that calls [`ExtractComponentPlugin`]. -pub struct ExtractComponentPlugin { +pub struct ExtractComponentPlugin { only_extract_visible: bool, marker: PhantomData (L, C, F)>, } -// pub type ExtractComponentPlugin = ExtractComponentPlugin; - -impl Default for ExtractComponentPlugin { +impl Default for ExtractComponentPlugin { fn default() -> Self { Self { only_extract_visible: false, @@ -73,7 +69,7 @@ impl Default for ExtractComponentPlugin { } } -impl ExtractComponentPlugin { +impl ExtractComponentPlugin { pub fn extract_visible() -> Self { Self { only_extract_visible: true, @@ -86,10 +82,10 @@ impl< L: AppLabel + Default + Clone + Copy + Eq, C: ExtractComponent, F: 'static + Send + Sync, - > Plugin for ExtractComponentPlugin + > Plugin for ExtractComponentPlugin { fn build(&self, app: &mut App) { - app.add_plugins(SyncComponentPlugin::::default()); + app.add_plugins(SyncComponentPlugin::::default()); if let Some(render_app) = app.get_sub_app_mut(L::default()) { if self.only_extract_visible { diff --git a/crates/bevy_extract/src/extract_param.rs b/crates/bevy_extract/src/extract_param.rs index 0659cec965403..cf841bcbe5978 100644 --- a/crates/bevy_extract/src/extract_param.rs +++ b/crates/bevy_extract/src/extract_param.rs @@ -33,12 +33,15 @@ use core::ops::{Deref, DerefMut}; /// /// ``` /// use bevy_ecs::prelude::*; -/// use bevy_render::Extract; -/// use bevy_render::sync_world::RenderEntity; +/// use bevy_extract::Extract; +/// use bevy_extract::sync_world::SubEntity; +/// use bevy_derive::AppLabel; +/// # #[derive(AppLabel, Debug, Hash, PartialEq, Eq, Clone, Default, Copy)] +/// # struct ExtractApp; /// # #[derive(Component)] /// // Do make sure to sync the cloud entities before extracting them. /// # struct Cloud; -/// fn extract_clouds(mut commands: Commands, clouds: Extract>>) { +/// fn extract_clouds(mut commands: Commands, clouds: Extract, With>>) { /// for cloud in &clouds { /// commands.entity(cloud).insert(Cloud); /// } diff --git a/crates/bevy_extract/src/extract_plugin.rs b/crates/bevy_extract/src/extract_plugin.rs index fff658eec51f5..d01fd4081ca95 100644 --- a/crates/bevy_extract/src/extract_plugin.rs +++ b/crates/bevy_extract/src/extract_plugin.rs @@ -149,6 +149,7 @@ pub fn extract(main_world: &mut World, render_world: &mut World) { #[cfg(test)] mod test { use bevy_app::{App, Startup}; + use bevy_derive::AppLabel; use bevy_ecs::{prelude::*, schedule::ScheduleLabel}; use crate::{ @@ -156,7 +157,6 @@ mod test { extract_plugin::ExtractPlugin, sync_component::SyncComponent, sync_world::MainEntity, - RenderApp, }; #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] @@ -165,6 +165,9 @@ mod test { PostCleanup, } + #[derive(AppLabel, Debug, Hash, PartialEq, Eq, Clone, Default, Copy)] + pub struct ExtractApp; + #[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone, Default)] pub struct MySchedule; @@ -190,17 +193,17 @@ mod test { struct RenderComponentExtra; #[derive(Component, Clone, Debug, ExtractComponent)] - #[extract_app(RenderApp)] + #[extract_app(ExtractApp)] struct RenderComponentSeparate; #[derive(Component, Clone, Debug)] struct RenderComponentNoExtract; - impl SyncComponent for RenderComponent { + impl SyncComponent for RenderComponent { type Target = (RenderComponent, RenderComponentExtra); } - impl ExtractComponent for RenderComponent { + impl ExtractComponent for RenderComponent { type QueryData = &'static Self; type QueryFilter = (); type Out = (RenderComponent, RenderComponentExtra); @@ -216,20 +219,20 @@ mod test { fn extraction_works() { let mut app = App::new(); - app.add_plugins(ExtractPlugin::::new( + app.add_plugins(ExtractPlugin::::new( |_, _| {}, MySchedule::base_schedule, MySchedule.intern(), MyScheduleSystems::ExtractCommands.intern(), MyScheduleSystems::PostCleanup.intern(), )); - app.add_plugins(ExtractComponentPlugin::::default()); - app.add_plugins(ExtractComponentPlugin::::default()); + app.add_plugins(ExtractComponentPlugin::::default()); + app.add_plugins(ExtractComponentPlugin::::default()); app.add_systems(Startup, |mut commands: Commands| { commands.spawn((RenderComponent, RenderComponentSeparate)); }); - let render_app = app.get_sub_app_mut(RenderApp).unwrap(); + let render_app = app.get_sub_app_mut(ExtractApp).unwrap(); // Normally RenderPlugin sets the RenderRecovery schedule as update, but for // testing we just use the Render schedule directly. @@ -248,7 +251,7 @@ mod test { // Check that all components have been extracted { - let render_app = app.get_sub_app_mut(RenderApp).unwrap(); + let render_app = app.get_sub_app_mut(ExtractApp).unwrap(); render_app .world_mut() .run_system_cached( @@ -283,7 +286,7 @@ mod test { // Check that the extracted components have been removed { - let render_app = app.get_sub_app_mut(RenderApp).unwrap(); + let render_app = app.get_sub_app_mut(ExtractApp).unwrap(); render_app .world_mut() .run_system_cached( diff --git a/crates/bevy_extract/src/extract_resource.rs b/crates/bevy_extract/src/extract_resource.rs index 46079fcff3b8f..05b7b0c00ae8c 100644 --- a/crates/bevy_extract/src/extract_resource.rs +++ b/crates/bevy_extract/src/extract_resource.rs @@ -2,10 +2,10 @@ use core::marker::PhantomData; use bevy_app::{App, AppLabel, Plugin}; use bevy_ecs::{component::Mutable, prelude::*}; -pub use bevy_render_macros::ExtractResource; +pub use bevy_extract_macros::ExtractResource; use bevy_utils::once; -use crate::{Extract, ExtractSchedule, RenderApp}; +use crate::{Extract, ExtractSchedule}; /// Describes how a resource gets extracted for rendering. /// @@ -30,13 +30,11 @@ pub trait ExtractResource: Resource { /// The marker type `F` is only used as a way to bypass the orphan rules. To /// implement the trait for a foreign type you can use a local type as the /// marker, e.g. the type of the plugin that calls [`ExtractResourcePlugin`]. -pub struct ExtractResourcePlugin, F = (), L: AppLabel = RenderApp>( +pub struct ExtractResourcePlugin, F = ()>( PhantomData<(L, R, F)>, ); -// pub type ExtractResourcePlugin = ExtractResourcePlugin; - -impl, F> Default for ExtractResourcePlugin { +impl, F> Default for ExtractResourcePlugin { fn default() -> Self { Self(PhantomData) } @@ -46,7 +44,7 @@ impl< L: AppLabel + Default, R: ExtractResource, F: 'static + Send + Sync, - > Plugin for ExtractResourcePlugin + > Plugin for ExtractResourcePlugin { fn build(&self, app: &mut App) { if let Some(render_app) = app.get_sub_app_mut(L::default()) { diff --git a/crates/bevy_extract/src/lib.rs b/crates/bevy_extract/src/lib.rs index c2923e88f6717..f5644238bec8f 100644 --- a/crates/bevy_extract/src/lib.rs +++ b/crates/bevy_extract/src/lib.rs @@ -11,7 +11,7 @@ html_logo_url = "https://bevy.org/assets/icon.png", html_favicon_url = "https://bevy.org/assets/icon.png" )] -// #![expect(unsafe_code, reason = "Unsafe code is used to improve performance.")] +#![expect(unsafe_code, reason = "Unsafe code is used to improve performance.")] //! This crate is about everything concerning extract. @@ -19,16 +19,16 @@ extern crate alloc; pub mod extract_component; pub mod extract_instances; -mod extract_param; +pub mod extract_param; pub mod extract_plugin; pub mod extract_resource; pub mod sync_component; pub mod sync_world; -// pub use extract_param::Extract; -// pub use extract_plugin::*; -// pub use extract_plugin::{ExtractSchedule, MainWorld}; -// pub use sync_world::*; +pub use extract_param::Extract; +pub use extract_plugin::*; +pub use extract_plugin::{ExtractSchedule, MainWorld}; +pub use sync_world::*; // Required to make proc macros work in bevy itself. extern crate self as bevy_extract; diff --git a/crates/bevy_extract/src/sync_component.rs b/crates/bevy_extract/src/sync_component.rs index 6a6781ec6b0d1..6f94c4cd88af1 100644 --- a/crates/bevy_extract/src/sync_component.rs +++ b/crates/bevy_extract/src/sync_component.rs @@ -9,10 +9,7 @@ use bevy_ecs::{ system::ResMut, }; -use crate::{ - sync_world::{EntityRecord, PendingSyncEntity, SyncToSubWorld}, - RenderApp, -}; +use crate::sync_world::{EntityRecord, PendingSyncEntity, SyncToSubWorld}; /// Plugin that registers a component for automatic sync to the render world. See [`SyncWorldPlugin`] for more information. /// @@ -29,11 +26,9 @@ use crate::{ /// /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin /// [`SyncWorldPlugin`]: crate::sync_world::SyncWorldPlugin -pub struct SyncComponentPlugin(PhantomData<(L, C, F)>); - -// pub type SyncComponentPlugin = SyncComponentPlugin; +pub struct SyncComponentPlugin(PhantomData<(L, C, F)>); -impl, F> Default for SyncComponentPlugin { +impl, F> Default for SyncComponentPlugin { fn default() -> Self { Self(PhantomData) } @@ -59,7 +54,7 @@ impl< L: AppLabel + Default + Clone + Copy + Eq, C: SyncComponent, F: Send + Sync + 'static, - > Plugin for SyncComponentPlugin + > Plugin for SyncComponentPlugin { fn build(&self, app: &mut App) { app.register_required_components::>(); diff --git a/crates/bevy_extract/src/sync_world.rs b/crates/bevy_extract/src/sync_world.rs index dcb18fd3a2998..1d80df34a8db2 100644 --- a/crates/bevy_extract/src/sync_world.rs +++ b/crates/bevy_extract/src/sync_world.rs @@ -127,8 +127,6 @@ impl Plugin for SyncWorldPlugin { #[component(storage = "SparseSet")] pub struct SyncToSubWorld(PhantomData); -pub type SyncToRenderWorld = SyncToSubWorld; - /// Component added on the main world entities that are synced to the Sub World in order to keep track of the corresponding sub world entity. /// /// Can also be used as a newtype wrapper for sub world entities. @@ -137,8 +135,6 @@ pub type SyncToRenderWorld = SyncToSubWorld; #[reflect(Component, Clone)] pub struct SubEntity(#[deref] Entity, PhantomData); -pub type RenderEntity = SubEntity; - impl SubEntity { #[inline] pub fn id(&self) -> Entity { @@ -206,8 +202,6 @@ pub type MainEntityHashSet = EntityEquivalentHashSet; #[reflect(Component, Default, Clone)] pub struct TemporaryEntity(PhantomData); -pub type TemporaryRenderEntity = TemporaryEntity; - /// A record enum to what entities with [`SyncToSubWorld`] have been added or removed. #[derive(Debug)] pub(crate) enum EntityRecord { @@ -554,7 +548,7 @@ mod sub_entities_world_query_impls { mod tests { use core::marker::PhantomData; - use bevy_app::AppLabel; + use bevy_derive::AppLabel; use bevy_ecs::{ component::Component, entity::Entity, diff --git a/crates/bevy_pbr/src/light_probe/environment_map.rs b/crates/bevy_pbr/src/light_probe/environment_map.rs index 329cdbb3c5bc6..d7e307970cd74 100644 --- a/crates/bevy_pbr/src/light_probe/environment_map.rs +++ b/crates/bevy_pbr/src/light_probe/environment_map.rs @@ -49,11 +49,11 @@ use bevy_ecs::{ query::{QueryData, QueryItem}, system::lifetimeless::Read, }; +use bevy_extract::extract_instances::ExtractInstance; use bevy_image::Image; use bevy_light::{EnvironmentMapLight, ParallaxCorrection}; use bevy_math::{Affine3A, Quat, Vec3}; use bevy_render::{ - extract_instances::ExtractInstance, render_asset::RenderAssets, render_resource::{ binding_types, BindGroupLayoutEntryBuilder, Sampler, SamplerBindingType, TextureSampleType, diff --git a/crates/bevy_pbr/src/light_probe/mod.rs b/crates/bevy_pbr/src/light_probe/mod.rs index 1a39e93810792..baf8ade657f8d 100644 --- a/crates/bevy_pbr/src/light_probe/mod.rs +++ b/crates/bevy_pbr/src/light_probe/mod.rs @@ -12,6 +12,7 @@ use bevy_ecs::{ schedule::IntoScheduleConfigs, system::{Commands, Local, Query, Res, ResMut}, }; +use bevy_extract::extract_instances::ExtractInstancesPlugin; use bevy_image::Image; use bevy_light::{ cluster::ClusterVisibilityClass, EnvironmentMapLight, IrradianceVolume, LightProbe, @@ -19,7 +20,6 @@ use bevy_light::{ use bevy_math::{Affine3A, FloatOrd, Mat4, Quat, Vec3, Vec4}; use bevy_platform::collections::HashMap; use bevy_render::{ - extract_instances::ExtractInstancesPlugin, render_asset::RenderAssets, render_resource::{DynamicUniformBuffer, Sampler, ShaderType, TextureView}, renderer::{RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue, WgpuWrapper}, diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 11580b9c2b147..03f9c70cc13c8 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -51,7 +51,6 @@ use bevy_render::{ batching::gpu_preprocessing::GpuPreprocessingSupport, extract_resource::ExtractResource, mesh::RenderMesh, - prelude::*, render_phase::*, render_resource::*, renderer::RenderDevice, diff --git a/crates/bevy_pbr/src/wireframe.rs b/crates/bevy_pbr/src/wireframe.rs index 002b5aa97d5af..07a8a174ee0f7 100644 --- a/crates/bevy_pbr/src/wireframe.rs +++ b/crates/bevy_pbr/src/wireframe.rs @@ -38,7 +38,6 @@ use bevy_render::{ allocator::{MeshAllocator, MeshAllocatorSettings, MeshSlabs}, RenderMesh, RenderMeshBufferInfo, }, - prelude::*, render_asset::{ prepare_assets, PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets, }, @@ -55,7 +54,8 @@ use bevy_render::{ ExtractedView, NoIndirectDrawing, RenderVisibilityRanges, RenderVisibleEntities, RetainedViewEntity, ViewDepthTexture, ViewTarget, }, - Extract, GpuResourceAppExt, Render, RenderApp, RenderDebugFlags, RenderStartup, RenderSystems, + Extract, ExtractSchedule, GpuResourceAppExt, Render, RenderApp, RenderDebugFlags, + RenderStartup, RenderSystems, }; use bevy_shader::Shader; use bytemuck::{Pod, Zeroable}; diff --git a/crates/bevy_render/macros/src/lib.rs b/crates/bevy_render/macros/src/lib.rs index 57165b90eea18..922e17eb96ec7 100644 --- a/crates/bevy_render/macros/src/lib.rs +++ b/crates/bevy_render/macros/src/lib.rs @@ -2,8 +2,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] mod as_bind_group; -mod extract_component; -mod extract_resource; mod specializer; use bevy_macro_utils::{derive_label, BevyManifest}; diff --git a/crates/bevy_render/src/gpu_readback.rs b/crates/bevy_render/src/gpu_readback.rs index 3488c6abeaa2b..eafdbc5ee7aea 100644 --- a/crates/bevy_render/src/gpu_readback.rs +++ b/crates/bevy_render/src/gpu_readback.rs @@ -25,11 +25,11 @@ use bevy_ecs::{ system::{Commands, Query, Res}, }; use bevy_ecs::{schedule::IntoScheduleConfigs, template::FromTemplate}; +use bevy_extract_macros::ExtractComponent; use bevy_image::{Image, TextureFormatPixelInfo}; use bevy_log::{debug, warn}; use bevy_platform::collections::HashMap; use bevy_reflect::Reflect; -use bevy_render_macros::ExtractComponent; use encase::internal::ReadFrom; use encase::private::Reader; use encase::ShaderType; diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index b6a6de1c9cdee..728846862b3bd 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -41,11 +41,25 @@ pub mod camera; pub mod diagnostic; pub mod erased_render_asset; pub mod error_handler; -pub mod extract_component; -pub mod extract_instances; -mod extract_param; -pub mod extract_plugin; -pub mod extract_resource; +pub mod extract_component { + pub type ExtractComponentPlugin = + bevy_extract::extract_component::ExtractComponentPlugin; + + pub use crate::uniform::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin}; + + pub use bevy_extract::extract_component::ExtractComponent; +} +// pub mod extract_instances; +// mod extract_param; +pub mod extract_plugin { + pub use bevy_extract::extract_plugin::ExtractPlugin; +} +pub mod extract_resource { + pub type ExtractResourcePlugin = + bevy_extract::extract_resource::ExtractResourcePlugin; + + pub use bevy_extract::extract_resource::{extract_resource, ExtractResource}; +} pub mod globals; pub mod gpu_component_array_buffer; pub mod gpu_readback; @@ -60,8 +74,21 @@ pub mod renderer; pub mod settings; pub mod slab_allocator; pub mod storage; -pub mod sync_component; -pub mod sync_world; +pub mod sync_component { + pub type SyncComponentPlugin = + bevy_extract::sync_component::SyncComponentPlugin; + + pub use bevy_extract::sync_component::SyncComponent; +} +pub mod sync_world { + pub type SyncToRenderWorld = bevy_extract::sync_world::SyncToSubWorld; + + pub type RenderEntity = bevy_extract::sync_world::SubEntity; + + pub type TemporaryRenderEntity = bevy_extract::sync_world::TemporaryEntity; + + pub use bevy_extract::sync_world::{MainEntity, MainEntityHashMap, MainEntityHashSet}; +} pub mod texture; pub mod uniform; pub mod view; @@ -76,13 +103,14 @@ pub mod prelude { view::Msaa, ExtractSchedule, }; } -pub use extract_param::Extract; -pub use extract_plugin::{ExtractSchedule, MainWorld}; +pub use bevy_extract::{ + extract_param::Extract, + extract_plugin::{ExtractSchedule, MainWorld}, +}; use crate::{ camera::CameraPlugin, error_handler::{RenderErrorHandler, RenderState}, - extract_plugin::ExtractPlugin, gpu_readback::GpuReadbackPlugin, mesh::{MeshRenderAssetPlugin, RenderMesh}, render_asset::prepare_assets, @@ -102,6 +130,7 @@ use bevy_ecs::{ prelude::*, schedule::{InternedScheduleLabel, ScheduleLabel}, }; +use bevy_extract::ExtractPlugin; use bevy_platform::time::Instant; use bevy_shader::{load_shader_library, Shader, ShaderLoader}; use bevy_time::TimeSender; diff --git a/crates/bevy_render/src/texture/manual_texture_view.rs b/crates/bevy_render/src/texture/manual_texture_view.rs index 17d7d0bcdb6fd..67b7ade119b65 100644 --- a/crates/bevy_render/src/texture/manual_texture_view.rs +++ b/crates/bevy_render/src/texture/manual_texture_view.rs @@ -1,8 +1,8 @@ use bevy_camera::ManualTextureViewHandle; use bevy_ecs::resource::Resource; +use bevy_extract_macros::ExtractResource; use bevy_math::UVec2; use bevy_platform::collections::HashMap; -use bevy_render_macros::ExtractResource; use wgpu::TextureFormat; use crate::{render_resource::TextureView, RenderApp}; diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index c986754dec584..477488d52bcb6 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -29,11 +29,11 @@ use bevy_app::{App, Plugin}; use bevy_color::{LinearRgba, Oklaba, Srgba}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{prelude::*, VariantDefaults}; +use bevy_extract_macros::ExtractComponent; use bevy_image::ToExtents; use bevy_math::{mat3, vec2, vec3, Mat3, Mat4, UVec4, Vec2, Vec3, Vec4, Vec4Swizzles}; use bevy_platform::collections::{hash_map::Entry, HashMap}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; -use bevy_render_macros::ExtractComponent; use bevy_shader::load_shader_library; use bevy_transform::components::GlobalTransform; use core::{ diff --git a/crates/bevy_sprite_render/src/mesh2d/wireframe2d.rs b/crates/bevy_sprite_render/src/mesh2d/wireframe2d.rs index b6b39ed9b9afb..5c6ac319faa5b 100644 --- a/crates/bevy_sprite_render/src/mesh2d/wireframe2d.rs +++ b/crates/bevy_sprite_render/src/mesh2d/wireframe2d.rs @@ -33,7 +33,6 @@ use bevy_render::{ allocator::{MeshAllocator, MeshSlabId, MeshSlabs}, RenderMesh, }, - prelude::*, render_asset::{ prepare_assets, PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets, }, @@ -49,7 +48,8 @@ use bevy_render::{ view::{ ExtractedView, RenderVisibleEntities, RetainedViewEntity, ViewDepthTexture, ViewTarget, }, - Extract, GpuResourceAppExt, Render, RenderApp, RenderDebugFlags, RenderStartup, RenderSystems, + Extract, ExtractSchedule, GpuResourceAppExt, Render, RenderApp, RenderDebugFlags, + RenderStartup, RenderSystems, }; use bevy_shader::Shader; use core::{hash::Hash, ops::Range}; From a3c5abfb8db9cbf9d199ce50d6ab9f74d08d8bc7 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Thu, 28 May 2026 17:20:03 +0800 Subject: [PATCH 14/15] Fix docs --- crates/bevy_extract/src/extract_component.rs | 4 ++-- crates/bevy_extract/src/extract_param.rs | 2 +- crates/bevy_extract/src/extract_plugin.rs | 4 ++-- crates/bevy_extract/src/sync_world.rs | 5 +++-- crates/bevy_render/src/pipelined_rendering.rs | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/bevy_extract/src/extract_component.rs b/crates/bevy_extract/src/extract_component.rs index 7104d239c28c1..495d70c2e4e3a 100644 --- a/crates/bevy_extract/src/extract_component.rs +++ b/crates/bevy_extract/src/extract_component.rs @@ -97,7 +97,7 @@ impl< } } -/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`crate::sync_world::SyncToRenderWorld`]. +/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`crate::sync_world::SyncToSubWorld`]. fn extract_components, F>( mut commands: Commands, mut previous_len: Local, @@ -115,7 +115,7 @@ fn extract_components commands.try_insert_batch(values); } -/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are visible and synced via [`crate::sync_world::SyncToRenderWorld`]. +/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are visible and synced via [`crate::sync_world::SyncToSubWorld`]. fn extract_visible_components, F>( mut commands: Commands, mut previous_len: Local, diff --git a/crates/bevy_extract/src/extract_param.rs b/crates/bevy_extract/src/extract_param.rs index cf841bcbe5978..a458c94efcde2 100644 --- a/crates/bevy_extract/src/extract_param.rs +++ b/crates/bevy_extract/src/extract_param.rs @@ -49,7 +49,7 @@ use core::ops::{Deref, DerefMut}; /// ``` /// /// [`ExtractSchedule`]: crate::ExtractSchedule -/// [Window]: bevy_window::Window +/// [`Window`]: https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html pub struct Extract<'w, 's, P> where P: ReadOnlySystemParam + 'static, diff --git a/crates/bevy_extract/src/extract_plugin.rs b/crates/bevy_extract/src/extract_plugin.rs index d01fd4081ca95..875e0a7222c71 100644 --- a/crates/bevy_extract/src/extract_plugin.rs +++ b/crates/bevy_extract/src/extract_plugin.rs @@ -13,8 +13,8 @@ use bevy_ecs::{ }; use bevy_utils::default; -/// Plugin that sets up the [`RenderApp`](`crate::RenderApp`) and handles extracting data from the -/// main world to the render world. +/// Plugin that sets up the sub app for the [`AppLabel`] and handles extracting data from the +/// main world to the sub world. pub struct ExtractPlugin { /// Function that gets run at the beginning of each extraction. /// diff --git a/crates/bevy_extract/src/sync_world.rs b/crates/bevy_extract/src/sync_world.rs index 1d80df34a8db2..1e2fbdd081724 100644 --- a/crates/bevy_extract/src/sync_world.rs +++ b/crates/bevy_extract/src/sync_world.rs @@ -83,12 +83,13 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// The render world probably cares about a `Position` component, but not a `Velocity` component. /// The extraction happens in its own step, independently from, and after synchronization. /// -/// Moreover, [`SyncWorldPlugin`] only synchronizes *entities*. [`RenderAsset`](crate::render_asset::RenderAsset)s like meshes and textures are handled +/// Moreover, [`SyncWorldPlugin`] only synchronizes *entities*. [`RenderAsset`]s like meshes and textures are handled /// differently. /// -/// [`PipelinedRenderingPlugin`]: crate::pipelined_rendering::PipelinedRenderingPlugin +/// [`PipelinedRenderingPlugin`]: https://docs.rs/bevy/latest/bevy/render/pipelined_rendering/struct.PipelinedRenderingPlugin.html /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin /// [`SyncComponentPlugin`]: crate::sync_component::SyncComponentPlugin +/// [`RenderAsset`]: https://docs.rs/bevy/latest/bevy/render/render_asset/trait.RenderAsset.html #[derive(Default)] pub struct SyncWorldPlugin(PhantomData); diff --git a/crates/bevy_render/src/pipelined_rendering.rs b/crates/bevy_render/src/pipelined_rendering.rs index 4440503bf7718..005a3d3a8854c 100644 --- a/crates/bevy_render/src/pipelined_rendering.rs +++ b/crates/bevy_render/src/pipelined_rendering.rs @@ -105,7 +105,7 @@ impl Drop for RenderAppChannels { /// - And finally the `main app schedule` is run. /// - Once both the `main app schedule` and the `render schedule` are finished running, `extract` is run again. /// -/// [`SyncWorldPlugin`]: crate::sync_world::SyncWorldPlugin +/// [`SyncWorldPlugin`]: bevy_extract::sync_world::SyncWorldPlugin #[derive(Default)] pub struct PipelinedRenderingPlugin; From 5678590ca9c251e27a8d20b3c55758e81aeb0232 Mon Sep 17 00:00:00 2001 From: Daniel Skates Date: Thu, 28 May 2026 17:27:46 +0800 Subject: [PATCH 15/15] Rework docs to remove most of render from bevy_extract --- crates/bevy_extract/src/extract_component.rs | 18 +++--- crates/bevy_extract/src/extract_param.rs | 4 +- crates/bevy_extract/src/extract_plugin.rs | 66 ++++++++++---------- crates/bevy_extract/src/extract_resource.rs | 16 ++--- crates/bevy_extract/src/sync_component.rs | 8 +-- crates/bevy_extract/src/sync_world.rs | 24 +++---- 6 files changed, 68 insertions(+), 68 deletions(-) diff --git a/crates/bevy_extract/src/extract_component.rs b/crates/bevy_extract/src/extract_component.rs index 495d70c2e4e3a..32977e3fc5af2 100644 --- a/crates/bevy_extract/src/extract_component.rs +++ b/crates/bevy_extract/src/extract_component.rs @@ -14,9 +14,9 @@ use core::marker::PhantomData; pub use bevy_extract_macros::ExtractComponent; -/// Describes how a component gets extracted for rendering. +/// Describes how a component gets extracted for processing. /// -/// Therefore the component is transferred from the "app world" into the "render +/// Therefore the component is transferred from the "app world" into the "sub /// world" in the [`ExtractSchedule`] step. This functionality is enabled by /// adding [`ExtractComponentPlugin`] with the component type. /// @@ -32,20 +32,20 @@ pub trait ExtractComponent: SyncComponent { type QueryFilter: QueryFilter; /// The output from extraction, i.e. [`ExtractComponent::extract_component`]. /// - /// The output components won't be removed automatically from the render world if the implementing component is removed, + /// The output components won't be removed automatically from the sub world if the implementing component is removed, /// unless you set them in the [`SyncComponent::Target`]. type Out: Bundle; // TODO: https://github.com/rust-lang/rust/issues/29661 // type Out: Bundle = Self; - /// Defines how the component is transferred into the "render world". + /// Defines how the component is transferred into the "sub world". /// /// Returning `None` based on the queried item will remove the [`SyncComponent::Target`] from the entity in - /// the render world. + /// the sub world. fn extract_component(item: QueryItem<'_, '_, Self::QueryData>) -> Option; } -/// This plugin extracts the components into the render world for synced +/// This plugin extracts the components into the sub world for synced /// entities. To do so, it sets up the [`ExtractSchedule`] step for the /// specified [`ExtractComponent`]. /// @@ -87,11 +87,11 @@ impl< fn build(&self, app: &mut App) { app.add_plugins(SyncComponentPlugin::::default()); - if let Some(render_app) = app.get_sub_app_mut(L::default()) { + if let Some(sub_app) = app.get_sub_app_mut(L::default()) { if self.only_extract_visible { - render_app.add_systems(ExtractSchedule, extract_visible_components::); + sub_app.add_systems(ExtractSchedule, extract_visible_components::); } else { - render_app.add_systems(ExtractSchedule, extract_components::); + sub_app.add_systems(ExtractSchedule, extract_components::); } } } diff --git a/crates/bevy_extract/src/extract_param.rs b/crates/bevy_extract/src/extract_param.rs index a458c94efcde2..a31cfcc9acdd1 100644 --- a/crates/bevy_extract/src/extract_param.rs +++ b/crates/bevy_extract/src/extract_param.rs @@ -23,8 +23,8 @@ use core::ops::{Deref, DerefMut}; /// ## Context /// /// [`ExtractSchedule`] is used to extract (move) data from the simulation world ([`MainWorld`]) to the -/// render world. The render world drives rendering each frame (generally to a `Window`). -/// This design is used to allow performing calculations related to rendering a prior frame at the same +/// sub world. The sub world drives processing each frame (generally to a `Window`). +/// This design is used to allow performing calculations related to processing a prior frame at the same /// time as the next frame is simulated, which increases throughput (FPS). /// /// [`Extract`] is used to get data from the main world during [`ExtractSchedule`]. diff --git a/crates/bevy_extract/src/extract_plugin.rs b/crates/bevy_extract/src/extract_plugin.rs index 875e0a7222c71..9154d56d61cbe 100644 --- a/crates/bevy_extract/src/extract_plugin.rs +++ b/crates/bevy_extract/src/extract_plugin.rs @@ -18,7 +18,7 @@ use bevy_utils::default; pub struct ExtractPlugin { /// Function that gets run at the beginning of each extraction. /// - /// Gets the main world and render world as arguments (in that order). + /// Gets the main world and sub world as arguments (in that order). pub pre_extract: fn(&mut World, &mut World), marker: PhantomData, @@ -54,25 +54,25 @@ impl Plugin for ExtractPlugin { app.add_plugins(SyncWorldPlugin::::default()); app.init_resource::(); - let mut render_app = SubApp::new(); + let mut sub_app = SubApp::new(); let mut extract_schedule = Schedule::new(ExtractSchedule); // We skip applying any commands during the ExtractSchedule - // so commands can be applied on the render thread. + // so commands can be applied on the sub thread. extract_schedule.set_build_settings(ScheduleBuildSettings { auto_insert_apply_deferred: false, ..default() }); extract_schedule.set_apply_final_deferred(false); - render_app + sub_app .add_schedule((self.base_schedule)()) .add_schedule(extract_schedule) .allow_ambiguous_resource::() .add_systems( self.schedule_label, ( - // This set applies the commands from the extract schedule while the render schedule + // This set applies the commands from the extract schedule while the sub schedule // is running in parallel with the main app. apply_extract_commands.in_set(self.extract_set), despawn_temporary_entities::.in_set(self.despawn_set), @@ -80,42 +80,42 @@ impl Plugin for ExtractPlugin { ); let pre_extract = self.pre_extract; - render_app.set_extract(move |main_world, render_world| { - pre_extract(main_world, render_world); + sub_app.set_extract(move |main_world, sub_world| { + pre_extract(main_world, sub_world); { #[cfg(feature = "trace")] let _stage_span = bevy_log::info_span!("entity_sync").entered(); - entity_sync_system::(main_world, render_world); + entity_sync_system::(main_world, sub_world); } // run extract schedule - extract(main_world, render_world); + extract(main_world, sub_world); }); - app.insert_sub_app(L::default(), render_app); + app.insert_sub_app(L::default(), sub_app); } } -/// Schedule in which data from the main world is 'extracted' into the render world. +/// Schedule in which data from the main world is 'extracted' into the sub world. /// /// This step should be kept as short as possible to increase the "pipelining potential" for -/// running the next frame while rendering the current frame. +/// running the next frame while processing the current frame. /// -/// This schedule is run on the render world, but it also has access to the main world. +/// This schedule is run on the sub world, but it also has access to the main world. /// See [`MainWorld`] and [`Extract`](crate::Extract) for details on how to access main world data from this schedule. #[derive(ScheduleLabel, PartialEq, Eq, Debug, Clone, Hash, Default)] pub struct ExtractSchedule; /// Applies the commands from the extract schedule. This happens during -/// the render schedule rather than during extraction to allow the commands to run in parallel with the -/// main app when pipelined rendering is enabled. -fn apply_extract_commands(render_world: &mut World) { - render_world.resource_scope(|render_world, mut schedules: Mut| { +/// the sub schedule rather than during extraction to allow the commands to run in parallel with the +/// main app when pipelined processing is enabled. +fn apply_extract_commands(sub_world: &mut World) { + sub_world.resource_scope(|sub_world, mut schedules: Mut| { schedules .get_mut(ExtractSchedule) .unwrap() - .apply_deferred(render_world); + .apply_deferred(sub_world); }); } /// The simulation [`World`] of the application, stored as a resource. @@ -131,17 +131,17 @@ pub struct MainWorld(World); #[derive(Resource, Default)] struct ScratchMainWorld(World); -/// Executes the [`ExtractSchedule`] step of the renderer. -/// This updates the render world with the extracted ECS data of the current frame. -pub fn extract(main_world: &mut World, render_world: &mut World) { - // temporarily add the app world to the render world as a resource +/// Executes the [`ExtractSchedule`] step of the processor. +/// This updates the sub world with the extracted ECS data of the current frame. +pub fn extract(main_world: &mut World, sub_world: &mut World) { + // temporarily add the app world to the sub world as a resource let scratch_world = main_world.remove_resource::().unwrap(); let inserted_world = core::mem::replace(main_world, scratch_world.0); - render_world.insert_resource(MainWorld(inserted_world)); - render_world.run_schedule(ExtractSchedule); + sub_world.insert_resource(MainWorld(inserted_world)); + sub_world.run_schedule(ExtractSchedule); // move the app world back, as if nothing happened. - let inserted_world = render_world.remove_resource::().unwrap(); + let inserted_world = sub_world.remove_resource::().unwrap(); let scratch_world = core::mem::replace(main_world, inserted_world.0); main_world.insert_resource(ScratchMainWorld(scratch_world)); } @@ -172,7 +172,7 @@ mod test { pub struct MySchedule; impl MySchedule { - /// Sets up the base structure of the rendering [`Schedule`]. + /// Sets up the base structure of the processing [`Schedule`]. /// /// The sets defined in this enum are configured to run in order. pub fn base_schedule() -> Schedule { @@ -232,13 +232,13 @@ mod test { commands.spawn((RenderComponent, RenderComponentSeparate)); }); - let render_app = app.get_sub_app_mut(ExtractApp).unwrap(); + let sub_app = app.get_sub_app_mut(ExtractApp).unwrap(); // Normally RenderPlugin sets the RenderRecovery schedule as update, but for // testing we just use the Render schedule directly. - render_app.update_schedule = Some(MySchedule.intern()); + sub_app.update_schedule = Some(MySchedule.intern()); - render_app.world_mut().add_observer( + sub_app.world_mut().add_observer( |event: On, mut commands: Commands| { // Simulate data that's not extracted commands @@ -251,8 +251,8 @@ mod test { // Check that all components have been extracted { - let render_app = app.get_sub_app_mut(ExtractApp).unwrap(); - render_app + let sub_app = app.get_sub_app_mut(ExtractApp).unwrap(); + sub_app .world_mut() .run_system_cached( |entity: Single<( @@ -286,8 +286,8 @@ mod test { // Check that the extracted components have been removed { - let render_app = app.get_sub_app_mut(ExtractApp).unwrap(); - render_app + let sub_app = app.get_sub_app_mut(ExtractApp).unwrap(); + sub_app .world_mut() .run_system_cached( |entity: Single<( diff --git a/crates/bevy_extract/src/extract_resource.rs b/crates/bevy_extract/src/extract_resource.rs index 05b7b0c00ae8c..ddbfc26558b44 100644 --- a/crates/bevy_extract/src/extract_resource.rs +++ b/crates/bevy_extract/src/extract_resource.rs @@ -7,9 +7,9 @@ use bevy_utils::once; use crate::{Extract, ExtractSchedule}; -/// Describes how a resource gets extracted for rendering. +/// Describes how a resource gets extracted for processing. /// -/// Therefore the resource is transferred from the "main world" into the "render world" +/// Therefore the resource is transferred from the "main world" into the "sub world" /// in the [`ExtractSchedule`] step. /// /// The marker type `F` is only used as a way to bypass the orphan rules. To @@ -18,11 +18,11 @@ use crate::{Extract, ExtractSchedule}; pub trait ExtractResource: Resource { type Source: Resource; - /// Defines how the resource is transferred into the "render world". + /// Defines how the resource is transferred into the "sub world". fn extract_resource(source: &Self::Source) -> Self; } -/// This plugin extracts the resources into the "render world". +/// This plugin extracts the resources into the "sub world". /// /// Therefore it sets up the[`ExtractSchedule`] step /// for the specified [`Resource`]. @@ -47,11 +47,11 @@ impl< > Plugin for ExtractResourcePlugin { fn build(&self, app: &mut App) { - if let Some(render_app) = app.get_sub_app_mut(L::default()) { - render_app.add_systems(ExtractSchedule, extract_resource::); + if let Some(sub_app) = app.get_sub_app_mut(L::default()) { + sub_app.add_systems(ExtractSchedule, extract_resource::); } else { once!(bevy_log::error!( - "Render app did not exist when trying to add `extract_resource` for <{}>.", + "Sub app did not exist when trying to add `extract_resource` for <{}>.", core::any::type_name::() )); } @@ -73,7 +73,7 @@ pub fn extract_resource() )); diff --git a/crates/bevy_extract/src/sync_component.rs b/crates/bevy_extract/src/sync_component.rs index 6f94c4cd88af1..b75b6fe4e1dd3 100644 --- a/crates/bevy_extract/src/sync_component.rs +++ b/crates/bevy_extract/src/sync_component.rs @@ -11,7 +11,7 @@ use bevy_ecs::{ use crate::sync_world::{EntityRecord, PendingSyncEntity, SyncToSubWorld}; -/// Plugin that registers a component for automatic sync to the render world. See [`SyncWorldPlugin`] for more information. +/// Plugin that registers a component for automatic sync to the sub world. See [`SyncWorldPlugin`] for more information. /// /// This plugin is automatically added by [`ExtractComponentPlugin`], and only needs to be added for manual extraction implementations. /// @@ -22,7 +22,7 @@ use crate::sync_world::{EntityRecord, PendingSyncEntity, SyncToSubWorld}; /// # Implementation details /// /// It adds [`SyncToSubWorld`] as a required component to make the [`SyncWorldPlugin`] aware of the component, and -/// handles cleanup of the component in the render world when it is removed from an entity. +/// handles cleanup of the component in the sub world when it is removed from an entity. /// /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin /// [`SyncWorldPlugin`]: crate::sync_world::SyncWorldPlugin @@ -35,7 +35,7 @@ impl, F> Default for SyncComponentPlugin, F> Default for SyncComponentPlugin: Component { - /// Describes what components should be removed from the render world if the + /// Describes what components should be removed from the sub world if the /// implementing component is removed. type Target: Bundle; // TODO: https://github.com/rust-lang/rust/issues/29661 diff --git a/crates/bevy_extract/src/sync_world.rs b/crates/bevy_extract/src/sync_world.rs index 1e2fbdd081724..e442391631560 100644 --- a/crates/bevy_extract/src/sync_world.rs +++ b/crates/bevy_extract/src/sync_world.rs @@ -17,7 +17,7 @@ use bevy_ecs::{ }; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; -/// A plugin that synchronizes entities with [`SyncToSubWorld`] between the main world and the render world. +/// A plugin that synchronizes entities with [`SyncToSubWorld`] between the main world and the sub world. /// /// All entities with the [`SyncToSubWorld`] component are kept in sync. It /// is automatically added as a required component by [`ExtractComponentPlugin`] @@ -31,25 +31,25 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// This is called "Pipelined Rendering", see [`PipelinedRenderingPlugin`] for more information. /// /// [`SyncWorldPlugin`] is the first thing that runs every frame and it maintains an entity-to-entity mapping -/// between the main world and the render world. -/// It does so by spawning and despawning entities in the render world, to match spawned and despawned entities in the main world. +/// between the main world and the sub world. +/// It does so by spawning and despawning entities in the sub world, to match spawned and despawned entities in the main world. /// The link between synced entities is maintained by the [`SubEntity`] and [`MainEntity`] components. /// -/// The [`SubEntity`] contains the corresponding render world entity of a main world entity, while [`MainEntity`] contains -/// the corresponding main world entity of a render world entity. +/// The [`SubEntity`] contains the corresponding sub world entity of a main world entity, while [`MainEntity`] contains +/// the corresponding main world entity of a sub world entity. /// For convenience, [`QueryData`](bevy_ecs::query::QueryData) implementations are provided for both components: /// adding [`MainEntity`] to a query (without a `&`) will return the corresponding main world [`Entity`], -/// and adding [`SubEntity`] will return the corresponding render world [`Entity`]. +/// and adding [`SubEntity`] will return the corresponding sub world [`Entity`]. /// If you have access to the component itself, the underlying entities can be accessed by calling `.id()`. /// /// Synchronization is necessary preparation for extraction ([`ExtractSchedule`](crate::ExtractSchedule)), which copies over component data from the main -/// to the render world for these entities. +/// to the sub world for these entities. /// /// ```text /// |--------------------------------------------------------------------| /// | | | Main world update | /// | sync | extract |---------------------------------------------------| -/// | | | Render world update | +/// | | | Sub world update | /// |--------------------------------------------------------------------| /// ``` /// @@ -63,7 +63,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// | ID: 18v1 | PointLight | SubEntity(ID: 5V1) | SyncToSubWorld | /// |-------------------------------------------------------------------| /// -/// |----------Render World-----------| +/// |----------Sub world-----------| /// | Entity | Component | /// |---------------------------------| /// | ID: 3v1 | MainEntity(ID: 1V1) | @@ -72,15 +72,15 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// /// ``` /// -/// Note that this effectively establishes a link between the main world entity and the render world entity. +/// Note that this effectively establishes a link between the main world entity and the sub world entity. /// Not every entity needs to be synchronized, however; only entities with the [`SyncToSubWorld`] component are synced. /// Adding [`SyncToSubWorld`] to a main world component will establish such a link. -/// Once a synchronized main entity is despawned, its corresponding render entity will be automatically +/// Once a synchronized main entity is despawned, its corresponding sub entity will be automatically /// despawned in the next `sync`. /// /// The sync step does not copy any of component data between worlds, since its often not necessary to transfer over all /// the components of a main world entity. -/// The render world probably cares about a `Position` component, but not a `Velocity` component. +/// The sub world probably cares about a `Position` component, but not a `Velocity` component. /// The extraction happens in its own step, independently from, and after synchronization. /// /// Moreover, [`SyncWorldPlugin`] only synchronizes *entities*. [`RenderAsset`]s like meshes and textures are handled