Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge NoHit sampling #4

Merged
merged 39 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
df36594
Added NoHit sampling
nonl4331 Oct 25, 2022
3b966ab
Fixed imports in frontend/main.rs
nonl4331 Oct 27, 2022
ea78ba8
Initial statistics rework
nonl4331 Jan 11, 2023
4d69578
Reimplemented MIS
nonl4331 Jan 14, 2023
0d1aa19
dependency refactor
nonl4331 Jan 15, 2023
3bcbf4e
Added initial scene loading code
nonl4331 Jan 21, 2023
d95b819
minor mis fix
nonl4331 Jan 21, 2023
dce5e9d
Added scene parsing
nonl4331 Jan 22, 2023
e42fbf9
Changed generic in Primitive to associated type
nonl4331 Jan 22, 2023
b054689
Initial GGX VNDF routines added
nonl4331 Jan 25, 2023
9f0f745
Changed AccelerationStructure to use associated traits
nonl4331 Jan 26, 2023
7be4bc2
Initial framework for rewrite
nonl4331 Jan 27, 2023
416a6e7
Removed phong and coffee scene
nonl4331 Jan 27, 2023
7f67699
Initial scene rework (highly WIP)
nonl4331 Jan 29, 2023
eff8bea
Suppressed errors for frontend rework
nonl4331 Jan 30, 2023
cc8e39b
Removed parsing code & changed to using albedo in lambertian
nonl4331 Jan 30, 2023
43fcf32
Moved statistics into implementations
nonl4331 Jan 31, 2023
61e0aad
Cleaned up TR/GGX code a bit
nonl4331 Feb 1, 2023
8f94496
cleaned up statistics/bxdfs
nonl4331 Feb 1, 2023
68c2394
removed accidental additions
nonl4331 Feb 1, 2023
dd6bb50
Added lambertian to statistics/bxdfs
nonl4331 Feb 1, 2023
d70bdf0
More TR/GGX cleanup
nonl4331 Feb 6, 2023
ad5adc1
Added g2 test
nonl4331 Feb 6, 2023
c76603c
reused TR utilities
nonl4331 Feb 27, 2023
e5f4875
frontend rework pt 1
nonl4331 Mar 13, 2023
3eb6393
rearranged project structure
nonl4331 Mar 14, 2023
65e85de
Moved most of the gui code to a workspace
nonl4331 Mar 14, 2023
39647f8
Improved logging p1
nonl4331 Mar 14, 2023
04451ee
Improved terminal printing + fixed crash on exit
nonl4331 Mar 15, 2023
f724566
Added loading support for aacuboids
nonl4331 Mar 15, 2023
786d009
Added model loading
nonl4331 Mar 16, 2023
ed94fa1
Fixed TrowbridgeReitz
nonl4331 Mar 21, 2023
014c5b7
Changed statistics::bxdfs to expect wo = -wo
nonl4331 Mar 22, 2023
b9f28a5
Changed to using VNDF for TR
nonl4331 Mar 22, 2023
b129785
Added sky sampling (for real)
nonl4331 Mar 25, 2023
aef0857
Added gamma control
nonl4331 Mar 25, 2023
84a9ca1
Optimised coordinate inversion
nonl4331 Mar 25, 2023
8512e74
Change image saving, exr now supported
nonl4331 Mar 27, 2023
6d431e5
Added integrators trait
nonl4331 Mar 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "frontend"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace]
members = ["crates/*"]

[dependencies]
clap = { version = "4.1.8", features = ["derive", "wrap_help"] }
gui = { path = "./crates/gui", optional = true }
implementations = { path = "./crates/implementations" }
indicatif = "0.17.3"
loader = { path = "./crates/loader" }
output = { path = "./crates/output" }
rand = { version = "0.8.3", features = [ "small_rng" ] }
rand_seeder = "0.2.2"
rayon = "1.5.1"
region = { path = "./crates/region" }
vulkano = { version = "0.28.0", optional = true }
vulkano-shaders = { version = "0.28.0", optional = true }
vulkano-win = { version = "0.28.0", optional = true }
winit = { version = "0.26.1", optional = true }

