@@ -1413,7 +1413,7 @@ impl RenderMeshInstanceGpuPrepared {
14131413 entity : MainEntity ,
14141414 render_mesh_instances : & mut MainEntityHashMap < RenderMeshInstanceGpu > ,
14151415 current_input_buffer : & mut InstanceInputUniformBuffer < MeshInputUniform > ,
1416- previous_input_buffer : & mut InstanceInputUniformBuffer < MeshInputUniform > ,
1416+ previous_input_buffer : & InstanceInputUniformBuffer < MeshInputUniform > ,
14171417 ) -> Option < u32 > {
14181418 // Did the last frame contain this entity as well?
14191419 let current_uniform_index;
@@ -1431,7 +1431,7 @@ impl RenderMeshInstanceGpuPrepared {
14311431 // shader will need it to compute motion vectors.
14321432 let previous_mesh_input_uniform =
14331433 current_input_buffer. get_unchecked ( current_uniform_index) ;
1434- let previous_input_index = previous_input_buffer. add ( previous_mesh_input_uniform) ;
1434+ let previous_input_index = previous_input_buffer. push ( previous_mesh_input_uniform) ;
14351435 self . mesh_input_uniform . previous_input_index = previous_input_index;
14361436
14371437 // Write in the new mesh input uniform.
@@ -1986,6 +1986,9 @@ pub fn collect_meshes_for_gpu_building(
19861986 mesh_culling_data_buffer. grow ( current_input_buffer. len ( ) as u32 ) ;
19871987 }
19881988
1989+ // Pre-allocate the previous input buffer for concurrent pushes.
1990+ previous_input_buffer. reserve ( current_input_buffer. len ( ) as u32 ) ;
1991+
19891992 // Channels used by parallel workers to send data to the single consumer.
19901993 let ( prepared_tx, prepared_rx) = mpsc:: channel ( ) ;
19911994 let ( reextract_tx, reextract_rx) = mpsc:: channel ( ) ;
@@ -2001,6 +2004,7 @@ pub fn collect_meshes_for_gpu_building(
20012004 let frame_count = * frame_count;
20022005 let render_mesh_instances = & * render_mesh_instances;
20032006 let current_input_buffer = & * current_input_buffer;
2007+ let previous_input_buffer = & * previous_input_buffer;
20042008 let mesh_culling_data_buffer = & * mesh_culling_data_buffer;
20052009
20062010 // Spawn workers on the taskpool to prepare and update meshes in parallel.
@@ -2069,7 +2073,7 @@ pub fn collect_meshes_for_gpu_building(
20692073 skin_uniforms,
20702074 frame_count,
20712075 ) {
2072- Some ( prepared) => {
2076+ Some ( mut prepared) => {
20732077 if let Some ( render_mesh_instance) =
20742078 render_mesh_instances. get ( & entity)
20752079 && prepared. render_layers
@@ -2090,6 +2094,15 @@ pub fn collect_meshes_for_gpu_building(
20902094 let current_uniform_index = render_mesh_instance
20912095 . gpu_specific
20922096 . current_uniform_index ( ) ;
2097+
2098+ let previous_mesh_input_uniform =
2099+ current_input_buffer
2100+ . get_unchecked ( current_uniform_index) ;
2101+ let previous_input_index = previous_input_buffer
2102+ . push ( previous_mesh_input_uniform) ;
2103+ prepared. mesh_input_uniform . previous_input_index =
2104+ previous_input_index;
2105+
20932106 current_input_buffer. set (
20942107 current_uniform_index,
20952108 prepared. mesh_input_uniform ,
@@ -2153,6 +2166,7 @@ pub fn collect_meshes_for_gpu_building(
21532166 let entity = batch;
21542167 meshes_to_reextract_next_frame. insert ( entity) ;
21552168 }
2169+ previous_input_buffer. truncate ( ) ;
21562170 // Buffers can't be empty. Make sure there's something in the previous input buffer.
21572171 previous_input_buffer. ensure_nonempty ( ) ;
21582172}
0 commit comments