@@ -15,13 +15,15 @@ use crate::world_mesh::cluster::{
1515} ;
1616
1717/// Light count at which `Auto` mode starts considering CPU froxel assignment.
18- pub ( super ) const AUTO_CPU_FROXEL_LIGHT_THRESHOLD : u32 = 128 ;
19- const CPU_FROXEL_PARALLEL_MIN_LIGHTS : usize = 128 ;
20- const CPU_FROXEL_LIGHT_CHUNK_SIZE : usize = 64 ;
18+ pub ( super ) const AUTO_CPU_FROXEL_LIGHT_THRESHOLD : u32 = 64 ;
19+ /// Light count at which CPU froxel assignment fans out across worker chunks.
20+ const CPU_FROXEL_PARALLEL_MIN_LIGHTS : usize = 64 ;
21+ /// Lights assigned to one CPU froxel worker chunk.
22+ const CPU_FROXEL_LIGHT_CHUNK_SIZE : usize = 32 ;
2123/// Froxel count at which count merge, offset, and prefix work uses Rayon.
22- const CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS : usize = 1_024 ;
24+ const CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS : usize = 512 ;
2325/// Cluster-count stride for local prefix-sum chunks.
24- const CPU_FROXEL_PREFIX_CHUNK_SIZE : usize = 1_024 ;
26+ const CPU_FROXEL_PREFIX_CHUNK_SIZE : usize = 512 ;
2527
2628/// Point light tag in [`GpuLight::light_type`].
2729const LIGHT_TYPE_POINT : u32 = 0 ;
@@ -122,14 +124,26 @@ impl FroxelLightPlanner {
122124 return Some ( CpuClusterAssignments :: default ( ) ) ;
123125 }
124126 let layouts = validated_eye_layouts ( eye_params, clusters_per_eye) ?;
125- if lights. len ( ) >= CPU_FROXEL_PARALLEL_MIN_LIGHTS {
127+ if should_parallelize_cpu_froxel_lights ( lights. len ( ) ) {
126128 build_parallel ( lights, eye_params, & layouts, clusters_per_eye)
127129 } else {
128130 build_serial ( lights, eye_params, & layouts, clusters_per_eye)
129131 }
130132 }
131133}
132134
135+ /// Returns whether CPU froxel assignment should split light ranges over Rayon.
136+ #[ inline]
137+ fn should_parallelize_cpu_froxel_lights ( light_count : usize ) -> bool {
138+ light_count >= CPU_FROXEL_PARALLEL_MIN_LIGHTS
139+ }
140+
141+ /// Returns whether CPU froxel prefix and merge helpers should use Rayon.
142+ #[ inline]
143+ fn should_parallelize_cpu_froxel_prefix ( cluster_count : usize ) -> bool {
144+ cluster_count >= CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS
145+ }
146+
133147fn validated_eye_layouts (
134148 eye_params : & [ ClusterFrameParams ] ,
135149 clusters_per_eye : u32 ,
@@ -281,7 +295,7 @@ fn merge_parallel_chunk_counts(
281295 chunks : & [ CpuFroxelCountChunk ] ,
282296 total_clusters : usize ,
283297) -> ( Vec < u32 > , CpuFroxelStats ) {
284- let counts = if total_clusters >= CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS {
298+ let counts = if should_parallelize_cpu_froxel_prefix ( total_clusters) {
285299 ( 0 ..total_clusters)
286300 . into_par_iter ( )
287301 . map ( |cluster_id| {
@@ -312,7 +326,7 @@ fn build_parallel_chunk_offsets(
312326 total_clusters : usize ,
313327) -> Vec < Vec < u32 > > {
314328 let chunk_count = chunks. len ( ) ;
315- if total_clusters >= CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS && chunk_count >= 2 {
329+ if should_parallelize_cpu_froxel_prefix ( total_clusters) && chunk_count >= 2 {
316330 let per_cluster_offsets = ( 0 ..total_clusters)
317331 . into_par_iter ( )
318332 . map ( |cluster_id| {
@@ -639,7 +653,7 @@ fn assign_bounded_light(
639653
640654/// Converts per-froxel counts into compact `[offset, count]` rows.
641655fn prefix_counts_to_ranges ( counts : & [ u32 ] ) -> Option < ( Vec < [ u32 ; 2 ] > , usize ) > {
642- if counts. len ( ) >= CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS {
656+ if should_parallelize_cpu_froxel_prefix ( counts. len ( ) ) {
643657 return prefix_counts_to_ranges_parallel ( counts) ;
644658 }
645659 prefix_counts_to_ranges_serial ( counts)
@@ -809,6 +823,34 @@ mod tests {
809823 & assignments. indices [ start..end]
810824 }
811825
826+ #[ test]
827+ fn cpu_froxel_light_parallel_gate_starts_at_two_chunks ( ) {
828+ assert_eq ! (
829+ CPU_FROXEL_PARALLEL_MIN_LIGHTS ,
830+ CPU_FROXEL_LIGHT_CHUNK_SIZE * 2
831+ ) ;
832+ assert ! ( !should_parallelize_cpu_froxel_lights(
833+ CPU_FROXEL_PARALLEL_MIN_LIGHTS - 1
834+ ) ) ;
835+ assert ! ( should_parallelize_cpu_froxel_lights(
836+ CPU_FROXEL_PARALLEL_MIN_LIGHTS
837+ ) ) ;
838+ }
839+
840+ #[ test]
841+ fn cpu_froxel_prefix_parallel_gate_starts_at_prefix_chunk ( ) {
842+ assert_eq ! (
843+ CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS ,
844+ CPU_FROXEL_PREFIX_CHUNK_SIZE
845+ ) ;
846+ assert ! ( !should_parallelize_cpu_froxel_prefix(
847+ CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS - 1
848+ ) ) ;
849+ assert ! ( should_parallelize_cpu_froxel_prefix(
850+ CPU_FROXEL_PREFIX_PARALLEL_MIN_CLUSTERS
851+ ) ) ;
852+ }
853+
812854 #[ test]
813855 fn empty_lights_write_zero_ranges_without_indices ( ) {
814856 let params = test_params ( ) ;
0 commit comments