Separate into different crates

kea_gpu for a higher level vulkan wrapper
kea_renderer for the path tracer
kea_renderer_shaders for the path tracer shaders
ray-query
Andrew O'Neil 11 months ago
parent d76f13bdc4
commit ba3ca3d994

113
Cargo.lock generated

@ -376,13 +376,13 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.6"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi 0.10.2+wasi-snapshot-preview1",
"wasi",
]
[[package]]
@ -422,6 +422,12 @@ dependencies = [
"ahash",
]
[[package]]
name = "hashbrown"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3"
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -445,12 +451,12 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "indexmap"
version = "1.8.2"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a"
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
dependencies = [
"autocfg",
"hashbrown",
"hashbrown 0.12.1",
]
[[package]]
@ -488,15 +494,15 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.57"
version = "0.3.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397"
checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "kea-gfx"
name = "kea_gpu"
version = "0.1.0"
dependencies = [
"ash",
@ -506,11 +512,33 @@ dependencies = [
"gpu-allocator",
"log",
"memoffset",
"shaders",
"spirv-builder",
"winit",
]
[[package]]
name = "kea_renderer"
version = "0.1.0"
dependencies = [
"ash",
"ash-window",
"env_logger",
"glam",
"gpu-allocator",
"kea_gpu",
"kea_renderer_shaders",
"log",
"memoffset",
"winit",
]
[[package]]
name = "kea_renderer_shaders"
version = "0.1.0"
dependencies = [
"spirv-std",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -608,13 +636,13 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.3"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799"
checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"wasi",
"windows-sys",
]
@ -798,18 +826,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.39"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
dependencies = [
"proc-macro2",
]
@ -901,7 +929,7 @@ source = "git+https://github.com/EmbarkStudios/rust-gpu#0866cf591a7fdbbd15bdb346
dependencies = [
"ar",
"bimap",
"hashbrown",
"hashbrown 0.11.2",
"indexmap",
"libc",
"num-traits",
@ -984,18 +1012,11 @@ dependencies = [
"serde",
]
[[package]]
name = "shaders"
version = "0.1.0"
dependencies = [
"spirv-std",
]
[[package]]
name = "smallvec"
version = "1.8.0"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
checksum = "cc88c725d61fc6c3132893370cac4a0200e3fedf5da8331c570664b1987f5ca2"
[[package]]
name = "smithay-client-toolkit"
@ -1093,9 +1114,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.96"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
dependencies = [
"proc-macro2",
"quote",
@ -1142,9 +1163,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
version = "1.0.0"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
[[package]]
name = "version_check"
@ -1152,12 +1173,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@ -1166,9 +1181,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.80"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad"
checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen-macro",
@ -1176,9 +1191,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.80"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4"
checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a"
dependencies = [
"bumpalo",
"lazy_static",
@ -1191,9 +1206,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.80"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5"
checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -1201,9 +1216,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.80"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b"
checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048"
dependencies = [
"proc-macro2",
"quote",
@ -1214,9 +1229,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.80"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744"
checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be"
[[package]]
name = "wayland-client"
@ -1293,9 +1308,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.57"
version = "0.3.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283"
checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90"
dependencies = [
"js-sys",
"wasm-bindgen",

@ -1,17 +1,6 @@
[package]
name = "kea-gfx"
version = "0.1.0"
edition = "2021"
[dependencies]
ash = { version = "0.37.0+1.3.209", features=["linked"] }
ash-window = "0.10.0"
winit = "0.26.1"
log = "0.4.17"
env_logger = "0.9.0"
gpu-allocator = "0.18.0"
glam = "0.20.5"
memoffset = "0.6.5"
spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu" }
shaders = { path = "src/shaders" }
[workspace]
members = [
"kea_gpu",
"kea_renderer",
"kea_renderer_shaders"
]

@ -0,0 +1 @@
/target

1409
kea_gpu/Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,16 @@
[package]
name = "kea_gpu"
version = "0.1.0"
edition = "2021"
[dependencies]
ash = { version = "0.37.0+1.3.209", features=["linked"] }
ash-window = "0.10.0"
winit = "0.26.1"
log = "0.4.17"
env_logger = "0.9.0"
gpu-allocator = "0.18.0"
glam = "0.20.5"
memoffset = "0.6.5"
spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu" }

@ -0,0 +1,9 @@
# If you see this, run `rustup self update` to get rustup 1.23 or newer.
# NOTE: above comment is for older `rustup` (before TOML support was added),
# which will treat the first line as the toolchain name, and therefore show it
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".
[toolchain]
channel = "nightly-2022-04-11"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

@ -11,8 +11,8 @@ pub struct ShaderModule {
}
impl ShaderModule {
pub fn new(device: Arc<Device>) -> ShaderModule {
let (entry_points, compiled_shaders) = Self::compile_shaders();
pub fn new(device: Arc<Device>, shader_crate_path: &str) -> ShaderModule {
let (entry_points, compiled_shaders) = Self::compile_shaders(&shader_crate_path);
let shader_create_info = vk::ShaderModuleCreateInfo::builder().code(&compiled_shaders);
@ -25,8 +25,8 @@ impl ShaderModule {
}
}
fn compile_shaders() -> (Vec<String>, Vec<u32>) {
let compile_result = SpirvBuilder::new("src/shaders", "spirv-unknown-vulkan1.2")
fn compile_shaders(shader_crate_path: &str) -> (Vec<String>, Vec<u32>) {
let compile_result = SpirvBuilder::new(shader_crate_path, "spirv-unknown-vulkan1.2")
.capability(spirv_builder::Capability::RayTracingKHR)
.extension("SPV_KHR_ray_tracing")
.print_metadata(MetadataPrintout::None)

@ -0,0 +1,8 @@
pub mod gpu;
mod kea;
mod presenter;
mod window;
pub use kea::Kea;
pub use presenter::Presenter;
pub use window::Window;

@ -0,0 +1 @@
/target

1464
kea_renderer/Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,17 @@
[package]
name = "kea_renderer"
version = "0.1.0"
edition = "2021"
[dependencies]
ash = { version = "0.37.0+1.3.209", features=["linked"] }
ash-window = "0.10.0"
winit = "0.26.1"
log = "0.4.17"
env_logger = "0.9.0"
gpu-allocator = "0.18.0"
glam = "0.20.5"
memoffset = "0.6.5"
kea_gpu = { path = "../kea_gpu" }
kea_renderer_shaders = { path = "../kea_renderer_shaders" }

@ -0,0 +1,9 @@
# If you see this, run `rustup self update` to get rustup 1.23 or newer.
# NOTE: above comment is for older `rustup` (before TOML support was added),
# which will treat the first line as the toolchain name, and therefore show it
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".
[toolchain]
channel = "nightly-2022-04-11"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

@ -1,25 +1,21 @@
use env_logger::Env;
use kea::Kea;
use kea_gpu::Kea;
use kea_gpu::Window;
use path_tracer::PathTracer;
use window::Window;
mod gpu;
mod kea;
mod path_tracer;
mod presenter;
mod window;
struct KeaApp {
struct KeaRendererApp {
kea: Kea,
path_tracer: PathTracer,
}
impl KeaApp {
pub fn new(window: &Window) -> KeaApp {
impl KeaRendererApp {
pub fn new(window: &Window) -> KeaRendererApp {
let kea = Kea::new(window);
let path_tracer = PathTracer::new(&kea);
KeaApp { kea, path_tracer }
KeaRendererApp { kea, path_tracer }
}
pub fn draw(&self) {
@ -33,7 +29,7 @@ fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init();
let window = Window::new(1920, 1080);
let app = KeaApp::new(&window);
let app = KeaRendererApp::new(&window);
window.event_loop(move || app.draw())
}

@ -1,4 +1,10 @@
use crate::{
use ash::vk;
use glam::{vec3, Vec3};
use gpu_allocator::{
vulkan::{Allocation, AllocationCreateDesc},
MemoryLocation,
};
use kea_gpu::{
gpu::{
buffer::{AllocatedBuffer, Buffer},
command::{CommandBufferRecorder, CommandPool},
@ -21,12 +27,6 @@ use crate::{
},
Kea,
};
use ash::vk;
use glam::{vec3, Vec3};
use gpu_allocator::{
vulkan::{Allocation, AllocationCreateDesc},
MemoryLocation,
};
use log::info;
use std::{
mem::{self, ManuallyDrop},
@ -321,7 +321,7 @@ impl PathTracer {
let pipeline_layout =
PipelineLayout::new(device.clone(), slice::from_ref(&descriptor_set_layout));
let shader_module = ShaderModule::new(device.clone());
let shader_module = ShaderModule::new(device.clone(), "./kea_renderer_shaders");
let shader_stages = [
PipelineShaderStage::new(
vk::ShaderStageFlags::RAYGEN_KHR,

@ -0,0 +1,110 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "glam"
version = "0.20.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43e957e744be03f5801a55472f593d43fabdebf25a4585db250f04d86b1675f"
dependencies = [
"num-traits",
]
[[package]]
name = "libm"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db"
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
"libm",
]
[[package]]
name = "proc-macro2"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
dependencies = [
"proc-macro2",
]
[[package]]
name = "shaders"
version = "0.1.0"
dependencies = [
"spirv-std",
]
[[package]]
name = "spirv-std"
version = "0.4.0-alpha.12"
source = "git+https://github.com/EmbarkStudios/rust-gpu#0866cf591a7fdbbd15bdb3468e192bb9b6189fd0"
dependencies = [
"bitflags",
"glam",
"num-traits",
"spirv-std-macros",
"spirv-types",
]
[[package]]
name = "spirv-std-macros"
version = "0.4.0-alpha.12"
source = "git+https://github.com/EmbarkStudios/rust-gpu#0866cf591a7fdbbd15bdb3468e192bb9b6189fd0"
dependencies = [
"proc-macro2",
"quote",
"spirv-types",
"syn",
]
[[package]]
name = "spirv-types"
version = "0.4.0-alpha.12"
source = "git+https://github.com/EmbarkStudios/rust-gpu#0866cf591a7fdbbd15bdb3468e192bb9b6189fd0"
[[package]]
name = "syn"
version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"

@ -0,0 +1,10 @@
[package]
name = "kea_renderer_shaders"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["dylib"]
[dependencies]
spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu", features = ["glam"] }

@ -0,0 +1,103 @@
#![cfg_attr(
target_arch = "spirv",
no_std,
feature(register_attr),
register_attr(spirv)
)]
// #![deny(warnings)]
#[cfg(not(target_arch = "spirv"))]
use spirv_std::macros::spirv;
use spirv_std::{
arch::report_intersection,
glam::{vec2, vec3, vec4, UVec2, UVec3, Vec3},
ray_tracing::{AccelerationStructure, RayFlags},
Image,
};
// Needed for .sqrt()
#[allow(unused_imports)]
use spirv_std::num_traits::Float;
#[repr(C)]
pub struct RayPayload {
color: Vec3,
}
#[spirv(ray_generation)]
pub fn generate_rays(
#[spirv(launch_id)] launch_id: UVec3,
#[spirv(ray_payload)] payload: &mut RayPayload,
#[spirv(descriptor_set = 0, binding = 0)] accel_structure: &AccelerationStructure,
#[spirv(descriptor_set = 0, binding = 1)] image: &mut Image!(2D, format=rgba32f, sampled=false),
) {
let ray_direction = ray_for_pixel(launch_id.x, launch_id.y);
unsafe {
accel_structure.trace_ray(
RayFlags::NONE,
0xff,
0,
0,
0,
vec3(0.0, 0.0, 0.0),
0.01,
ray_direction,
1000.0,
payload,
);
image.write(
UVec2::new(launch_id.x, launch_id.y),
vec4(payload.color.x, payload.color.y, payload.color.z, 1.0),
);
}
}
pub fn ray_for_pixel(x: u32, y: u32) -> Vec3 {
let pixel_center = vec2(x as f32 + 0.5, y as f32 + 0.5);
let uv = pixel_center / vec2(1920.0, 1080.0);
let direction = uv * 2.0 - 1.0;
let target = vec3(direction.x, direction.y, 1.0);
target.normalize()
}
#[spirv(miss)]
pub fn ray_miss(#[spirv(incoming_ray_payload)] ray_payload: &mut RayPayload) {
ray_payload.color = vec3(0.0, 0.0, 1.0);
}
#[spirv(closest_hit)]
pub fn ray_hit(#[spirv(incoming_ray_payload)] ray_payload: &mut RayPayload) {
ray_payload.color = vec3(1.0, 0.0, 0.0);
}
#[repr(C)]
pub struct Sphere {
position: Vec3,
radius: f32,
}
#[spirv(intersection)]
pub fn intersect_sphere(
#[spirv(world_ray_origin)] ray_origin: Vec3,
#[spirv(world_ray_direction)] ray_direction: Vec3,
#[spirv(ray_geometry_index)] sphere_id: usize,
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] spheres: &mut [Sphere],
) {
let sphere = &spheres[sphere_id as usize];
let oc = ray_origin - sphere.position;
let a = ray_direction.dot(ray_direction);
let b = 2.0 * oc.dot(ray_direction);
let c = oc.dot(oc) - (sphere.radius * sphere.radius);
let discriminant = b * b - (4.0 * a * c);
if discriminant >= 0.0 {
let hit = (-b - discriminant.sqrt()) / (2.0 * a);
unsafe {
report_intersection(hit, 4);
}
}
}
Loading…
Cancel
Save