From 2fddcae0fd90e1a6474ab46acc5a872fa957aa2d Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Fri, 28 Jun 2019 22:22:41 +0900 Subject: [PATCH] Reduced the size of a hot return value. Gives a small performance boost. --- src/accel/bvh4.rs | 8 ++++---- src/accel/bvh4_simd.rs | 6 +++--- src/light/rectangle_light.rs | 2 +- src/light/sphere_light.rs | 8 ++++---- src/ray.rs | 2 +- src/surface/triangle_mesh.rs | 2 +- src/tracer.rs | 6 +++--- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/accel/bvh4.rs b/src/accel/bvh4.rs index b21a5a2..6ee9525 100644 --- a/src/accel/bvh4.rs +++ b/src/accel/bvh4.rs @@ -125,9 +125,9 @@ impl<'a> BVH4<'a> { if hit { hit_count += 1; - ([0, 1, 2, 3, 4, 5, 6, 7], children.len()) + ([0, 1, 2, 3], children.len()) } else { - ([0, 1, 2, 3, 4, 5, 6, 7], 0) + ([0; 4], 0) } }); @@ -201,9 +201,9 @@ impl<'a> BVH4<'a> { ); if hit { hit_count += 1; - ([0, 1, 2, 3, 4, 5, 6, 7], object_count) + ([0, 1, 2, 3], object_count) } else { - ([0, 1, 2, 3, 4, 5, 6, 7], 0) + ([0; 4], 0) } }); diff --git a/src/accel/bvh4_simd.rs b/src/accel/bvh4_simd.rs index 06a9f15..95b042f 100644 --- a/src/accel/bvh4_simd.rs +++ b/src/accel/bvh4_simd.rs @@ -133,7 +133,7 @@ impl<'a> BVH4<'a> { // Ray testing ray_stack.pop_do_next_task(children.len(), |ray_idx| { if rays.is_done(ray_idx) { - ([0, 1, 2, 3, 4, 5, 6, 7], 0) + ([0; 4], 0) } else { let hits = lerp_slice(bounds, rays.time(ray_idx)) .intersect_ray( @@ -145,7 +145,7 @@ impl<'a> BVH4<'a> { if hits != 0 { all_hits |= hits; - let mut lanes = [0u8; 8]; + let mut lanes = [0u8; 4]; let mut lane_count = 0; for i in 0..children.len() { if (hits >> i) & 1 != 0 { @@ -155,7 +155,7 @@ impl<'a> BVH4<'a> { } (lanes, lane_count) } else { - ([0, 1, 2, 3, 4, 5, 6, 7], 0) + ([0; 4], 0) } } }); diff --git a/src/light/rectangle_light.rs b/src/light/rectangle_light.rs index f7af205..8df2890 100644 --- a/src/light/rectangle_light.rs +++ b/src/light/rectangle_light.rs @@ -333,7 +333,7 @@ impl<'a> Surface for RectangleLight<'a> { } } - ([0, 0, 0, 0, 0, 0, 0, 0], 0) + ([0; 4], 0) }); } } diff --git a/src/light/sphere_light.rs b/src/light/sphere_light.rs index ace32f7..8c596a8 100644 --- a/src/light/sphere_light.rs +++ b/src/light/sphere_light.rs @@ -242,7 +242,7 @@ impl<'a> Surface for SphereLight<'a> { let discriminant = (b * b) - (4.0 * a * c); if discriminant < 0.0 { // Discriminant less than zero? No solution => no intersection. - return ([0, 0, 0, 0, 0, 0, 0, 0], 0); + return ([0; 4], 0); } let discriminant = discriminant.sqrt(); @@ -268,7 +268,7 @@ impl<'a> Surface for SphereLight<'a> { // Check our intersection for validity against this ray's extents if t0 > rays.max_t(ray_idx) || t1 <= 0.0 { // Didn't hit because sphere is entirely outside of ray's extents - return ([0, 0, 0, 0, 0, 0, 0, 0], 0); + return ([0; 4], 0); } let t = if t0 > 0.0 { @@ -278,7 +278,7 @@ impl<'a> Surface for SphereLight<'a> { } else { // Didn't hit because ray is entirely within the sphere, and // therefore doesn't hit its surface. - return ([0, 0, 0, 0, 0, 0, 0, 0], 0); + return ([0; 4], 0); }; // We hit the sphere, so calculate intersection info. @@ -335,7 +335,7 @@ impl<'a> Surface for SphereLight<'a> { rays.set_max_t(ray_idx, t); } - ([0, 0, 0, 0, 0, 0, 0, 0], 0) + ([0; 4], 0) }); } } diff --git a/src/ray.rs b/src/ray.rs index 852f5c9..4312f32 100644 --- a/src/ray.rs +++ b/src/ray.rs @@ -297,7 +297,7 @@ impl RayStack { /// of lanes (by index) to add the given ray index back into. pub fn pop_do_next_task(&mut self, needed_lanes: usize, mut handle_ray: F) where - F: FnMut(usize) -> ([u8; 8], usize), + F: FnMut(usize) -> ([u8; 4], usize), { // Prepare lanes. self.ensure_lane_count(needed_lanes); diff --git a/src/surface/triangle_mesh.rs b/src/surface/triangle_mesh.rs index a1f8cb6..906b7a5 100644 --- a/src/surface/triangle_mesh.rs +++ b/src/surface/triangle_mesh.rs @@ -276,7 +276,7 @@ impl<'a> Surface for TriangleMesh<'a> { } } - ([0, 0, 0, 0, 0, 0, 0, 0], 0) + ([0; 4], 0) }); }, ); diff --git a/src/tracer.rs b/src/tracer.rs index d11d0bb..8ba78c3 100644 --- a/src/tracer.rs +++ b/src/tracer.rs @@ -99,7 +99,7 @@ impl<'a> TracerInner<'a> { ray_stack.pop_do_next_task(2, |ray_idx| { let t = rays.time(ray_idx); rays.update_local(ray_idx, &lerp_slice(xforms, t)); - ([0, 1, 2, 3, 4, 5, 6, 7], 2) + ([0, 1, 0, 0], 2) }); ray_stack.push_lanes_to_tasks(&[0, 1]); } @@ -132,13 +132,13 @@ impl<'a> TracerInner<'a> { ray_stack.pop_do_next_task(0, |ray_idx| { let t = rays.time(ray_idx); rays.update_local(ray_idx, &lerp_slice(xforms, t)); - ([0, 1, 2, 3, 4, 5, 6, 7], 0) + ([0; 4], 0) }); } else { let ident = Matrix4x4::new(); ray_stack.pop_do_next_task(0, |ray_idx| { rays.update_local(ray_idx, &ident); - ([0, 1, 2, 3, 4, 5, 6, 7], 0) + ([0; 4], 0) }); } }