Skip to content

Material, mesh, skin extraction optimization #17976

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,11 @@ fn early_sweep_material_instances<M>(
/// preparation for a new frame.
fn late_sweep_material_instances(
mut material_instances: ResMut<RenderMaterialInstances>,
mut removed_visibilities_query: Extract<RemovedComponents<ViewVisibility>>,
mut removed_meshes_query: Extract<RemovedComponents<Mesh3d>>,
) {
let last_change_tick = material_instances.current_change_tick;

for entity in removed_visibilities_query.read() {
for entity in removed_meshes_query.read() {
if let Entry::Occupied(occupied_entry) = material_instances.instances.entry(entity.into()) {
// Only sweep the entry if it wasn't updated this frame. It's
// possible that a `ViewVisibility` component was removed and
Expand Down
8 changes: 1 addition & 7 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,8 +1451,6 @@ pub fn extract_meshes_for_gpu_building(
>,
>,
all_meshes_query: Extract<Query<GpuMeshExtractionQuery>>,
mut removed_visibilities_query: Extract<RemovedComponents<ViewVisibility>>,
mut removed_global_transforms_query: Extract<RemovedComponents<GlobalTransform>>,
mut removed_meshes_query: Extract<RemovedComponents<Mesh3d>>,
gpu_culling_query: Extract<Query<(), (With<Camera>, Without<NoIndirectDrawing>)>>,
meshes_to_reextract_next_frame: ResMut<MeshesToReextractNextFrame>,
Expand Down Expand Up @@ -1508,11 +1506,7 @@ pub fn extract_meshes_for_gpu_building(
}

// Also record info about each mesh that became invisible.
for entity in removed_visibilities_query
.read()
.chain(removed_global_transforms_query.read())
.chain(removed_meshes_query.read())
{
for entity in removed_meshes_query.read() {
// Only queue a mesh for removal if we didn't pick it up above.
// It's possible that a necessary component was removed and re-added in
// the same frame.
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_pbr/src/render/skin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ pub fn extract_skins(
skinned_mesh_inverse_bindposes: Extract<Res<Assets<SkinnedMeshInverseBindposes>>>,
changed_transforms: Extract<Query<(Entity, &GlobalTransform), Changed<GlobalTransform>>>,
joints: Extract<Query<&GlobalTransform>>,
mut removed_visibilities_query: Extract<RemovedComponents<ViewVisibility>>,
mut removed_skinned_meshes_query: Extract<RemovedComponents<SkinnedMesh>>,
) {
let skin_uniforms = skin_uniforms.into_inner();
Expand All @@ -335,10 +334,7 @@ pub fn extract_skins(
);

// Delete skins that became invisible.
for skinned_mesh_entity in removed_visibilities_query
.read()
.chain(removed_skinned_meshes_query.read())
{
for skinned_mesh_entity in removed_skinned_meshes_query.read() {
// Only remove a skin if we didn't pick it up in `add_or_delete_skins`.
// It's possible that a necessary component was removed and re-added in
// the same frame.
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_sprite/src/mesh2d/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ pub fn extract_mesh_materials_2d<M: Material2d>(
Or<(Changed<ViewVisibility>, Changed<MeshMaterial2d<M>>)>,
>,
>,
mut removed_visibilities_query: Extract<RemovedComponents<ViewVisibility>>,
mut removed_materials_query: Extract<RemovedComponents<MeshMaterial2d<M>>>,
) {
for (entity, view_visibility, material) in &changed_meshes_query {
Expand All @@ -342,10 +341,7 @@ pub fn extract_mesh_materials_2d<M: Material2d>(
}
}

for entity in removed_visibilities_query
.read()
.chain(removed_materials_query.read())
{
for entity in removed_materials_query.read() {
// Only queue a mesh for removal if we didn't pick it up above.
// It's possible that a necessary component was removed and re-added in
// the same frame.
Expand Down