aboutsummaryrefslogtreecommitdiff
path: root/src/render/coordinator.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-12 23:33:50 +0100
committerJulian T <julian@jtle.dk>2021-02-12 23:34:09 +0100
commit14f7b47f2c2315d0de5e52d31c57fe07a15d08ad (patch)
treef512e7e0939fd151cf9196004611e3cd82a95773 /src/render/coordinator.rs
parent49c6adb0db70ffc30eaac33b66eacf7574b34e26 (diff)
Implement multithreaded compiling of tiles
Diffstat (limited to 'src/render/coordinator.rs')
-rw-r--r--src/render/coordinator.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/render/coordinator.rs b/src/render/coordinator.rs
index a9a7d06..a8d8afb 100644
--- a/src/render/coordinator.rs
+++ b/src/render/coordinator.rs
@@ -7,7 +7,8 @@ use crate::camera::Film;
use crate::core::{Bound2i, Vector2i};
use crate::sample::Sampler;
-use std::sync::Mutex;
+use std::sync::{Arc, Mutex};
+use std::thread;
struct Tiler {
tilesize: Vector2i,
@@ -112,4 +113,15 @@ impl<'a> RenderCoord<'a> {
self.finish_task(&task);
}
}
+
+ pub fn run_threaded(&self, ctx: &RenderContext, sampler: &mut (dyn Sampler + Send), threads: u32) {
+ crossbeam::scope(|scope| {
+ for _ in 0..threads {
+ let mut sampler = sampler.clone_and_seed();
+ scope.spawn(move |_| {
+ self.work(ctx, sampler.as_mut());
+ });
+ }
+ }).unwrap();
+ }
}