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

Vastly Clean Up Rend3 Routine Internals #542

Merged
merged 8 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Per Keep a Changelog there are 6 main categories of changes:

### Major Changes
- rend3: `add_mesh`, `add_skeleton` and `add_texture_*` now return Results with fully typed errors. This will catch all errors on all platforms except for web, where wgpu allocation errors will not be caught. @cwfitzgerald
- rend3-routine: Argument structs broken up into multiple sub-structs for better ergonomics. @cwfitzgerald

### Added
- rend3-egui: Added the ability to create egui textures (egui::TextureId) with the wgpu backend @AlbinSjoegren
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ inherits = "dev"
debug = false
incremental = false

[profile.dev-release]
inherits = "dev"
[profile.ci.package."*"]
opt-level = 0

[profile.dev-release.package."*"]
[profile.dev.package."*"]
opt-level = 3

[profile.release]
Expand Down
26 changes: 17 additions & 9 deletions examples/animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,23 @@ impl rend3_framework::App for AnimationExample {
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
&eval_output,
&pbr_routine,
None,
&tonemapping_routine,
frame_handle,
resolution,
SAMPLE_COUNT,
glam::Vec4::splat(0.15),
glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: SAMPLE_COUNT,
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
);

// Dispatch a render using the built up rendergraph!
Expand Down
26 changes: 17 additions & 9 deletions examples/cube-no-framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,23 @@ fn main() {
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
&eval_output,
&pbr_routine,
None,
&tonemapping_routine,
frame_handle,
resolution,
rend3::types::SampleCount::One,
glam::Vec4::ZERO,
glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: rend3::types::SampleCount::One,
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
);

// Dispatch a render using the built up rendergraph!
Expand Down
26 changes: 17 additions & 9 deletions examples/cube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,23 @@ impl rend3_framework::App for CubeExample {
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
&eval_output,
&pbr_routine,
None,
&tonemapping_routine,
frame_handle,
resolution,
SAMPLE_COUNT,
glam::Vec4::ZERO,
glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: SAMPLE_COUNT,
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
);

// Dispatch a render using the built up rendergraph!
Expand Down
26 changes: 17 additions & 9 deletions examples/egui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,23 @@ impl rend3_framework::App for EguiExample {
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
&eval_output,
&pbr_routine,
None,
&tonemapping_routine,
frame_handle,
resolution,
SAMPLE_COUNT,
glam::Vec4::ZERO,
glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: SAMPLE_COUNT,
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
);

// Add egui on top of all the other passes
Expand Down
26 changes: 17 additions & 9 deletions examples/scene-viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,23 @@ impl rend3_framework::App for SceneViewer {
// Add the default rendergraph
base_rendergraph.add_to_graph(
&mut graph,
&eval_output,
&pbr_routine,
Some(&skybox_routine),
&tonemapping_routine,
frame_handle,
resolution,
self.samples,
Vec3::splat(self.ambient_light_level).extend(1.0),
glam::Vec4::new(0.0, 0.0, 0.0, 1.0),
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: Some(&skybox_routine),
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: self.samples,
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: Vec3::splat(self.ambient_light_level).extend(1.0),
clear_color: glam::Vec4::new(0.0, 0.0, 0.0, 1.0),
},
);

// Dispatch a render using the built up rendergraph!
Expand Down
26 changes: 17 additions & 9 deletions examples/skinning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,23 @@ impl rend3_framework::App for SkinningExample {
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
&eval_output,
&pbr_routine,
None,
&tonemapping_routine,
frame_handle,
resolution,
SAMPLE_COUNT,
glam::Vec4::splat(0.15),
glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: SAMPLE_COUNT,
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
);

