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

Gpu culling #489

Merged
merged 68 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
e7ff10e
Defer object deletion for a frame
cwfitzgerald Jan 16, 2023
876a62d
Always-pass per-triangle culling
cwfitzgerald Jan 17, 2023
a8906a9
Add zero size and backface triangle culling
cwfitzgerald Jan 17, 2023
312b697
Fix issue with transparency
cwfitzgerald Jan 21, 2023
f4a34bb
Micro-triangle culling
cwfitzgerald Jan 21, 2023
b4fc092
Add camera movement
cwfitzgerald Jan 21, 2023
f4f5157
Format
cwfitzgerald Jan 21, 2023
8b18991
Fix output
cwfitzgerald Jan 23, 2023
83d12cb
Temp
cwfitzgerald Jan 23, 2023
2c06673
Closer to something
cwfitzgerald Jan 24, 2023
a07b992
Debug
cwfitzgerald Jan 24, 2023
fe31cc9
Two pass culling
cwfitzgerald Jan 25, 2023
0ff614f
remove unneeded file
cwfitzgerald Jan 25, 2023
1b3d3f8
Working Hi-Z
cwfitzgerald Jan 25, 2023
d18c956
Occlusion culling kinda sorta maybe
cwfitzgerald Jan 25, 2023
ed2b21f
Fix bugs
cwfitzgerald Jan 26, 2023
768aba4
Well that's better...
cwfitzgerald Mar 21, 2023
f1d4585
Hi-z creation and reading improvements
cwfitzgerald Apr 30, 2023
aafb865
Try to fix it
cwfitzgerald May 7, 2023
14912c2
Fixes
cwfitzgerald Jul 9, 2023
e8dbfda
More fixes
cwfitzgerald Jul 10, 2023
d057f9e
Fix shadow passes
cwfitzgerald Jul 13, 2023
167173a
Format
cwfitzgerald Jul 13, 2023
f565a77
So much closer
cwfitzgerald Jul 13, 2023
18b148f
Fix rendering issue with transparents
cwfitzgerald Jul 15, 2023
6c745d1
More rendering fixes
cwfitzgerald Jul 15, 2023
69b0db2
OOB
cwfitzgerald Jul 16, 2023
9c3ee5a
Merge remote-tracking branch 'origin/trunk' into gpu-culling
cwfitzgerald Jul 16, 2023
063f356
Clippy
cwfitzgerald Jul 16, 2023
4a35dbd
Remove old todos
cwfitzgerald Jul 16, 2023
b757112
Remove unused variable
cwfitzgerald Jul 16, 2023
661c79c
Merge remote-tracking branch 'origin/trunk' into gpu-culling
cwfitzgerald Jul 16, 2023
7568339
Merge branch 'trunk' into gpu-culling
cwfitzgerald Jul 16, 2023
e5a362c
Fix webgpu shader
cwfitzgerald Jul 16, 2023
feaa75c
Merge branch 'trunk' into gpu-culling
cwfitzgerald Aug 2, 2023
9e7c07e
Fix Culling Direction
cwfitzgerald Aug 3, 2023
daa755a
Format
cwfitzgerald Aug 3, 2023
7dea244
Merge branch 'trunk' into gpu-culling
cwfitzgerald Aug 6, 2023
8e96fab
Always upload artifacts
cwfitzgerald Aug 6, 2023
7f3f584
Fix various shadow issues
cwfitzgerald Aug 8, 2023
05b3192
Unconditionally capture tests
cwfitzgerald Aug 8, 2023
4e77595
Add thresholds to test
cwfitzgerald Aug 8, 2023
cf3ae56
Fix wasm and mac
cwfitzgerald Aug 8, 2023
4d2cda8
Fix mac 2
cwfitzgerald Aug 8, 2023
8b460ef
Fix mac 2
cwfitzgerald Aug 8, 2023
ea2a1c2
Merge remote-tracking branch 'origin/trunk' into gpu-culling
cwfitzgerald Aug 12, 2023
e2bcc7e
Merge remote-tracking branch 'origin/trunk' into gpu-culling
cwfitzgerald Aug 12, 2023
612184c
Fix issue with per-material buffer growing
cwfitzgerald Aug 12, 2023
1065400
Multi-frame add test
cwfitzgerald Aug 13, 2023
8fcd0b4
Further commenting of test
cwfitzgerald Aug 13, 2023
0565d40
Functioning MSAA
cwfitzgerald Aug 13, 2023
d1c1e90
Disable small triangle culling with MSAA
cwfitzgerald Aug 17, 2023
45d49cd
Format
cwfitzgerald Aug 17, 2023
5ece37f
Completely refactor culling shader
cwfitzgerald Aug 30, 2023
4ac1e9d
CPU side buffer stuff
cwfitzgerald Sep 4, 2023
9bb69be
Debug time
cwfitzgerald Sep 4, 2023
cbf091d
Debugging
cwfitzgerald Sep 5, 2023
1be3ac3
Further Debugging
cwfitzgerald Sep 18, 2023
eb96c91
Fix multisampled example
cwfitzgerald Sep 18, 2023
737c64f
Convert culling data buffer to be separate buffer every frame
cwfitzgerald Sep 25, 2023
e0377cc
Fix culling logic
cwfitzgerald Sep 27, 2023
0f45d6e
Fix crash with zero objects
cwfitzgerald Sep 27, 2023
459b6f8
Merge remote-tracking branch 'origin/trunk' into gpu-culling
cwfitzgerald Oct 16, 2023
bd4670e
Many comments
cwfitzgerald Oct 17, 2023
bb2297e
Deny
cwfitzgerald Oct 17, 2023
dfb56bc
Final comments
cwfitzgerald Nov 11, 2023
f9e9ad6
Culling change
cwfitzgerald Nov 11, 2023
7286d03
Merge branch 'trunk' into gpu-culling
cwfitzgerald Nov 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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ jobs:
if: matrix.target != 'wasm32-unknown-unknown'

