From 53de75a3a32d4efd02cf743730c1291a7fe4cee8 Mon Sep 17 00:00:00 2001 From: Chris Russell <8494645+chescock@users.noreply.github.com> Date: Fri, 10 Mar 2023 11:38:59 -0500 Subject: [PATCH] Pass query change ticks to QueryParIter instead of always using change ticks from World. --- crates/bevy_ecs/src/query/par_iter.rs | 16 +++++++--------- crates/bevy_ecs/src/query/state.rs | 4 ++++ crates/bevy_ecs/src/system/query.rs | 4 ++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/bevy_ecs/src/query/par_iter.rs b/crates/bevy_ecs/src/query/par_iter.rs index 72744a8efa7f4..4d3393c8f0ceb 100644 --- a/crates/bevy_ecs/src/query/par_iter.rs +++ b/crates/bevy_ecs/src/query/par_iter.rs @@ -1,4 +1,4 @@ -use crate::world::World; +use crate::{component::Tick, world::World}; use bevy_tasks::ComputeTaskPool; use std::ops::Range; @@ -81,6 +81,8 @@ impl BatchingStrategy { pub struct QueryParIter<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> { pub(crate) world: &'w World, pub(crate) state: &'s QueryState, + pub(crate) last_run: Tick, + pub(crate) this_run: Tick, pub(crate) batching_strategy: BatchingStrategy, } @@ -148,12 +150,8 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> QueryParIter<'w, 's, Q, F> { ) { let thread_count = ComputeTaskPool::get().thread_num(); if thread_count <= 1 { - self.state.for_each_unchecked_manual( - self.world, - func, - self.world.last_change_tick(), - self.world.read_change_tick(), - ); + self.state + .for_each_unchecked_manual(self.world, func, self.last_run, self.this_run); } else { // Need a batch size of at least 1. let batch_size = self.get_batch_size(thread_count).max(1); @@ -161,8 +159,8 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> QueryParIter<'w, 's, Q, F> { self.world, batch_size, func, - self.world.last_change_tick(), - self.world.read_change_tick(), + self.last_run, + self.this_run, ); } } diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index d85c2965dec27..eaa898ac72dbc 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -820,6 +820,8 @@ impl QueryState { QueryParIter { world, state: self, + last_run: world.last_change_tick(), + this_run: world.read_change_tick(), batching_strategy: BatchingStrategy::new(), } } @@ -835,6 +837,8 @@ impl QueryState { QueryParIter { world, state: self, + last_run: world.last_change_tick(), + this_run: world.read_change_tick(), batching_strategy: BatchingStrategy::new(), } } diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index e8c54472dae42..bda0401a57fc0 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -728,6 +728,8 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> { QueryParIter { world: self.world, state: self.state.as_readonly(), + last_run: self.last_run, + this_run: self.this_run, batching_strategy: BatchingStrategy::new(), } } @@ -742,6 +744,8 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> { QueryParIter { world: self.world, state: self.state, + last_run: self.last_run, + this_run: self.this_run, batching_strategy: BatchingStrategy::new(), } }