Skip to content

Commit

Permalink
checkpoint - depth pyramid
Browse files Browse the repository at this point in the history
  • Loading branch information
schell committed Oct 10, 2024
1 parent e2679ca commit ee6292c
Show file tree
Hide file tree
Showing 41 changed files with 1,179 additions and 934 deletions.
738 changes: 362 additions & 376 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ resolver = "2"
assert_approx_eq = "1.1.0"
async-channel = "1.8"
bytemuck = { version = "1.13.0", features = ["derive"] }
crabslab = { version = "0.6.0", default-features = false }
crabslab = { version = "0.6.0", path = "../crabslab/crates/crabslab", default-features = false }
ctor = "0.2.2"
dagga = "0.2.1"
env_logger = "0.10.0"
futures-lite = "1.13"
glam = { version = "0.24.2", default-features = false }
glam = { version = "0.29", default-features = false }
gltf = { version = "1.4,1", features = ["KHR_lights_punctual", "KHR_materials_unlit", "KHR_materials_emissive_strength", "extras", "extensions"] }
image = "0.24"
log = "0.4"
naga = { version = "0.19", features = ["spv-in", "wgsl-out", "wgsl-in", "msl-out"] }
naga = { version = "22.0.0", features = ["spv-in", "wgsl-out", "wgsl-in", "msl-out"] }
pretty_assertions = "1.4.0"
proc-macro2 = { version = "1.0", features = ["span-locations"] }
rustc-hash = "1.1"
Expand All @@ -38,7 +38,7 @@ wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = "0.3"
winit = { version = "0.30" }
wgpu = "22.1.0"
wgpu = "22.0.0"

[profile.dev]
opt-level = 1
Expand All @@ -48,3 +48,9 @@ opt-level = 3

[profile.dev.package.gltf]
opt-level = 3

[patch.crates-io]
naga = { git = "https://github.com/schell/wgpu.git", branch = "fix/spv-in-sampling-result-for-depth-texture-is-scalar" }
wgpu = { git = "https://github.com/schell/wgpu.git", branch = "fix/spv-in-sampling-result-for-depth-texture-is-scalar" }
spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu" }

73 changes: 3 additions & 70 deletions crates/renderling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,83 +15,16 @@ readme = "../../README.md"
crate-type = ["rlib", "cdylib"]

[features]
default = ["gltf", "shaders", "tutorial", "winit"]
shaders = [
"array_test",
"bloom",
"brdf_lut_convolution_fragment",
"brdf_lut_convolution_vertex",
"compute_frustum_culling",
"compute_occlusion_culling",
"generate_mipmap_fragment",
"generate_mipmap_vertex",
"prefilter_environment_cubemap_fragment",
"prefilter_environment_cubemap_vertex",
"renderlet_fragment",
"renderlet_vertex",
"skybox_cubemap_fragment",
"skybox_cubemap_vertex",
"skybox_equirectangular_fragment",
"skybox_vertex",
"test_i8_i16_extraction",
"tonemapping_fragment",
"tonemapping_vertex"
]
default = ["gltf", "tutorial", "winit"]
gltf = ["dep:gltf", "dep:serde_json"]
tutorial = [
"tutorial_passthru_fragment",
"tutorial_implicit_isosceles_vertex",
"tutorial_slabbed_vertices_no_instance",
"tutorial_slabbed_vertices",
"tutorial_slabbed_renderlet"
]
bloom = [
"bloom_downsample_fragment",
"bloom_upsample_fragment",
"bloom_mix_fragment",
"bloom_vertex"
]
# shaders
# optional shaders
array_test = []
bloom_downsample_fragment = []
bloom_upsample_fragment = []
bloom_mix_fragment = []
bloom_vertex = []
brdf_lut_convolution_fragment = []
brdf_lut_convolution_vertex = []
compute_frustum_culling = []
compute_occlusion_culling = []
generate_mipmap_fragment = []
generate_mipmap_vertex = []
prefilter_environment_cubemap_fragment = []
prefilter_environment_cubemap_vertex = []
#raymarch_fragment = []
#raymarch_rays_fragment = []
#raymarch_vertex = []
#sdf_shape_fragment = []
#sdf_shape_vertex = []
#sdf_prim_fragment_test = []
renderlet_fragment = []
renderlet_vertex = []
skybox_cubemap_fragment = []
skybox_cubemap_vertex = []
skybox_equirectangular_fragment = []
skybox_vertex = []
test_i8_i16_extraction = []
test_spirv_atomics = []
tonemapping_fragment = []
tonemapping_vertex = []
tutorial_passthru_fragment = []
tutorial_implicit_isosceles_vertex = []
tutorial_slabbed_vertices_no_instance = []
tutorial_slabbed_vertices = []
tutorial_slabbed_renderlet = []
tutorial = []

