Compare commits

...

2 commits

Author SHA1 Message Date
Bruno BELANYI 9e29a5cb7d library: render: scene: remove FIXME about chunks 2020-03-19 21:55:42 +01:00
Antoine Martin ce64403449 library: render: split rows in chunks for perf 2020-03-19 21:55:04 +01:00

View file

@ -61,14 +61,17 @@ impl Scene {
Self::pixel Self::pixel
}; };
let mut rows: Vec<_> = image.enumerate_rows_mut().collect();
rayon::scope(|s| { rayon::scope(|s| {
// FIXME(Bruno): it would go even faster to cut the image in blocks of rows, leading to let chunk_size = self.camera.film().height() as usize / rayon::current_num_threads();
// better cache-line behaviour... // `chunks_size + 1` to have exactly num_threads tasks spawned, even with rounding
for (_, row) in image.enumerate_rows_mut() { for chunk in rows.chunks_mut(chunk_size + 1) {
s.spawn(|_| { s.spawn(|_| {
for (x, y, pixel) in row { for (_, row) in chunk {
*pixel = pixel_func(&self, x as f32, y as f32).into(); for (x, y, pixel) in row {
pb.inc(1); *pixel = pixel_func(&self, x as f32, y as f32).into();
pb.inc(1);
}
} }
}) })
} }