Skip to content

Commit

Permalink
added asset preprocessing and compression
Browse files Browse the repository at this point in the history
  • Loading branch information
sshashank124 committed Jan 9, 2024
1 parent 531f6d2 commit 0ca2c04
Show file tree
Hide file tree
Showing 39 changed files with 590 additions and 467 deletions.
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ members = [
"shaders/pathtracer",
"shaders/rasterizer",
"shaders/tonemap",
"scene",
]
resolver = "2"

[workspace.package]
version = "0.1.0"
edition = "2021"
authors = ["Shashank Singh <[email protected]>"]
repository = "https://github.com/sshashank124/tsunami"

[workspace.dependencies]
bytemuck = { version = "1.14", features = ["derive"] }
glam = { version = "0.24", default-features = false, features = ["libm"] }
scene = { path = "scene" }
serde = { version = "1.0", default-features = false }
shared = { path = "shared" }
spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu" }
spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu" }

[profile.release]
opt-level = 3
codegen-units = 16
Expand Down
11 changes: 7 additions & 4 deletions runner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
[package]
name = "runner"
version = "0.1.0"
version.workspace = true
edition.workspace = true

[dependencies]
ash = { version = "0.37", features = ["linked"] }
gltf = "1"
bytemuck = { workspace = true }
glam = { workspace = true }
gpu-allocator = { version = "0.23", default-features = false, features = [ "vulkan" ] }
image = "0.24"
shared = { path = "../shared" }
scene = { workspace = true }
shared = { workspace = true }
spirv-std = { workspace = true }
tobj = "4"
winit = "0.29"

[build-dependencies]
spirv-builder = "0.9"
spirv-builder = { workspace = true }
6 changes: 3 additions & 3 deletions runner/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use winit::{
};

use crate::{
data::{camera, gltf_scene::GltfScene},
data::camera,
gpu::{context::Context, Destroy},
input, render,
};
Expand All @@ -31,10 +31,10 @@ pub struct App {
}

impl App {
pub fn new(window: &Window, gltf_file: &str) -> Self {
pub fn new(window: &Window, scene_file: &str) -> Self {
let mut ctx = Context::init(window);

let scene = GltfScene::load(gltf_file);
let scene = scene::load(scene_file);

let camera_controller = camera::Controller::new(
scene.info.bounding_box.size() * 1.2 + scene.info.bounding_box.center(),
Expand Down
2 changes: 1 addition & 1 deletion runner/src/data/camera.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use shared::{glam, Camera, Transform};
use shared::{Camera, Transform};

mod conf {
pub const Z_NEAR: f32 = 1e-1;
Expand Down
208 changes: 0 additions & 208 deletions runner/src/data/gltf_scene.rs

This file was deleted.

2 changes: 0 additions & 2 deletions runner/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
pub mod bounding_box;
pub mod camera;
pub mod gltf_scene;
31 changes: 14 additions & 17 deletions runner/src/gpu/acceleration_structure.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{ops::Deref, slice};

use ash::vk;
use shared::{self, bytemuck};

use shared::{scene, Vertex};

use crate::{
data::gltf_scene,
gpu::{query_pool::QueryPool, scene::Scene, scope::FlushableScope},
util,
};
Expand Down Expand Up @@ -339,21 +339,21 @@ impl<'a> GeometryInfo<'a> {
}

fn for_primitive(
scene_info: &'a shared::SceneInfo,
primitive_info: &shared::PrimitiveInfo,
primitive_size: &gltf_scene::PrimitiveSize,
scene: &'a Scene,
primitive_info: &scene::PrimitiveInfo,
primitive_size: &scene::PrimitiveSize,
) -> Self {
let triangles = vk::AccelerationStructureGeometryTrianglesDataKHR::builder()
.vertex_format(vk::Format::R32G32B32_SFLOAT)
.vertex_stride(std::mem::size_of::<shared::Vertex>() as _)
.vertex_stride(std::mem::size_of::<Vertex>() as _)
.max_vertex(primitive_size.vertices_size - 1)
.vertex_data(vk::DeviceOrHostAddressConstKHR {
device_address: scene_info.vertices_address
+ bytemuck::offset_of!(shared::Vertex, position) as vk::DeviceAddress,
device_address: scene.device_addresses.vertices
+ bytemuck::offset_of!(Vertex, position) as vk::DeviceAddress,
})
.index_type(vk::IndexType::UINT32)
.index_data(vk::DeviceOrHostAddressConstKHR {
device_address: scene_info.indices_address,
device_address: scene.device_addresses.indices,
})
.build();

Expand All @@ -379,7 +379,7 @@ impl<'a> GeometryInfo<'a> {
.iter()
.zip(scene.host_info.primitive_sizes.iter())
.map(|(primitive_info, primitive_size)| {
Self::for_primitive(&scene.device_info, primitive_info, primitive_size)
Self::for_primitive(scene, primitive_info, primitive_size)
})
.collect()
}
Expand All @@ -388,8 +388,8 @@ impl<'a> GeometryInfo<'a> {
impl InstancesInfo {
fn for_instances(
ctx: &mut Context,
scope: &mut FlushableScope,
instances: &[gltf_scene::Instance],
scope: &FlushableScope,
instances: &[scene::Instance],
blases: &[AccelerationStructure],
) -> Self {
let instances = Instance::for_instances(instances, blases);
Expand Down Expand Up @@ -426,7 +426,7 @@ impl InstancesInfo {
}

impl Instance {
fn for_instance(instance: &gltf_scene::Instance, blases: &[AccelerationStructure]) -> Self {
fn for_instance(instance: &scene::Instance, blases: &[AccelerationStructure]) -> Self {
let t = &instance.transform;
Self(vk::AccelerationStructureInstanceKHR {
transform: vk::TransformMatrixKHR {
Expand All @@ -450,10 +450,7 @@ impl Instance {
})
}

fn for_instances(
instances: &[gltf_scene::Instance],
blases: &[AccelerationStructure],
) -> Vec<Self> {
fn for_instances(instances: &[scene::Instance], blases: &[AccelerationStructure]) -> Vec<Self> {
instances
.iter()
.map(|instance| Self::for_instance(instance, blases))
Expand Down
2 changes: 0 additions & 2 deletions runner/src/gpu/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::{ops::Deref, slice};

use ash::vk;

use shared::bytemuck;

use super::{alloc, context::Context, scope::OneshotScope, Destroy};

pub struct Buffer {
Expand Down
Loading

0 comments on commit 0ca2c04

Please sign in to comment.