// Dispatch a render using the built up rendergraph!
Expand Down
26 changes: 17 additions & 9 deletions examples/static-gltf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,23 @@ impl rend3_framework::App for GltfExample {
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
&eval_output,
&pbr_routine,
None,
&tonemapping_routine,
frame_handle,
resolution,
SAMPLE_COUNT,
glam::Vec4::ZERO,
glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: SAMPLE_COUNT,
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
);
// Dispatch a render using the built up rendergraph!
graph.execute(renderer, &mut eval_output);
Expand Down
26 changes: 17 additions & 9 deletions examples/textured-quad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,23 @@ impl rend3_framework::App for TexturedQuadExample {
// Add the default rendergraph
base_rendergraph.add_to_graph(
&mut graph,
&eval_output,
&pbr_routine,
None,
&tonemapping_routine,
frame_handle,
resolution,
SAMPLE_COUNT,
glam::Vec4::ZERO,
glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: SAMPLE_COUNT,
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
);

// Dispatch a render using the built up rendergraph!
Expand Down
24 changes: 13 additions & 11 deletions rend3-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
use std::{mem, sync::Arc};

use egui::TexturesDelta;
use glam::Vec4;
use rend3::{
graph::{NodeResourceUsage, RenderGraph, RenderPassTarget, RenderPassTargets, RenderTargetHandle},
types::SampleCount,
Renderer,
};
use wgpu::{Color, TextureFormat};
use wgpu::TextureFormat;

pub struct EguiRenderRoutine {
pub internal: egui_wgpu::Renderer,
Expand Down Expand Up @@ -58,16 +59,17 @@ impl EguiRenderRoutine {
) {
let mut builder = graph.add_node("egui");

let output_handle = builder.add_render_target(output, NodeResourceUsage::InputOutput);

let rpass_handle = builder.add_renderpass(RenderPassTargets {
targets: vec![RenderPassTarget {
color: output_handle,
clear: Color::BLACK,
resolve: None,
}],
depth_stencil: None,
});
let rpass_handle = builder.add_renderpass(
RenderPassTargets {
targets: vec![RenderPassTarget {
color: output,
clear: Vec4::ZERO,
resolve: None,
}],
depth_stencil: None,
},
NodeResourceUsage::Output,
);

// We can't free textures directly after the call to `execute_with_renderpass` as it freezes
// the lifetime of `self` for the remainder of the closure. so we instead buffer the textures
Expand Down
20 changes: 16 additions & 4 deletions rend3-routine/shaders/src/cull.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct ObjectSearchResult {
}

fn find_object_info(wid: u32) -> ObjectSearchResult {
let target_invocation = wid * 64u;
let target_invocation = wid * 256u;
// pulled directly from https://doc.rust-lang.org/src/core/slice/mod.rs.html#2412-2438

var size = culling_job.total_objects;
Expand All @@ -206,13 +206,19 @@ fn find_object_info(wid: u32) -> ObjectSearchResult {
return ObjectSearchResult(object_info, 0xFFFFFFFFu);
}

// 64 workgroup size / 32 bits
var<workgroup> workgroup_culling_results: array<atomic<u32>, 2>;
// 256 workgroup size / 32 bits
var<workgroup> workgroup_culling_results: array<atomic<u32>, 8>;

fn clear_culling_results(lid: u32) {
if lid == 0u {
atomicStore(&workgroup_culling_results[0], 0u);
atomicStore(&workgroup_culling_results[1], 0u);
atomicStore(&workgroup_culling_results[2], 0u);
atomicStore(&workgroup_culling_results[3], 0u);
atomicStore(&workgroup_culling_results[4], 0u);
atomicStore(&workgroup_culling_results[5], 0u);
atomicStore(&workgroup_culling_results[6], 0u);
atomicStore(&workgroup_culling_results[7], 0u);
}
}

Expand All @@ -225,6 +231,12 @@ fn save_culling_results(global_invocation: u32, lid: u32) {
let culling_results_index = culling_results.output_offset + (global_invocation / 32u);
culling_results.bits[culling_results_index + 0u] = atomicLoad(&workgroup_culling_results[0]);
culling_results.bits[culling_results_index + 1u] = atomicLoad(&workgroup_culling_results[1]);
culling_results.bits[culling_results_index + 2u] = atomicLoad(&workgroup_culling_results[2]);
culling_results.bits[culling_results_index + 3u] = atomicLoad(&workgroup_culling_results[3]);
culling_results.bits[culling_results_index + 4u] = atomicLoad(&workgroup_culling_results[4]);
culling_results.bits[culling_results_index + 5u] = atomicLoad(&workgroup_culling_results[5]);
culling_results.bits[culling_results_index + 6u] = atomicLoad(&workgroup_culling_results[6]);
culling_results.bits[culling_results_index + 7u] = atomicLoad(&workgroup_culling_results[7]);
}
}

Expand Down Expand Up @@ -311,7 +323,7 @@ fn execute_culling(
return true;
}

@compute @workgroup_size(64)
@compute @workgroup_size(256)
fn cs_main(
@builtin(workgroup_id) wid: vec3<u32>,
@builtin(global_invocation_id) gid: vec3<u32>,
Expand Down
2 changes: 1 addition & 1 deletion rend3-routine/shaders/src/uniform_prep.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var<storage> object_buffer: array<Object>;
@group(0) @binding(1)
var<storage, read_write> per_camera_uniform: PerCameraUniform;

@compute @workgroup_size(64)
@compute @workgroup_size(256)
fn cs_main(
@builtin(global_invocation_id) gid: vec3<u32>,
) {
Expand Down
Loading
Loading