Skip to content

Commit

Permalink
Parallelise meshlet buffer writes
Browse files Browse the repository at this point in the history
  • Loading branch information
ricky26 committed Jan 12, 2024
1 parent c895e49 commit 20083fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.12.0", features = [
"bevy",
] }
bevy_render = { path = "../bevy_render", version = "0.12.0" }
bevy_tasks = { path = "../bevy_tasks", version = "0.12.0" }
bevy_transform = { path = "../bevy_transform", version = "0.12.0" }
bevy_utils = { path = "../bevy_utils", version = "0.12.0" }
bevy_window = { path = "../bevy_window", version = "0.12.0" }
Expand Down
45 changes: 30 additions & 15 deletions crates/bevy_pbr/src/meshlet/gpu_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use bevy_render::{
MainWorld,
};
use bevy_transform::components::GlobalTransform;
use bevy_tasks::ComputeTaskPool;
use bevy_utils::{default, EntityHashMap, HashMap, HashSet};
use std::{
ops::{DerefMut, Range},
Expand Down Expand Up @@ -144,21 +145,35 @@ pub fn prepare_meshlet_per_frame_resources(
return;
}

gpu_scene
.instance_uniforms
.write_buffer(&render_device, &render_queue);
gpu_scene
.instance_material_ids
.write_buffer(&render_device, &render_queue);
gpu_scene
.thread_instance_ids
.write_buffer(&render_device, &render_queue);
gpu_scene
.thread_meshlet_ids
.write_buffer(&render_device, &render_queue);
gpu_scene
.previous_thread_ids
.write_buffer(&render_device, &render_queue);
let gpu_scene = gpu_scene.as_mut();
ComputeTaskPool::get()
.scope(|scope| {
scope.spawn(async {
gpu_scene
.instance_uniforms
.write_buffer(&render_device, &render_queue)
});
scope.spawn(async {
gpu_scene
.instance_material_ids
.write_buffer(&render_device, &render_queue)
});
scope.spawn(async {
gpu_scene
.thread_instance_ids
.write_buffer(&render_device, &render_queue)
});
scope.spawn(async {
gpu_scene
.thread_meshlet_ids
.write_buffer(&render_device, &render_queue)
});
scope.spawn(async {
gpu_scene
.previous_thread_ids
.write_buffer(&render_device, &render_queue)
});
});

let needed_buffer_size = 4 * gpu_scene.scene_index_count;
let visibility_buffer_draw_index_buffer =
Expand Down

0 comments on commit 20083fa

Please sign in to comment.