From abe4aa6115df490f8798ae6082cdab769993dece Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 15 Feb 2023 17:13:22 -0600 Subject: [PATCH] more stuff --- assignment-1b/.gitignore | 2 ++ assignment-1b/Cargo.toml | 4 ++++ assignment-1b/src/main.rs | 9 +++------ assignment-1b/src/scene/input_file.rs | 2 +- assignment-1b/src/utils.rs | 5 +++-- flake.nix | 1 + 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/assignment-1b/.gitignore b/assignment-1b/.gitignore index 699e25f..841bbdb 100644 --- a/assignment-1b/.gitignore +++ b/assignment-1b/.gitignore @@ -5,3 +5,5 @@ *.ppm *.zip *.pdf +perf.data* +flamegraph.svg diff --git a/assignment-1b/Cargo.toml b/assignment-1b/Cargo.toml index 6adca8d..2e779a3 100644 --- a/assignment-1b/Cargo.toml +++ b/assignment-1b/Cargo.toml @@ -4,6 +4,10 @@ authors = ["Michael Zhang "] version = "0.1.0" edition = "2021" +# For profiling with flamegraphs +[profile.release] +debug = true + [[bin]] name = "raytracer1b" path = "src/main.rs" diff --git a/assignment-1b/src/main.rs b/assignment-1b/src/main.rs index bd2a51b..5faa46e 100644 --- a/assignment-1b/src/main.rs +++ b/assignment-1b/src/main.rs @@ -6,6 +6,7 @@ use assignment_1b::image::Image; use assignment_1b::ray::Ray; use assignment_1b::scene::Scene; use clap::Parser; +use rayon::prelude::{IntoParallelIterator, ParallelIterator}; /// Simple raycaster. #[derive(Parser)] @@ -69,12 +70,8 @@ fn main() -> Result<()> { // Generate a parallel iterator for pixels // The iterator preserves order and uses row-major order let pixels_iter = (0..scene.image_height) - // .into_par_iter() - .flat_map(|y| { - (0..scene.image_width) - // .into_par_iter() - .map(move |x| (x, y)) - }); + .into_par_iter() + .flat_map(|y| (0..scene.image_width).into_par_iter().map(move |x| (x, y))); // Loop through every single pixel of the output file let pixels = pixels_iter diff --git a/assignment-1b/src/scene/input_file.rs b/assignment-1b/src/scene/input_file.rs index 8fb4a5d..6c5c637 100644 --- a/assignment-1b/src/scene/input_file.rs +++ b/assignment-1b/src/scene/input_file.rs @@ -80,7 +80,7 @@ impl Scene { 1 => LightKind::Point { location: read_vec3(0)?, }, - _ => bail!("Invalid w"), + _ => bail!("Invalid w; must be either 0 or 1"), }; let light = Light { kind, diff --git a/assignment-1b/src/utils.rs b/assignment-1b/src/utils.rs index 1c798f7..21f183b 100644 --- a/assignment-1b/src/utils.rs +++ b/assignment-1b/src/utils.rs @@ -33,9 +33,10 @@ pub fn compute_rotation_matrix( a: Vector3, b: Vector3, ) -> Result> { - // Special case: if a and b are in the same direction, just return the identity matrix + // Special case: if a and b are in the same direction, just return the + // identity matrix. if a.normalize() == b.normalize() { - return Ok(Matrix3::identity()) + return Ok(Matrix3::identity()); } let cos_t = a.dot(&b); diff --git a/flake.nix b/flake.nix index 7971020..8825492 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,7 @@ cargo-flamegraph cargo-watch imagemagick + linuxPackages_latest.perf pandoc texlive.combined.scheme-full unzip