Async send the pixels to the workers, and bound queue to 2xthreads.
All checks were successful
continuous-integration/drone/push Build is passing

This should allow the program to start recieving rendered pixels before
all of the x,y's have been sent to the workers.  Reducing the time to
first pixel.
This commit is contained in:
Bill Thiede 2019-10-10 21:20:48 -07:00
parent 2a0460f2cb
commit 9a45ba6d72

View File

@ -256,11 +256,13 @@ fn render_worker(
}
pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::io::Error> {
let (pixel_req_tx, pixel_req_rx) = channel::unbounded();
let (pixel_resp_tx, pixel_resp_rx) = channel::unbounded();
let cpus = num_cpus::get();
let (pixel_req_tx, pixel_req_rx) = channel::bounded(2 * cpus);
let (pixel_resp_tx, pixel_resp_rx) = channel::bounded(2 * cpus);
let scene = sync::Arc::new(scene);
for i in 0..num_cpus::get() {
println!("Creating {} render threads", cpus);
for i in 0..cpus {
let s = sync::Arc::clone(&scene);
let pixel_req_rx = pixel_req_rx.clone();
let pixel_resp_tx = pixel_resp_tx.clone();
@ -271,12 +273,15 @@ pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::i
drop(pixel_req_rx);
drop(pixel_resp_tx);
for y in 0..scene.height {
for x in 0..scene.width {
pixel_req_tx.send(PixelRequest { x, y });
let (w, h) = (scene.width, scene.height);
thread::spawn(move || {
for y in 0..w {
for x in 0..h {
pixel_req_tx.send(PixelRequest { x, y });
}
}
}
drop(pixel_req_tx);
drop(pixel_req_tx);
});
println!("Rendering with {} subsamples", scene.subsamples);
let mut img = RgbImage::new(scene.width as u32, scene.height as u32);