Add flag to set number of threads.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1687077f4a
commit
235a9d1204
@ -119,6 +119,9 @@ pub struct Opt {
|
||||
/// Image height
|
||||
#[structopt(short = "h", long = "height", default_value = "1024")]
|
||||
pub height: usize,
|
||||
/// Number of threads
|
||||
#[structopt(short = "t", long = "num_threads")]
|
||||
pub num_threads: Option<usize>,
|
||||
/// Sub-samples per pixel
|
||||
#[structopt(short = "s", long = "subsample", default_value = "8")]
|
||||
pub subsamples: usize,
|
||||
@ -139,6 +142,7 @@ pub struct Opt {
|
||||
}
|
||||
|
||||
pub fn opt_hash(opt: &Opt) -> String {
|
||||
// TODO(wathiede): add threads.
|
||||
format!(
|
||||
"w:{}-h:{}-s:{}-pprof:{}-model:{}-use_accel:{}-{}",
|
||||
opt.width,
|
||||
@ -155,6 +159,7 @@ pub struct Scene {
|
||||
pub world: Box<Hit>,
|
||||
pub camera: Camera,
|
||||
pub subsamples: usize,
|
||||
pub num_threads: Option<usize>,
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
pub global_illumination: bool,
|
||||
@ -269,13 +274,13 @@ fn render_worker(
|
||||
}
|
||||
|
||||
pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::io::Error> {
|
||||
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 num_threads = scene.num_threads.unwrap_or_else(num_cpus::get);
|
||||
let (pixel_req_tx, pixel_req_rx) = channel::bounded(2 * num_threads);
|
||||
let (pixel_resp_tx, pixel_resp_rx) = channel::bounded(2 * num_threads);
|
||||
|
||||
let scene = sync::Arc::new(scene);
|
||||
println!("Creating {} render threads", cpus);
|
||||
for i in 0..cpus {
|
||||
println!("Creating {} render threads", num_threads);
|
||||
for i in 0..num_threads {
|
||||
let s = sync::Arc::clone(&scene);
|
||||
let pixel_req_rx = pixel_req_rx.clone();
|
||||
let pixel_resp_tx = pixel_resp_tx.clone();
|
||||
|
||||
@ -69,6 +69,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: true,
|
||||
|
||||
@ -51,6 +51,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: true,
|
||||
|
||||
@ -63,6 +63,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: true,
|
||||
|
||||
@ -130,6 +130,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: false,
|
||||
|
||||
@ -115,6 +115,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: false,
|
||||
|
||||
@ -166,6 +166,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world: Box::new(HitableList::new(list)),
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: false,
|
||||
|
||||
@ -144,6 +144,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: false,
|
||||
|
||||
@ -65,6 +65,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: true,
|
||||
|
||||
@ -142,6 +142,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: false,
|
||||
|
||||
@ -70,6 +70,7 @@ pub fn new(opt: &Opt) -> Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
num_threads: opt.num_threads,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
global_illumination: true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user