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

[Merged by Bors] - Move system_commands spans into apply_buffers #6900

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
8 changes: 4 additions & 4 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
)*
}

fn apply(&mut self, world: &mut World) {
self.0.apply(world)
fn apply(&mut self, system_meta: &SystemMeta, world: &mut World) {
self.0.apply(system_meta, world)
}
}

Expand Down Expand Up @@ -450,8 +450,8 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
self.state.new_archetype(archetype, system_meta)
}

fn apply(&mut self, world: &mut #path::world::World) {
self.state.apply(world)
fn apply(&mut self, system_meta: &#path::system::SystemMeta, world: &mut #path::world::World) {
self.state.apply(system_meta, world)
}
}

Expand Down
44 changes: 6 additions & 38 deletions crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,10 @@ impl SystemStage {
}

pub fn apply_buffers(&mut self, world: &mut World) {
#[cfg(feature = "trace")]
let _span = bevy_utils::tracing::info_span!("stage::apply_buffers").entered();
for container in &mut self.parallel {
let system = container.system_mut();
#[cfg(feature = "trace")]
let _span = bevy_utils::tracing::info_span!("system_commands", name = &*system.name())
.entered();
system.apply_buffers(world);
container.system_mut().apply_buffers(world);
}
}

Expand Down Expand Up @@ -781,15 +779,7 @@ impl Stage for SystemStage {
.entered();
container.system_mut().run((), world);
}
{
#[cfg(feature = "trace")]
let _system_span = bevy_utils::tracing::info_span!(
"system_commands",
name = &*container.name()
)
.entered();
container.system_mut().apply_buffers(world);
}
container.system_mut().apply_buffers(world);
}
}

Expand All @@ -813,28 +803,14 @@ impl Stage for SystemStage {
.entered();
container.system_mut().run((), world);
}
{
#[cfg(feature = "trace")]
let _system_span = bevy_utils::tracing::info_span!(
"system_commands",
name = &*container.name()
)
.entered();
container.system_mut().apply_buffers(world);
}
container.system_mut().apply_buffers(world);
}
}

// Apply parallel systems' buffers.
if self.apply_buffers {
for container in &mut self.parallel {
if container.should_run {
#[cfg(feature = "trace")]
let _span = bevy_utils::tracing::info_span!(
"system_commands",
name = &*container.name()
)
.entered();
container.system_mut().apply_buffers(world);
}
}
Expand All @@ -852,15 +828,7 @@ impl Stage for SystemStage {
.entered();
container.system_mut().run((), world);
}
{
#[cfg(feature = "trace")]
let _system_span = bevy_utils::tracing::info_span!(
"system_commands",
name = &*container.name()
)
.entered();
container.system_mut().apply_buffers(world);
}
container.system_mut().apply_buffers(world);
}
}

Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_ecs/src/system/commands/parallel_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use thread_local::ThreadLocal;
use crate::{
entity::Entities,
prelude::World,
system::{SystemParam, SystemParamFetch, SystemParamState},
system::{SystemMeta, SystemParam, SystemParamFetch, SystemParamState},
};

use super::{CommandQueue, Commands};
Expand Down Expand Up @@ -74,7 +74,11 @@ unsafe impl SystemParamState for ParallelCommandsState {
Self::default()
}

fn apply(&mut self, world: &mut World) {
fn apply(&mut self, _system_meta: &SystemMeta, world: &mut World) {
#[cfg(feature = "trace")]
let _system_span =
bevy_utils::tracing::info_span!("system_commands", name = _system_meta.name())
.entered();
for cq in &mut self.thread_local_storage {
cq.get_mut().apply(world);
}
Expand Down
10 changes: 8 additions & 2 deletions crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ impl SystemMeta {
}
}

/// Returns the system's name
#[inline]
pub fn name(&self) -> &str {
&self.name
}

/// Returns true if the system is [`Send`].
#[inline]
pub fn is_send(&self) -> bool {
Expand Down Expand Up @@ -188,7 +194,7 @@ impl<Param: SystemParam> SystemState<Param> {
/// This function should be called manually after the values returned by [`SystemState::get`] and [`SystemState::get_mut`]
/// are finished being used.
pub fn apply(&mut self, world: &mut World) {
self.param_state.apply(world);
self.param_state.apply(&self.meta, world);
}

#[inline]
Expand Down Expand Up @@ -422,7 +428,7 @@ where
#[inline]
fn apply_buffers(&mut self, world: &mut World) {
let param_state = self.param_state.as_mut().expect(Self::PARAM_MESSAGE);
param_state.apply(world);
param_state.apply(&self.system_meta, world);
}

#[inline]
Expand Down
17 changes: 11 additions & 6 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub unsafe trait SystemParamState: Send + Sync + 'static {
#[inline]
fn new_archetype(&mut self, _archetype: &Archetype, _system_meta: &mut SystemMeta) {}
#[inline]
fn apply(&mut self, _world: &mut World) {}
#[allow(unused_variables)]
fn apply(&mut self, system_meta: &SystemMeta, _world: &mut World) {}
}

/// A [`SystemParamFetch`] that only reads a given [`World`].
Expand Down Expand Up @@ -595,7 +596,11 @@ unsafe impl SystemParamState for CommandQueue {
Default::default()
}

fn apply(&mut self, world: &mut World) {
fn apply(&mut self, _system_meta: &SystemMeta, world: &mut World) {
#[cfg(feature = "trace")]
let _system_span =
bevy_utils::tracing::info_span!("system_commands", name = _system_meta.name())
.entered();
self.apply(world);
}
}
Expand Down Expand Up @@ -1499,9 +1504,9 @@ macro_rules! impl_system_param_tuple {
}

#[inline]
fn apply(&mut self, _world: &mut World) {
fn apply(&mut self, _system_meta: &SystemMeta, _world: &mut World) {
let ($($param,)*) = self;
$($param.apply(_world);)*
$($param.apply(_system_meta, _world);)*
}
}
};
Expand Down Expand Up @@ -1640,8 +1645,8 @@ unsafe impl<S: SystemParamState, P: SystemParam + 'static> SystemParamState
self.0.new_archetype(archetype, system_meta);
}

fn apply(&mut self, world: &mut World) {
self.0.apply(world);
fn apply(&mut self, system_meta: &SystemMeta, world: &mut World) {
self.0.apply(system_meta, world);
}
}

Expand Down