@@ -401,7 +401,7 @@ fn clear_histogram(ctx: &GpuContext, histogram: &GpuHistogram) -> Result<(), Gpu
401401 pass. set_pipeline ( & ctx. pipelines . histogram_clear ) ;
402402 pass. set_bind_group ( 0 , & bind_group, & [ ] ) ;
403403
404- let workgroups = ( NUM_HISTOGRAM_BUCKETS as u32 + WORKGROUP_SIZE - 1 ) / WORKGROUP_SIZE ;
404+ let workgroups = ( NUM_HISTOGRAM_BUCKETS as u32 ) . div_ceil ( WORKGROUP_SIZE ) ;
405405 pass. dispatch_workgroups ( workgroups, 1 , 1 ) ;
406406 }
407407
@@ -501,14 +501,14 @@ fn accumulate_histogram(
501501 pass. set_bind_group ( 0 , & bind_group, & [ ] ) ;
502502
503503 let pixel_count = image. pixel_count ( ) ;
504- let total_workgroups = ( pixel_count + WORKGROUP_SIZE - 1 ) / WORKGROUP_SIZE ;
504+ let total_workgroups = pixel_count. div_ceil ( WORKGROUP_SIZE ) ;
505505
506506 // Use 2D dispatch for large images
507507 let ( workgroups_x, workgroups_y) = if total_workgroups <= MAX_WORKGROUPS_PER_DIM {
508508 ( total_workgroups, 1 )
509509 } else {
510510 let side = ( ( total_workgroups as f64 ) . sqrt ( ) . ceil ( ) as u32 ) . min ( MAX_WORKGROUPS_PER_DIM ) ;
511- let other = ( total_workgroups + side - 1 ) / side ;
511+ let other = total_workgroups. div_ceil ( side) ;
512512 ( side, other. min ( MAX_WORKGROUPS_PER_DIM ) )
513513 } ;
514514 pass. dispatch_workgroups ( workgroups_x, workgroups_y, 1 ) ;
@@ -784,6 +784,7 @@ fn clamp_working_range(
784784const MAX_WORKGROUPS_PER_DIM : u32 = 65535 ;
785785
786786/// Maximum pixels per single dispatch (65535 workgroups * 256 threads)
787+ #[ allow( dead_code) ]
787788const MAX_PIXELS_PER_DISPATCH : u32 = MAX_WORKGROUPS_PER_DIM * WORKGROUP_SIZE ;
788789
789790/// Generic compute dispatch for storage + uniform pattern
@@ -838,7 +839,7 @@ fn dispatch_compute(
838839 ] ,
839840 } ) ;
840841
841- let total_workgroups = ( pixel_count + WORKGROUP_SIZE - 1 ) / WORKGROUP_SIZE ;
842+ let total_workgroups = pixel_count. div_ceil ( WORKGROUP_SIZE ) ;
842843
843844 // If within limits, do a single dispatch
844845 if total_workgroups <= MAX_WORKGROUPS_PER_DIM {
@@ -865,7 +866,7 @@ fn dispatch_compute(
865866 // This allows up to 65535 * 65535 workgroups = ~4 billion workgroups
866867 // Calculate grid dimensions: try to make it roughly square for efficiency
867868 let side = ( ( total_workgroups as f64 ) . sqrt ( ) . ceil ( ) as u32 ) . min ( MAX_WORKGROUPS_PER_DIM ) ;
868- let workgroups_y = ( total_workgroups + side - 1 ) / side ;
869+ let workgroups_y = total_workgroups. div_ceil ( side) ;
869870
870871 if workgroups_y > MAX_WORKGROUPS_PER_DIM {
871872 return Err ( GpuError :: Other ( format ! (
@@ -902,7 +903,7 @@ fn dispatch_compute(
902903/// CPU-side base estimation (statistical analysis)
903904fn estimate_base_cpu ( decoded : & DecodedImage , _options : & ConvertOptions ) -> BaseEstimation {
904905 // Delegate to the existing CPU implementation
905- crate :: pipeline:: estimate_base ( decoded, None , None , None ) . unwrap_or_else ( |_| BaseEstimation {
906+ crate :: pipeline:: estimate_base ( decoded, None , None , None ) . unwrap_or ( BaseEstimation {
906907 roi : None ,
907908 medians : [ 0.5 , 0.5 , 0.5 ] ,
908909 noise_stats : None ,
@@ -978,10 +979,10 @@ fn compute_auto_color_gains(
978979 let mut sum: f64 = 0.0 ;
979980 let mut count: u64 = 0 ;
980981
981- for i in low_idx..= high_idx. min ( buckets - 1 ) {
982+ for ( i , & bin_count ) in hist . iter ( ) . enumerate ( ) . take ( high_idx. min ( buckets - 1 ) + 1 ) . skip ( low_idx ) {
982983 let value = i as f64 / buckets as f64 ;
983- sum += value * hist [ i ] as f64 ;
984- count += hist [ i ] as u64 ;
984+ sum += value * bin_count as f64 ;
985+ count += bin_count as u64 ;
985986 }
986987
987988 if count > 0 {
0 commit comments