@@ -7,8 +7,10 @@ use crate::shared::{VertexAttributeDescriptor, VertexAttributeFormat, VertexAttr
77use super :: super :: gpu_mesh:: attribute_reader:: AttributeReader ;
88use super :: buffer_layout:: vertex_format_size;
99
10+ /// Vertices assigned to one stream expansion worker chunk.
11+ const VERTEX_STREAM_PARALLEL_CHUNK_VERTICES : usize = 512 ;
1012/// Vertex count above which stream expansion fans out across Rayon workers.
11- const VERTEX_STREAM_PARALLEL_MIN : usize = 1_024 ;
13+ const VERTEX_STREAM_PARALLEL_MIN : usize = VERTEX_STREAM_PARALLEL_CHUNK_VERTICES * 2 ;
1214
1315/// Host UV channels exposed through the mesh-forward vertex path.
1416pub const UV_VERTEX_ATTRIBUTE_TYPES : [ VertexAttributeType ; 8 ] = [
@@ -98,7 +100,12 @@ pub fn extract_float3_position_normal_as_vec4_streams(
98100 if should_parallelize_vertex_stream ( vertex_count) {
99101 pos_out
100102 . par_chunks_exact_mut ( 16 )
101- . zip ( nrm_out. par_chunks_exact_mut ( 16 ) )
103+ . with_min_len ( VERTEX_STREAM_PARALLEL_CHUNK_VERTICES )
104+ . zip (
105+ nrm_out
106+ . par_chunks_exact_mut ( 16 )
107+ . with_min_len ( VERTEX_STREAM_PARALLEL_CHUNK_VERTICES ) ,
108+ )
102109 . enumerate ( )
103110 . try_for_each ( |( i, ( pos_slot, nrm_slot) ) | {
104111 write_position_normal_vertex (
@@ -163,7 +170,9 @@ fn fill_normal_stream_with_forward_z(out: &mut [u8]) {
163170 chunk[ 12 ..16 ] . copy_from_slice ( & zero) ;
164171 } ;
165172 if should_parallelize_vertex_stream ( out. len ( ) / 16 ) {
166- out. par_chunks_exact_mut ( 16 ) . for_each ( write_chunk) ;
173+ out. par_chunks_exact_mut ( 16 )
174+ . with_min_len ( VERTEX_STREAM_PARALLEL_CHUNK_VERTICES )
175+ . for_each ( write_chunk) ;
167176 } else {
168177 out. chunks_exact_mut ( 16 ) . for_each ( write_chunk) ;
169178 }
@@ -220,6 +229,7 @@ pub fn vertex_float2_stream_bytes(
220229 } ;
221230 if should_parallelize_vertex_stream ( vertex_count) {
222231 out. par_chunks_exact_mut ( 8 )
232+ . with_min_len ( VERTEX_STREAM_PARALLEL_CHUNK_VERTICES )
223233 . enumerate ( )
224234 . try_for_each ( |( i, slot) | write_vertex_float2 ( & reader, i, slot) ) ?;
225235 } else {
@@ -269,6 +279,7 @@ pub fn wide_uv_stream_bytes(
269279
270280 if should_parallelize_vertex_stream ( vertex_count) {
271281 out. par_chunks_exact_mut ( WIDE_UV_VERTEX_STRIDE_BYTES )
282+ . with_min_len ( VERTEX_STREAM_PARALLEL_CHUNK_VERTICES )
272283 . enumerate ( )
273284 . try_for_each ( |( vertex, slot) | write_wide_uv_vertex ( & readers, vertex, slot) ) ?;
274285 } else {
@@ -327,6 +338,7 @@ fn vertex_float4_stream_bytes_with_kind(
327338 } ;
328339 if should_parallelize_vertex_stream ( vertex_count) {
329340 out. par_chunks_exact_mut ( 16 )
341+ . with_min_len ( VERTEX_STREAM_PARALLEL_CHUNK_VERTICES )
330342 . enumerate ( )
331343 . try_for_each ( |( i, slot) | write_vertex_float4 ( & reader, i, slot, default) ) ?;
332344 } else {
@@ -428,6 +440,7 @@ pub fn color_float4_stream_bytes(
428440
429441 if should_parallelize_vertex_stream ( vertex_count) {
430442 out. par_chunks_exact_mut ( 16 )
443+ . with_min_len ( VERTEX_STREAM_PARALLEL_CHUNK_VERTICES )
431444 . enumerate ( )
432445 . try_for_each ( |( i, slot) | write_vertex_float4 ( & reader, i, slot, [ 1.0 ; 4 ] ) ) ?;
433446 } else {
@@ -448,7 +461,9 @@ fn fill_float4_stream_with_default(out: &mut [u8], default: [f32; 4]) {
448461 }
449462 } ;
450463 if should_parallelize_vertex_stream ( out. len ( ) / 16 ) {
451- out. par_chunks_exact_mut ( 16 ) . for_each ( write_chunk) ;
464+ out. par_chunks_exact_mut ( 16 )
465+ . with_min_len ( VERTEX_STREAM_PARALLEL_CHUNK_VERTICES )
466+ . for_each ( write_chunk) ;
452467 } else {
453468 out. chunks_exact_mut ( 16 ) . for_each ( write_chunk) ;
454469 }
0 commit comments