library: render: pathtracer: avoid row allocation

This commit is contained in:
Antoine Martin 2020-04-08 19:31:46 +02:00
parent 00dae425d9
commit faa1ef1fb8

View file

@ -49,25 +49,16 @@ impl Pathtracer {
let mut buffer: Vec<LinearColor> = Vec::new(); let mut buffer: Vec<LinearColor> = Vec::new();
buffer.resize_with(total as usize, LinearColor::black); buffer.resize_with(total as usize, LinearColor::black);
(0..height) buffer
.into_par_iter() .par_chunks_mut(width as usize)
.map(|y| { .enumerate()
let mut row: Vec<LinearColor> = Vec::new(); .for_each(|(y, row)| {
row.resize_with(width as usize, LinearColor::black);
for x in 0..width { for x in 0..width {
row[x as usize] += self.pixel_ray(x as f32, y as f32); row[x as usize] += self.pixel_ray(x as f32, y as f32);
} }
});
row buffer
})
.reduce(
|| Vec::new(),
|mut buf, row| {
buf.extend(row);
buf
},
)
}) })
.fold( .fold(
{ {