Skip to content

Commit

Permalink
use duration for core_build_time
Browse files Browse the repository at this point in the history
  • Loading branch information
DGriffin91 committed Jul 25, 2024
1 parent 5f098cf commit f4b3dab
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 27 deletions.
6 changes: 4 additions & 2 deletions embree/src/embree_managed.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

use glam::Mat4;
use obvhs::{
ray::{Ray, RayHit},
Expand All @@ -9,7 +11,7 @@ pub fn embree_attach_geometry(
objects: &Vec<Vec<Triangle>>,
device: &embree4_rs::Device,
embree_scene: &embree4_rs::Scene,
blas_build_time: &mut f32,
blas_build_time: &mut Duration,
) {
for object in objects {
let mut verts = Vec::with_capacity(object.len() * 3 * 3);
Expand All @@ -26,7 +28,7 @@ pub fn embree_attach_geometry(
let tri_mesh =
embree4_rs::geometry::TriangleMeshGeometry::try_new(&device, &verts, &indices).unwrap();
embree_scene.attach_geometry(&tri_mesh).unwrap();
*blas_build_time += start_time.elapsed().as_secs_f32();
*blas_build_time += start_time.elapsed();
}
}

Expand Down
10 changes: 5 additions & 5 deletions embree/src/gpu_bvh_builder_embree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use obvhs::{
cwbvh::{CwBvh, BRANCHING},
triangle::Triangle,
};
use std::time::Instant;
use std::time::{Duration, Instant};

use crate::{
bvh_embree::{self, UserData},
Expand All @@ -24,7 +24,7 @@ pub const USE_EMBREE_PRESPLITS: bool = false;

pub fn embree_build_cwbvh_from_tris(
triangles: &[Triangle],
core_build_time: &mut f32,
core_build_time: &mut Duration,
device: *mut embree4_sys::RTCDeviceTy,
) -> CwBvh {
let indices = (0..triangles.len() as u32).map(|i| i).collect::<Vec<u32>>();
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn embree_build_cwbvh_from_tris(
converter.convert_to_cwbvh(&total_aabb, root);
converter
};
*core_build_time += start_time.elapsed().as_secs_f32();
*core_build_time += start_time.elapsed();

assert!(!converter.nodes.is_empty());

Expand All @@ -123,7 +123,7 @@ pub fn embree_build_cwbvh_from_tris(

pub fn embree_build_cwbvh_from_aabbs(
aabbs: &[Aabb],
core_build_time: &mut f32,
core_build_time: &mut Duration,
device: *mut embree4_sys::RTCDeviceTy,
) -> CwBvh {
let indices = (0..aabbs.len() as u32).map(|i| i).collect::<Vec<u32>>();
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn embree_build_cwbvh_from_aabbs(
converter.convert_to_cwbvh(&total_aabb, root);
converter
};
*core_build_time += start_time.elapsed().as_secs_f32();
*core_build_time += start_time.elapsed();

assert!(!converter.nodes.is_empty());

Expand Down
6 changes: 3 additions & 3 deletions embree/src/gpu_bvh_builder_embree_bvh2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use obvhs::{
triangle::Triangle,
BvhBuildParams,
};
use std::time::Instant;
use std::time::{Duration, Instant};

use crate::bvh_embree::{self, UserData};

pub fn embree_build_bvh2_cwbvh_from_tris(
triangles: &[Triangle],
config: BvhBuildParams,
core_build_time: &mut f32,
core_build_time: &mut Duration,
device: *mut embree4_sys::RTCDeviceTy,
) -> CwBvh {
let indices = (0..triangles.len() as u32).map(|i| i).collect::<Vec<u32>>();
Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn embree_build_bvh2_cwbvh_from_tris(
converter.calculate_cost(config.max_prims_per_leaf);
converter.convert_to_cwbvh();

*core_build_time += start_time.elapsed().as_secs_f32();
*core_build_time += start_time.elapsed();

let cwbvh = CwBvh {
nodes: converter.nodes,
Expand Down
5 changes: 3 additions & 2 deletions src/cwbvh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use obvhs::{
ray::{Ray, RayHit},
triangle::Triangle,
};
use std::time::Duration;

#[cfg(feature = "embree")]
use obvhs_embree::{
Expand All @@ -20,7 +21,7 @@ use crate::{build_params_from_options, Options};
pub fn cwbvh_from_tris(
triangles: &[Triangle],
options: &Options,
core_build_time: &mut f32,
core_build_time: &mut Duration,
#[cfg(feature = "embree")] embree_device: Option<&embree4_rs::Device>,
) -> CwBvh {
if options.verbose {
Expand Down Expand Up @@ -71,7 +72,7 @@ pub fn cwbvh_from_tris(
pub fn tlas_from_blas(
blas: &Vec<CwBvh>,
options: &Options,
tlas_build_time: &mut f32,
tlas_build_time: &mut Duration,
#[cfg(feature = "embree")] embree_device: Option<&embree4_rs::Device>,
) -> CwBvh {
let tlas_aabbs = blas.iter().map(|b| b.total_aabb).collect::<Vec<_>>();
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cargo run --release -- --benchmark --preset very_fast_build --render-time 5.0 -i
*/

use std::{
collections::HashMap, fs::File, io::BufReader, path::{Path, PathBuf}
collections::HashMap, fs::File, io::BufReader, path::{Path, PathBuf}, time::Duration
};

use auto_tune::tune;
Expand Down Expand Up @@ -287,8 +287,8 @@ fn render_from_options(
#[cfg(not(feature = "hardware_rt"))]
panic!("Need to enable hardware_rt feature and use wgpu ray query PR");
} else {
let mut blas_build_time = 0.0;
let mut tlas_build_time = 0.0;
let mut blas_build_time = Duration::ZERO;
let mut tlas_build_time = Duration::ZERO;

let frame_time = if options.cpu {
match options.build.as_str() {
Expand All @@ -309,7 +309,7 @@ fn render_from_options(
);
let start_time = std::time::Instant::now();
let committed_scene = embree_scene.commit().unwrap();
blas_build_time += start_time.elapsed().as_secs_f32();
blas_build_time += start_time.elapsed();
let objects = objects
.iter()
.map(|mesh| {
Expand Down Expand Up @@ -400,8 +400,8 @@ fn render_from_options(
stats.push(Stats {
name: file_name.to_string(),
traversal_ms: frame_time,
blas_build_time_s: blas_build_time,
tlas_build_time_ms: tlas_build_time * 1000.0, // Convert to ms
blas_build_time_s: blas_build_time.as_secs_f32(),
tlas_build_time_ms: (tlas_build_time).as_secs_f32() * 1000.0, // Convert to ms
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/parry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::Instant;
use std::time::{Duration, Instant};

use glam::Mat4;
use nalgebra::{Point, SVector};
Expand Down Expand Up @@ -54,7 +54,7 @@ pub struct ParryScene {
}

impl ParryScene {
pub fn new(tris: &[obvhs::triangle::Triangle], core_build_time: &mut f32) -> Self {
pub fn new(tris: &[obvhs::triangle::Triangle], core_build_time: &mut Duration) -> Self {
let parry_tris = tris
.iter()
.map(|t| {
Expand All @@ -76,7 +76,7 @@ impl ParryScene {
let mut qbvh = Qbvh::<u32>::new();
qbvh.clear_and_rebuild(indexed_aabbs.clone(), 0.0);

*core_build_time += start_time.elapsed().as_secs_f32();
*core_build_time += start_time.elapsed();

ParryScene {
qbvh,
Expand Down
6 changes: 4 additions & 2 deletions src/rt_cpu/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod rt_cpu;

use std::time::Duration;

use crate::{
cwbvh::{cwbvh_from_tris, tlas_from_blas, CwBvhScene, CwBvhTlasScene},
Options, Scene,
Expand All @@ -15,8 +17,8 @@ use traversable::{Intersectable, SceneRtTri, Traversable};
pub fn cwbvh_cpu_runner(
objects: &Vec<Vec<Triangle>>,
options: &Options,
blas_build_time: &mut f32,
tlas_build_time: &mut f32,
blas_build_time: &mut Duration,
tlas_build_time: &mut Duration,
file_name: &str,
scene: Scene,
#[cfg(feature = "embree")] embree_device: Option<&embree4_rs::Device>,
Expand Down
6 changes: 4 additions & 2 deletions src/rt_gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub mod rt_gpu_hardware;
pub mod rt_gpu_software;
pub mod shader_utils;

use std::time::Duration;

use crate::{
cwbvh::{cwbvh_from_tris, tlas_from_blas},
Options, Scene,
Expand All @@ -17,8 +19,8 @@ pub fn cwbvh_gpu_runner(
event_loop: &mut EventLoop<()>,
objects: &Vec<Vec<Triangle>>,
options: &Options,
blas_build_time: &mut f32,
tlas_build_time: &mut f32,
blas_build_time: &mut Duration,
tlas_build_time: &mut Duration,
scene: Scene,
#[cfg(feature = "embree")] embree_device: Option<&embree4_rs::Device>,
) -> f32 {
Expand Down
6 changes: 4 additions & 2 deletions src/svenstaro.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

use bvh::bounding_hierarchy::BHShape;

use bvh::bvh::Bvh;
Expand All @@ -13,15 +15,15 @@ use bvh::bounding_hierarchy::BoundingHierarchy;

pub fn build_svenstaro_scene(
objects: &Vec<Vec<Triangle>>,
blas_build_time: &mut f32,
blas_build_time: &mut Duration,
) -> SvenstaroScene {
let mut shapes = svenstaro_bbox_shapes(&*objects[0]);
let start_time = std::time::Instant::now();
#[cfg(feature = "parallel_build")]
let bvh = bvh::bvh::Bvh::build_par(&mut shapes);
#[cfg(not(feature = "parallel_build"))]
let bvh = bvh::bvh::Bvh::build(&mut shapes);
*blas_build_time += start_time.elapsed().as_secs_f32();
*blas_build_time += start_time.elapsed();
SvenstaroScene { shapes, bvh }
}

Expand Down

0 comments on commit f4b3dab

Please sign in to comment.