[features]
f64 = ["implementations/f64"]
gui = ["dep:vulkano", "dep:vulkano-win", "dep:vulkano-shaders", "dep:winit", "dep:gui"]
674 changes: 0 additions & 674 deletions LICENSE

This file was deleted.

12 changes: 12 additions & 0 deletions crates/gui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "gui"
version = "0.1.0"
edition = "2021"

[dependencies]
vulkano = { version = "0.28.0" }
vulkano-shaders = { version = "0.28.0" }
vulkano-win = { version = "0.28.0" }
winit = { version = "0.26.1" }
implementations = { path = "../implementations" }
indicatif = "0.17.3"
35 changes: 18 additions & 17 deletions frontend/src/gui.rs → crates/gui/src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::rendering::*;
use crate::rendering::CpuRendering;
use crate::rendering::RenderInfo;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use vulkano::{
command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, PrimaryAutoCommandBuffer},
Expand Down Expand Up @@ -40,10 +42,11 @@ pub struct Gui {
render_info: RenderInfo,
combined_buffer: Arc<StorageImage>,
presentation_finished: Option<Box<dyn GpuFuture + 'static>>,
exit: Arc<AtomicBool>,
}

impl Gui {
pub fn new(instance: &Arc<Instance>, width: u32, height: u32) -> Self {
pub fn new(instance: &Arc<Instance>, width: u32, height: u32, exit: Arc<AtomicBool>) -> Self {
let event_loop: EventLoop<RenderEvent> = EventLoop::with_user_event();
let surface = WindowBuilder::new()
.build_vk_surface(&event_loop, instance.clone())
Expand Down Expand Up @@ -139,9 +142,7 @@ impl Gui {
let cpu_rendering = CpuRendering::new(&physical_device, device.clone(), width, height);

mod cs {
vulkano_shaders::shader! {
ty: "compute",
src:
vulkano_shaders::shader! {ty: "compute",src:
"#version 460

layout(local_size_x = 32, local_size_y = 32) in;
Expand All @@ -151,8 +152,8 @@ layout(set = 0, binding = 0, rgba32f) uniform readonly image2D cpu_input;
layout(set = 0, binding = 1, rgba8) uniform writeonly image2D image_output;

void main() {
vec4 data = sqrt(imageLoad(cpu_input, ivec2(gl_GlobalInvocationID.xy)));
imageStore(image_output, ivec2(gl_GlobalInvocationID.xy), data);
vec4 data = sqrt(imageLoad(cpu_input, ivec2(gl_GlobalInvocationID.xy)));
imageStore(image_output, ivec2(gl_GlobalInvocationID.xy), data);
}"}
}

Expand Down Expand Up @@ -201,6 +202,7 @@ void main() {
presentation_command_buffers,
combined_buffer,
presentation_finished: None,
exit,
}
}

Expand All @@ -213,14 +215,14 @@ void main() {
Event::DeviceEvent {
event: winit::event::DeviceEvent::Key(key),
..
} => match key.virtual_keycode {
Some(code) => {
} => {
if let Some(code) = key.virtual_keycode {
if code == winit::event::VirtualKeyCode::Escape {
self.exit.store(true, std::sync::atomic::Ordering::Relaxed);
*control_flow = ControlFlow::Exit;
}
}
None => {}
},
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
Expand All @@ -246,9 +248,8 @@ void main() {
}

fn update(&mut self) {
match self.presentation_finished.as_mut() {
Some(future) => future.cleanup_finished(),
None => {}
if let Some(future) = self.presentation_finished.as_mut() {
future.cleanup_finished()
}
self.presentation_finished = Some(sync::now(self.device.clone()).boxed());

Expand All @@ -260,7 +261,7 @@ void main() {
return;
}
Err(e) => {
panic!("Failed to acquire next image: {:?}", e)
panic!("Failed to acquire next image: {e:?}")
}
};

Expand Down Expand Up @@ -328,7 +329,7 @@ void main() {
self.presentation_finished = Some(sync::now(self.device.clone()).boxed());
}
Err(e) => {
println!("Failed to flush future: {:?}", e);
println!("Failed to flush future: {e:?}");
self.presentation_finished = Some(sync::now(self.device.clone()).boxed());
}
}
Expand All @@ -339,7 +340,7 @@ void main() {
match self.swapchain.recreate().dimensions(dimensions).build() {
Ok(r) => r,
Err(SwapchainCreationError::UnsupportedDimensions) => return,
Err(e) => panic!("Failed to recreate swapchain: {:?}", e),
Err(e) => panic!("Failed to recreate swapchain: {e:?}"),
};
let extent: [u32; 2] = self.surface.window().inner_size().into();

Expand Down
184 changes: 184 additions & 0 deletions crates/gui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
mod gui;
mod rendering;

use implementations::SamplerProgress;
use indicatif::ProgressBar;
use indicatif::ProgressStyle;

use {
std::sync::{
atomic::{AtomicBool, AtomicU64, Ordering},
Arc,
},
vulkano::{
buffer::CpuAccessibleBuffer,
command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, PrimaryAutoCommandBuffer},
device::{Device, Queue},
image::StorageImage,
sync::{self, GpuFuture},
},
winit::event_loop::EventLoopProxy,
};

pub use crate::gui::{Gui, RenderEvent};
pub use crate::rendering::Future;

pub struct Data {
pub queue: Arc<Queue>,
pub device: Arc<Device>,
pub to_sc: rendering::Future,
pub from_sc: rendering::Future,
pub command_buffers: [Arc<PrimaryAutoCommandBuffer>; 2],
pub buffer: Arc<CpuAccessibleBuffer<[f32]>>,
pub sc_index: Arc<AtomicBool>,
pub samples: Arc<AtomicU64>,
pub total_samples: u64,
pub rays_shot: Arc<AtomicU64>,
pub event_proxy: EventLoopProxy<RenderEvent>,
pub exit: Arc<AtomicBool>,
pub bar: ProgressBar,
}

impl Data {
pub fn new(
queue: Arc<Queue>,
device: Arc<Device>,
to_sc: rendering::Future,
from_sc: rendering::Future,
command_buffers: [Arc<PrimaryAutoCommandBuffer>; 2],
buffer: Arc<CpuAccessibleBuffer<[f32]>>,
sc_index: Arc<AtomicBool>,
samples: Arc<AtomicU64>,
total_samples: u64,
rays_shot: Arc<AtomicU64>,
exit: Arc<AtomicBool>,
event_proxy: EventLoopProxy<RenderEvent>,
) -> Self {
Data {
queue,
device,
to_sc,
from_sc,
command_buffers,
buffer,
sc_index,
samples,
total_samples,
rays_shot,
event_proxy,
exit,
bar: ProgressBar::new(total_samples).with_style(
ProgressStyle::default_bar()
.template("[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}")
.unwrap(),
),
}
}
}

pub fn create_command_buffers(
device: Arc<Device>,
queue: Arc<Queue>,
buffer: Arc<CpuAccessibleBuffer<[f32]>>,
sc: [Arc<StorageImage>; 2],
) -> [Arc<PrimaryAutoCommandBuffer>; 2] {
let mut command_buffer_0 = None;
let mut command_buffer_1 = None;
for (i, sc_image) in sc.iter().enumerate() {
let mut builder = AutoCommandBufferBuilder::primary(
device.clone(),
queue.family(),
CommandBufferUsage::MultipleSubmit,
)
.unwrap();

builder
.copy_buffer_to_image(buffer.clone(), sc_image.clone())
.unwrap();
if i == 0 {
command_buffer_0 = Some(builder.build().unwrap());
} else {
command_buffer_1 = Some(builder.build().unwrap());
}
}

[
Arc::new(command_buffer_0.unwrap()),
Arc::new(command_buffer_1.unwrap()),
]
}

pub fn sample_update(data: &mut Data, previous: &SamplerProgress, i: u64) -> bool {
if data.exit.load(Ordering::Relaxed) {
return true;
}
// update infomation about the rays shot and samples completed in the current render
data.samples.fetch_add(1, Ordering::Relaxed);
data.rays_shot
.fetch_add(previous.rays_shot, Ordering::Relaxed);

// wait on from_sc future if is_some()
match &*data.from_sc.lock().unwrap() {
Some(future) => {
future.wait(None).unwrap();
}
None => {}
}
match &*data.to_sc.lock().unwrap() {
Some(future) => {
future.wait(None).unwrap();
}
None => {}
}

{
// get access to CpuAccessibleBuffer
let mut buf = data.buffer.write().unwrap();
buf.chunks_mut(4)
.zip(previous.current_image.chunks(3))
.for_each(|(pres, acc)| {
pres[0] += (acc[0] as f32 - pres[0]) / i as f32;
pres[1] += (acc[1] as f32 - pres[1]) / i as f32;
pres[2] += (acc[2] as f32 - pres[2]) / i as f32;
pres[3] = 1.0;
});
}

// copy to cpu swapchain
let command_buffer =
data.command_buffers[data.sc_index.load(Ordering::Relaxed) as usize].clone();

// copy to swapchain and store op in to_sc future
{
let to_sc = &mut *data.to_sc.lock().unwrap();
*to_sc = Some(
match to_sc.take() {
Some(future) => future
.then_execute(data.queue.clone(), command_buffer)
.unwrap()
.boxed_send_sync(),
None => sync::now(data.device.clone())
.then_execute(data.queue.clone(), command_buffer)
.unwrap()
.boxed_send_sync(),
}
.then_signal_fence_and_flush()
.unwrap(), // change to match
);
}

// modify sc_index to !sc_index
data.sc_index
.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |x| Some(!x))
.unwrap();

data.bar.set_position(data.samples.load(Ordering::Relaxed));
if data.samples.load(Ordering::Relaxed) == data.total_samples {
data.bar.abandon()
}

// signal sample is ready to be presented
data.event_proxy
.send_event(RenderEvent::SampleCompleted)
.is_err()
}
File renamed without changes.
16 changes: 13 additions & 3 deletions implementations/Cargo.toml → crates/implementations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ edition = "2021"

[dependencies]
image = "0.24.3"
proc = {path = "./proc"}
proc = { path = "./proc" }
rand = { version = "0.8.3", features = [ "small_rng" ] }
rayon = "1.5.1"
rt_core = {path = "../rt_core"}
rt_core = { path = "../rt_core" }
bumpalo = {version="3.12.0", features=["collections"]}
num_cpus = "1.15"
region = { path = "../region"}
statrs = "0.16.0"
clap = { version = "4.1.8", features = [ "derive" ] }



[dev-dependencies]
chrono = "0.4.19"
statrs = "0.16.0"
statrs = "0.16.0"

[features]
f64 = ["rt_core/f64"]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn derive_primitive(tokens: TokenStream) -> TokenStream {

let func_names_primitive = [
(
quote!(get_int(&self, __one: &Ray) -> Option<SurfaceIntersection #ty_generics>),
quote!(get_int(&self, __one: &Ray) -> Option<SurfaceIntersection<Self::Material>>),
quote!(get_int(__one)),
),
(
Expand Down Expand Up @@ -177,7 +177,10 @@ pub fn derive_primitive(tokens: TokenStream) -> TokenStream {
});

quote! {
impl #impl_generics Primitive #ty_generics for #enum_name #ty_generics #where_clause {#( #functions_primitive )*}
impl #impl_generics Primitive for #enum_name #ty_generics #where_clause {
type Material = M;
#( #functions_primitive )*
}
impl #impl_generics AABound for #enum_name #ty_generics #where_clause { #( #functions_aabound )*}
}
.into()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utility::gamma;
use rt_core::{Float, Ray, Vec3};
use rt_core::*;

pub trait AABound {
fn get_aabb(&self) -> AABB;
Expand Down
Loading