-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[Merged by Bors] - Reduce the use of atomics in the render phase #7084
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
Changes from 21 commits
b411da6
702b2c4
2c099b1
8e4f9ff
45f227a
03d6ca3
22fd3c7
4a5638f
1a4083a
5efcff3
54cd232
1756709
aa146b3
68f4a36
4d4d9b4
c09c358
f63f670
d034b09
0a84aaa
592dd8e
ef78c5b
0a79eec
266583c
84a2d7f
b90341e
ce70df9
15b8527
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,15 +170,17 @@ impl<Param: SystemParam> SystemState<Param> { | |
| where | ||
| Param: ReadOnlySystemParam, | ||
| { | ||
| self.validate_world_and_update_archetypes(world); | ||
| self.validate_world(world); | ||
| self.update_archetypes(world); | ||
| // SAFETY: Param is read-only and doesn't allow mutable access to World. It also matches the World this SystemState was created with. | ||
| unsafe { self.get_unchecked_manual(world) } | ||
| } | ||
|
|
||
| /// Retrieve the mutable [`SystemParam`] values. | ||
| #[inline] | ||
| pub fn get_mut<'w, 's>(&'s mut self, world: &'w mut World) -> SystemParamItem<'w, 's, Param> { | ||
| self.validate_world_and_update_archetypes(world); | ||
| self.validate_world(world); | ||
| self.update_archetypes(world); | ||
| // SAFETY: World is uniquely borrowed and matches the World this SystemState was created with. | ||
| unsafe { self.get_unchecked_manual(world) } | ||
| } | ||
|
|
@@ -196,8 +198,13 @@ impl<Param: SystemParam> SystemState<Param> { | |
| self.world_id == world.id() | ||
| } | ||
|
|
||
| fn validate_world_and_update_archetypes(&mut self, world: &World) { | ||
| #[inline] | ||
| fn validate_world(&mut self, world: &World) { | ||
| assert!(self.matches_world(world), "Encountered a mismatched World. A SystemState cannot be used with Worlds other than the one it was created with."); | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn update_archetypes(&mut self, world: &World) { | ||
james7132 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let archetypes = world.archetypes(); | ||
| let new_generation = archetypes.generation(); | ||
| let old_generation = std::mem::replace(&mut self.archetype_generation, new_generation); | ||
|
|
@@ -211,6 +218,42 @@ impl<Param: SystemParam> SystemState<Param> { | |
| } | ||
| } | ||
|
|
||
| /// Retrieve the [`SystemParam`] values. This can only be called when all parameters are read-only. | ||
| /// This will not update archetypes automatically nor increment the world's change tick. | ||
james7132 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// For this to return accurate results, ensure [`SystemState::update_archetypes`] is called before this | ||
| /// function. | ||
|
Comment on lines
+233
to
+234
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In what way will the results be inaccurate? Is it just that any newly-added archetypes will be skipped? Not suggesting a change necessarily, just asking why this function is safe.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New archetypes are ignored. Queries, for example, will just not return the target entity in those new archetypes. The prior archetypes are still accessed correctly, so this shouldn't cause any UB if not updated. |
||
| /// | ||
| /// Users should strongly prefer to use [`SystemState::get`] over this function. | ||
| #[inline] | ||
| pub fn get_manual<'w, 's>(&'s mut self, world: &'w World) -> SystemParamItem<'w, 's, Param> | ||
| where | ||
| Param: ReadOnlySystemParam, | ||
| { | ||
| self.validate_world(world); | ||
| let change_tick = world.read_change_tick(); | ||
| // SAFETY: Param is read-only and doesn't allow mutable access to World. It also matches the World this SystemState was created with. | ||
| unsafe { self.fetch(world, change_tick) } | ||
| } | ||
|
|
||
| /// Retrieve the mutable [`SystemParam`] values. This will not update archetypes automatically nor increment | ||
| /// the world's change tick. | ||
| /// | ||
| /// For this to return accurate results, ensure [`SystemState::update_archetypes`] is called before this | ||
| /// function. | ||
| /// | ||
| /// Users should strongly prefer to use [`SystemState::get_mut`] over this function. | ||
| #[inline] | ||
| pub fn get_manual_mut<'w, 's>( | ||
| &'s mut self, | ||
| world: &'w mut World, | ||
| ) -> SystemParamItem<'w, 's, Param> { | ||
| self.validate_world(world); | ||
| let change_tick = world.change_tick(); | ||
| // SAFETY: World is uniquely borrowed and matches the World this SystemState was created with. | ||
| unsafe { self.fetch(world, change_tick) } | ||
| } | ||
|
|
||
| /// Retrieve the [`SystemParam`] values. This will not update archetypes automatically. | ||
| /// | ||
| /// # Safety | ||
|
|
@@ -223,6 +266,19 @@ impl<Param: SystemParam> SystemState<Param> { | |
| world: &'w World, | ||
| ) -> SystemParamItem<'w, 's, Param> { | ||
| let change_tick = world.increment_change_tick(); | ||
| self.fetch(world, change_tick) | ||
| } | ||
|
|
||
| /// # Safety | ||
| /// This call might access any of the input parameters in a way that violates Rust's mutability rules. Make sure the data | ||
| /// access is safe in the context of global [`World`] access. The passed-in [`World`] _must_ be the [`World`] the [`SystemState`] was | ||
| /// created with. | ||
| #[inline] | ||
| unsafe fn fetch<'w, 's>( | ||
| &'s mut self, | ||
| world: &'w World, | ||
| change_tick: u32, | ||
| ) -> SystemParamItem<'w, 's, Param> { | ||
| let param = <Param::State as SystemParamState>::get_param( | ||
| &mut self.param_state, | ||
| &self.meta, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.