Skip to content

Commit

Permalink
refactor: rewrite timer
Browse files Browse the repository at this point in the history
  • Loading branch information
w3ntao committed Apr 14, 2024
1 parent a57c9fe commit d69b073
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_and_render.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
pull_request:
branches: [ "*" ]
schedule:
- cron: "0 0 * * 0"
# runs on 00:00 every Sunday (UTC)
- cron: "0 0 1 * *"
# runs on 00:00 1st day of every month
# 00:00 UTC = 08:00 Beijing
workflow_dispatch:

Expand Down
1 change: 0 additions & 1 deletion src/base/film.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ pub trait Film: Send + Sync {
}

image.export_to_png(filename);
println!("image saved to `{}`", filename);
}
}
13 changes: 5 additions & 8 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ fn render(file_path: &str, samples_per_pixel: usize) {

let mut builder = SceneBuilder::default();
let mut scene_config = builder.parse_scene(file_path, samples_per_pixel);
let preprocessing_finished = Instant::now();

println!(
"preprocessing (spectra computing + BVH building): {:.2} seconds",
start.elapsed().as_secs_f32(),
);

let cpu_num = num_cpus::get();

scene_config.render(samples_per_pixel, cpu_num);
println!(
"total times: ({} + {}) second ({} spp with {} cores)",
(preprocessing_finished - start).as_secs(),
preprocessing_finished.elapsed().as_secs(),
samples_per_pixel,
cpu_num
);
}

fn main() {
Expand Down
11 changes: 11 additions & 0 deletions src/scene/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ impl Renderer {
}

pub fn render(&mut self, num_samples: usize, num_cores: usize) {
let start = Instant::now();

let resolution = self.film.lock().unwrap().get_resolution();

let job_list = Arc::new(Mutex::new((0..resolution.y).collect::<Vec<i32>>()));
Expand Down Expand Up @@ -114,5 +116,14 @@ impl Renderer {
.lock()
.unwrap()
.export_image(&filename, resolution);

println!(
"rendering took: {:.2} seconds ({} spp with {} cores)",
start.elapsed().as_secs_f32(),
num_samples,
num_cores,
);

println!("image saved to `{}`", filename);
}
}

0 comments on commit d69b073

Please sign in to comment.