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 all 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 @@ -26,13 +27,13 @@ pub(super) struct ExtractedStateBuffers {

pub(super) fn extract_buffers(
mut commands: Commands,
changed: Extract<Query<(Entity, &AutoExposure), Changed<AutoExposure>>>,
changed: Extract<Query<(&RenderEntity, &AutoExposure), Changed<AutoExposure>>>,
mut removed: Extract<RemovedComponents<AutoExposure>>,
) {
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 @@ -4,6 +4,7 @@ use crate::{
};
use bevy_ecs::prelude::*;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::world_sync::SyncToRenderWorld;
use bevy_render::{
camera::{
Camera, CameraMainTextureUsages, CameraProjection, CameraRenderGraph,
Expand Down Expand Up @@ -35,6 +36,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 @@ -55,6 +58,7 @@ impl Default for Camera2dBundle {
deband_dither: DebandDither::Disabled,
main_texture_usages: Default::default(),
msaa: Default::default(),
sync: Default::default(),
}
}
}
Expand Down Expand Up @@ -88,6 +92,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
4 changes: 4 additions & 0 deletions crates/bevy_core_pipeline/src/core_3d/camera_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bevy_render::{
primitives::Frustum,
render_resource::{LoadOp, TextureUsages},
view::{ColorGrading, Msaa, VisibleEntities},
world_sync::SyncToRenderWorld,
};
use bevy_transform::prelude::{GlobalTransform, Transform};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -153,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 @@ -173,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 @@ -51,6 +51,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 @@ -809,7 +810,7 @@ impl SpecializedRenderPipeline for DepthOfFieldPipeline {
/// Extracts all [`DepthOfField`] components into the render world.
fn extract_depth_of_field_settings(
mut commands: Commands,
mut query: Extract<Query<(Entity, &DepthOfField, &Projection)>>,
mut query: Extract<Query<(&RenderEntity, &DepthOfField, &Projection)>>,
) {
if !DEPTH_TEXTURE_SAMPLING_SUPPORTED {
info_once!(
Expand All @@ -819,6 +820,7 @@ fn extract_depth_of_field_settings(
}

for (entity, depth_of_field, 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
23 changes: 15 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 @@ -351,20 +352,26 @@ 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 TemporalAntiAliasing), (
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 TemporalAntiAliasing,
), (
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
3 changes: 2 additions & 1 deletion crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ use {
ShaderStages, ShaderType, VertexFormat,
},
renderer::RenderDevice,
world_sync::TemporaryRenderEntity,
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
},
bytemuck::cast_slice,
Expand All @@ -113,7 +114,6 @@ use {
any(feature = "bevy_pbr", feature = "bevy_sprite"),
))]
use bevy_render::render_resource::{VertexAttribute, VertexBufferLayout, VertexStepMode};

use bevy_time::Fixed;
use bevy_utils::TypeIdMap;
use config::{
Expand Down Expand Up @@ -459,6 +459,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 @@ -15,6 +15,7 @@ use bevy_render::{
mesh::Mesh,
primitives::{CascadesFrusta, CubemapFrusta, Frustum},
view::{InheritedVisibility, ViewVisibility, Visibility},
world_sync::SyncToRenderWorld,
};
use bevy_transform::components::{GlobalTransform, Transform};

Expand Down Expand Up @@ -108,6 +109,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 @@ -124,6 +127,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 @@ -142,4 +147,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 @@ -525,7 +526,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 @@ -544,13 +546,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 @@ -439,6 +439,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
Loading