Reduced the size of a hot return value.

Gives a small performance boost.
This commit is contained in:
Nathan Vegdahl 2019-06-28 22:22:41 +09:00
parent aed0f2ede1
commit 2fddcae0fd
7 changed files with 17 additions and 17 deletions

View File

@ -125,9 +125,9 @@ impl<'a> BVH4<'a> {
if hit { if hit {
hit_count += 1; hit_count += 1;
([0, 1, 2, 3, 4, 5, 6, 7], children.len()) ([0, 1, 2, 3], children.len())
} else { } else {
([0, 1, 2, 3, 4, 5, 6, 7], 0) ([0; 4], 0)
} }
}); });
@ -201,9 +201,9 @@ impl<'a> BVH4<'a> {
); );
if hit { if hit {
hit_count += 1; hit_count += 1;
([0, 1, 2, 3, 4, 5, 6, 7], object_count) ([0, 1, 2, 3], object_count)
} else { } else {
([0, 1, 2, 3, 4, 5, 6, 7], 0) ([0; 4], 0)
} }
}); });

View File

@ -133,7 +133,7 @@ impl<'a> BVH4<'a> {
// Ray testing // Ray testing
ray_stack.pop_do_next_task(children.len(), |ray_idx| { ray_stack.pop_do_next_task(children.len(), |ray_idx| {
if rays.is_done(ray_idx) { if rays.is_done(ray_idx) {
([0, 1, 2, 3, 4, 5, 6, 7], 0) ([0; 4], 0)
} else { } else {
let hits = lerp_slice(bounds, rays.time(ray_idx)) let hits = lerp_slice(bounds, rays.time(ray_idx))
.intersect_ray( .intersect_ray(
@ -145,7 +145,7 @@ impl<'a> BVH4<'a> {
if hits != 0 { if hits != 0 {
all_hits |= hits; all_hits |= hits;
let mut lanes = [0u8; 8]; let mut lanes = [0u8; 4];
let mut lane_count = 0; let mut lane_count = 0;
for i in 0..children.len() { for i in 0..children.len() {
if (hits >> i) & 1 != 0 { if (hits >> i) & 1 != 0 {
@ -155,7 +155,7 @@ impl<'a> BVH4<'a> {
} }
(lanes, lane_count) (lanes, lane_count)
} else { } else {
([0, 1, 2, 3, 4, 5, 6, 7], 0) ([0; 4], 0)
} }
} }
}); });

View File

@ -333,7 +333,7 @@ impl<'a> Surface for RectangleLight<'a> {
} }
} }
([0, 0, 0, 0, 0, 0, 0, 0], 0) ([0; 4], 0)
}); });
} }
} }

View File

@ -242,7 +242,7 @@ impl<'a> Surface for SphereLight<'a> {
let discriminant = (b * b) - (4.0 * a * c); let discriminant = (b * b) - (4.0 * a * c);
if discriminant < 0.0 { if discriminant < 0.0 {
// Discriminant less than zero? No solution => no intersection. // 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(); let discriminant = discriminant.sqrt();
@ -268,7 +268,7 @@ impl<'a> Surface for SphereLight<'a> {
// Check our intersection for validity against this ray's extents // Check our intersection for validity against this ray's extents
if t0 > rays.max_t(ray_idx) || t1 <= 0.0 { if t0 > rays.max_t(ray_idx) || t1 <= 0.0 {
// Didn't hit because sphere is entirely outside of ray's extents // 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 { let t = if t0 > 0.0 {
@ -278,7 +278,7 @@ impl<'a> Surface for SphereLight<'a> {
} else { } else {
// Didn't hit because ray is entirely within the sphere, and // Didn't hit because ray is entirely within the sphere, and
// therefore doesn't hit its surface. // 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. // 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); rays.set_max_t(ray_idx, t);
} }
([0, 0, 0, 0, 0, 0, 0, 0], 0) ([0; 4], 0)
}); });
} }
} }

View File

@ -297,7 +297,7 @@ impl RayStack {
/// of lanes (by index) to add the given ray index back into. /// of lanes (by index) to add the given ray index back into.
pub fn pop_do_next_task<F>(&mut self, needed_lanes: usize, mut handle_ray: F) pub fn pop_do_next_task<F>(&mut self, needed_lanes: usize, mut handle_ray: F)
where where
F: FnMut(usize) -> ([u8; 8], usize), F: FnMut(usize) -> ([u8; 4], usize),
{ {
// Prepare lanes. // Prepare lanes.
self.ensure_lane_count(needed_lanes); self.ensure_lane_count(needed_lanes);

View File

@ -276,7 +276,7 @@ impl<'a> Surface for TriangleMesh<'a> {
} }
} }
([0, 0, 0, 0, 0, 0, 0, 0], 0) ([0; 4], 0)
}); });
}, },
); );

View File

@ -99,7 +99,7 @@ impl<'a> TracerInner<'a> {
ray_stack.pop_do_next_task(2, |ray_idx| { ray_stack.pop_do_next_task(2, |ray_idx| {
let t = rays.time(ray_idx); let t = rays.time(ray_idx);
rays.update_local(ray_idx, &lerp_slice(xforms, t)); 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]); 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| { ray_stack.pop_do_next_task(0, |ray_idx| {
let t = rays.time(ray_idx); let t = rays.time(ray_idx);
rays.update_local(ray_idx, &lerp_slice(xforms, t)); rays.update_local(ray_idx, &lerp_slice(xforms, t));
([0, 1, 2, 3, 4, 5, 6, 7], 0) ([0; 4], 0)
}); });
} else { } else {
let ident = Matrix4x4::new(); let ident = Matrix4x4::new();
ray_stack.pop_do_next_task(0, |ray_idx| { ray_stack.pop_do_next_task(0, |ray_idx| {
rays.update_local(ray_idx, &ident); rays.update_local(ray_idx, &ident);
([0, 1, 2, 3, 4, 5, 6, 7], 0) ([0; 4], 0)
}); });
} }
} }