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

Cleanup: Use Parallel in extract_meshes #12084

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Cleanup: Use Parallel in extract_meshes
  • Loading branch information
james7132 committed Feb 24, 2024
commit 0ce6291ee50bcc13c89823bf9e38cc758b1d8d20
1 change: 0 additions & 1 deletion crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ fixedbitset = "0.4"
bytemuck = { version = "1", features = ["derive"] }
radsort = "0.1"
smallvec = "1.6"
thread_local = "1.0"

[lints]
workspace = true
33 changes: 15 additions & 18 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ use bevy_render::{
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_transform::components::GlobalTransform;
use bevy_utils::{tracing::error, Entry, HashMap, Hashed};
use std::cell::Cell;
use thread_local::ThreadLocal;
use bevy_utils::{tracing::error, Entry, HashMap, Hashed, Parallel};

#[cfg(debug_assertions)]
use bevy_utils::warn_once;
Expand Down Expand Up @@ -268,7 +266,7 @@ pub struct RenderMeshInstances(EntityHashMap<RenderMeshInstance>);

pub fn extract_meshes(
mut render_mesh_instances: ResMut<RenderMeshInstances>,
mut thread_local_queues: Local<ThreadLocal<Cell<Vec<(Entity, RenderMeshInstance)>>>>,
mut thread_local_queues: Local<Parallel<Vec<(Entity, RenderMeshInstance)>>>,
meshes_query: Extract<
Query<(
Entity,
Expand Down Expand Up @@ -316,25 +314,24 @@ pub fn extract_meshes(
previous_transform: (&previous_transform).into(),
flags: flags.bits(),
};
let tls = thread_local_queues.get_or_default();
let mut queue = tls.take();
queue.push((
entity,
RenderMeshInstance {
mesh_asset_id: handle.id(),
transforms,
shadow_caster: !not_shadow_caster,
material_bind_group_id: AtomicMaterialBindGroupId::default(),
automatic_batching: !no_automatic_batching,
},
));
tls.set(queue);
thread_local_queues.scope(|queue| {
queue.push((
entity,
RenderMeshInstance {
mesh_asset_id: handle.id(),
transforms,
shadow_caster: !not_shadow_caster,
material_bind_group_id: AtomicMaterialBindGroupId::default(),
automatic_batching: !no_automatic_batching,
},
))
});
},
);

render_mesh_instances.clear();
for queue in thread_local_queues.iter_mut() {
render_mesh_instances.extend(queue.get_mut().drain(..));
render_mesh_instances.extend(queue.drain(..));
}
}

Expand Down
Loading