From d9ce54fc60706418a6e7b743051d649376307b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Tue, 1 Oct 2024 23:57:46 +0200 Subject: [PATCH 01/13] Synchronize removed components with the render world --- crates/bevy_pbr/src/lib.rs | 15 ++++++++++++++ crates/bevy_render/src/extract_component.rs | 16 ++++++++------ crates/bevy_render/src/world_sync.rs | 23 +++++++++++++++++---- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 1b446b57a645b..06a01458cbe69 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -126,6 +126,7 @@ use bevy_render::{ render_resource::Shader, texture::{GpuImage, Image}, view::{check_visibility, VisibilitySystems}, + world_sync::{EntityRecord, PendingSyncEntity}, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_transform::TransformSystem; @@ -422,6 +423,20 @@ impl Plugin for PbrPlugin { }, ); + app.world_mut() + .register_component_hooks::() + .on_remove(|mut world, entity, _component_id| { + let mut pending = world.resource_mut::(); + pending.push(EntityRecord::ComponentRemoved(entity)); + }); + + app.world_mut() + .register_component_hooks::() + .on_remove(|mut world, entity, _component_id| { + let mut pending = world.resource_mut::(); + pending.push(EntityRecord::ComponentRemoved(entity)); + }); + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_render/src/extract_component.rs index cfbdaa4f1d078..c4c376407693f 100644 --- a/crates/bevy_render/src/extract_component.rs +++ b/crates/bevy_render/src/extract_component.rs @@ -2,7 +2,7 @@ use crate::{ render_resource::{encase::internal::WriteInto, DynamicUniformBuffer, ShaderType}, renderer::{RenderDevice, RenderQueue}, view::ViewVisibility, - world_sync::{RenderEntity, SyncToRenderWorld}, + world_sync::{EntityRecord, PendingSyncEntity, RenderEntity, SyncToRenderWorld}, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_app::{App, Plugin}; @@ -12,7 +12,6 @@ use bevy_ecs::{ prelude::*, query::{QueryFilter, QueryItem, ReadOnlyQueryData}, system::lifetimeless::Read, - world::OnAdd, }; use core::{marker::PhantomData, ops::Deref}; @@ -194,10 +193,15 @@ impl ExtractComponentPlugin { impl Plugin for ExtractComponentPlugin { fn build(&self, app: &mut App) { - // TODO: use required components - app.observe(|trigger: Trigger, mut commands: Commands| { - commands.entity(trigger.entity()).insert(SyncToRenderWorld); - }); + app.register_required_components::(); + + app.world_mut().register_component_hooks::().on_remove( + |mut world, entity, _component_id| { + let mut pending = world.resource_mut::(); + pending.push(EntityRecord::ComponentRemoved(entity)); + }, + ); + if let Some(render_app) = app.get_sub_app_mut(RenderApp) { if self.only_extract_visible { render_app.add_systems(ExtractSchedule, extract_visible_components::); diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/world_sync.rs index cec1ce748c386..64dc7e4d0f5fe 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/world_sync.rs @@ -127,18 +127,22 @@ impl MainEntity { pub struct TemporaryRenderEntity; /// A record enum to what entities with [`SyncToRenderWorld`] have been added or removed. -pub(crate) enum EntityRecord { +#[derive(Debug)] +pub enum EntityRecord { /// When an entity is spawned on the main world, notify the render 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(Entity), + /// When a component is removed from an entity, notify the render world so that the corresponding component can be + /// removed. This contains the main world entity. + ComponentRemoved(Entity), } // Entity Record in MainWorld pending to Sync #[derive(Resource, Default, Deref, DerefMut)] -pub(crate) struct PendingSyncEntity { +pub struct PendingSyncEntity { records: Vec, } @@ -161,11 +165,22 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl }; } } - EntityRecord::Removed(e) => { - if let Some(ec) = render_world.get_entity_mut(e) { + EntityRecord::Removed(entity) => { + if let Some(ec) = render_world.get_entity_mut(entity) { ec.despawn(); }; } + EntityRecord::ComponentRemoved(entity) => { + // It's difficult to remove only the relevant component because component ids aren't stable across worlds, + // so we just clear the entire render world entity. + let mut render_entity = world.get_mut::(entity).unwrap(); + if let Some(render_world_entity) = render_world.get_entity_mut(render_entity.id()) { + render_world_entity.despawn(); + + let id = render_world.spawn(MainEntity(entity)).id(); + render_entity.0 = id; + } + }, } } }); From 32057b2bfa047c8dacd543cf08f5bf4ba7712f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Wed, 2 Oct 2024 12:29:10 +0200 Subject: [PATCH 02/13] more changes --- crates/bevy_pbr/src/lib.rs | 20 ++++---------- .../bevy_pbr/src/light/directional_light.rs | 5 ++-- crates/bevy_pbr/src/light/point_light.rs | 10 ++----- crates/bevy_pbr/src/light/spot_light.rs | 4 +-- crates/bevy_pbr/src/volumetric_fog/mod.rs | 3 +++ crates/bevy_render/src/extract_component.rs | 21 +++------------ crates/bevy_render/src/lib.rs | 1 + crates/bevy_render/src/sync_component.rs | 27 +++++++++++++++++++ crates/bevy_render/src/world_sync.rs | 4 +-- examples/3d/fog_volumes.rs | 5 +--- 10 files changed, 48 insertions(+), 52 deletions(-) create mode 100644 crates/bevy_render/src/sync_component.rs diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 06a01458cbe69..5cbce42572a43 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -124,9 +124,9 @@ use bevy_render::{ render_asset::prepare_assets, render_graph::RenderGraph, render_resource::Shader, + sync_component::SyncComponentPlugin, texture::{GpuImage, Image}, view::{check_visibility, VisibilitySystems}, - world_sync::{EntityRecord, PendingSyncEntity}, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_transform::TransformSystem; @@ -341,6 +341,10 @@ impl Plugin for PbrPlugin { VolumetricFogPlugin, ScreenSpaceReflectionsPlugin, )) + .add_plugins(( + SyncComponentPlugin::::default(), + SyncComponentPlugin::::default(), + )) .configure_sets( PostUpdate, ( @@ -423,20 +427,6 @@ impl Plugin for PbrPlugin { }, ); - app.world_mut() - .register_component_hooks::() - .on_remove(|mut world, entity, _component_id| { - let mut pending = world.resource_mut::(); - pending.push(EntityRecord::ComponentRemoved(entity)); - }); - - app.world_mut() - .register_component_hooks::() - .on_remove(|mut world, entity, _component_id| { - let mut pending = world.resource_mut::(); - pending.push(EntityRecord::ComponentRemoved(entity)); - }); - let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; diff --git a/crates/bevy_pbr/src/light/directional_light.rs b/crates/bevy_pbr/src/light/directional_light.rs index 1c53e924b2edb..3bc8c49cd2c88 100644 --- a/crates/bevy_pbr/src/light/directional_light.rs +++ b/crates/bevy_pbr/src/light/directional_light.rs @@ -1,4 +1,4 @@ -use bevy_render::{view::Visibility, world_sync::SyncToRenderWorld}; +use bevy_render::view::Visibility; use super::*; @@ -57,8 +57,7 @@ use super::*; CascadeShadowConfig, CascadesVisibleEntities, Transform, - Visibility, - SyncToRenderWorld + Visibility )] pub struct DirectionalLight { /// The color of the light. diff --git a/crates/bevy_pbr/src/light/point_light.rs b/crates/bevy_pbr/src/light/point_light.rs index 8b351985a0aa7..a351913aabd86 100644 --- a/crates/bevy_pbr/src/light/point_light.rs +++ b/crates/bevy_pbr/src/light/point_light.rs @@ -1,4 +1,4 @@ -use bevy_render::{view::Visibility, world_sync::SyncToRenderWorld}; +use bevy_render::view::Visibility; use super::*; @@ -21,13 +21,7 @@ use super::*; /// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting) #[derive(Component, Debug, Clone, Copy, Reflect)] #[reflect(Component, Default, Debug)] -#[require( - CubemapFrusta, - CubemapVisibleEntities, - Transform, - Visibility, - SyncToRenderWorld -)] +#[require(CubemapFrusta, CubemapVisibleEntities, Transform, Visibility)] pub struct PointLight { /// The color of this light source. pub color: Color, diff --git a/crates/bevy_pbr/src/light/spot_light.rs b/crates/bevy_pbr/src/light/spot_light.rs index b8345e13e00aa..9b78291b02c4c 100644 --- a/crates/bevy_pbr/src/light/spot_light.rs +++ b/crates/bevy_pbr/src/light/spot_light.rs @@ -1,4 +1,4 @@ -use bevy_render::{view::Visibility, world_sync::SyncToRenderWorld}; +use bevy_render::view::Visibility; use super::*; @@ -9,7 +9,7 @@ use super::*; /// the transform, and can be specified with [`Transform::looking_at`](Transform::looking_at). #[derive(Component, Debug, Clone, Copy, Reflect)] #[reflect(Component, Default, Debug)] -#[require(Frustum, VisibleMeshEntities, Transform, Visibility, SyncToRenderWorld)] +#[require(Frustum, VisibleMeshEntities, Transform, Visibility)] pub struct SpotLight { /// The color of the light. /// diff --git a/crates/bevy_pbr/src/volumetric_fog/mod.rs b/crates/bevy_pbr/src/volumetric_fog/mod.rs index 1636f8734bb8a..7a94a1e135797 100644 --- a/crates/bevy_pbr/src/volumetric_fog/mod.rs +++ b/crates/bevy_pbr/src/volumetric_fog/mod.rs @@ -51,6 +51,7 @@ use bevy_render::{ mesh::{Mesh, Meshable}, render_graph::{RenderGraphApp, ViewNodeRunner}, render_resource::{Shader, SpecializedRenderPipelines}, + sync_component::SyncComponentPlugin, texture::Image, view::{InheritedVisibility, ViewVisibility, Visibility}, ExtractSchedule, Render, RenderApp, RenderSet, @@ -231,6 +232,8 @@ impl Plugin for VolumetricFogPlugin { app.register_type::() .register_type::(); + app.add_plugins(SyncComponentPlugin::::default()); + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_render/src/extract_component.rs index c4c376407693f..0d8848e434f44 100644 --- a/crates/bevy_render/src/extract_component.rs +++ b/crates/bevy_render/src/extract_component.rs @@ -1,8 +1,9 @@ use crate::{ render_resource::{encase::internal::WriteInto, DynamicUniformBuffer, ShaderType}, renderer::{RenderDevice, RenderQueue}, + sync_component::SyncComponentPlugin, view::ViewVisibility, - world_sync::{EntityRecord, PendingSyncEntity, RenderEntity, SyncToRenderWorld}, + world_sync::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_app::{App, Plugin}; @@ -159,15 +160,6 @@ fn prepare_uniform_components( /// This plugin extracts the components into the render world for synced entities. /// /// To do so, it sets up the [`ExtractSchedule`] step for the specified [`ExtractComponent`]. -/// -/// # Warning -/// -/// Be careful when removing the [`ExtractComponent`] from an entity. When an [`ExtractComponent`] -/// is added to an entity, that entity is automatically synced with the render world (see also -/// [`WorldSyncPlugin`](crate::world_sync::WorldSyncPlugin)). When removing the entity in the main -/// world, the synced entity also gets removed. However, if only the [`ExtractComponent`] is removed -/// this *doesn't* happen, and the synced entity stays around with the old extracted data. -/// We recommend despawning the entire entity, instead of only removing [`ExtractComponent`]. pub struct ExtractComponentPlugin { only_extract_visible: bool, marker: PhantomData (C, F)>, @@ -193,14 +185,7 @@ impl ExtractComponentPlugin { impl Plugin for ExtractComponentPlugin { fn build(&self, app: &mut App) { - app.register_required_components::(); - - app.world_mut().register_component_hooks::().on_remove( - |mut world, entity, _component_id| { - let mut pending = world.resource_mut::(); - pending.push(EntityRecord::ComponentRemoved(entity)); - }, - ); + app.add_plugins(SyncComponentPlugin::::default()); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { if self.only_extract_visible { diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 51bd01c612d30..9ad83385f03cf 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -38,6 +38,7 @@ pub mod renderer; pub mod settings; mod spatial_bundle; pub mod storage; +pub mod sync_component; pub mod texture; pub mod view; pub mod world_sync; diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs new file mode 100644 index 0000000000000..63452ebef42bb --- /dev/null +++ b/crates/bevy_render/src/sync_component.rs @@ -0,0 +1,27 @@ +use std::marker::PhantomData; + +use bevy_app::{App, Plugin}; +use bevy_ecs::component::Component; + +use crate::world_sync::{EntityRecord, PendingSyncEntity, SyncToRenderWorld}; + +pub struct SyncComponentPlugin(PhantomData); + +impl Default for SyncComponentPlugin { + fn default() -> Self { + Self(PhantomData) + } +} + +impl Plugin for SyncComponentPlugin { + fn build(&self, app: &mut App) { + app.register_required_components::(); + + app.world_mut().register_component_hooks::().on_remove( + |mut world, entity, _component_id| { + let mut pending = world.resource_mut::(); + pending.push(EntityRecord::ComponentRemoved(entity)); + }, + ); + } +} diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/world_sync.rs index 64dc7e4d0f5fe..febfbcd0ffd1d 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/world_sync.rs @@ -128,7 +128,7 @@ pub struct TemporaryRenderEntity; /// A record enum to what entities with [`SyncToRenderWorld`] have been added or removed. #[derive(Debug)] -pub enum EntityRecord { +pub(crate) enum EntityRecord { /// When an entity is spawned on the main world, notify the render world so that it can spawn a corresponding /// entity. This contains the main world entity. Added(Entity), @@ -142,7 +142,7 @@ pub enum EntityRecord { // Entity Record in MainWorld pending to Sync #[derive(Resource, Default, Deref, DerefMut)] -pub struct PendingSyncEntity { +pub(crate) struct PendingSyncEntity { records: Vec, } diff --git a/examples/3d/fog_volumes.rs b/examples/3d/fog_volumes.rs index c161240b3de67..f0e4da0be0954 100644 --- a/examples/3d/fog_volumes.rs +++ b/examples/3d/fog_volumes.rs @@ -9,7 +9,6 @@ use bevy::{ math::vec3, pbr::{FogVolume, VolumetricFog, VolumetricLight}, prelude::*, - render::world_sync::SyncToRenderWorld, }; /// Entry point. @@ -44,9 +43,7 @@ fn setup(mut commands: Commands, asset_server: Res) { // up. scattering: 1.0, ..default() - }) - // indicates that this fog volume needs to be Synchronized to the render world - .insert(SyncToRenderWorld); + }); // Spawn a bright directional light that illuminates the fog well. commands.spawn(( From bd088a9733309775b7eb26b58eb98cc5c2c891f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Wed, 2 Oct 2024 22:18:27 +0200 Subject: [PATCH 03/13] more fixes --- crates/bevy_pbr/src/lib.rs | 2 +- crates/bevy_pbr/src/render/mesh.rs | 20 ++++++++++++++------ crates/bevy_render/src/gpu_readback.rs | 7 ++++--- crates/bevy_render/src/world_sync.rs | 21 +++++++++++---------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 5cbce42572a43..7dfb1fad05b3b 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -309,7 +309,6 @@ impl Plugin for PbrPlugin { .register_type::() .register_type::() .register_type::() - .register_type::() .register_type::() .init_resource::() .init_resource::() @@ -344,6 +343,7 @@ impl Plugin for PbrPlugin { .add_plugins(( SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), + SyncComponentPlugin::::default(), )) .configure_sets( PostUpdate, diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index c1c9a29129563..df2b206b65a0a 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -37,6 +37,7 @@ use bevy_render::{ prepare_view_targets, GpuCulling, RenderVisibilityRanges, ViewTarget, ViewUniformOffset, ViewVisibility, VisibilityRange, }, + world_sync::RenderEntity, Extract, }; use bevy_transform::components::GlobalTransform; @@ -494,6 +495,7 @@ pub struct RenderMeshInstanceGpu { /// CPU data that the render world needs to keep about each entity that contains /// a mesh. +#[derive(Debug)] pub struct RenderMeshInstanceShared { /// The [`AssetId`] of the mesh. pub mesh_asset_id: AssetId, @@ -549,11 +551,11 @@ pub enum RenderMeshInstanceGpuQueue { /// The version of [`RenderMeshInstanceGpuQueue`] that omits the /// [`MeshCullingData`], so that we don't waste space when GPU /// culling is disabled. - CpuCulling(Vec<(Entity, RenderMeshInstanceGpuBuilder)>), + CpuCulling(Vec<(RenderEntity, RenderMeshInstanceGpuBuilder)>), /// The version of [`RenderMeshInstanceGpuQueue`] that contains the /// [`MeshCullingData`], used when any view has GPU culling /// enabled. - GpuCulling(Vec<(Entity, RenderMeshInstanceGpuBuilder, MeshCullingData)>), + GpuCulling(Vec<(RenderEntity, RenderMeshInstanceGpuBuilder, MeshCullingData)>), } /// The per-thread queues containing mesh instances, populated during the @@ -732,7 +734,7 @@ impl RenderMeshInstanceGpuQueue { /// Adds a new mesh to this queue. fn push( &mut self, - entity: Entity, + entity: RenderEntity, instance_builder: RenderMeshInstanceGpuBuilder, culling_data_builder: Option, ) { @@ -964,6 +966,7 @@ pub fn extract_meshes_for_gpu_building( meshes_query: Extract< Query<( Entity, + &RenderEntity, &ViewVisibility, &GlobalTransform, Option<&PreviousGlobalTransform>, @@ -998,6 +1001,7 @@ pub fn extract_meshes_for_gpu_building( |queue, ( entity, + render_entity, view_visibility, transform, previous_transform, @@ -1056,7 +1060,11 @@ pub fn extract_meshes_for_gpu_building( previous_input_index, }; - queue.push(entity, gpu_mesh_instance_builder, gpu_mesh_culling_data); + queue.push( + *render_entity, + gpu_mesh_instance_builder, + gpu_mesh_culling_data, + ); }, ); } @@ -1129,7 +1137,7 @@ pub fn collect_meshes_for_gpu_building( RenderMeshInstanceGpuQueue::CpuCulling(ref mut queue) => { for (entity, mesh_instance_builder) in queue.drain(..) { mesh_instance_builder.add_to( - entity, + entity.id(), &mut *render_mesh_instances, current_input_buffer, &mesh_allocator, @@ -1139,7 +1147,7 @@ pub fn collect_meshes_for_gpu_building( RenderMeshInstanceGpuQueue::GpuCulling(ref mut queue) => { for (entity, mesh_instance_builder, mesh_culling_builder) in queue.drain(..) { let instance_data_index = mesh_instance_builder.add_to( - entity, + entity.id(), &mut *render_mesh_instances, current_input_buffer, &mesh_allocator, diff --git a/crates/bevy_render/src/gpu_readback.rs b/crates/bevy_render/src/gpu_readback.rs index ffbf83ab11731..81736bb547c75 100644 --- a/crates/bevy_render/src/gpu_readback.rs +++ b/crates/bevy_render/src/gpu_readback.rs @@ -6,6 +6,7 @@ use crate::{ renderer::{render_system, RenderDevice}, storage::{GpuShaderStorageBuffer, ShaderStorageBuffer}, texture::{GpuImage, TextureFormatPixelInfo}, + world_sync::MainEntity, ExtractSchedule, MainWorld, Render, RenderApp, RenderSet, }; use async_channel::{Receiver, Sender}; @@ -232,7 +233,7 @@ fn prepare_buffers( mut buffer_pool: ResMut, gpu_images: Res>, ssbos: Res>, - handles: Query<(Entity, &Readback)>, + handles: Query<(&MainEntity, &Readback)>, ) { for (entity, readback) in handles.iter() { match readback { @@ -254,7 +255,7 @@ fn prepare_buffers( ); let (tx, rx) = async_channel::bounded(1); readbacks.requested.push(GpuReadback { - entity, + entity: entity.id(), src: ReadbackSource::Texture { texture: gpu_image.texture.clone(), layout, @@ -272,7 +273,7 @@ fn prepare_buffers( let buffer = buffer_pool.get(&render_device, size); let (tx, rx) = async_channel::bounded(1); readbacks.requested.push(GpuReadback { - entity, + entity: entity.id(), src: ReadbackSource::Buffer { src_start: 0, dst_start: 0, diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/world_sync.rs index febfbcd0ffd1d..913a84279f587 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/world_sync.rs @@ -86,7 +86,7 @@ impl Plugin for WorldSyncPlugin { mut pending: ResMut, query: Query<&RenderEntity>| { if let Ok(e) = query.get(trigger.entity()) { - pending.push(EntityRecord::Removed(e.id())); + pending.push(EntityRecord::Removed(*e)); }; }, ); @@ -134,7 +134,7 @@ pub(crate) enum EntityRecord { 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(Entity), + Removed(RenderEntity), /// When a component is removed from an entity, notify the render world so that the corresponding component can be /// removed. This contains the main world entity. ComponentRemoved(Entity), @@ -150,10 +150,11 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl main_world.resource_scope(|world, mut pending: Mut| { // TODO : batching record for record in pending.drain(..) { + println!("EntityRecord: {:?}", record); match record { EntityRecord::Added(e) => { - if let Some(mut entity) = world.get_entity_mut(e) { - match entity.entry::() { + if let Some(mut main_entity) = world.get_entity_mut(e) { + match main_entity.entry::() { bevy_ecs::world::Entry::Occupied(_) => { panic!("Attempting to synchronize an entity that has already been synchronized!"); } @@ -165,19 +166,19 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl }; } } - EntityRecord::Removed(entity) => { - if let Some(ec) = render_world.get_entity_mut(entity) { + EntityRecord::Removed(render_entity) => { + if let Some(ec) = render_world.get_entity_mut(render_entity.id()) { ec.despawn(); }; } - EntityRecord::ComponentRemoved(entity) => { + EntityRecord::ComponentRemoved(main_entity) => { // It's difficult to remove only the relevant component because component ids aren't stable across worlds, // so we just clear the entire render world entity. - let mut render_entity = world.get_mut::(entity).unwrap(); + let mut render_entity = world.get_mut::(main_entity).unwrap(); if let Some(render_world_entity) = render_world.get_entity_mut(render_entity.id()) { render_world_entity.despawn(); - let id = render_world.spawn(MainEntity(entity)).id(); + let id = render_world.spawn(MainEntity(main_entity)).id(); render_entity.0 = id; } }, @@ -237,7 +238,7 @@ mod tests { mut pending: ResMut, query: Query<&RenderEntity>| { if let Ok(e) = query.get(trigger.entity()) { - pending.push(EntityRecord::Removed(e.id())); + pending.push(EntityRecord::Removed(*e)); }; }, ); From 831adf2c9ab359b070862bbae78ca1dccb2ebe45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Wed, 2 Oct 2024 22:48:49 +0200 Subject: [PATCH 04/13] ci --- crates/bevy_pbr/src/render/mesh.rs | 1 - crates/bevy_render/src/extract_component.rs | 4 ++-- crates/bevy_render/src/sync_component.rs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index df2b206b65a0a..42598c9c21522 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -495,7 +495,6 @@ pub struct RenderMeshInstanceGpu { /// CPU data that the render world needs to keep about each entity that contains /// a mesh. -#[derive(Debug)] pub struct RenderMeshInstanceShared { /// The [`AssetId`] of the mesh. pub mesh_asset_id: AssetId, diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_render/src/extract_component.rs index 0d8848e434f44..5be7518970197 100644 --- a/crates/bevy_render/src/extract_component.rs +++ b/crates/bevy_render/src/extract_component.rs @@ -208,7 +208,7 @@ impl ExtractComponent for Handle { } } -/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`SyncToRenderWorld`]. +/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`crate::world_sync::SyncToRenderWorld`]. fn extract_components( mut commands: Commands, mut previous_len: Local, @@ -224,7 +224,7 @@ fn extract_components( commands.insert_or_spawn_batch(values); } -/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are visible and synced via [`SyncToRenderWorld`]. +/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are visible and synced via [`crate::world_sync::SyncToRenderWorld`]. fn extract_visible_components( mut commands: Commands, mut previous_len: Local, diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs index 63452ebef42bb..70747f0ca2d40 100644 --- a/crates/bevy_render/src/sync_component.rs +++ b/crates/bevy_render/src/sync_component.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use core::marker::PhantomData; use bevy_app::{App, Plugin}; use bevy_ecs::component::Component; From 642e97ffdf6d91cb6213f3115e56c6a803d1d7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Wed, 2 Oct 2024 22:58:43 +0200 Subject: [PATCH 05/13] fix --- crates/bevy_render/src/world_sync.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/world_sync.rs index 913a84279f587..5f003fb814a16 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/world_sync.rs @@ -150,7 +150,6 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl main_world.resource_scope(|world, mut pending: Mut| { // TODO : batching record for record in pending.drain(..) { - println!("EntityRecord: {:?}", record); match record { EntityRecord::Added(e) => { if let Some(mut main_entity) = world.get_entity_mut(e) { @@ -174,7 +173,9 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl EntityRecord::ComponentRemoved(main_entity) => { // It's difficult to remove only the relevant component because component ids aren't stable across worlds, // so we just clear the entire render world entity. - let mut render_entity = world.get_mut::(main_entity).unwrap(); + let Some(mut render_entity) = world.get_mut::(main_entity) else { + continue; + }; if let Some(render_world_entity) = render_world.get_entity_mut(render_entity.id()) { render_world_entity.despawn(); From 057241a8ac6c18bdfcc477bcc3d74b2892f27f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Sat, 5 Oct 2024 01:34:26 +0200 Subject: [PATCH 06/13] Add some docs --- crates/bevy_render/src/sync_component.rs | 11 +++++++++++ crates/bevy_render/src/world_sync.rs | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs index 70747f0ca2d40..537ec27ebc0f6 100644 --- a/crates/bevy_render/src/sync_component.rs +++ b/crates/bevy_render/src/sync_component.rs @@ -5,6 +5,17 @@ use bevy_ecs::component::Component; use crate::world_sync::{EntityRecord, PendingSyncEntity, SyncToRenderWorld}; +/// Plugin that registers a component for automatic sync to the render world. See [`WorldSyncPlugin`] for more information. +/// +/// This plugin is automatically added by [`ExtractComponentPlugin`], and only needs to be added for manual extraction implementations. +/// +/// # Implementation details +/// +/// It adds [`SyncToRenderWorld`] as a required component to make the [`WorldSyncPlugin`] 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 +/// [`WorldSyncPlugin`]: crate::world_sync::WorldSyncPlugin pub struct SyncComponentPlugin(PhantomData); impl Default for SyncComponentPlugin { diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/world_sync.rs index 5f003fb814a16..efebaabd123a8 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/world_sync.rs @@ -13,6 +13,12 @@ use bevy_reflect::Reflect; /// A plugin that synchronizes entities with [`SyncToRenderWorld`] between the main world and the render world. /// +/// [`SyncToRenderWorld`] is automatically added as a required components by +/// [`ExtractComponentPlugin`] and [`SyncComponentPlugin`], so doesn't need be +/// added manually when spawning or as a required component when either of these are used. +/// +/// # Implementation +/// /// Bevy's renderer is architected independently from the main app. /// It operates in its own separate ECS [`World`], so the renderer logic can run in parallel with the main world logic. /// This is called "Pipelined Rendering", see [`PipelinedRenderingPlugin`] for more information. @@ -70,6 +76,8 @@ use bevy_reflect::Reflect; /// differently. /// /// [`PipelinedRenderingPlugin`]: crate::pipelined_rendering::PipelinedRenderingPlugin +/// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin +/// [`SyncComponentPlugin`]: crate::sync_component::SyncComponentPlugin #[derive(Default)] pub struct WorldSyncPlugin; @@ -102,6 +110,8 @@ impl Plugin for WorldSyncPlugin { pub struct SyncToRenderWorld; /// 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 +/// +/// Can also be used as a newtype wrapper for render world entities. #[derive(Component, Deref, Clone, Debug, Copy)] pub struct RenderEntity(Entity); impl RenderEntity { @@ -112,6 +122,8 @@ impl RenderEntity { } /// Component added on the render 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, Clone, Debug)] pub struct MainEntity(Entity); impl MainEntity { @@ -171,12 +183,12 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl }; } EntityRecord::ComponentRemoved(main_entity) => { - // It's difficult to remove only the relevant component because component ids aren't stable across worlds, - // so we just clear the entire render world entity. let Some(mut render_entity) = world.get_mut::(main_entity) else { continue; }; if let Some(render_world_entity) = render_world.get_entity_mut(render_entity.id()) { + // In order to handle components that extract to derived components, we clear the entity + // and let the extraction system re-add the components. render_world_entity.despawn(); let id = render_world.spawn(MainEntity(main_entity)).id(); From f66517bd5a9f6ba4939643f301d953b0bd4d058b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Sat, 5 Oct 2024 01:39:51 +0200 Subject: [PATCH 07/13] more docs --- crates/bevy_render/src/sync_component.rs | 3 +++ crates/bevy_render/src/world_sync.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs index 537ec27ebc0f6..1fdd1dca0bb60 100644 --- a/crates/bevy_render/src/sync_component.rs +++ b/crates/bevy_render/src/sync_component.rs @@ -14,6 +14,9 @@ use crate::world_sync::{EntityRecord, PendingSyncEntity, SyncToRenderWorld}; /// It adds [`SyncToRenderWorld`] as a required component to make the [`WorldSyncPlugin`] aware of the component, and /// handles cleanup of the component in the render world when it is removed from an entity. /// +/// NOTE: When the component is removed from the main world entity, all components are removed from the entity in the render world. +/// This is in order to handle components with custom extraction logic. +/// /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin /// [`WorldSyncPlugin`]: crate::world_sync::WorldSyncPlugin pub struct SyncComponentPlugin(PhantomData); diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/world_sync.rs index efebaabd123a8..3fea5212ef34d 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/world_sync.rs @@ -14,7 +14,7 @@ use bevy_reflect::Reflect; /// A plugin that synchronizes entities with [`SyncToRenderWorld`] between the main world and the render world. /// /// [`SyncToRenderWorld`] is automatically added as a required components by -/// [`ExtractComponentPlugin`] and [`SyncComponentPlugin`], so doesn't need be +/// [`ExtractComponentPlugin`] and [`SyncComponentPlugin`], so it doesn't need be /// added manually when spawning or as a required component when either of these are used. /// /// # Implementation From 54dc0247900f58ea7b0991ec843872f303cfefb1 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Tue, 8 Oct 2024 09:05:05 -0400 Subject: [PATCH 08/13] Typos Co-authored-by: Trashtalk217 --- crates/bevy_render/src/world_sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/world_sync.rs index 3fea5212ef34d..55e3533d733bc 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/world_sync.rs @@ -13,8 +13,8 @@ use bevy_reflect::Reflect; /// A plugin that synchronizes entities with [`SyncToRenderWorld`] between the main world and the render world. /// -/// [`SyncToRenderWorld`] is automatically added as a required components by -/// [`ExtractComponentPlugin`] and [`SyncComponentPlugin`], so it doesn't need be +/// [`SyncToRenderWorld`] 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 are used. /// /// # Implementation From d85d5efcd8c3498aa19569ed421e7b5753fbb312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Tue, 8 Oct 2024 19:55:06 +0200 Subject: [PATCH 09/13] More docs --- crates/bevy_render/src/sync_component.rs | 5 +++-- crates/bevy_render/src/world_sync.rs | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs index 1fdd1dca0bb60..8d5b399556ee6 100644 --- a/crates/bevy_render/src/sync_component.rs +++ b/crates/bevy_render/src/sync_component.rs @@ -14,8 +14,9 @@ use crate::world_sync::{EntityRecord, PendingSyncEntity, SyncToRenderWorld}; /// It adds [`SyncToRenderWorld`] as a required component to make the [`WorldSyncPlugin`] aware of the component, and /// handles cleanup of the component in the render world when it is removed from an entity. /// -/// NOTE: When the component is removed from the main world entity, all components are removed from the entity in the render world. -/// This is in order to handle components with custom extraction logic. +/// # Warning +/// When the component is removed from the main world entity, all components are removed from the entity in the render world. +/// This is done in order to handle components with custom extraction logic and derived state. /// /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin /// [`WorldSyncPlugin`]: crate::world_sync::WorldSyncPlugin diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/world_sync.rs index 71e9c2e64cb81..e73fc62768c41 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/world_sync.rs @@ -13,9 +13,10 @@ use bevy_reflect::Reflect; /// A plugin that synchronizes entities with [`SyncToRenderWorld`] between the main world and the render world. /// -/// [`SyncToRenderWorld`] 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 are used. +/// All entities with the [`SyncToRenderWorld`] 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. /// /// # Implementation /// @@ -100,16 +101,22 @@ impl Plugin for WorldSyncPlugin { ); } } -/// 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 render world. +/// +/// This component is automatically added as a required component by [`ExtractComponentPlugin`] and [`SyncComponentPlugin`]. +/// For more information see [`SyncWorldPlugin`]. /// /// NOTE: This component should persist throughout the entity's entire lifecycle. /// If this component is removed from its entity, the entity will be despawned. +/// +/// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin +/// [`SyncComponentPlugin`]: crate::sync_component::SyncComponentPlugin #[derive(Component, Clone, Debug, Default, Reflect)] #[reflect[Component]] #[component(storage = "SparseSet")] pub struct SyncToRenderWorld; -/// 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 Render World in order to keep track of the corresponding render world entity. /// /// Can also be used as a newtype wrapper for render world entities. #[derive(Component, Deref, Clone, Debug, Copy)] @@ -121,7 +128,7 @@ impl RenderEntity { } } -/// Component added on the render world entities to keep track of the corresponding main world entity +/// Component added on the render 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, Clone, Debug)] From 9fca5c973965f4409e9551334cbf0f5033225415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Tue, 8 Oct 2024 19:38:53 +0200 Subject: [PATCH 10/13] Rename WorldSync to SyncWorld --- crates/bevy_core_pipeline/src/auto_exposure/buffers.rs | 2 +- crates/bevy_core_pipeline/src/core_2d/camera_2d.rs | 2 +- crates/bevy_core_pipeline/src/core_2d/mod.rs | 2 +- crates/bevy_core_pipeline/src/core_3d/camera_3d.rs | 2 +- crates/bevy_core_pipeline/src/core_3d/mod.rs | 2 +- crates/bevy_core_pipeline/src/dof/mod.rs | 2 +- crates/bevy_core_pipeline/src/taa/mod.rs | 2 +- crates/bevy_gizmos/src/lib.rs | 2 +- crates/bevy_pbr/src/bundle.rs | 2 +- crates/bevy_pbr/src/cluster/mod.rs | 2 +- crates/bevy_pbr/src/light_probe/mod.rs | 2 +- crates/bevy_pbr/src/prepass/mod.rs | 2 +- crates/bevy_pbr/src/render/light.rs | 2 +- crates/bevy_pbr/src/render/mesh.rs | 2 +- crates/bevy_pbr/src/ssao/mod.rs | 2 +- crates/bevy_pbr/src/volumetric_fog/render.rs | 2 +- crates/bevy_render/src/camera/camera.rs | 2 +- crates/bevy_render/src/extract_component.rs | 6 +++--- crates/bevy_render/src/gpu_readback.rs | 2 +- crates/bevy_render/src/lib.rs | 8 ++++---- crates/bevy_render/src/pipelined_rendering.rs | 6 +++--- crates/bevy_render/src/sync_component.rs | 8 ++++---- .../bevy_render/src/{world_sync.rs => sync_world.rs} | 10 +++++----- crates/bevy_sprite/src/bundle.rs | 2 +- crates/bevy_sprite/src/render/mod.rs | 2 +- crates/bevy_text/src/text2d.rs | 2 +- crates/bevy_ui/src/render/mod.rs | 2 +- crates/bevy_ui/src/render/ui_material_pipeline.rs | 2 +- crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs | 2 +- 29 files changed, 43 insertions(+), 43 deletions(-) rename crates/bevy_render/src/{world_sync.rs => sync_world.rs} (98%) diff --git a/crates/bevy_core_pipeline/src/auto_exposure/buffers.rs b/crates/bevy_core_pipeline/src/auto_exposure/buffers.rs index 4991a0925bee9..459a072406c3b 100644 --- a/crates/bevy_core_pipeline/src/auto_exposure/buffers.rs +++ b/crates/bevy_core_pipeline/src/auto_exposure/buffers.rs @@ -2,7 +2,7 @@ use bevy_ecs::prelude::*; use bevy_render::{ render_resource::{StorageBuffer, UniformBuffer}, renderer::{RenderDevice, RenderQueue}, - world_sync::RenderEntity, + sync_world::RenderEntity, Extract, }; use bevy_utils::{Entry, HashMap}; diff --git a/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs b/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs index 5e3ef674d3bdf..9f8073e3f51df 100644 --- a/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs +++ b/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs @@ -6,7 +6,7 @@ use crate::{ }; use bevy_ecs::prelude::*; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; -use bevy_render::world_sync::SyncToRenderWorld; +use bevy_render::sync_world::SyncToRenderWorld; use bevy_render::{ camera::{ Camera, CameraMainTextureUsages, CameraProjection, CameraRenderGraph, diff --git a/crates/bevy_core_pipeline/src/core_2d/mod.rs b/crates/bevy_core_pipeline/src/core_2d/mod.rs index 9f07f19bf8a81..a4227fc23cd7c 100644 --- a/crates/bevy_core_pipeline/src/core_2d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_2d/mod.rs @@ -57,7 +57,7 @@ use bevy_render::{ renderer::RenderDevice, texture::TextureCache, view::{Msaa, ViewDepthTexture}, - world_sync::RenderEntity, + sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; diff --git a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs index 81955f76b361e..e2ba8e718ed14 100644 --- a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs +++ b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs @@ -12,7 +12,7 @@ use bevy_render::{ primitives::Frustum, render_resource::{LoadOp, TextureUsages}, view::{ColorGrading, Msaa, VisibleEntities}, - world_sync::SyncToRenderWorld, + sync_world::SyncToRenderWorld, }; use bevy_transform::prelude::{GlobalTransform, Transform}; use serde::{Deserialize, Serialize}; diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index 0c94bc6767e38..c17a7e7bd92da 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -91,7 +91,7 @@ use bevy_render::{ renderer::RenderDevice, texture::{BevyDefault, ColorAttachment, Image, TextureCache}, view::{ExtractedView, ViewDepthTexture, ViewTarget}, - world_sync::RenderEntity, + sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_utils::{tracing::warn, HashMap}; diff --git a/crates/bevy_core_pipeline/src/dof/mod.rs b/crates/bevy_core_pipeline/src/dof/mod.rs index 76087b63a69bd..6b7f7f40805ea 100644 --- a/crates/bevy_core_pipeline/src/dof/mod.rs +++ b/crates/bevy_core_pipeline/src/dof/mod.rs @@ -51,7 +51,7 @@ use bevy_render::{ prepare_view_targets, ExtractedView, Msaa, ViewDepthTexture, ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms, }, - world_sync::RenderEntity, + sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_utils::{info_once, prelude::default, warn_once}; diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index d5b66a51b8d3c..c43bb323fe0b2 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -34,7 +34,7 @@ use bevy_render::{ renderer::{RenderContext, RenderDevice}, texture::{BevyDefault, CachedTexture, TextureCache}, view::{ExtractedView, Msaa, ViewTarget}, - world_sync::RenderEntity, + sync_world::RenderEntity, ExtractSchedule, MainWorld, Render, RenderApp, RenderSet, }; use bevy_utils::tracing::warn; diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index b94930ee0331d..e5f8e7b086de9 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -105,7 +105,7 @@ use { ShaderStages, ShaderType, VertexFormat, }, renderer::RenderDevice, - world_sync::TemporaryRenderEntity, + sync_world::TemporaryRenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }, bytemuck::cast_slice, diff --git a/crates/bevy_pbr/src/bundle.rs b/crates/bevy_pbr/src/bundle.rs index 55cdb3609a892..60e461da4aef9 100644 --- a/crates/bevy_pbr/src/bundle.rs +++ b/crates/bevy_pbr/src/bundle.rs @@ -16,7 +16,7 @@ use bevy_render::{ mesh::Mesh3d, primitives::{CascadesFrusta, CubemapFrusta, Frustum}, view::{InheritedVisibility, ViewVisibility, Visibility}, - world_sync::SyncToRenderWorld, + sync_world::SyncToRenderWorld, }; use bevy_transform::components::{GlobalTransform, Transform}; diff --git a/crates/bevy_pbr/src/cluster/mod.rs b/crates/bevy_pbr/src/cluster/mod.rs index 375861e294907..ce54c20a8acd2 100644 --- a/crates/bevy_pbr/src/cluster/mod.rs +++ b/crates/bevy_pbr/src/cluster/mod.rs @@ -20,7 +20,7 @@ use bevy_render::{ UniformBuffer, }, renderer::{RenderDevice, RenderQueue}, - world_sync::RenderEntity, + sync_world::RenderEntity, Extract, }; use bevy_utils::{hashbrown::HashSet, tracing::warn}; diff --git a/crates/bevy_pbr/src/light_probe/mod.rs b/crates/bevy_pbr/src/light_probe/mod.rs index 2bfd2408a9fe4..14d2fd7339618 100644 --- a/crates/bevy_pbr/src/light_probe/mod.rs +++ b/crates/bevy_pbr/src/light_probe/mod.rs @@ -23,7 +23,7 @@ use bevy_render::{ settings::WgpuFeatures, texture::{FallbackImage, GpuImage, Image}, view::ExtractedView, - world_sync::RenderEntity, + sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_transform::{components::Transform, prelude::GlobalTransform}; diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index dc4bb77be1325..f3f6fcbb04d8e 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -3,7 +3,7 @@ mod prepass_bindings; use bevy_render::{ mesh::{Mesh3d, MeshVertexBufferLayoutRef, RenderMesh}, render_resource::binding_types::uniform_buffer, - world_sync::RenderEntity, + sync_world::RenderEntity, }; pub use prepass_bindings::*; diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 584c6f4fef433..18a5a0955d6a3 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -8,7 +8,7 @@ use bevy_ecs::{ system::lifetimeless::Read, }; use bevy_math::{ops, Mat4, UVec4, Vec2, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; -use bevy_render::world_sync::RenderEntity; +use bevy_render::sync_world::RenderEntity; use bevy_render::{ diagnostic::RecordDiagnostics, mesh::RenderMesh, diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 0648309224a52..40e1accd476b3 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -33,12 +33,12 @@ use bevy_render::{ }, render_resource::*, renderer::{RenderDevice, RenderQueue}, + sync_world::RenderEntity, texture::{BevyDefault, DefaultImageSampler, ImageSampler, TextureFormatPixelInfo}, view::{ prepare_view_targets, GpuCulling, RenderVisibilityRanges, ViewTarget, ViewUniformOffset, ViewVisibility, VisibilityRange, }, - world_sync::RenderEntity, Extract, }; use bevy_transform::components::GlobalTransform; diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index b81a013d65f33..b813ecaeff6f4 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -32,7 +32,7 @@ use bevy_render::{ renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue}, texture::{CachedTexture, TextureCache}, view::{Msaa, ViewUniform, ViewUniformOffset, ViewUniforms}, - world_sync::RenderEntity, + sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_utils::{ diff --git a/crates/bevy_pbr/src/volumetric_fog/render.rs b/crates/bevy_pbr/src/volumetric_fog/render.rs index ae1e0e7f81bc3..e8eb0b01e4d95 100644 --- a/crates/bevy_pbr/src/volumetric_fog/render.rs +++ b/crates/bevy_pbr/src/volumetric_fog/render.rs @@ -38,7 +38,7 @@ use bevy_render::{ renderer::{RenderContext, RenderDevice, RenderQueue}, texture::{BevyDefault as _, GpuImage, Image}, view::{ExtractedView, Msaa, ViewDepthTexture, ViewTarget, ViewUniformOffset}, - world_sync::RenderEntity, + sync_world::RenderEntity, Extract, }; use bevy_transform::components::GlobalTransform; diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index b34dcb4717f65..dfbdd43c25513 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -11,7 +11,7 @@ use crate::{ ColorGrading, ExtractedView, ExtractedWindows, GpuCulling, Msaa, RenderLayers, Visibility, VisibleEntities, }, - world_sync::{RenderEntity, SyncToRenderWorld}, + sync_world::{RenderEntity, SyncToRenderWorld}, Extract, }; use bevy_asset::{AssetEvent, AssetId, Assets, Handle}; diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_render/src/extract_component.rs index 5be7518970197..29c9d229abf62 100644 --- a/crates/bevy_render/src/extract_component.rs +++ b/crates/bevy_render/src/extract_component.rs @@ -2,8 +2,8 @@ use crate::{ render_resource::{encase::internal::WriteInto, DynamicUniformBuffer, ShaderType}, renderer::{RenderDevice, RenderQueue}, sync_component::SyncComponentPlugin, + sync_world::RenderEntity, view::ViewVisibility, - world_sync::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_app::{App, Plugin}; @@ -208,7 +208,7 @@ impl ExtractComponent for Handle { } } -/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`crate::world_sync::SyncToRenderWorld`]. +/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`crate::sync_world::SyncToRenderWorld`]. fn extract_components( mut commands: Commands, mut previous_len: Local, @@ -224,7 +224,7 @@ fn extract_components( commands.insert_or_spawn_batch(values); } -/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are visible and synced via [`crate::world_sync::SyncToRenderWorld`]. +/// 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( mut commands: Commands, mut previous_len: Local, diff --git a/crates/bevy_render/src/gpu_readback.rs b/crates/bevy_render/src/gpu_readback.rs index 81736bb547c75..55ade09edca00 100644 --- a/crates/bevy_render/src/gpu_readback.rs +++ b/crates/bevy_render/src/gpu_readback.rs @@ -6,7 +6,7 @@ use crate::{ renderer::{render_system, RenderDevice}, storage::{GpuShaderStorageBuffer, ShaderStorageBuffer}, texture::{GpuImage, TextureFormatPixelInfo}, - world_sync::MainEntity, + sync_world::MainEntity, ExtractSchedule, MainWorld, Render, RenderApp, RenderSet, }; use async_channel::{Receiver, Sender}; diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 1b9fbb786c629..a682f2b954413 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -39,9 +39,9 @@ pub mod settings; mod spatial_bundle; pub mod storage; pub mod sync_component; +pub mod sync_world; pub mod texture; pub mod view; -pub mod world_sync; /// The render prelude. /// @@ -78,8 +78,8 @@ use extract_resource::ExtractResourcePlugin; use globals::GlobalsPlugin; use render_asset::RenderAssetBytesPerFrame; use renderer::{RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue}; -use world_sync::{ - despawn_temporary_render_entities, entity_sync_system, SyncToRenderWorld, WorldSyncPlugin, +use sync_world::{ + despawn_temporary_render_entities, entity_sync_system, SyncToRenderWorld, SyncWorldPlugin, }; use crate::gpu_readback::GpuReadbackPlugin; @@ -372,7 +372,7 @@ impl Plugin for RenderPlugin { GlobalsPlugin, MorphPlugin, BatchingPlugin, - WorldSyncPlugin, + SyncWorldPlugin, StoragePlugin, GpuReadbackPlugin::default(), )); diff --git a/crates/bevy_render/src/pipelined_rendering.rs b/crates/bevy_render/src/pipelined_rendering.rs index f17209665b7b5..41279e7d25db1 100644 --- a/crates/bevy_render/src/pipelined_rendering.rs +++ b/crates/bevy_render/src/pipelined_rendering.rs @@ -81,7 +81,7 @@ impl Drop for RenderAppChannels { /// The plugin is dependent on the [`RenderApp`] added by [`crate::RenderPlugin`] and so must /// be added after that plugin. If it is not added after, the plugin will do nothing. /// -/// A single frame of execution looks something like below +/// A single frame of execution looks something like below /// /// ```text /// |---------------------------------------------------------------------------| @@ -92,7 +92,7 @@ impl Drop for RenderAppChannels { /// ``` /// /// - `sync` is the step where the entity-entity mapping between the main and render world is updated. -/// This is run on the main app's thread. For more information checkout [`WorldSyncPlugin`]. +/// This is run on the main app's thread. For more information checkout [`SyncWorldPlugin`]. /// - `extract` is the step where data is copied from the main world to the render world. /// This is run on the main app's thread. /// - On the render thread, we first apply the `extract commands`. This is not run during extract, so the @@ -104,7 +104,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. /// -/// [`WorldSyncPlugin`]: crate::world_sync::WorldSyncPlugin +/// [`SyncWorldPlugin`]: crate::sync_world::SyncWorldPlugin #[derive(Default)] pub struct PipelinedRenderingPlugin; diff --git a/crates/bevy_render/src/sync_component.rs b/crates/bevy_render/src/sync_component.rs index 8d5b399556ee6..0fac10b409a17 100644 --- a/crates/bevy_render/src/sync_component.rs +++ b/crates/bevy_render/src/sync_component.rs @@ -3,15 +3,15 @@ use core::marker::PhantomData; use bevy_app::{App, Plugin}; use bevy_ecs::component::Component; -use crate::world_sync::{EntityRecord, PendingSyncEntity, SyncToRenderWorld}; +use crate::sync_world::{EntityRecord, PendingSyncEntity, SyncToRenderWorld}; -/// Plugin that registers a component for automatic sync to the render world. See [`WorldSyncPlugin`] for more information. +/// Plugin that registers a component for automatic sync to the render world. See [`SyncWorldPlugin`] for more information. /// /// This plugin is automatically added by [`ExtractComponentPlugin`], and only needs to be added for manual extraction implementations. /// /// # Implementation details /// -/// It adds [`SyncToRenderWorld`] as a required component to make the [`WorldSyncPlugin`] aware of the component, and +/// It adds [`SyncToRenderWorld`] 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. /// /// # Warning @@ -19,7 +19,7 @@ use crate::world_sync::{EntityRecord, PendingSyncEntity, SyncToRenderWorld}; /// This is done in order to handle components with custom extraction logic and derived state. /// /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin -/// [`WorldSyncPlugin`]: crate::world_sync::WorldSyncPlugin +/// [`SyncWorldPlugin`]: crate::sync_world::SyncWorldPlugin pub struct SyncComponentPlugin(PhantomData); impl Default for SyncComponentPlugin { diff --git a/crates/bevy_render/src/world_sync.rs b/crates/bevy_render/src/sync_world.rs similarity index 98% rename from crates/bevy_render/src/world_sync.rs rename to crates/bevy_render/src/sync_world.rs index e73fc62768c41..c60220f772603 100644 --- a/crates/bevy_render/src/world_sync.rs +++ b/crates/bevy_render/src/sync_world.rs @@ -24,7 +24,7 @@ use bevy_reflect::Reflect; /// It operates in its own separate ECS [`World`], so the renderer logic can run in parallel with the main world logic. /// This is called "Pipelined Rendering", see [`PipelinedRenderingPlugin`] for more information. /// -/// [`WorldSyncPlugin`] is the first thing that runs every frame and it maintains an entity-to-entity mapping +/// [`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. @@ -73,16 +73,16 @@ use bevy_reflect::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, [`WorldSyncPlugin`] only synchronizes *entities*. [`RenderAsset`](crate::render_asset::RenderAsset)s like meshes and textures are handled +/// Moreover, [`SyncWorldPlugin`] only synchronizes *entities*. [`RenderAsset`](crate::render_asset::RenderAsset)s like meshes and textures are handled /// differently. /// /// [`PipelinedRenderingPlugin`]: crate::pipelined_rendering::PipelinedRenderingPlugin /// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin /// [`SyncComponentPlugin`]: crate::sync_component::SyncComponentPlugin #[derive(Default)] -pub struct WorldSyncPlugin; +pub struct SyncWorldPlugin; -impl Plugin for WorldSyncPlugin { +impl Plugin for SyncWorldPlugin { fn build(&self, app: &mut bevy_app::App) { app.init_resource::(); app.observe( @@ -243,7 +243,7 @@ mod tests { struct RenderDataComponent; #[test] - fn world_sync() { + fn sync_world() { let mut main_world = World::new(); let mut render_world = World::new(); main_world.init_resource::(); diff --git a/crates/bevy_sprite/src/bundle.rs b/crates/bevy_sprite/src/bundle.rs index df9e99e622dee..94ca30fc9b70b 100644 --- a/crates/bevy_sprite/src/bundle.rs +++ b/crates/bevy_sprite/src/bundle.rs @@ -4,7 +4,7 @@ use bevy_ecs::bundle::Bundle; use bevy_render::{ texture::Image, view::{InheritedVisibility, ViewVisibility, Visibility}, - world_sync::SyncToRenderWorld, + sync_world::SyncToRenderWorld, }; use bevy_transform::components::{GlobalTransform, Transform}; diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 63b025d5a6747..ddef9b173958a 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -39,7 +39,7 @@ use bevy_render::{ ExtractedView, Msaa, ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms, ViewVisibility, VisibleEntities, }, - world_sync::{RenderEntity, TemporaryRenderEntity}, + sync_world::{RenderEntity, TemporaryRenderEntity}, Extract, }; use bevy_transform::components::GlobalTransform; diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 646e28a748e12..db175fd09d436 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -15,7 +15,7 @@ use bevy_ecs::{ system::{Commands, Local, Query, Res, ResMut}, }; use bevy_math::Vec2; -use bevy_render::world_sync::TemporaryRenderEntity; +use bevy_render::sync_world::TemporaryRenderEntity; use bevy_render::{ primitives::Aabb, texture::Image, diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 18b8022860fd3..a78ab64201b3f 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -34,7 +34,7 @@ use bevy_render::{ render_phase::{PhaseItem, PhaseItemExtraIndex}, texture::GpuImage, view::ViewVisibility, - world_sync::{RenderEntity, TemporaryRenderEntity}, + sync_world::{RenderEntity, TemporaryRenderEntity}, ExtractSchedule, Render, }; use bevy_sprite::TextureAtlasLayout; diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index 71cbb2dcb4fb0..525f5ce2ba041 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -20,7 +20,7 @@ use bevy_render::{ renderer::{RenderDevice, RenderQueue}, texture::BevyDefault, view::*, - world_sync::{RenderEntity, TemporaryRenderEntity}, + sync_world::{RenderEntity, TemporaryRenderEntity}, Extract, ExtractSchedule, Render, RenderSet, }; use bevy_transform::prelude::GlobalTransform; diff --git a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs index 9811376a32fa4..233218216f7ad 100644 --- a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs @@ -18,7 +18,7 @@ use bevy_render::{ renderer::{RenderDevice, RenderQueue}, texture::{BevyDefault, GpuImage, Image, TRANSPARENT_IMAGE_HANDLE}, view::*, - world_sync::{RenderEntity, TemporaryRenderEntity}, + sync_world::{RenderEntity, TemporaryRenderEntity}, Extract, ExtractSchedule, Render, RenderSet, }; use bevy_sprite::{ From 3f8e74d7689e779636a802d1d4ba9b411a7af70b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Tue, 8 Oct 2024 20:22:19 +0200 Subject: [PATCH 11/13] Fixes --- crates/bevy_render/src/extract_param.rs | 2 +- crates/bevy_render/src/sync_world.rs | 2 +- crates/bevy_ui/src/render/box_shadow.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_render/src/extract_param.rs b/crates/bevy_render/src/extract_param.rs index 801a6b2d1c20d..ca86ba3a40fe2 100644 --- a/crates/bevy_render/src/extract_param.rs +++ b/crates/bevy_render/src/extract_param.rs @@ -30,7 +30,7 @@ use core::ops::{Deref, DerefMut}; /// ``` /// use bevy_ecs::prelude::*; /// use bevy_render::Extract; -/// use bevy_render::world_sync::RenderEntity; +/// use bevy_render::sync_world::RenderEntity; /// # #[derive(Component)] /// // Do make sure to sync the cloud entities before extracting them. /// # struct Cloud; diff --git a/crates/bevy_render/src/sync_world.rs b/crates/bevy_render/src/sync_world.rs index c60220f772603..3ee9f25fbdbe5 100644 --- a/crates/bevy_render/src/sync_world.rs +++ b/crates/bevy_render/src/sync_world.rs @@ -193,7 +193,7 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl let Some(mut render_entity) = world.get_mut::(main_entity) else { continue; }; - if let Some(render_world_entity) = render_world.get_entity_mut(render_entity.id()) { + if let Ok(render_world_entity) = render_world.get_entity_mut(render_entity.id()) { // In order to handle components that extract to derived components, we clear the entity // and let the extraction system re-add the components. render_world_entity.despawn(); diff --git a/crates/bevy_ui/src/render/box_shadow.rs b/crates/bevy_ui/src/render/box_shadow.rs index a53f07b99544b..8f56581ce6f9d 100644 --- a/crates/bevy_ui/src/render/box_shadow.rs +++ b/crates/bevy_ui/src/render/box_shadow.rs @@ -19,9 +19,9 @@ use bevy_render::{ render_phase::*, render_resource::{binding_types::uniform_buffer, *}, renderer::{RenderDevice, RenderQueue}, + sync_world::{RenderEntity, TemporaryRenderEntity}, texture::BevyDefault, view::*, - world_sync::{RenderEntity, TemporaryRenderEntity}, Extract, ExtractSchedule, Render, RenderSet, }; use bevy_transform::prelude::GlobalTransform; From 6a16c6098b4bc50fce5b5f3e28ef04d311c8bfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Tue, 8 Oct 2024 21:47:49 +0200 Subject: [PATCH 12/13] A previous fix broke for reasons I dont understand --- crates/bevy_pbr/src/render/mesh.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 40e1accd476b3..1f8836ff87b2f 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -33,7 +33,6 @@ use bevy_render::{ }, render_resource::*, renderer::{RenderDevice, RenderQueue}, - sync_world::RenderEntity, texture::{BevyDefault, DefaultImageSampler, ImageSampler, TextureFormatPixelInfo}, view::{ prepare_view_targets, GpuCulling, RenderVisibilityRanges, ViewTarget, ViewUniformOffset, @@ -558,11 +557,11 @@ pub enum RenderMeshInstanceGpuQueue { /// The version of [`RenderMeshInstanceGpuQueue`] that omits the /// [`MeshCullingData`], so that we don't waste space when GPU /// culling is disabled. - CpuCulling(Vec<(RenderEntity, RenderMeshInstanceGpuBuilder)>), + CpuCulling(Vec<(Entity, RenderMeshInstanceGpuBuilder)>), /// The version of [`RenderMeshInstanceGpuQueue`] that contains the /// [`MeshCullingData`], used when any view has GPU culling /// enabled. - GpuCulling(Vec<(RenderEntity, RenderMeshInstanceGpuBuilder, MeshCullingData)>), + GpuCulling(Vec<(Entity, RenderMeshInstanceGpuBuilder, MeshCullingData)>), } /// The per-thread queues containing mesh instances, populated during the @@ -740,7 +739,7 @@ impl RenderMeshInstanceGpuQueue { /// Adds a new mesh to this queue. fn push( &mut self, - entity: RenderEntity, + entity: Entity, instance_builder: RenderMeshInstanceGpuBuilder, culling_data_builder: Option, ) { @@ -972,7 +971,6 @@ pub fn extract_meshes_for_gpu_building( meshes_query: Extract< Query<( Entity, - &RenderEntity, &ViewVisibility, &GlobalTransform, Option<&PreviousGlobalTransform>, @@ -1007,7 +1005,6 @@ pub fn extract_meshes_for_gpu_building( |queue, ( entity, - render_entity, view_visibility, transform, previous_transform, @@ -1066,11 +1063,7 @@ pub fn extract_meshes_for_gpu_building( previous_input_index, }; - queue.push( - *render_entity, - gpu_mesh_instance_builder, - gpu_mesh_culling_data, - ); + queue.push(entity, gpu_mesh_instance_builder, gpu_mesh_culling_data); }, ); } @@ -1143,7 +1136,7 @@ pub fn collect_meshes_for_gpu_building( RenderMeshInstanceGpuQueue::CpuCulling(ref mut queue) => { for (entity, mesh_instance_builder) in queue.drain(..) { mesh_instance_builder.add_to( - entity.id(), + entity, &mut *render_mesh_instances, current_input_buffer, &mesh_allocator, @@ -1153,7 +1146,7 @@ pub fn collect_meshes_for_gpu_building( RenderMeshInstanceGpuQueue::GpuCulling(ref mut queue) => { for (entity, mesh_instance_builder, mesh_culling_builder) in queue.drain(..) { let instance_data_index = mesh_instance_builder.add_to( - entity.id(), + entity, &mut *render_mesh_instances, current_input_buffer, &mesh_allocator, From f0fef727cfa3249a4ea68407d21d00ec66024170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Tue, 8 Oct 2024 21:56:55 +0200 Subject: [PATCH 13/13] format --- crates/bevy_core_pipeline/src/core_2d/mod.rs | 2 +- crates/bevy_core_pipeline/src/core_3d/camera_3d.rs | 2 +- crates/bevy_core_pipeline/src/core_3d/mod.rs | 2 +- crates/bevy_core_pipeline/src/dof/mod.rs | 2 +- crates/bevy_core_pipeline/src/taa/mod.rs | 2 +- crates/bevy_pbr/src/bundle.rs | 2 +- crates/bevy_pbr/src/light_probe/mod.rs | 2 +- crates/bevy_pbr/src/ssao/mod.rs | 2 +- crates/bevy_pbr/src/volumetric_fog/render.rs | 2 +- crates/bevy_render/src/camera/camera.rs | 2 +- crates/bevy_render/src/gpu_readback.rs | 2 +- crates/bevy_sprite/src/bundle.rs | 2 +- crates/bevy_sprite/src/render/mod.rs | 2 +- crates/bevy_ui/src/render/mod.rs | 2 +- crates/bevy_ui/src/render/ui_material_pipeline.rs | 2 +- crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/bevy_core_pipeline/src/core_2d/mod.rs b/crates/bevy_core_pipeline/src/core_2d/mod.rs index a4227fc23cd7c..c621ebc7fd215 100644 --- a/crates/bevy_core_pipeline/src/core_2d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_2d/mod.rs @@ -55,9 +55,9 @@ use bevy_render::{ TextureFormat, TextureUsages, }, renderer::RenderDevice, + sync_world::RenderEntity, texture::TextureCache, view::{Msaa, ViewDepthTexture}, - sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; diff --git a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs index e2ba8e718ed14..3b60d8fde6b06 100644 --- a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs +++ b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs @@ -11,8 +11,8 @@ use bevy_render::{ extract_component::ExtractComponent, primitives::Frustum, render_resource::{LoadOp, TextureUsages}, - view::{ColorGrading, Msaa, VisibleEntities}, sync_world::SyncToRenderWorld, + view::{ColorGrading, Msaa, VisibleEntities}, }; use bevy_transform::prelude::{GlobalTransform, Transform}; use serde::{Deserialize, Serialize}; diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index c17a7e7bd92da..5389e5c9bdf13 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -89,9 +89,9 @@ use bevy_render::{ Texture, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, TextureView, }, renderer::RenderDevice, + sync_world::RenderEntity, texture::{BevyDefault, ColorAttachment, Image, TextureCache}, view::{ExtractedView, ViewDepthTexture, ViewTarget}, - sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_utils::{tracing::warn, HashMap}; diff --git a/crates/bevy_core_pipeline/src/dof/mod.rs b/crates/bevy_core_pipeline/src/dof/mod.rs index 6b7f7f40805ea..c09373ee3ab10 100644 --- a/crates/bevy_core_pipeline/src/dof/mod.rs +++ b/crates/bevy_core_pipeline/src/dof/mod.rs @@ -46,12 +46,12 @@ use bevy_render::{ TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureUsages, }, renderer::{RenderContext, RenderDevice}, + sync_world::RenderEntity, texture::{BevyDefault, CachedTexture, TextureCache}, view::{ prepare_view_targets, ExtractedView, Msaa, ViewDepthTexture, ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms, }, - sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_utils::{info_once, prelude::default, warn_once}; diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index c43bb323fe0b2..af7aaea58889f 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -32,9 +32,9 @@ use bevy_render::{ TextureDimension, TextureFormat, TextureSampleType, TextureUsages, }, renderer::{RenderContext, RenderDevice}, + sync_world::RenderEntity, texture::{BevyDefault, CachedTexture, TextureCache}, view::{ExtractedView, Msaa, ViewTarget}, - sync_world::RenderEntity, ExtractSchedule, MainWorld, Render, RenderApp, RenderSet, }; use bevy_utils::tracing::warn; diff --git a/crates/bevy_pbr/src/bundle.rs b/crates/bevy_pbr/src/bundle.rs index 60e461da4aef9..107c56f719838 100644 --- a/crates/bevy_pbr/src/bundle.rs +++ b/crates/bevy_pbr/src/bundle.rs @@ -15,8 +15,8 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::{ mesh::Mesh3d, primitives::{CascadesFrusta, CubemapFrusta, Frustum}, - view::{InheritedVisibility, ViewVisibility, Visibility}, sync_world::SyncToRenderWorld, + view::{InheritedVisibility, ViewVisibility, Visibility}, }; use bevy_transform::components::{GlobalTransform, Transform}; diff --git a/crates/bevy_pbr/src/light_probe/mod.rs b/crates/bevy_pbr/src/light_probe/mod.rs index 14d2fd7339618..68a401c60ad27 100644 --- a/crates/bevy_pbr/src/light_probe/mod.rs +++ b/crates/bevy_pbr/src/light_probe/mod.rs @@ -21,9 +21,9 @@ use bevy_render::{ render_resource::{DynamicUniformBuffer, Sampler, Shader, ShaderType, TextureView}, renderer::{RenderDevice, RenderQueue}, settings::WgpuFeatures, + sync_world::RenderEntity, texture::{FallbackImage, GpuImage, Image}, view::ExtractedView, - sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_transform::{components::Transform, prelude::GlobalTransform}; diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index b813ecaeff6f4..eb9357278c72c 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -30,9 +30,9 @@ use bevy_render::{ *, }, renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue}, + sync_world::RenderEntity, texture::{CachedTexture, TextureCache}, view::{Msaa, ViewUniform, ViewUniformOffset, ViewUniforms}, - sync_world::RenderEntity, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_utils::{ diff --git a/crates/bevy_pbr/src/volumetric_fog/render.rs b/crates/bevy_pbr/src/volumetric_fog/render.rs index e8eb0b01e4d95..d6b151fd95b91 100644 --- a/crates/bevy_pbr/src/volumetric_fog/render.rs +++ b/crates/bevy_pbr/src/volumetric_fog/render.rs @@ -36,9 +36,9 @@ use bevy_render::{ TextureSampleType, TextureUsages, VertexState, }, renderer::{RenderContext, RenderDevice, RenderQueue}, + sync_world::RenderEntity, texture::{BevyDefault as _, GpuImage, Image}, view::{ExtractedView, Msaa, ViewDepthTexture, ViewTarget, ViewUniformOffset}, - sync_world::RenderEntity, Extract, }; use bevy_transform::components::GlobalTransform; diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index dfbdd43c25513..a272df4e6c167 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -6,12 +6,12 @@ use crate::{ render_asset::RenderAssets, render_graph::{InternedRenderSubGraph, RenderSubGraph}, render_resource::TextureView, + sync_world::{RenderEntity, SyncToRenderWorld}, texture::GpuImage, view::{ ColorGrading, ExtractedView, ExtractedWindows, GpuCulling, Msaa, RenderLayers, Visibility, VisibleEntities, }, - sync_world::{RenderEntity, SyncToRenderWorld}, Extract, }; use bevy_asset::{AssetEvent, AssetId, Assets, Handle}; diff --git a/crates/bevy_render/src/gpu_readback.rs b/crates/bevy_render/src/gpu_readback.rs index 55ade09edca00..434b4603cac7c 100644 --- a/crates/bevy_render/src/gpu_readback.rs +++ b/crates/bevy_render/src/gpu_readback.rs @@ -5,8 +5,8 @@ use crate::{ render_resource::{Buffer, BufferUsages, Extent3d, ImageDataLayout, Texture, TextureFormat}, renderer::{render_system, RenderDevice}, storage::{GpuShaderStorageBuffer, ShaderStorageBuffer}, - texture::{GpuImage, TextureFormatPixelInfo}, sync_world::MainEntity, + texture::{GpuImage, TextureFormatPixelInfo}, ExtractSchedule, MainWorld, Render, RenderApp, RenderSet, }; use async_channel::{Receiver, Sender}; diff --git a/crates/bevy_sprite/src/bundle.rs b/crates/bevy_sprite/src/bundle.rs index 94ca30fc9b70b..8d4cf1365f5de 100644 --- a/crates/bevy_sprite/src/bundle.rs +++ b/crates/bevy_sprite/src/bundle.rs @@ -2,9 +2,9 @@ use crate::Sprite; use bevy_asset::Handle; use bevy_ecs::bundle::Bundle; use bevy_render::{ + sync_world::SyncToRenderWorld, texture::Image, view::{InheritedVisibility, ViewVisibility, Visibility}, - sync_world::SyncToRenderWorld, }; use bevy_transform::components::{GlobalTransform, Transform}; diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index ddef9b173958a..d3bef973748b4 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -31,6 +31,7 @@ use bevy_render::{ *, }, renderer::{RenderDevice, RenderQueue}, + sync_world::{RenderEntity, TemporaryRenderEntity}, texture::{ BevyDefault, DefaultImageSampler, FallbackImage, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, @@ -39,7 +40,6 @@ use bevy_render::{ ExtractedView, Msaa, ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms, ViewVisibility, VisibleEntities, }, - sync_world::{RenderEntity, TemporaryRenderEntity}, Extract, }; use bevy_transform::components::GlobalTransform; diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index a78ab64201b3f..3d6a57cbe57a4 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -32,9 +32,9 @@ use bevy_render::{ }; use bevy_render::{ render_phase::{PhaseItem, PhaseItemExtraIndex}, + sync_world::{RenderEntity, TemporaryRenderEntity}, texture::GpuImage, view::ViewVisibility, - sync_world::{RenderEntity, TemporaryRenderEntity}, ExtractSchedule, Render, }; use bevy_sprite::TextureAtlasLayout; diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index f3d44821e47a7..b8d85906286e5 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -18,9 +18,9 @@ use bevy_render::{ render_phase::*, render_resource::{binding_types::uniform_buffer, *}, renderer::{RenderDevice, RenderQueue}, + sync_world::{RenderEntity, TemporaryRenderEntity}, texture::BevyDefault, view::*, - sync_world::{RenderEntity, TemporaryRenderEntity}, Extract, ExtractSchedule, Render, RenderSet, }; use bevy_transform::prelude::GlobalTransform; diff --git a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs index 233218216f7ad..f33f50b1717f3 100644 --- a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs @@ -16,9 +16,9 @@ use bevy_render::{ render_phase::*, render_resource::{binding_types::uniform_buffer, *}, renderer::{RenderDevice, RenderQueue}, + sync_world::{RenderEntity, TemporaryRenderEntity}, texture::{BevyDefault, GpuImage, Image, TRANSPARENT_IMAGE_HANDLE}, view::*, - sync_world::{RenderEntity, TemporaryRenderEntity}, Extract, ExtractSchedule, Render, RenderSet, }; use bevy_sprite::{