- uses: actions/upload-artifact@v3
# always run
if: ${{ !cancelled() }}
with:
name: comparison-images-${{ matrix.name }}
path: |
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = [
"rend3-gltf",
"rend3-routine",
"rend3-test",
"rend3-types"
"rend3-types",
]

[profile.ci]
Expand Down
2 changes: 0 additions & 2 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ license-files = [{ path = "COPYRIGHT", hash = 972598577 }]
multiple-versions = "deny"
wildcards = "allow"
skip = [
# hashbrown
{ name = "ahash", version = "0.7.6" },
# gltf / reqwest
{ name = "base64", version = "0.13.1" },
# ddsfile
Expand Down
10 changes: 7 additions & 3 deletions examples/animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::Path, sync::Arc};

use rend3::types::DirectionalLightHandle;

const SAMPLE_COUNT: rend3::types::SampleCount = rend3::types::SampleCount::Four;
const SAMPLE_COUNT: rend3::types::SampleCount = rend3::types::SampleCount::One;

/// The application data, can only be obtained at `setup` time, so it's under an
/// Option in the main struct.
Expand Down Expand Up @@ -164,8 +164,12 @@ impl rend3_framework::App for AnimationExample {
let mut graph = rend3::graph::RenderGraph::new();

// Import the surface texture into the render graph.
let frame_handle =
graph.add_imported_render_target(&frame, 0..1, rend3::graph::ViewportRect::from_size(resolution));
let frame_handle = graph.add_imported_render_target(
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
);
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
Expand Down
13 changes: 10 additions & 3 deletions examples/cube-no-framework/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(target_arch = "wasm32", allow(clippy::arc_with_non_send_sync))]

use std::sync::Arc;

