Skip to content

Commit

Permalink
Vectorize reset_view_visibility (#12797)
Browse files Browse the repository at this point in the history
# Objective
Speed up CPU-side rendering.

## Solution
Use `QueryIter::for_each` and `Mut::bypass_change_detection` to minimize
the total amount of data being written and allow autovectorization to
speed up iteration.

## Performance
Tested against the default `many_cubes`, this results in greater than
15x speed up: 281us -> 18.4us.

![image](https://github.com/bevyengine/bevy/assets/3137680/18369285-843e-4eb6-9716-c99c6f5ea4e2)

As `ViewVisibility::HIDDEN` just wraps false, this is likely just
degenerating into `memset(0)`s on the tables.
  • Loading branch information
james7132 authored Mar 30, 2024
1 parent 4dadebd commit 24030d2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ fn propagate_recursive(
/// Entities that are visible will be marked as such later this frame
/// by a [`VisibilitySystems::CheckVisibility`] system.
fn reset_view_visibility(mut query: Query<&mut ViewVisibility>) {
for mut view_visibility in &mut query {
query.iter_mut().for_each(|mut view_visibility| {
// NOTE: We do not use `set_if_neq` here, as we don't care about
// change detection for view visibility, and adding a branch to every
// loop iteration would pessimize performance.
*view_visibility = ViewVisibility::HIDDEN;
}
*view_visibility.bypass_change_detection() = ViewVisibility::HIDDEN;
});
}

/// System updating the visibility of entities each frame.
Expand Down

0 comments on commit 24030d2

Please sign in to comment.