Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain Rendering World (adopted) #15320

Merged
merged 95 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
95b7f0b
init
re0312 Jul 6, 2024
17f2bb0
sync
re0312 Jul 7, 2024
35fe01e
cleanup
re0312 Jul 22, 2024
f9bae87
clean
re0312 Jul 22, 2024
34853b2
fix
re0312 Jul 22, 2024
000cef4
Fly
re0312 Jul 22, 2024
2255b21
Merge branch 'main' into retain_world
re0312 Jul 22, 2024
f90c360
fly entity
re0312 Jul 22, 2024
756b082
sync world
re0312 Jul 22, 2024
5b5ef76
ui
re0312 Jul 22, 2024
e15e3a3
lighting
re0312 Jul 22, 2024
e4e0bc0
fix example
re0312 Jul 22, 2024
33cae8d
ui
re0312 Jul 22, 2024
4a58b0e
fix ui
re0312 Jul 22, 2024
3fc2207
fix gizmos
re0312 Jul 22, 2024
f9c8d5a
fix light
re0312 Jul 22, 2024
44d36a4
cleanup
re0312 Jul 22, 2024
9a7d641
Merge branch 'main' into retain_world
re0312 Jul 22, 2024
7989d21
fix cli
re0312 Jul 22, 2024
9485455
fix ui
re0312 Jul 23, 2024
bb3289b
clean
re0312 Jul 23, 2024
39e4f2e
fix cli
re0312 Jul 23, 2024
4b6506e
fix ui_material
re0312 Jul 23, 2024
03a6e09
fix sprite
re0312 Jul 23, 2024
b8b8225
whilelist
re0312 Jul 23, 2024
24212f5
Revert "whilelist"
re0312 Jul 23, 2024
2de636a
address review
re0312 Jul 24, 2024
1fbb76c
Update crates/bevy_render/src/world_sync.rs
re0312 Jul 24, 2024
c25d560
Update crates/bevy_render/src/world_sync.rs
re0312 Jul 24, 2024
457e83f
Update crates/bevy_render/src/world_sync.rs
re0312 Jul 24, 2024
16c1093
Merge branch 'main' into retain_world
re0312 Jul 25, 2024
cba1183
address review
re0312 Jul 25, 2024
2821849
fmt
re0312 Jul 25, 2024
a86dd39
address review
re0312 Jul 25, 2024
8422a48
comment
re0312 Jul 25, 2024
dc5f10f
remove mapping
re0312 Jul 26, 2024
2a6df8d
retain sprite
re0312 Jul 27, 2024
ce2ea36
cache state
re0312 Aug 1, 2024
c1a4fb9
fix cli
re0312 Aug 1, 2024
672778d
fix
re0312 Aug 1, 2024
0eed037
fix point light
re0312 Aug 1, 2024
5a83da4
fix regression
re0312 Aug 9, 2024
ed296f1
fix cli
re0312 Aug 9, 2024
bb8774d
Merge branch 'main' into retain_world
re0312 Aug 9, 2024
94be0cd
fix conflict
re0312 Aug 9, 2024
560ce59
Merge branch 'main' into retain_world
re0312 Aug 9, 2024
ab22138
Merge branch 'main' into retain_world
re0312 Aug 11, 2024
fd36379
Apply suggestions from code review
re0312 Aug 12, 2024
4bdfd60
Merge branch 'main' into retain_world
re0312 Aug 12, 2024
6214e6d
Merge branch 'retain_world' of https://github.com/re0312/bevy into re…
re0312 Aug 12, 2024
67e7a07
fix cli
re0312 Aug 12, 2024
1507437
Merge branch 'main' into retain_world
re0312 Aug 25, 2024
e5254be
fix
re0312 Aug 25, 2024
d9ecccd
Merge branch 'main' into retain_world
re0312 Aug 27, 2024
faf5ef2
fix
re0312 Aug 27, 2024
f127719
to render world
re0312 Aug 27, 2024
c7ba466
SyncRenderWorld
re0312 Aug 27, 2024
23a8bba
extract_component
re0312 Aug 27, 2024
37944a8
document and test
re0312 Aug 28, 2024
1e8601f
fix
re0312 Aug 28, 2024
7167cc0
typo
re0312 Aug 28, 2024
bfad1de
cleanup
re0312 Aug 28, 2024
8d2c81a
rename
re0312 Aug 28, 2024
d857e6e
Apply suggestions from code review
re0312 Aug 31, 2024
9c1a523
Cleared up some documentation
Trashtalk217 Sep 3, 2024
753d286
Merge pull request #1 from Trashtalk217/retain_world
re0312 Sep 8, 2024
1af8e69
addressed comments wilk10 and nth about docs
Trashtalk217 Sep 18, 2024
e57fb41
addressed (some) comments JMS55
Trashtalk217 Sep 19, 2024
be1752c
Renamed SyncRenderWorld to SyncToRenderWorld
Trashtalk217 Sep 19, 2024
96ee2fb
Added warning to ExtractComponentPlugin
Trashtalk217 Sep 19, 2024
6fe8d40
Merge remote-tracking branch 'upstream' into retain_world
Trashtalk217 Sep 20, 2024
7c1116d
cargo fmt
Trashtalk217 Sep 20, 2024
8816517
Update crates/bevy_render/src/extract_component.rs
Trashtalk217 Sep 20, 2024
96eba2d
removed unnecessary import
Trashtalk217 Sep 20, 2024
f814a97
fix mistakes during last merge
Trashtalk217 Sep 21, 2024
e62b9f8
adressed hymm comments
Trashtalk217 Sep 22, 2024
eb0b2e0
automatically sync extract components
Trashtalk217 Sep 23, 2024
4b03e4f
fixed doc links
Trashtalk217 Sep 23, 2024
4ea31bf
added a warning to ExtractComponentPlugin
Trashtalk217 Sep 23, 2024
ffbbc55
added a comment about the number 6
Trashtalk217 Sep 23, 2024
ed66a59
added TODO
Trashtalk217 Sep 23, 2024
4e98422
cargo fmt
Trashtalk217 Sep 23, 2024
9d2ac1b
Merge branch 'main' into retain_world
Trashtalk217 Sep 23, 2024
37af9d8
despawn unsynced entities unrecursively
Trashtalk217 Sep 24, 2024
7521deb
Merge branch 'main' into retain_world
Trashtalk217 Sep 25, 2024
f7fb546
fix import error
Trashtalk217 Sep 26, 2024
cc39f26
minor fixes
Trashtalk217 Sep 26, 2024
bab6d98
Apply suggestions from code review
Trashtalk217 Sep 26, 2024
a34562d
added docs for alice
Trashtalk217 Sep 26, 2024
88f4396
Merge branch 'main' into retain_world
Trashtalk217 Sep 27, 2024
2c45e5c
cargo fmt
Trashtalk217 Sep 27, 2024
6f015fb
doc fix
Trashtalk217 Sep 29, 2024
8d944a1
Merge branch 'main' into retain_world
Trashtalk217 Sep 29, 2024
66d1cf1
CI plz
alice-i-cecile Sep 30, 2024
7831f35
Merge branch 'main' into retain_world
Trashtalk217 Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/bevy_core_pipeline/src/auto_exposure/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bevy_ecs::prelude::*;
use bevy_render::{
render_resource::{StorageBuffer, UniformBuffer},
renderer::{RenderDevice, RenderQueue},
world_sync::RenderEntity,
Extract,
};
use bevy_utils::{Entry, HashMap};
Expand All @@ -27,13 +28,13 @@ pub(super) struct ExtractedStateBuffers {

pub(super) fn extract_buffers(
mut commands: Commands,
changed: Extract<Query<(Entity, &AutoExposureSettings), Changed<AutoExposureSettings>>>,
changed: Extract<Query<(&RenderEntity, &AutoExposureSettings), Changed<AutoExposureSettings>>>,
mut removed: Extract<RemovedComponents<AutoExposureSettings>>,
) {
commands.insert_resource(ExtractedStateBuffers {
changed: changed
.iter()
.map(|(entity, settings)| (entity, settings.clone()))
.map(|(entity, settings)| (entity.id(), settings.clone()))
.collect(),
removed: removed.read().collect(),
});
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_core_pipeline/src/core_2d/camera_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::tonemapping::{DebandDither, Tonemapping};
use bevy_ecs::prelude::*;
use bevy_reflect::Reflect;
use bevy_render::prelude::Msaa;
use bevy_render::world_sync::SyncToRenderWorld;
use bevy_render::{
camera::{
Camera, CameraMainTextureUsages, CameraProjection, CameraRenderGraph,
Expand Down Expand Up @@ -37,6 +38,8 @@ pub struct Camera2dBundle {
pub deband_dither: DebandDither,
pub main_texture_usages: CameraMainTextureUsages,
pub msaa: Msaa,
/// Marker component that indicates that its entity needs to be synchronized to the render world
pub sync: SyncToRenderWorld,
}

impl Default for Camera2dBundle {
Expand All @@ -61,6 +64,7 @@ impl Default for Camera2dBundle {
deband_dither: DebandDither::Disabled,
main_texture_usages: Default::default(),
msaa: Default::default(),
sync: Default::default(),
}
}
}
Expand Down Expand Up @@ -94,6 +98,7 @@ impl Camera2dBundle {
deband_dither: DebandDither::Disabled,
main_texture_usages: Default::default(),
msaa: Default::default(),
sync: Default::default(),
}
}
}
7 changes: 3 additions & 4 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use bevy_render::{
renderer::RenderDevice,
texture::TextureCache,
view::{Msaa, ViewDepthTexture},
world_sync::RenderEntity,
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};

Expand Down Expand Up @@ -357,11 +358,10 @@ impl CachedRenderPipelinePhaseItem for Transparent2d {
}

pub fn extract_core_2d_camera_phases(
mut commands: Commands,
mut transparent_2d_phases: ResMut<ViewSortedRenderPhases<Transparent2d>>,
mut opaque_2d_phases: ResMut<ViewBinnedRenderPhases<Opaque2d>>,
mut alpha_mask_2d_phases: ResMut<ViewBinnedRenderPhases<AlphaMask2d>>,
cameras_2d: Extract<Query<(Entity, &Camera), With<Camera2d>>>,
cameras_2d: Extract<Query<(&RenderEntity, &Camera), With<Camera2d>>>,
mut live_entities: Local<EntityHashSet>,
) {
live_entities.clear();
Expand All @@ -370,8 +370,7 @@ pub fn extract_core_2d_camera_phases(
if !camera.is_active {
continue;
}

commands.get_or_spawn(entity);
let entity = entity.id();
transparent_2d_phases.insert_or_clear(entity);
opaque_2d_phases.insert_or_clear(entity);
alpha_mask_2d_phases.insert_or_clear(entity);
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_core_pipeline/src/core_3d/camera_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::{
};
use bevy_ecs::prelude::*;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_render::view::Msaa;
use bevy_render::{
camera::{Camera, CameraMainTextureUsages, CameraRenderGraph, Exposure, Projection},
extract_component::ExtractComponent,
primitives::Frustum,
render_resource::{LoadOp, TextureUsages},
view::{ColorGrading, VisibleEntities},
};
use bevy_render::{view::Msaa, world_sync::SyncToRenderWorld};
use bevy_transform::prelude::{GlobalTransform, Transform};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -154,6 +154,8 @@ pub struct Camera3dBundle {
pub exposure: Exposure,
pub main_texture_usages: CameraMainTextureUsages,
pub msaa: Msaa,
/// Marker component that indicates that its entity needs to be synchronized to the render world
pub sync: SyncToRenderWorld,
}

// NOTE: ideally Perspective and Orthographic defaults can share the same impl, but sadly it breaks rust's type inference
Expand All @@ -174,6 +176,7 @@ impl Default for Camera3dBundle {
main_texture_usages: Default::default(),
deband_dither: DebandDither::Enabled,
msaa: Default::default(),
sync: Default::default(),
}
}
}
23 changes: 14 additions & 9 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ use bevy_render::{
renderer::RenderDevice,
texture::{BevyDefault, ColorAttachment, Image, TextureCache},
view::{ExtractedView, ViewDepthTexture, ViewTarget},
world_sync::RenderEntity,
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_utils::{tracing::warn, HashMap};
Expand Down Expand Up @@ -504,23 +505,21 @@ impl CachedRenderPipelinePhaseItem for Transparent3d {
}

pub fn extract_core_3d_camera_phases(
mut commands: Commands,
mut opaque_3d_phases: ResMut<ViewBinnedRenderPhases<Opaque3d>>,
mut alpha_mask_3d_phases: ResMut<ViewBinnedRenderPhases<AlphaMask3d>>,
mut transmissive_3d_phases: ResMut<ViewSortedRenderPhases<Transmissive3d>>,
mut transparent_3d_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
cameras_3d: Extract<Query<(Entity, &Camera), With<Camera3d>>>,
cameras_3d: Extract<Query<(&RenderEntity, &Camera), With<Camera3d>>>,
mut live_entities: Local<EntityHashSet>,
) {
live_entities.clear();

for (entity, camera) in &cameras_3d {
for (render_entity, camera) in &cameras_3d {
if !camera.is_active {
continue;
}

commands.get_or_spawn(entity);

let entity = render_entity.id();
opaque_3d_phases.insert_or_clear(entity);
alpha_mask_3d_phases.insert_or_clear(entity);
transmissive_3d_phases.insert_or_clear(entity);
Expand All @@ -545,7 +544,7 @@ pub fn extract_camera_prepass_phase(
cameras_3d: Extract<
Query<
(
Entity,
&RenderEntity,
&Camera,
Has<DepthPrepass>,
Has<NormalPrepass>,
Expand All @@ -559,13 +558,20 @@ pub fn extract_camera_prepass_phase(
) {
live_entities.clear();

for (entity, camera, depth_prepass, normal_prepass, motion_vector_prepass, deferred_prepass) in
cameras_3d.iter()
for (
render_entity,
camera,
depth_prepass,
normal_prepass,
motion_vector_prepass,
deferred_prepass,
) in cameras_3d.iter()
{
if !camera.is_active {
continue;
}

let entity = render_entity.id();
if depth_prepass || normal_prepass || motion_vector_prepass {
opaque_3d_prepass_phases.insert_or_clear(entity);
alpha_mask_3d_prepass_phases.insert_or_clear(entity);
Expand All @@ -581,7 +587,6 @@ pub fn extract_camera_prepass_phase(
opaque_3d_deferred_phases.remove(&entity);
alpha_mask_3d_deferred_phases.remove(&entity);
}

live_entities.insert(entity);

commands
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_core_pipeline/src/dof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use bevy_render::{
prepare_view_targets, ExtractedView, Msaa, ViewDepthTexture, ViewTarget, ViewUniform,
ViewUniformOffset, ViewUniforms,
},
world_sync::RenderEntity,
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_utils::{info_once, prelude::default, warn_once};
Expand Down Expand Up @@ -798,7 +799,7 @@ impl SpecializedRenderPipeline for DepthOfFieldPipeline {
/// Extracts all [`DepthOfFieldSettings`] components into the render world.
fn extract_depth_of_field_settings(
mut commands: Commands,
mut query: Extract<Query<(Entity, &DepthOfFieldSettings, &Projection)>>,
mut query: Extract<Query<(&RenderEntity, &DepthOfFieldSettings, &Projection)>>,
) {
if !DEPTH_TEXTURE_SAMPLING_SUPPORTED {
info_once!(
Expand All @@ -808,6 +809,7 @@ fn extract_depth_of_field_settings(
}

for (entity, dof_settings, projection) in query.iter_mut() {
let entity = entity.id();
// Depth of field is nonsensical without a perspective projection.
let Projection::Perspective(ref perspective_projection) = *projection else {
continue;
Expand Down
21 changes: 13 additions & 8 deletions crates/bevy_core_pipeline/src/taa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use bevy_render::{
renderer::{RenderContext, RenderDevice},
texture::{BevyDefault, CachedTexture, TextureCache},
view::{ExtractedView, Msaa, ViewTarget},
world_sync::RenderEntity,
ExtractSchedule, MainWorld, Render, RenderApp, RenderSet,
};
use bevy_utils::tracing::warn;
Expand Down Expand Up @@ -346,20 +347,24 @@ impl SpecializedRenderPipeline for TaaPipeline {
}

fn extract_taa_settings(mut commands: Commands, mut main_world: ResMut<MainWorld>) {
let mut cameras_3d = main_world
.query_filtered::<(Entity, &Camera, &Projection, &mut TemporalAntiAliasSettings), (
With<Camera3d>,
With<TemporalJitter>,
With<DepthPrepass>,
With<MotionVectorPrepass>,
)>();
let mut cameras_3d = main_world.query_filtered::<(
Trashtalk217 marked this conversation as resolved.
Show resolved Hide resolved
&RenderEntity,
&Camera,
&Projection,
&mut TemporalAntiAliasSettings,
), (
With<Camera3d>,
With<TemporalJitter>,
With<DepthPrepass>,
With<MotionVectorPrepass>,
)>();

for (entity, camera, camera_projection, mut taa_settings) in
cameras_3d.iter_mut(&mut main_world)
{
let has_perspective_projection = matches!(camera_projection, Projection::Perspective(_));
if camera.is_active && has_perspective_projection {
commands.get_or_spawn(entity).insert(taa_settings.clone());
commands.get_or_spawn(entity.id()).insert(taa_settings.clone());
taa_settings.reset = false;
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ use bevy_render::{
ShaderType, VertexFormat,
},
renderer::RenderDevice,
world_sync::TemporaryRenderEntity,
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};

Expand Down Expand Up @@ -452,6 +453,7 @@ fn extract_gizmo_data(
(*handle).clone_weak(),
#[cfg(any(feature = "bevy_pbr", feature = "bevy_sprite"))]
config::GizmoMeshConfig::from(config),
TemporaryRenderEntity,
));
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_pbr/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bevy_derive::{Deref, DerefMut};
use bevy_ecs::entity::{Entity, EntityHashMap};
use bevy_ecs::{bundle::Bundle, component::Component, reflect::ReflectComponent};
use bevy_reflect::Reflect;
use bevy_render::world_sync::SyncToRenderWorld;
use bevy_render::{
mesh::Mesh,
primitives::{CascadesFrusta, CubemapFrusta, Frustum},
Expand Down Expand Up @@ -103,6 +104,8 @@ pub struct PointLightBundle {
pub inherited_visibility: InheritedVisibility,
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
pub view_visibility: ViewVisibility,
/// Marker component that indicates that its entity needs to be synchronized to the render world
pub sync: SyncToRenderWorld,
}

/// A component bundle for spot light entities
Expand All @@ -119,6 +122,8 @@ pub struct SpotLightBundle {
pub inherited_visibility: InheritedVisibility,
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
pub view_visibility: ViewVisibility,
/// Marker component that indicates that its entity needs to be synchronized to the render world
pub sync: SyncToRenderWorld,
}

/// A component bundle for [`DirectionalLight`] entities.
Expand All @@ -137,4 +142,6 @@ pub struct DirectionalLightBundle {
pub inherited_visibility: InheritedVisibility,
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
pub view_visibility: ViewVisibility,
/// Marker component that indicates that its entity needs to be synchronized to the render world
pub sync: SyncToRenderWorld,
}
14 changes: 9 additions & 5 deletions crates/bevy_pbr/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use bevy_render::{
UniformBuffer,
},
renderer::{RenderDevice, RenderQueue},
world_sync::RenderEntity,
Extract,
};
use bevy_utils::{hashbrown::HashSet, tracing::warn};
Expand Down Expand Up @@ -512,7 +513,8 @@ pub(crate) fn clusterable_object_order(
/// Extracts clusters from the main world from the render world.
pub fn extract_clusters(
mut commands: Commands,
views: Extract<Query<(Entity, &Clusters, &Camera)>>,
views: Extract<Query<(&RenderEntity, &Clusters, &Camera)>>,
mapper: Extract<Query<&RenderEntity>>,
) {
for (entity, clusters, camera) in &views {
if !camera.is_active {
Expand All @@ -531,13 +533,15 @@ pub fn extract_clusters(
cluster_objects.spot_light_count as u32,
));
for clusterable_entity in &cluster_objects.entities {
data.push(ExtractedClusterableObjectElement::ClusterableObjectEntity(
*clusterable_entity,
));
if let Ok(entity) = mapper.get(*clusterable_entity) {
data.push(ExtractedClusterableObjectElement::ClusterableObjectEntity(
entity.id(),
));
}
}
}

commands.get_or_spawn(entity).insert((
commands.get_or_spawn(entity.id()).insert((
ExtractedClusterableObjects { data },
ExtractedClusterConfig {
near: clusters.near,
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ impl Plugin for PbrPlugin {
)
.init_resource::<LightMeta>();

render_app.world_mut().observe(add_light_view_entities);
render_app.world_mut().observe(remove_light_view_entities);

let shadow_pass_node = ShadowPassNode::new(render_app.world_mut());
let mut graph = render_app.world_mut().resource_mut::<RenderGraph>();
let draw_3d_graph = graph.get_sub_graph_mut(Core3d).unwrap();
Expand Down
Loading