Compare commits

..

No commits in common. "690048cbef6beab333850d6f239e00e3254b8c68" and "7b5571344e5b7a8995c14c39acfd04c695750a45" have entirely different histories.

9 changed files with 37 additions and 60 deletions

View File

@ -13,7 +13,7 @@ steps:
commands:
- sccache -s
- apt-get update && apt-get install -y libgoogle-perftools-dev
- (cd rtiow && ./build_all_features.sh)
- (cd rtiow && cargo build --verbose --all)
- (cd rtiow && cargo test --verbose --all)
- sccache -s

View File

@ -1,6 +0,0 @@
set -e
export RUSTFLAGS="-D warnings"
cargo build
cargo build --features=prom
cargo build --features=profile
cargo build --features=prom,profile

View File

@ -153,7 +153,7 @@ fn render_noise(noise_params: NoiseParams) -> image::GrayImage {
const SEED: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
let rng: &mut XorShiftRng = &mut SeedableRng::from_seed(SEED);
let mut img = image::GrayImage::new(noise_params.width, noise_params.height);
let tex: NoiseTexture<Box<dyn noise::NoiseSource>> = match noise_params.noise_source {
let tex: NoiseTexture<Box<noise::NoiseSource>> = match noise_params.noise_source {
NoiseSource::Perlin => {
NoiseTexture::new(Box::new(Perlin::new(rng)), noise_params.noise_type)
}

View File

@ -8,13 +8,13 @@ extern crate rtiow;
extern crate stderrlog;
extern crate structopt;
#[macro_use]
#[cfg(feature = "prom")]
extern crate lazy_static;
#[macro_use]
#[cfg(feature = "prom")]
extern crate prometheus;
use std::fs;
use std::time::Instant;
use chrono::DateTime;
use chrono::Utc;
@ -46,7 +46,7 @@ fn push_metrics(_push_gateway_addr: &str, _instance: String, start_time: &DateTi
#[cfg(feature = "prom")]
fn push_metrics(push_gateway_addr: &str, instance: String, start_time: &DateTime<Utc>) {
let runtime = (Utc::now() - *start_time).to_std().unwrap();
let runtime = start_instant.elapsed();
info!(
"Render time {}.{} seconds",
runtime.as_secs(),
@ -88,10 +88,8 @@ fn push_metrics(push_gateway_addr: &str, instance: String, start_time: &DateTime
}
}
#[cfg(not(feature = "profile"))]
struct MockTimer;
#[cfg(not(feature = "profile"))]
impl MockTimer {
fn start<T: Into<Vec<u8>>>(&self, _: T) -> Result<(), ()> {
Ok(())
@ -101,10 +99,8 @@ impl MockTimer {
}
}
#[cfg(not(feature = "profile"))]
struct MockProfiler;
#[cfg(not(feature = "profile"))]
impl MockProfiler {
fn lock(&self) -> Option<MockTimer> {
Some(MockTimer {})
@ -121,6 +117,7 @@ fn main() -> Result<(), std::io::Error> {
.init()
.unwrap();
let start_time: DateTime<Utc> = Utc::now();
let start_instant = Instant::now();
let opt = Opt::from_args();
let scene = opt.model.scene(&opt);
fs::create_dir_all(&opt.output)?;

View File

@ -1,4 +1,3 @@
#![allow(dead_code)]
#![doc(html_root_url = "https://docs.rs/human_format")]
//! From https://raw.githubusercontent.com/BobGneu/human-format-rs/master/src/lib.rs
@ -73,7 +72,7 @@ impl Formatter {
Formatter {
decimals: 2,
separator: " ".to_owned(),
scales: Scales::si(),
scales: Scales::SI(),
forced_units: "".to_owned(),
forced_suffix: "".to_owned(),
}
@ -152,11 +151,11 @@ impl Formatter {
impl Scales {
/// Instantiates a new `Scales` with SI keys
pub fn new() -> Self {
Scales::si()
Scales::SI()
}
/// Instantiates a new `Scales` with SI keys
pub fn si() -> Self {
pub fn SI() -> Self {
Scales {
base: 1000,
suffixes: vec![
@ -174,7 +173,7 @@ impl Scales {
}
/// Instantiates a new `Scales` with Binary keys
pub fn binary() -> Self {
pub fn Binary() -> Self {
Scales {
base: 1000,
suffixes: vec![
@ -212,6 +211,8 @@ impl Scales {
}
fn get_magnitude_multipler(&self, value: &str) -> f64 {
let ndx = 0;
for ndx in 0..self.suffixes.len() {
if value == self.suffixes[ndx] {
return self.base.pow(ndx as u32) as f64;

View File

@ -31,5 +31,7 @@ extern crate structopt;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate lazy_static;
#[macro_use]
#[cfg(feature = "prom")]
extern crate prometheus;

View File

@ -15,8 +15,6 @@ use std::time;
use image;
use image::RgbImage;
#[cfg(feature = "prom")]
use lazy_static::lazy_static;
use num_cpus;
use rand;
use rand::Rng;
@ -38,9 +36,7 @@ lazy_static! {
register_counter_vec!("rays", "Number of rays fired", &["level"]).unwrap();
}
#[cfg(not(feature = "prom"))]
struct MockPrometheus;
#[cfg(not(feature = "prom"))]
impl MockPrometheus {
fn with_label_values(&self, _: &[&str]) -> &MockPrometheus {
self
@ -150,12 +146,9 @@ pub struct Opt {
/// Sub-samples per pixel
#[structopt(short = "s", long = "subsample", default_value = "8")]
pub subsamples: usize,
/// Use adaptive subsampling
#[structopt(long = "adaptive")]
pub adaptive_subsampling: bool,
/// Select scene to render, one of: "bench", "book", "tutorial", "bvh", "test", "cornell_box",
/// "cornell_smoke", "perlin_debug", "final"
#[structopt(long = "model", default_value = "book")]
#[structopt(long = "model", default_value = "perlin_debug")]
pub model: Model,
/// Path to store pprof profile data, i.e. /tmp/cpuprofile.pprof
#[structopt(long = "pprof", parse(from_os_str))]
@ -187,8 +180,6 @@ pub struct Scene {
pub world: Box<dyn Hit>,
pub camera: Camera,
pub subsamples: usize,
/// overrides subsamples setting.
pub adaptive_subsampling: bool,
pub num_threads: Option<usize>,
pub width: usize,
pub height: usize,
@ -223,7 +214,6 @@ impl Default for Scene {
)),
camera,
subsamples: 0,
adaptive_subsampling: false,
num_threads: None,
width: 0,
height: 0,
@ -298,22 +288,26 @@ enum Request {
}
enum Response {
Pixel { x: usize, y: usize, pixel: Vec3 },
Line { y: usize, pixels: Vec<Vec3> },
Pixel {
x: usize,
y: usize,
pixel: Vec3,
},
Line {
width: usize,
y: usize,
pixels: Vec<Vec3>,
},
}
static PIXEL_COUNT: AtomicUsize = AtomicUsize::new(0);
fn render_pixel(scene: &Scene, x: usize, y: usize) -> Vec3 {
let mut pixel: Vec3 = Default::default();
let pixel = if scene.adaptive_subsampling {
Default::default()
} else {
for _ in 0..scene.subsamples {
pixel = pixel + trace_pixel(x, y, scene);
}
pixel / scene.subsamples as f32
};
for _ in 0..scene.subsamples {
pixel = pixel + trace_pixel(x, y, scene);
}
pixel = pixel / scene.subsamples as f32;
// Gamma correct, use gamma 2 correction, which is 1/gamma where gamma=2 which is 1/2 or
// sqrt.
PIXEL_COUNT.fetch_add(1, Ordering::SeqCst);
@ -337,16 +331,12 @@ fn render_worker(
Request::Line { width, y } => {
trace!("tid {} width {} y {}", tid, width, y);
let pixels = (0..width).map(|x| render_pixel(scene, x, y)).collect();
output_chan
.send(Response::Line { y, pixels })
.expect("failed to send pixel response");
output_chan.send(Response::Line { width, y, pixels });
}
Request::Pixel { x, y } => {
trace!("tid {} x {} y {}", tid, x, y);
let pixel = render_pixel(scene, x, y);
output_chan
.send(Response::Pixel { x, y, pixel })
.expect("failed to send line response");
output_chan.send(Response::Pixel { x, y, pixel });
}
},
}
@ -361,7 +351,6 @@ pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::i
let scene = Arc::new(scene);
let pixel_req_rx = Arc::new(Mutex::new(pixel_req_rx));
info!("Creating {} render threads", num_threads);
info!("Adaptive subsampling: {}", scene.adaptive_subsampling);
for i in 0..num_threads {
let s = sync::Arc::clone(&scene);
let pixel_req_rx = pixel_req_rx.clone();
@ -378,16 +367,12 @@ pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::i
let batch_line_requests = true;
if batch_line_requests {
for y in 0..h {
pixel_req_tx
.send(Request::Line { width: w, y })
.expect("failed to send line request");
pixel_req_tx.send(Request::Line { width: w, y });
}
} else {
for y in 0..h {
for x in 0..w {
pixel_req_tx
.send(Request::Pixel { x, y })
.expect("failed to send pixel request");
pixel_req_tx.send(Request::Pixel { x, y });
}
}
}
@ -439,7 +424,11 @@ pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::i
]),
);
}
Response::Line { y, pixels } => {
Response::Line {
width: _,
y,
pixels,
} => {
for (x, pixel) in pixels.iter().enumerate() {
let y_inv = scene.height - y - 1;
img.put_pixel(

View File

@ -51,7 +51,6 @@ pub fn new(opt: &Opt) -> Scene {
camera,
world,
subsamples: opt.subsamples,
adaptive_subsampling: opt.adaptive_subsampling,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,

View File

@ -1,5 +0,0 @@
export RUSTFLAGS="-D warnings"
cargo watch -x 'build' \
-x 'build --features=prom' \
-x 'build --features=profile' \
-x 'build --features=prom,profile'