-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from Walther/2024-02-06
2024-02-06 work
- Loading branch information
Showing
15 changed files
with
191 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use clovers::scenes::{initialize, Scene, SceneFile}; | ||
use clovers::RenderOpts; | ||
use clovers_draw_cpu::draw; | ||
use divan::{black_box, AllocProfiler}; | ||
|
||
#[global_allocator] | ||
static ALLOC: AllocProfiler = AllocProfiler::system(); | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
const WIDTH: u32 = 256; | ||
const HEIGHT: u32 = 256; | ||
const OPTS: RenderOpts = RenderOpts { | ||
width: WIDTH, | ||
height: HEIGHT, | ||
samples: 1, | ||
max_depth: 100, | ||
quiet: true, | ||
normalmap: false, | ||
}; | ||
|
||
#[divan::bench] | ||
fn draw_cornell(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(get_cornell) | ||
.counter(1u32) | ||
.bench_values(|scene| black_box(draw(OPTS, &scene))) | ||
} | ||
|
||
fn get_cornell<'scene>() -> Scene<'scene> { | ||
const INPUT: &str = include_str!("../../scenes/cornell.json"); | ||
let scene_file: SceneFile = serde_json::from_str(INPUT).unwrap(); | ||
let scene: Scene = initialize(scene_file, WIDTH, HEIGHT); | ||
scene | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::f32::{INFINITY, NEG_INFINITY}; | ||
|
||
use clovers::hitable::HitableTrait; | ||
use clovers::materials::Material; | ||
use clovers::objects::Triangle; | ||
use clovers::ray::Ray; | ||
use clovers::wavelength::random_wavelength; | ||
use clovers::Vec3; | ||
use divan::black_box; | ||
use divan::AllocProfiler; | ||
use rand::rngs::SmallRng; | ||
use rand::{Rng, SeedableRng}; | ||
|
||
#[global_allocator] | ||
static ALLOC: AllocProfiler = AllocProfiler::system(); | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
#[divan::bench] | ||
fn new(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(random_triangle_ingredients) | ||
.counter(1u32) | ||
.bench_values(|(a, b, c, material)| black_box(Triangle::new(a, b, c, material))) | ||
} | ||
|
||
#[divan::bench] | ||
fn hit(bencher: divan::Bencher) { | ||
bencher | ||
.with_inputs(|| { | ||
let rng = SmallRng::from_entropy(); | ||
let (triangle, ray) = random_triangle_and_ray(); | ||
(triangle, ray, rng) | ||
}) | ||
.counter(1u32) | ||
.bench_values(|(triangle, ray, mut rng)| { | ||
black_box( | ||
triangle | ||
.hit(&ray, NEG_INFINITY, INFINITY, &mut rng) | ||
.is_some(), | ||
) | ||
}) | ||
} | ||
|
||
fn random_vec(rng: &mut SmallRng) -> Vec3 { | ||
Vec3::new(rng.gen(), rng.gen(), rng.gen()) | ||
} | ||
|
||
fn random_3_coords(rng: &mut SmallRng) -> (Vec3, Vec3, Vec3) { | ||
let a = random_vec(rng); | ||
let b = random_vec(rng); | ||
let c = random_vec(rng); | ||
(a, b, c) | ||
} | ||
|
||
fn random_triangle_ingredients() -> (Vec3, Vec3, Vec3, &'static Material) { | ||
let mut rng = SmallRng::from_entropy(); | ||
let material: &'static Material = Box::leak(Box::default()); | ||
let (a, b, c) = random_3_coords(&mut rng); | ||
(a, b, c, material) | ||
} | ||
|
||
fn random_triangle() -> Triangle<'static> { | ||
let (a, b, c, material) = random_triangle_ingredients(); | ||
Triangle::new(a, b, c, material) | ||
} | ||
|
||
fn random_ray() -> Ray { | ||
let mut rng = SmallRng::from_entropy(); | ||
black_box(Ray { | ||
origin: Vec3::new(0.0, 0.0, 0.0), | ||
direction: Vec3::new(rng.gen(), rng.gen(), rng.gen()), | ||
time: rng.gen(), | ||
wavelength: random_wavelength(&mut rng), | ||
}) | ||
} | ||
|
||
fn random_triangle_and_ray() -> (Triangle<'static>, Ray) { | ||
(random_triangle(), random_ray()) | ||
} |
Oops, something went wrong.