From d15ea7d35c885517f4a8da95ff3993d88c21dde8 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 15:11:04 +0100 Subject: [PATCH 01/20] relax unnecessary &mut GlobalTransform to &GlobalTransform --- crates/bevy_audio/src/audio_output.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_audio/src/audio_output.rs b/crates/bevy_audio/src/audio_output.rs index 9870c7496dcaf..83af58547ac03 100644 --- a/crates/bevy_audio/src/audio_output.rs +++ b/crates/bevy_audio/src/audio_output.rs @@ -288,7 +288,7 @@ pub(crate) fn audio_output_available(audio_output: Res) -> bool { /// Updates spatial audio sinks when emitter positions change. pub(crate) fn update_emitter_positions( - mut emitters: Query<(&mut GlobalTransform, &SpatialAudioSink), Changed>, + mut emitters: Query<(&GlobalTransform, &SpatialAudioSink), Changed>, spatial_scale: Res, ) { for (transform, sink) in emitters.iter_mut() { From 510ee3c9cff5688418c9989712c912aec3ba56c7 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 14:26:09 +0100 Subject: [PATCH 02/20] remove after relation to different schedule --- crates/bevy_ui/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index e72eb5ea777d2..fa504825518a5 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -47,10 +47,9 @@ use crate::prelude::UiCameraConfig; #[cfg(feature = "bevy_text")] use crate::widget::TextFlags; use bevy_app::prelude::*; -use bevy_asset::Assets; use bevy_ecs::prelude::*; use bevy_input::InputSystem; -use bevy_render::{extract_component::ExtractComponentPlugin, texture::Image, RenderApp}; +use bevy_render::{extract_component::ExtractComponentPlugin, RenderApp}; use bevy_transform::TransformSystem; use stack::ui_stack_system; pub use stack::UiStack; @@ -155,9 +154,7 @@ impl Plugin for UiPlugin { // Since both systems will only ever insert new [`Image`] assets, // they will never observe each other's effects. .ambiguous_with(bevy_text::update_text2d_layout), - widget::text_system - .after(UiSystem::Layout) - .before(Assets::::track_assets), + widget::text_system.after(UiSystem::Layout), ), ); #[cfg(feature = "bevy_text")] From f468a7649552dcf40d08a7d2c8686c70bfbb21aa Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 14:59:30 +0100 Subject: [PATCH 03/20] refactor: merge add_systems --- crates/bevy_winit/src/accessibility.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/bevy_winit/src/accessibility.rs b/crates/bevy_winit/src/accessibility.rs index b0f4b6b1229a0..efd93d1777ecf 100644 --- a/crates/bevy_winit/src/accessibility.rs +++ b/crates/bevy_winit/src/accessibility.rs @@ -149,12 +149,11 @@ impl Plugin for AccessibilityPlugin { .add_event::() .add_systems( PostUpdate, - (window_closed, poll_receivers).in_set(AccessibilitySystem::Update), - ) - .add_systems( - PostUpdate, - update_accessibility_nodes - .run_if(should_update_accessibility_nodes) + ( + window_closed, + poll_receivers, + update_accessibility_nodes.run_if(should_update_accessibility_nodes), + ) .in_set(AccessibilitySystem::Update), ); } From 6849743284cd66a6fa22af7022eb3b10c5f48075 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 15:00:55 +0100 Subject: [PATCH 04/20] run winit accessibility window_closed before poll_receivers and update_accessibility_nodes --- crates/bevy_winit/src/accessibility.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_winit/src/accessibility.rs b/crates/bevy_winit/src/accessibility.rs index efd93d1777ecf..09bfe65c6c9fa 100644 --- a/crates/bevy_winit/src/accessibility.rs +++ b/crates/bevy_winit/src/accessibility.rs @@ -150,9 +150,11 @@ impl Plugin for AccessibilityPlugin { .add_systems( PostUpdate, ( - window_closed, poll_receivers, update_accessibility_nodes.run_if(should_update_accessibility_nodes), + window_closed + .before(poll_receivers) + .before(update_accessibility_nodes), ) .in_set(AccessibilitySystem::Update), ); From bc59251d2581a8ddc066e7d0abc7852701555592 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 13:58:21 +0100 Subject: [PATCH 05/20] run bevy_ui::calc_bounds after CameraUpdateSystem --- crates/bevy_ui/src/accessibility.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/accessibility.rs b/crates/bevy_ui/src/accessibility.rs index 50e883695524a..9fac1f78c9d13 100644 --- a/crates/bevy_ui/src/accessibility.rs +++ b/crates/bevy_ui/src/accessibility.rs @@ -15,7 +15,7 @@ use bevy_ecs::{ world::Ref, }; use bevy_hierarchy::Children; -use bevy_render::prelude::Camera; +use bevy_render::{camera::CameraUpdateSystem, prelude::Camera}; use bevy_text::Text; use bevy_transform::prelude::GlobalTransform; @@ -150,7 +150,9 @@ impl Plugin for AccessibilityPlugin { app.add_systems( PostUpdate, ( - calc_bounds.after(bevy_transform::TransformSystem::TransformPropagate), + calc_bounds + .after(bevy_transform::TransformSystem::TransformPropagate) + .after(CameraUpdateSystem), button_changed, image_changed, label_changed, From efed1137e2dab4fa54fc27d5bb4be9883976697c Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 12:21:17 +0100 Subject: [PATCH 06/20] ignore render schedule ambiguities --- crates/bevy_core_pipeline/src/blit/mod.rs | 4 ++++ crates/bevy_pbr/src/material.rs | 4 +++- crates/bevy_pbr/src/prepass/mod.rs | 5 ++++- crates/bevy_pbr/src/render/mesh.rs | 1 + crates/bevy_render/src/view/mod.rs | 3 ++- crates/bevy_ui/src/render/mod.rs | 1 + 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/bevy_core_pipeline/src/blit/mod.rs b/crates/bevy_core_pipeline/src/blit/mod.rs index b6698838f4a54..5549fc4ee6f13 100644 --- a/crates/bevy_core_pipeline/src/blit/mod.rs +++ b/crates/bevy_core_pipeline/src/blit/mod.rs @@ -13,6 +13,10 @@ pub struct BlitPlugin; impl Plugin for BlitPlugin { fn build(&self, app: &mut App) { load_internal_asset!(app, BLIT_SHADER_HANDLE, "blit.wgsl", Shader::from_wgsl); + + if let Ok(render_app) = app.get_sub_app_mut(RenderApp) { + render_app.allow_ambiguous_resource::>(); + } } fn finish(&self, app: &mut App) { diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index d5884bb65530c..478f66bcb605f 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -234,7 +234,9 @@ where .after(prepare_materials::), queue_material_meshes:: .in_set(RenderSet::QueueMeshes) - .after(prepare_materials::), + .after(prepare_materials::) + // queue_material_meshes only writes to `material_bind_group_id`, which `queue_shadows` doesn't read + .ambiguous_with(render::queue_shadows::), ), ); } diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 6f2dfed69e12d..af2c5e2a9e272 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -97,6 +97,7 @@ where ) .init_resource::() .init_resource::>>() + .allow_ambiguous_resource::>>() .init_resource::(); } @@ -167,7 +168,9 @@ where Render, queue_prepass_material_meshes:: .in_set(RenderSet::QueueMeshes) - .after(prepare_materials::), + .after(prepare_materials::) + // queue_material_meshes only writes to `material_bind_group_id`, which `queue_prepass_material_meshes` doesn't read + .ambiguous_with(queue_material_meshes::), ); } } diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 8c87d27129c2d..95aeaa3e548b2 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -123,6 +123,7 @@ impl Plugin for MeshRenderPlugin { .init_resource::() .init_resource::() .init_resource::() + .allow_ambiguous_resource::>() .add_systems( ExtractSchedule, (extract_meshes, extract_skins, extract_morphs), diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 73d8bf9c24e80..5295d2b14c219 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -59,7 +59,8 @@ impl Plugin for ViewPlugin { prepare_view_targets .in_set(RenderSet::ManageViews) .after(prepare_windows) - .after(crate::render_asset::prepare_assets::), + .after(crate::render_asset::prepare_assets::) + .ambiguous_with(crate::camera::sort_cameras), // doesn't use `sorted_camera_index_for_target` prepare_view_uniforms.in_set(RenderSet::PrepareResources), ), ); diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index f63fd1a0dc36c..b60986da3e25c 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -74,6 +74,7 @@ pub fn build_ui_render(app: &mut App) { .init_resource::() .init_resource::() .init_resource::() + .allow_ambiguous_resource::() .init_resource::>() .add_render_command::() .add_systems( From b086945b44964a4b342ba4c8ade7d6730ec39ca9 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 14:16:01 +0100 Subject: [PATCH 07/20] ignore accessibility ambiguities --- crates/bevy_a11y/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_a11y/src/lib.rs b/crates/bevy_a11y/src/lib.rs index 576b920f4183b..1a84def4c2344 100644 --- a/crates/bevy_a11y/src/lib.rs +++ b/crates/bevy_a11y/src/lib.rs @@ -106,6 +106,7 @@ impl Plugin for AccessibilityPlugin { fn build(&self, app: &mut bevy_app::App) { app.init_resource::() .init_resource::() - .init_resource::(); + .init_resource::() + .allow_ambiguous_component::(); } } From 8f7202206160fb5cb906ad51ad43464b910f76d7 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 14:56:34 +0100 Subject: [PATCH 08/20] ignore ui/text ambiguities --- crates/bevy_text/src/lib.rs | 1 + crates/bevy_ui/src/lib.rs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/bevy_text/src/lib.rs b/crates/bevy_text/src/lib.rs index 6a1981fa6110b..f6a59c209322a 100644 --- a/crates/bevy_text/src/lib.rs +++ b/crates/bevy_text/src/lib.rs @@ -96,6 +96,7 @@ impl Plugin for TextPlugin { PostUpdate, ( update_text2d_layout + .after(font_atlas_set::remove_dropped_font_atlas_sets) // Potential conflict: `Assets` // In practice, they run independently since `bevy_render::camera_update_system` // will only ever observe its own render target, and `update_text2d_layout` diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index fa504825518a5..288a2f5604520 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -153,14 +153,26 @@ impl Plugin for UiPlugin { // Potential conflict: `Assets` // Since both systems will only ever insert new [`Image`] assets, // they will never observe each other's effects. + .ambiguous_with(bevy_text::update_text2d_layout) + // We assume Text is on disjoint UI entities to UiImage and UiTextureAtlasImage + // FIXME: Add an archetype invariant for this https://github.com/bevyengine/bevy/issues/1481. + .ambiguous_with(widget::update_image_content_size_system) + .ambiguous_with(widget::update_atlas_content_size_system), + widget::text_system + .after(UiSystem::Layout) + .after(bevy_text::remove_dropped_font_atlas_sets) + // Text2d and bevy_ui text are entirely on separate entities .ambiguous_with(bevy_text::update_text2d_layout), - widget::text_system.after(UiSystem::Layout), ), ); #[cfg(feature = "bevy_text")] app.add_plugins(accessibility::AccessibilityPlugin); app.add_systems(PostUpdate, { - let system = widget::update_image_content_size_system.before(UiSystem::Layout); + let system = widget::update_image_content_size_system + .before(UiSystem::Layout) + // We assume UiImage, UiTextureAtlasImage are disjoint UI entities + // FIXME: Add an archetype invariant for this https://github.com/bevyengine/bevy/issues/1481. + .ambiguous_with(widget::update_atlas_content_size_system); // Potential conflicts: `Assets` // They run independently since `widget::image_node_system` will only ever observe // its own UiImage, and `widget::text_system` & `bevy_text::update_text2d_layout` From ef7b2a1c1264144dae208214f9f64199ab7a619f Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 14:16:10 +0100 Subject: [PATCH 09/20] ignore ui ambiguities --- crates/bevy_ui/src/accessibility.rs | 5 ++++- crates/bevy_ui/src/lib.rs | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/bevy_ui/src/accessibility.rs b/crates/bevy_ui/src/accessibility.rs index 9fac1f78c9d13..7620c18519208 100644 --- a/crates/bevy_ui/src/accessibility.rs +++ b/crates/bevy_ui/src/accessibility.rs @@ -152,7 +152,10 @@ impl Plugin for AccessibilityPlugin { ( calc_bounds .after(bevy_transform::TransformSystem::TransformPropagate) - .after(CameraUpdateSystem), + .after(CameraUpdateSystem) + // the listed systems do not affect calculated size + .ambiguous_with(crate::resolve_outlines_system) + .ambiguous_with(crate::ui_stack_system), button_changed, image_changed, label_changed, diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 288a2f5604520..239518f5bd530 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -196,8 +196,17 @@ impl Plugin for UiPlugin { .before(TransformSystem::TransformPropagate), resolve_outlines_system .in_set(UiSystem::Outlines) - .after(UiSystem::Layout), - ui_stack_system.in_set(UiSystem::Stack), + .after(UiSystem::Layout) + // clipping doesn't care about outlines + .ambiguous_with(update_clipping_system) + .ambiguous_with(widget::text_system), + ui_stack_system + .in_set(UiSystem::Stack) + // the systems don't care about stack index + .ambiguous_with(update_clipping_system) + .ambiguous_with(resolve_outlines_system) + .ambiguous_with(ui_layout_system) + .ambiguous_with(widget::text_system), update_clipping_system.after(TransformSystem::TransformPropagate), ), ); From a6d3eb36422a5b0c1e4276c75bb38be04e21f666 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 13:11:42 +0100 Subject: [PATCH 10/20] add standalone ambiguous_with function for acknowledging an ambiguity outside the system adding --- crates/bevy_app/src/app.rs | 32 +++++++++++++++++++++++ crates/bevy_ecs/src/schedule/schedule.rs | 33 +++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 821612a23214e..93fab649e11a7 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -983,6 +983,38 @@ impl App { self.world.allow_ambiguous_resource::(); self } + + /// Suppress warnings and errors that would result from systems in these sets having ambiguities + /// (conflicting access but indeterminate order) with systems in `set`. + /// + /// When possible, do this directly in the `.add_systems(Update, a.ambiguous_with(b))` call. + /// However, sometimes two independant plugins `A` and `B` are reported as ambiguous, which you + /// can only supress as the consumer of both. + #[track_caller] + pub fn ambiguous_with( + &mut self, + schedule: impl ScheduleLabel, + a: S1, + b: S2, + ) -> &mut Self + where + S1: IntoSystemSet + IntoSystem<(), (), M1>, + S2: IntoSystemSet + IntoSystem<(), (), M2>, + { + let schedule = schedule.intern(); + let mut schedules = self.world.resource_mut::(); + + if let Some(schedule) = schedules.get_mut(schedule) { + let schedule: &mut Schedule = schedule; + schedule.ambiguous_with(a, b); + } else { + let mut new_schedule = Schedule::new(schedule); + (&mut new_schedule).ambiguous_with(a, b); + schedules.insert(new_schedule); + } + + self + } } fn run_once(mut app: App) { diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index 82732b1a7e052..d71aefb5c53ae 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -21,7 +21,7 @@ use crate::{ component::{ComponentId, Components, Tick}, prelude::Component, schedule::*, - system::{BoxedSystem, Resource, System}, + system::{BoxedSystem, IntoSystem, Resource, System}, world::World, }; @@ -232,6 +232,37 @@ impl Schedule { self } + /// Suppress warnings and errors that would result from systems in these sets having ambiguities + /// (conflicting access but indeterminate order) with systems in `set`. + #[track_caller] + pub fn ambiguous_with(&mut self, a: S1, b: S2) -> &mut Self + where + S1: IntoSystemSet + IntoSystem<(), (), M1>, + S2: IntoSystemSet + IntoSystem<(), (), M2>, + { + let a = a.into_system_set(); + let b = b.into_system_set(); + + let Some(&a_id) = self.graph.system_set_ids.get(&a.intern()) else { + panic!( + "Could not mark system as ambiguous, `{:?}` was not found in the schedule. + Did you try to call `ambiguous_with` before adding the system to the world?", + a + ); + }; + let Some(&b_id) = self.graph.system_set_ids.get(&b.intern()) else { + panic!( + "Could not mark system as ambiguous, `{:?}` was not found in the schedule. + Did you try to call `ambiguous_with` before adding the system to the world?", + b + ); + }; + + self.graph.ambiguous_with.add_edge(a_id, b_id, ()); + + self + } + /// Configures a system set in this schedule, adding it if it does not exist. #[deprecated(since = "0.12.0", note = "Please use `configure_sets` instead.")] #[track_caller] From c77396f7e5c7739429412c38b5c6abf9814c5e75 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 13:48:17 +0100 Subject: [PATCH 11/20] ignore core_pipeline/bevy_pbr ambiguity --- crates/bevy_pbr/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 8e1cfdd41d34b..bedf1922ff158 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -364,6 +364,15 @@ impl Plugin for PbrPlugin { draw_3d_graph::node::SHADOW_PASS, bevy_core_pipeline::core_3d::graph::node::START_MAIN_PASS, ); + + render_app.ambiguous_with( + bevy_render::Render, + bevy_core_pipeline::core_3d::prepare_core_3d_transmission_textures, + bevy_render::batching::batch_and_prepare_render_phase::< + bevy_core_pipeline::core_3d::Transmissive3d, + MeshPipeline, + >, + ); } fn finish(&self, app: &mut App) { From 6e1975a5d75f5e041a2359228b01b8764334cb79 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 14:24:20 +0100 Subject: [PATCH 12/20] ignore bevy_animation/bevy_ui transform ambiguity --- crates/bevy_internal/src/default_plugins.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index d95957ab43dbf..45798f7b44249 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -1,4 +1,4 @@ -use bevy_app::{PluginGroup, PluginGroupBuilder}; +use bevy_app::{Plugin, PluginGroup, PluginGroupBuilder}; /// This plugin group will add all the default plugins for a *Bevy* application: /// * [`LogPlugin`](crate::log::LogPlugin) @@ -133,10 +133,26 @@ impl PluginGroup for DefaultPlugins { group = group.add(bevy_gizmos::GizmoPlugin); } + group = group.add(IgnoreAmbiguitiesPlugin); + group } } +struct IgnoreAmbiguitiesPlugin; + +impl Plugin for IgnoreAmbiguitiesPlugin { + fn build(&self, app: &mut bevy_app::App) { + // bevy_ui owns the Transform and cannot be animated + #[cfg(all(feature = "bevy_animation", feature = "bevy_ui"))] + app.ambiguous_with( + bevy_app::PostUpdate, + bevy_animation::animation_player, + bevy_ui::ui_layout_system, + ); + } +} + /// This plugin group will add the minimal plugins for a *Bevy* application: /// * [`TaskPoolPlugin`](crate::core::TaskPoolPlugin) /// * [`TypeRegistrationPlugin`](crate::core::TypeRegistrationPlugin) From 64c4845a8e611b64312fd444060e2df0d942ef79 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 16:05:34 +0100 Subject: [PATCH 13/20] rename ambiguous_with -> ignore_ambiguities --- crates/bevy_app/src/app.rs | 6 +++--- crates/bevy_ecs/src/schedule/schedule.rs | 2 +- crates/bevy_internal/src/default_plugins.rs | 2 +- crates/bevy_pbr/src/lib.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 93fab649e11a7..101158a51b0f4 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -991,7 +991,7 @@ impl App { /// However, sometimes two independant plugins `A` and `B` are reported as ambiguous, which you /// can only supress as the consumer of both. #[track_caller] - pub fn ambiguous_with( + pub fn ignore_ambiguities( &mut self, schedule: impl ScheduleLabel, a: S1, @@ -1006,10 +1006,10 @@ impl App { if let Some(schedule) = schedules.get_mut(schedule) { let schedule: &mut Schedule = schedule; - schedule.ambiguous_with(a, b); + schedule.ignore_ambiguities(a, b); } else { let mut new_schedule = Schedule::new(schedule); - (&mut new_schedule).ambiguous_with(a, b); + new_schedule.ignore_ambiguities(a, b); schedules.insert(new_schedule); } diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index d71aefb5c53ae..4556535bafe66 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -235,7 +235,7 @@ impl Schedule { /// Suppress warnings and errors that would result from systems in these sets having ambiguities /// (conflicting access but indeterminate order) with systems in `set`. #[track_caller] - pub fn ambiguous_with(&mut self, a: S1, b: S2) -> &mut Self + pub fn ignore_ambiguities(&mut self, a: S1, b: S2) -> &mut Self where S1: IntoSystemSet + IntoSystem<(), (), M1>, S2: IntoSystemSet + IntoSystem<(), (), M2>, diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index 45798f7b44249..eb4adb5060454 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -145,7 +145,7 @@ impl Plugin for IgnoreAmbiguitiesPlugin { fn build(&self, app: &mut bevy_app::App) { // bevy_ui owns the Transform and cannot be animated #[cfg(all(feature = "bevy_animation", feature = "bevy_ui"))] - app.ambiguous_with( + app.ignore_ambiguities( bevy_app::PostUpdate, bevy_animation::animation_player, bevy_ui::ui_layout_system, diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index bedf1922ff158..90b89263b4fdb 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -365,7 +365,7 @@ impl Plugin for PbrPlugin { bevy_core_pipeline::core_3d::graph::node::START_MAIN_PASS, ); - render_app.ambiguous_with( + render_app.ignore_ambiguities( bevy_render::Render, bevy_core_pipeline::core_3d::prepare_core_3d_transmission_textures, bevy_render::batching::batch_and_prepare_render_phase::< From 0643193a94feb539966112f2a86446d5b6702112 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 16:23:26 +0100 Subject: [PATCH 14/20] allow sets in ignore_ambiguities --- crates/bevy_app/src/app.rs | 4 ++-- crates/bevy_ecs/src/schedule/schedule.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 101158a51b0f4..08b76abb988df 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -998,8 +998,8 @@ impl App { b: S2, ) -> &mut Self where - S1: IntoSystemSet + IntoSystem<(), (), M1>, - S2: IntoSystemSet + IntoSystem<(), (), M2>, + S1: IntoSystemSet, + S2: IntoSystemSet, { let schedule = schedule.intern(); let mut schedules = self.world.resource_mut::(); diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index 4556535bafe66..603fd34b3240f 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -21,7 +21,7 @@ use crate::{ component::{ComponentId, Components, Tick}, prelude::Component, schedule::*, - system::{BoxedSystem, IntoSystem, Resource, System}, + system::{BoxedSystem, Resource, System}, world::World, }; @@ -237,8 +237,8 @@ impl Schedule { #[track_caller] pub fn ignore_ambiguities(&mut self, a: S1, b: S2) -> &mut Self where - S1: IntoSystemSet + IntoSystem<(), (), M1>, - S2: IntoSystemSet + IntoSystem<(), (), M2>, + S1: IntoSystemSet, + S2: IntoSystemSet, { let a = a.into_system_set(); let b = b.into_system_set(); From ce4bdb28e4618fad67e6e48a1f3596ee05bc6478 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 16:23:47 +0100 Subject: [PATCH 15/20] label gizmo queue sets and ignore ambiguity --- crates/bevy_gizmos/src/lib.rs | 13 ++++++++++- crates/bevy_gizmos/src/pipeline_2d.rs | 10 ++++++--- crates/bevy_gizmos/src/pipeline_3d.rs | 10 ++++++--- crates/bevy_internal/src/default_plugins.rs | 24 +++++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 446605b43e4f8..102cf6aa9fb00 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -16,6 +16,17 @@ //! //! See the documentation on [`Gizmos`] for more examples. +/// Label for the the render systems handling the +#[derive(SystemSet, Clone, Debug, Hash, PartialEq, Eq)] +pub enum GizmoRenderSystem { + /// Reads all [`LineGizmo`]s and draws them into the [`Transparent2d`](bevy_core_pipeline::core_2d::Transparent2d) render phase + #[cfg(feature = "bevy_sprite")] + QueueLineGizmos2d, + /// Reads all [`LineGizmo`]s and draws them into the [`Transparent3d`](bevy_core_pipeline::core_3d::Transparent3d) render phase + #[cfg(feature = "bevy_pbr")] + QueueLineGizmos3d, +} + pub mod gizmos; #[cfg(feature = "bevy_sprite")] @@ -38,7 +49,7 @@ use bevy_ecs::{ entity::Entity, query::{ROQueryItem, Without}, reflect::ReflectComponent, - schedule::IntoSystemConfigs, + schedule::{IntoSystemConfigs, SystemSet}, system::{ lifetimeless::{Read, SRes}, Commands, Query, Res, ResMut, Resource, SystemParamItem, diff --git a/crates/bevy_gizmos/src/pipeline_2d.rs b/crates/bevy_gizmos/src/pipeline_2d.rs index 5b64598eb403f..dd53a40e5fc9e 100644 --- a/crates/bevy_gizmos/src/pipeline_2d.rs +++ b/crates/bevy_gizmos/src/pipeline_2d.rs @@ -1,5 +1,5 @@ use crate::{ - line_gizmo_vertex_buffer_layouts, DrawLineGizmo, GizmoConfig, LineGizmo, + line_gizmo_vertex_buffer_layouts, DrawLineGizmo, GizmoConfig, GizmoRenderSystem, LineGizmo, LineGizmoUniformBindgroupLayout, SetLineGizmoBindGroup, LINE_SHADER_HANDLE, }; use bevy_app::{App, Plugin}; @@ -8,7 +8,7 @@ use bevy_core_pipeline::core_2d::Transparent2d; use bevy_ecs::{ prelude::Entity, - schedule::IntoSystemConfigs, + schedule::{IntoSystemConfigs, IntoSystemSetConfigs}, system::{Query, Res, ResMut, Resource}, world::{FromWorld, World}, }; @@ -34,10 +34,14 @@ impl Plugin for LineGizmo2dPlugin { render_app .add_render_command::() .init_resource::>() + .configure_sets( + Render, + GizmoRenderSystem::QueueLineGizmos2d.in_set(RenderSet::Queue), + ) .add_systems( Render, queue_line_gizmos_2d - .in_set(RenderSet::Queue) + .in_set(GizmoRenderSystem::QueueLineGizmos2d) .after(prepare_assets::), ); } diff --git a/crates/bevy_gizmos/src/pipeline_3d.rs b/crates/bevy_gizmos/src/pipeline_3d.rs index 2cb016753513b..9ea991e4753a2 100644 --- a/crates/bevy_gizmos/src/pipeline_3d.rs +++ b/crates/bevy_gizmos/src/pipeline_3d.rs @@ -1,5 +1,5 @@ use crate::{ - line_gizmo_vertex_buffer_layouts, DrawLineGizmo, GizmoConfig, LineGizmo, + line_gizmo_vertex_buffer_layouts, DrawLineGizmo, GizmoConfig, GizmoRenderSystem, LineGizmo, LineGizmoUniformBindgroupLayout, SetLineGizmoBindGroup, LINE_SHADER_HANDLE, }; use bevy_app::{App, Plugin}; @@ -12,7 +12,7 @@ use bevy_core_pipeline::{ use bevy_ecs::{ prelude::Entity, query::Has, - schedule::IntoSystemConfigs, + schedule::{IntoSystemConfigs, IntoSystemSetConfigs}, system::{Query, Res, ResMut, Resource}, world::{FromWorld, World}, }; @@ -36,10 +36,14 @@ impl Plugin for LineGizmo3dPlugin { render_app .add_render_command::() .init_resource::>() + .configure_sets( + Render, + GizmoRenderSystem::QueueLineGizmos3d.in_set(RenderSet::Queue), + ) .add_systems( Render, queue_line_gizmos_3d - .in_set(RenderSet::Queue) + .in_set(GizmoRenderSystem::QueueLineGizmos3d) .after(prepare_assets::), ); } diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index eb4adb5060454..8646757fcd999 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -150,6 +150,30 @@ impl Plugin for IgnoreAmbiguitiesPlugin { bevy_animation::animation_player, bevy_ui::ui_layout_system, ); + + if let Ok(render_app) = app.get_sub_app_mut(bevy_render::RenderApp) { + #[cfg(all(feature = "bevy_gizmos", feature = "bevy_sprite"))] + { + render_app.ignore_ambiguities( + bevy_render::Render, + bevy_gizmos::GizmoRenderSystem::QueueLineGizmos2d, + bevy_sprite::queue_sprites, + ); + render_app.ignore_ambiguities( + bevy_render::Render, + bevy_gizmos::GizmoRenderSystem::QueueLineGizmos2d, + bevy_sprite::queue_material2d_meshes::, + ); + } + #[cfg(all(feature = "bevy_gizmos", feature = "bevy_pbr"))] + { + render_app.ignore_ambiguities( + bevy_render::Render, + bevy_gizmos::GizmoRenderSystem::QueueLineGizmos3d, + bevy_pbr::queue_material_meshes::, + ); + } + } } } From 90698b27e6af8bca65476bb5aa7c3b1b409d0c8a Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 18:11:12 +0100 Subject: [PATCH 16/20] rename ignore_ambiguities -> ignore_ambiguity --- crates/bevy_app/src/app.rs | 6 +++--- crates/bevy_ecs/src/schedule/schedule.rs | 2 +- crates/bevy_internal/src/default_plugins.rs | 8 ++++---- crates/bevy_pbr/src/lib.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 08b76abb988df..c787fef928182 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -991,7 +991,7 @@ impl App { /// However, sometimes two independant plugins `A` and `B` are reported as ambiguous, which you /// can only supress as the consumer of both. #[track_caller] - pub fn ignore_ambiguities( + pub fn ignore_ambiguity( &mut self, schedule: impl ScheduleLabel, a: S1, @@ -1006,10 +1006,10 @@ impl App { if let Some(schedule) = schedules.get_mut(schedule) { let schedule: &mut Schedule = schedule; - schedule.ignore_ambiguities(a, b); + schedule.ignore_ambiguity(a, b); } else { let mut new_schedule = Schedule::new(schedule); - new_schedule.ignore_ambiguities(a, b); + new_schedule.ignore_ambiguity(a, b); schedules.insert(new_schedule); } diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index 603fd34b3240f..61fbf0d0bfb7e 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -235,7 +235,7 @@ impl Schedule { /// Suppress warnings and errors that would result from systems in these sets having ambiguities /// (conflicting access but indeterminate order) with systems in `set`. #[track_caller] - pub fn ignore_ambiguities(&mut self, a: S1, b: S2) -> &mut Self + pub fn ignore_ambiguity(&mut self, a: S1, b: S2) -> &mut Self where S1: IntoSystemSet, S2: IntoSystemSet, diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index 8646757fcd999..60da2023539f8 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -145,7 +145,7 @@ impl Plugin for IgnoreAmbiguitiesPlugin { fn build(&self, app: &mut bevy_app::App) { // bevy_ui owns the Transform and cannot be animated #[cfg(all(feature = "bevy_animation", feature = "bevy_ui"))] - app.ignore_ambiguities( + app.ignore_ambiguity( bevy_app::PostUpdate, bevy_animation::animation_player, bevy_ui::ui_layout_system, @@ -154,12 +154,12 @@ impl Plugin for IgnoreAmbiguitiesPlugin { if let Ok(render_app) = app.get_sub_app_mut(bevy_render::RenderApp) { #[cfg(all(feature = "bevy_gizmos", feature = "bevy_sprite"))] { - render_app.ignore_ambiguities( + render_app.ignore_ambiguity( bevy_render::Render, bevy_gizmos::GizmoRenderSystem::QueueLineGizmos2d, bevy_sprite::queue_sprites, ); - render_app.ignore_ambiguities( + render_app.ignore_ambiguity( bevy_render::Render, bevy_gizmos::GizmoRenderSystem::QueueLineGizmos2d, bevy_sprite::queue_material2d_meshes::, @@ -167,7 +167,7 @@ impl Plugin for IgnoreAmbiguitiesPlugin { } #[cfg(all(feature = "bevy_gizmos", feature = "bevy_pbr"))] { - render_app.ignore_ambiguities( + render_app.ignore_ambiguity( bevy_render::Render, bevy_gizmos::GizmoRenderSystem::QueueLineGizmos3d, bevy_pbr::queue_material_meshes::, diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 90b89263b4fdb..eabc681802071 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -365,7 +365,7 @@ impl Plugin for PbrPlugin { bevy_core_pipeline::core_3d::graph::node::START_MAIN_PASS, ); - render_app.ignore_ambiguities( + render_app.ignore_ambiguity( bevy_render::Render, bevy_core_pipeline::core_3d::prepare_core_3d_transmission_textures, bevy_render::batching::batch_and_prepare_render_phase::< From 87cc4145ae1b581be6b372caa8abc29b3cad75ec Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Mon, 6 Nov 2023 18:16:57 +0100 Subject: [PATCH 17/20] fix doc comment mentioning private type --- crates/bevy_gizmos/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 102cf6aa9fb00..27165b22b3880 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -19,10 +19,10 @@ /// Label for the the render systems handling the #[derive(SystemSet, Clone, Debug, Hash, PartialEq, Eq)] pub enum GizmoRenderSystem { - /// Reads all [`LineGizmo`]s and draws them into the [`Transparent2d`](bevy_core_pipeline::core_2d::Transparent2d) render phase + /// Adds gizmos to the [`Transparent2d`](bevy_core_pipeline::core_2d::Transparent2d) render phase #[cfg(feature = "bevy_sprite")] QueueLineGizmos2d, - /// Reads all [`LineGizmo`]s and draws them into the [`Transparent3d`](bevy_core_pipeline::core_3d::Transparent3d) render phase + /// Adds gizmos to the [`Transparent3d`](bevy_core_pipeline::core_3d::Transparent3d) render phase #[cfg(feature = "bevy_pbr")] QueueLineGizmos3d, } From f5bc124741b3b54d11b1313b805104a34ff0222e Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Mon, 8 Jan 2024 17:11:45 -0500 Subject: [PATCH 18/20] cargo fmt --- crates/bevy_gizmos/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index c98e4ba3412c1..00bffa1d48797 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -26,7 +26,6 @@ pub enum GizmoRenderSystem { QueueLineGizmos3d, } - pub mod arcs; pub mod arrows; pub mod circles; From 43e7d05050c056a7c4221112408f6b0888c7e7dc Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Tue, 9 Jan 2024 11:12:04 -0500 Subject: [PATCH 19/20] Only access the render app wtih bevy_render MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- crates/bevy_internal/src/default_plugins.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index 60da2023539f8..9f2e296beb522 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -151,6 +151,7 @@ impl Plugin for IgnoreAmbiguitiesPlugin { bevy_ui::ui_layout_system, ); + #[cfg(feature = "bevy_render")] if let Ok(render_app) = app.get_sub_app_mut(bevy_render::RenderApp) { #[cfg(all(feature = "bevy_gizmos", feature = "bevy_sprite"))] { From be2c42d0a62f2aba5ccf40451bf8d4830cd54c79 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Tue, 9 Jan 2024 13:55:19 -0500 Subject: [PATCH 20/20] Allow unused variables --- crates/bevy_internal/src/default_plugins.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index 9f2e296beb522..0b87248f86a93 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -142,6 +142,7 @@ impl PluginGroup for DefaultPlugins { struct IgnoreAmbiguitiesPlugin; impl Plugin for IgnoreAmbiguitiesPlugin { + #[allow(unused_variables)] // Variables are used depending on enabled features fn build(&self, app: &mut bevy_app::App) { // bevy_ui owns the Transform and cannot be animated #[cfg(all(feature = "bevy_animation", feature = "bevy_ui"))]