Skip to content

Commit

Permalink
Gpu culling (#489)
Browse files Browse the repository at this point in the history
Co-authored-by: Connor Fitzgerald <[email protected]>
  • Loading branch information
cwfitzgerald and cwfitzgerald authored Nov 27, 2023
1 parent f0df67c commit 7d1e012
Show file tree
Hide file tree
Showing 68 changed files with 2,730 additions and 496 deletions.
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

0 comments on commit 7d1e012

Please sign in to comment.