diff --git a/src/accel/bvh.rs b/src/accel/bvh.rs index c78b477..675e5d3 100644 --- a/src/accel/bvh.rs +++ b/src/accel/bvh.rs @@ -13,6 +13,7 @@ use timer::Timer; use super::bvh_base::{BVHBase, BVHBaseNode, BVH_MAX_DEPTH}; use super::ACCEL_TRAV_TIME; +use super::ACCEL_NODE_RAY_TESTS; #[derive(Copy, Clone, Debug)] @@ -80,6 +81,7 @@ impl<'a> BVH<'a> { let mut timer = Timer::new(); let mut trav_time: f64 = 0.0; + let mut node_tests: u64 = 0; let ray_sign = [ rays[0].dir_inv.x() >= 0.0, @@ -93,6 +95,7 @@ impl<'a> BVH<'a> { let mut stack_ptr = 1; while stack_ptr > 0 { + node_tests += ray_i_stack[stack_ptr] as u64; match node_stack[stack_ptr] { &BVHNode::Internal { children, @@ -152,6 +155,10 @@ impl<'a> BVH<'a> { let v = att.get(); att.set(v + trav_time); }); + ACCEL_NODE_RAY_TESTS.with(|anv| { + let v = anv.get(); + anv.set(v + node_tests); + }); } fn construct_from_base( diff --git a/src/accel/bvh4.rs b/src/accel/bvh4.rs index 50247e3..ea2eefe 100644 --- a/src/accel/bvh4.rs +++ b/src/accel/bvh4.rs @@ -14,6 +14,7 @@ use timer::Timer; use bvh_order::{TRAVERSAL_TABLE, SplitAxes, calc_traversal_code}; use super::bvh_base::{BVHBase, BVHBaseNode, BVH_MAX_DEPTH}; use super::ACCEL_TRAV_TIME; +use super::ACCEL_NODE_RAY_TESTS; #[derive(Copy, Clone, Debug)] @@ -79,6 +80,7 @@ impl<'a> BVH4<'a> { let mut timer = Timer::new(); let mut trav_time: f64 = 0.0; + let mut node_tests: u64 = 0; let traversal_table = { let ray_sign_is_neg = [ @@ -97,6 +99,7 @@ impl<'a> BVH4<'a> { let mut stack_ptr = 1; while stack_ptr > 0 { + node_tests += ray_i_stack[stack_ptr] as u64; match node_stack[stack_ptr] { &BVH4Node::Inner { traversal_code, @@ -195,6 +198,10 @@ impl<'a> BVH4<'a> { let v = att.get(); att.set(v + trav_time); }); + ACCEL_NODE_RAY_TESTS.with(|anv| { + let v = anv.get(); + anv.set(v + node_tests); + }); } fn construct_from_base( diff --git a/src/accel/mod.rs b/src/accel/mod.rs index 1f54ad7..b11b3ad 100644 --- a/src/accel/mod.rs +++ b/src/accel/mod.rs @@ -18,6 +18,7 @@ pub use self::light_array::LightArray; // Track BVH traversal time thread_local! { pub static ACCEL_TRAV_TIME: Cell = Cell::new(0.0); + pub static ACCEL_NODE_RAY_TESTS: Cell = Cell::new(0); } pub trait LightAccel { diff --git a/src/main.rs b/src/main.rs index 17c0301..4efc7d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -316,6 +316,7 @@ fn main() { "\t\t\tTraversal: {:.3}s", ntime * rstats.accel_traversal_time ); + println!("\t\t\tRay/node tests: {}", rstats.accel_node_visits); println!( "\t\tInitial ray generation: {:.3}s", ntime * rstats.initial_ray_generation_time diff --git a/src/renderer.rs b/src/renderer.rs index 9259ca8..cadbb92 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -10,7 +10,7 @@ use scoped_threadpool::Pool; use halton; -use accel::ACCEL_TRAV_TIME; +use accel::{ACCEL_TRAV_TIME, ACCEL_NODE_RAY_TESTS}; use algorithm::partition_pair; use color::{Color, XYZ, SpectralSample, map_0_1_to_wavelength}; use float4::Float4; @@ -40,6 +40,7 @@ pub struct Renderer<'a> { pub struct RenderStats { pub trace_time: f64, pub accel_traversal_time: f64, + pub accel_node_visits: u64, pub initial_ray_generation_time: f64, pub ray_generation_time: f64, pub sample_writing_time: f64, @@ -51,6 +52,7 @@ impl RenderStats { RenderStats { trace_time: 0.0, accel_traversal_time: 0.0, + accel_node_visits: 0, initial_ray_generation_time: 0.0, ray_generation_time: 0.0, sample_writing_time: 0.0, @@ -61,6 +63,7 @@ impl RenderStats { fn collect(&mut self, other: RenderStats) { self.trace_time += other.trace_time; self.accel_traversal_time += other.accel_traversal_time; + self.accel_node_visits += other.accel_node_visits; self.initial_ray_generation_time += other.initial_ray_generation_time; self.ray_generation_time += other.ray_generation_time; self.sample_writing_time += other.sample_writing_time; @@ -341,6 +344,10 @@ impl<'a> Renderer<'a> { stats.accel_traversal_time = att.get(); att.set(0.0); }); + ACCEL_NODE_RAY_TESTS.with(|anv| { + stats.accel_node_visits = anv.get(); + anv.set(0); + }); // Collect stats collected_stats.write().unwrap().collect(stats);