fn vertex(pos: [f32; 3]) -> glam::Vec3 {
Expand Down Expand Up @@ -107,8 +109,13 @@ fn main() {
let base_rendergraph = rend3_routine::base::BaseRenderGraph::new(&renderer, &spp);

let mut data_core = renderer.data_core.lock();
let pbr_routine =
rend3_routine::pbr::PbrRoutine::new(&renderer, &mut data_core, &spp, &base_rendergraph.interfaces);
let pbr_routine = rend3_routine::pbr::PbrRoutine::new(
&renderer,
&mut data_core,
&spp,
&base_rendergraph.interfaces,
&base_rendergraph.gpu_culler.culling_buffer_map_handle,
);
drop(data_core);
let tonemapping_routine = rend3_routine::tonemapping::TonemappingRoutine::new(
&renderer,
Expand Down Expand Up @@ -209,7 +216,7 @@ fn main() {

// Import the surface texture into the render graph.
let frame_handle =
graph.add_imported_render_target(&frame, 0..1, rend3::graph::ViewportRect::from_size(resolution));
graph.add_imported_render_target(&frame, 0..1, 0..1, rend3::graph::ViewportRect::from_size(resolution));
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
Expand Down
8 changes: 6 additions & 2 deletions examples/cube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ impl rend3_framework::App for CubeExample {
let mut graph = rend3::graph::RenderGraph::new();

// Import the surface texture into the render graph.
let frame_handle =
graph.add_imported_render_target(&frame, 0..1, rend3::graph::ViewportRect::from_size(resolution));
let frame_handle = graph.add_imported_render_target(
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
);
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
Expand Down
8 changes: 6 additions & 2 deletions examples/egui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,12 @@ impl rend3_framework::App for EguiExample {
let mut graph = rend3::graph::RenderGraph::new();

// Import the surface texture into the render graph.
let frame_handle =
graph.add_imported_render_target(&frame, 0..1, rend3::graph::ViewportRect::from_size(resolution));
let frame_handle = graph.add_imported_render_target(
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
);
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
Expand Down
48 changes: 41 additions & 7 deletions examples/scene-viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ fn extract_vsync(value: &str) -> Result<rend3::types::PresentMode, &'static str>
})
}

fn extract_array<const N: usize>(value: &str, default: [f32; N]) -> Result<[f32; N], &'static str> {
let mut res = default;
let split: Vec<_> = value.split(',').enumerate().collect();

if split.len() != N {
return Err("Mismatched argument count");
}

for (idx, inner) in split {
let inner = inner.trim();

res[idx] = inner.parse().map_err(|_| "Cannot parse argument number")?;
}
Ok(res)
}

fn extract_vec3(value: &str) -> Result<Vec3, &'static str> {
let mut res = [0.0_f32, 0.0, 0.0];
let split: Vec<_> = value.split(',').enumerate().collect();
Expand Down Expand Up @@ -254,6 +270,7 @@ Assets:
Controls:
--walk <speed> Walk speed (speed without holding shift) in units/second (typically meters). Default 10.
--run <speed> Run speed (speed while holding shift) in units/second (typically meters). Default 50.
--camera x,y,z,pitch,yaw Spawns the camera at the given position. Press Period to get the current camera position.
";

struct SceneViewer {
Expand Down Expand Up @@ -326,6 +343,10 @@ impl SceneViewer {
// Controls
let walk_speed = args.value_from_str("--walk").unwrap_or(10.0_f32);
let run_speed = args.value_from_str("--run").unwrap_or(50.0_f32);
let camera_default = [3.0, 3.0, 3.0, -std::f32::consts::FRAC_PI_8, std::f32::consts::FRAC_PI_4];
let camera_info = args
.value_from_str("--camera")
.map_or(camera_default, |s: String| extract_array(&s, camera_default).unwrap());

// Free args
let file_to_load: Option<String> = args.free_from_str().ok();
Expand Down Expand Up @@ -382,9 +403,9 @@ impl SceneViewer {
fullscreen,

scancode_status: FastHashMap::default(),
camera_pitch: -std::f32::consts::FRAC_PI_8,
camera_yaw: std::f32::consts::FRAC_PI_4,
camera_location: Vec3A::new(3.0, 3.0, 3.0),
camera_pitch: camera_info[3],
camera_yaw: camera_info[4],
camera_location: Vec3A::new(camera_info[0], camera_info[1], camera_info[2]),
previous_profiling_stats: None,
timestamp_last_second: Instant::now(),
timestamp_last_frame: Instant::now(),
Expand Down Expand Up @@ -524,6 +545,8 @@ impl rend3_framework::App for SceneViewer {

self.timestamp_last_frame = now;

// std::thread::sleep(Duration::from_millis(100));

let rotation =
Mat3A::from_euler(glam::EulerRot::XYZ, -self.camera_pitch, -self.camera_yaw, 0.0).transpose();
let forward = -rotation.z_axis;
Expand All @@ -549,8 +572,15 @@ impl rend3_framework::App for SceneViewer {
if button_pressed(&self.scancode_status, platform::Scancodes::Q) {
self.camera_location += up * velocity * delta_time.as_secs_f32();
}
if button_pressed(&self.scancode_status, platform::Scancodes::Z) {
self.camera_location -= up * velocity * delta_time.as_secs_f32();
if button_pressed(&self.scancode_status, platform::Scancodes::PERIOD) {
println!(
"{x},{y},{z},{pitch},{yaw}",
x = self.camera_location.x,
y = self.camera_location.y,
z = self.camera_location.z,
pitch = self.camera_pitch,
yaw = self.camera_yaw
);
}

if button_pressed(&self.scancode_status, platform::Scancodes::ESCAPE) {
Expand Down Expand Up @@ -595,8 +625,12 @@ impl rend3_framework::App for SceneViewer {
// Build a rendergraph
let mut graph = rend3::graph::RenderGraph::new();

let frame_handle =
graph.add_imported_render_target(&frame, 0..1, rend3::graph::ViewportRect::from_size(resolution));
let frame_handle = graph.add_imported_render_target(
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
);
// Add the default rendergraph
base_rendergraph.add_to_graph(
&mut graph,
Expand Down
8 changes: 6 additions & 2 deletions examples/skinning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ impl rend3_framework::App for SkinningExample {
// Build a rendergraph
let mut graph = rend3::graph::RenderGraph::new();

let frame_handle =
graph.add_imported_render_target(&frame, 0..1, rend3::graph::ViewportRect::from_size(resolution));
let frame_handle = graph.add_imported_render_target(
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
);
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
Expand Down
8 changes: 6 additions & 2 deletions examples/static-gltf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ impl rend3_framework::App for GltfExample {
let mut graph = rend3::graph::RenderGraph::new();

// Import the surface texture into the render graph.
let frame_handle =
graph.add_imported_render_target(&frame, 0..1, rend3::graph::ViewportRect::from_size(resolution));
let frame_handle = graph.add_imported_render_target(
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
);
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
Expand Down
8 changes: 6 additions & 2 deletions examples/textured-quad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ impl rend3_framework::App for TexturedQuadExample {
let mut graph = rend3::graph::RenderGraph::new();

// Import the surface texture into the render graph.
let frame_handle =
graph.add_imported_render_target(&frame, 0..1, rend3::graph::ViewportRect::from_size(resolution));
let frame_handle = graph.add_imported_render_target(
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
);
// Add the default rendergraph
base_rendergraph.add_to_graph(
&mut graph,
Expand Down
1 change: 1 addition & 0 deletions rend3-framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ pub async fn async_start<A: App<T> + 'static, T: 'static>(mut app: A, window_bui
&mut data_core,
&spp,
&base_rendergraph.interfaces,
&base_rendergraph.gpu_culler.culling_buffer_map_handle,
)),
skybox: Mutex::new(rend3_routine::skybox::SkyboxRoutine::new(
&renderer,
Expand Down
8 changes: 3 additions & 5 deletions rend3-routine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ rust-version = "1.71"
arrayvec = "0.7"
bitflags = "2"
bytemuck = "1"
codespan-reporting = "0.11"
encase = { version = "0.6", features = ["glam"] }
flume = "0.11"
glam = { version = "0.24.0", features = ["bytemuck"] }
log = "0.4"
naga = { version = "0.14", features = ["wgsl-in"] }
ordered-float = "4"
parking_lot = "0.12"
profiling = {version = "1", default-features = false }
rend3 = { version = "^0.3.0", path = "../rend3" }
rust-embed = { version = "8", features = ["interpolate-folder-path"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
wgpu = "0.18.0"
wgpu-profiler = "0.15.0"

[dev-dependencies]
codespan-reporting = "0.11"
naga = { version = "0.14", features = ["wgsl-in"] }
serde_json = { version = "1" }
Loading
Loading