library: render: scene: use rayon scope parallelism

The implementation was very easy to write, but is not yet optimal. It
would be better to use `join` to divide into tasks directly on the
stack. And it would be better to iterate over entire blocks of rows
instead of giving a row per-thread: this would lead to better cache-line
behaviour with the fully linear memory accesses.
This commit is contained in:
Bruno BELANYI 2020-03-18 19:16:15 +01:00
parent 923a8fe20c
commit 3257598913

View file

@ -49,9 +49,17 @@ impl Scene {
} else {
Self::pixel
};
for (x, y, pixel) in image.enumerate_pixels_mut() {
*pixel = pixel_func(&self, x as f32, y as f32).into()
}
rayon::scope(|s| {
// FIXME(Bruno): it would go even faster to cut the image in blocks of rows, leading to
// better cache-line behaviour...
for (_, row) in image.enumerate_rows_mut() {
s.spawn(|_| {
for (x, y, pixel) in row {
*pixel = pixel_func(&self, x as f32, y as f32).into()
}
})
}
});
image
}