wasm = ["wgpu/fragile-send-sync-non-atomic-wasm"]

[patch.crates-io]
spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu" }

# dependencies for CPU and GPU code
[dependencies]
spirv-std = { version = "0.9" }
Expand Down
4 changes: 0 additions & 4 deletions crates/renderling/src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod cpu;
#[cfg(not(target_arch = "spirv"))]
pub use cpu::*;

#[cfg(feature = "bloom_vertex")]
/// Bloom vertex shader.
///
/// This is a pass-through vertex shader to facilitate a bloom effect.
Expand All @@ -28,7 +27,6 @@ pub fn bloom_vertex(
*out_id = in_id;
}

#[cfg(feature = "bloom_downsample_fragment")]
/// Bloom downsampling shader.
///
/// Performs successive downsampling from a source texture.
Expand Down Expand Up @@ -102,7 +100,6 @@ pub fn bloom_downsample_fragment(
*downsample = (center + inner + outer + furthest).max(min);
}

#[cfg(feature = "bloom_upsample_fragment")]
/// Bloom upsampling shader.
///
/// This shader performs successive upsampling on a source texture.
Expand Down Expand Up @@ -169,7 +166,6 @@ pub fn bloom_upsample_fragment(
*upsample = sample.extend(0.5);
}

#[cfg(feature = "bloom_mix_fragment")]
#[spirv(fragment)]
#[allow(clippy::too_many_arguments)]
/// Bloom "mix" shader.
Expand Down
18 changes: 9 additions & 9 deletions crates/renderling/src/bloom/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn create_bloom_downsample_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeli
layout: Some(&layout),
vertex: wgpu::VertexState {
module: &vertex_module.module,
entry_point: vertex_module.entry_point,
entry_point: Some(vertex_module.entry_point),
buffers: &[],
compilation_options: Default::default(),
},
Expand All @@ -75,7 +75,7 @@ fn create_bloom_downsample_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeli
multisample: wgpu::MultisampleState::default(),
fragment: Some(wgpu::FragmentState {
module: &fragment_module.module,
entry_point: fragment_module.entry_point,
entry_point: Some(fragment_module.entry_point),
targets: &[Some(wgpu::ColorTargetState {
format: wgpu::TextureFormat::Rgba16Float,
blend: None,
Expand Down Expand Up @@ -103,7 +103,7 @@ fn create_bloom_upsample_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline
layout: Some(&layout),
vertex: wgpu::VertexState {
module: &vertex_module.module,
entry_point: vertex_module.entry_point,
entry_point: Some(vertex_module.entry_point),
buffers: &[],
compilation_options: Default::default(),
},
Expand All @@ -120,7 +120,7 @@ fn create_bloom_upsample_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline
multisample: wgpu::MultisampleState::default(),
fragment: Some(wgpu::FragmentState {
module: &fragment_module.module,
entry_point: fragment_module.entry_point,
entry_point: Some(fragment_module.entry_point),
targets: &[Some(wgpu::ColorTargetState {
format: wgpu::TextureFormat::Rgba16Float,
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
Expand Down Expand Up @@ -312,7 +312,7 @@ fn create_mix_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline {
layout: Some(&layout),
vertex: wgpu::VertexState {
module: &vertex_module.module,
entry_point: vertex_module.entry_point,
entry_point: Some(vertex_module.entry_point),
buffers: &[],
compilation_options: Default::default(),
},
Expand All @@ -329,7 +329,7 @@ fn create_mix_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline {
multisample: wgpu::MultisampleState::default(),
fragment: Some(wgpu::FragmentState {
module: &fragment_module.module,
entry_point: fragment_module.entry_point,
entry_point: Some(fragment_module.entry_point),
targets: &[Some(wgpu::ColorTargetState {
format: wgpu::TextureFormat::Rgba16Float,
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
Expand Down Expand Up @@ -599,7 +599,7 @@ impl Bloom {
occlusion_query_set: None,
});
render_pass.set_pipeline(&self.downsample_pipeline);
render_pass.set_bind_group(0, bindgroup, &[]);
render_pass.set_bind_group(0, Some(bindgroup), &[]);
let id = pixel_size.into();
render_pass.draw(0..6, id..id + 1);
}
Expand Down Expand Up @@ -645,7 +645,7 @@ impl Bloom {
occlusion_query_set: None,
});
render_pass.set_pipeline(&self.upsample_pipeline);
render_pass.set_bind_group(0, bindgroup, &[]);
render_pass.set_bind_group(0, Some(bindgroup), &[]);
let id = self.upsample_filter_radius.id().into();
render_pass.draw(0..6, id..id + 1);
}
Expand Down Expand Up @@ -675,7 +675,7 @@ impl Bloom {
occlusion_query_set: None,
});
render_pass.set_pipeline(&self.mix_pipeline);
render_pass.set_bind_group(0, &mix_bindgroup, &[]);
render_pass.set_bind_group(0, Some(&mix_bindgroup), &[]);
let id = self.mix_strength.id().into();
render_pass.draw(0..6, id..id + 1);
}
Expand Down
14 changes: 7 additions & 7 deletions crates/renderling/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ async fn device(
adapter: &wgpu::Adapter,
) -> Result<(wgpu::Device, wgpu::Queue), wgpu::RequestDeviceError> {
let wanted_features = wgpu::Features::INDIRECT_FIRST_INSTANCE
| wgpu::Features::MULTI_DRAW_INDIRECT
//// when debugging rust-gpu shader miscompilation it's nice to have this
//| wgpu::Features::SPIRV_SHADER_PASSTHROUGH
// this one is a funny requirement, it seems it is needed if using storage buffers in
// vertex shaders, even if those shaders are read-only
| wgpu::Features::VERTEX_WRITABLE_STORAGE
| wgpu::Features::CLEAR_TEXTURE;
| wgpu::Features::MULTI_DRAW_INDIRECT
//// when debugging rust-gpu shader miscompilation it's nice to have this
//| wgpu::Features::SPIRV_SHADER_PASSTHROUGH
// this one is a funny requirement, it seems it is needed if using storage buffers in
// vertex shaders, even if those shaders are read-only
| wgpu::Features::VERTEX_WRITABLE_STORAGE
| wgpu::Features::CLEAR_TEXTURE;
let supported_features = adapter.features();
let required_features = wanted_features.intersection(supported_features);
let unsupported_features = wanted_features.difference(supported_features);
Expand Down
6 changes: 0 additions & 6 deletions crates/renderling/src/convolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ pub struct VertexPrefilterEnvironmentCubemapIds {
pub roughness: Id<f32>,
}

#[cfg(feature = "prefilter_environment_cubemap_vertex")]
/// Vertex shader for rendering a "prefilter environment" cubemap.
#[spirv(vertex)]
pub fn prefilter_environment_cubemap_vertex(
Expand All @@ -177,7 +176,6 @@ pub fn prefilter_environment_cubemap_vertex(
*gl_pos = camera.view_projection() * in_pos.extend(1.0);
}

#[cfg(feature = "prefilter_environment_cubemap_fragment")]
/// Fragment shader for rendering a "prefilter environment" cubemap.
///
/// Lambertian prefilter.
Expand Down Expand Up @@ -242,7 +240,6 @@ pub fn calc_lod(n_dot_l: f32) -> f32 {
0.5 * (6.0 * cube_width * cube_width / (SAMPLE_COUNT as f32 * pdf).max(f32::EPSILON)).log2()
}

#[cfg(feature = "generate_mipmap_vertex")]
#[spirv(vertex)]
/// Vertex shader for generating texture mips.
pub fn generate_mipmap_vertex(
Expand All @@ -255,7 +252,6 @@ pub fn generate_mipmap_vertex(
*gl_pos = crate::math::CLIP_SPACE_COORD_QUAD_CCW[i];
}

#[cfg(feature = "generate_mipmap_fragment")]
#[spirv(fragment)]
/// Fragment shader for generating texture mips.
pub fn generate_mipmap_fragment(
Expand Down Expand Up @@ -296,7 +292,6 @@ const BRDF_VERTS: [Vert; 6] = {
[bl, br, tr, bl, tr, tl]
};

#[cfg(feature = "brdf_lut_convolution_vertex")]
#[spirv(vertex)]
/// Vertex shader for creating a BRDF LUT.
pub fn brdf_lut_convolution_vertex(
Expand All @@ -309,7 +304,6 @@ pub fn brdf_lut_convolution_vertex(
*gl_pos = Vec3::from(pos).extend(1.0);
}

#[cfg(feature = "brdf_lut_convolution_fragment")]
#[spirv(fragment)]
/// Fragment shader for creating a BRDF LUT.
pub fn brdf_lut_convolution_fragment(in_uv: glam::Vec2, out_color: &mut glam::Vec2) {
Expand Down
4 changes: 2 additions & 2 deletions crates/renderling/src/cubemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl CubemapMakingRenderPipeline {
layout: Some(&pp_layout),
vertex: wgpu::VertexState {
module: &vertex_linkage.module,
entry_point: vertex_linkage.entry_point,
entry_point: Some(vertex_linkage.entry_point),
buffers: &[],
compilation_options: Default::default(),
},
Expand All @@ -105,7 +105,7 @@ impl CubemapMakingRenderPipeline {
},
fragment: Some(wgpu::FragmentState {
module: &fragment_linkage.module,
entry_point: fragment_linkage.entry_point,
entry_point: Some(fragment_linkage.entry_point),
targets: &[Some(wgpu::ColorTargetState {
format,
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
Expand Down
Loading

0 comments on commit ee6292c

Please sign in to comment.