Skip to content

Commit

Permalink
Refactor rend3 to use Vertex Pulling (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald authored Jan 15, 2023
1 parent 5003f7b commit 0fa5292
Show file tree
Hide file tree
Showing 115 changed files with 6,021 additions and 6,051 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: '1.62'
toolchain: '1.65'
target: ${{ matrix.target }}
components: clippy
default: true
Expand Down
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ max_width = 120
use_field_init_shorthand = true
use_try_shorthand = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
edition = "2021"
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ debug = true
lto = "thin"

[patch.crates-io]
# wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "f42342bbbfd9d7ebd61745acccc0669fc0e064d2" }
# wgpu-core = { git = "https://github.com/gfx-rs/wgpu.git", rev = "f42342bbbfd9d7ebd61745acccc0669fc0e064d2" }
# wgpu-hal = { git = "https://github.com/gfx-rs/wgpu.git", rev = "f42342bbbfd9d7ebd61745acccc0669fc0e064d2" }
# wgpu-types = { git = "https://github.com/gfx-rs/wgpu.git", rev = "f42342bbbfd9d7ebd61745acccc0669fc0e064d2" }
wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "fac4731288117d951d0944d96cf0b00fa006dd6c" }
wgpu-core = { git = "https://github.com/gfx-rs/wgpu.git", rev = "fac4731288117d951d0944d96cf0b00fa006dd6c" }
wgpu-hal = { git = "https://github.com/gfx-rs/wgpu.git", rev = "fac4731288117d951d0944d96cf0b00fa006dd6c" }
wgpu-types = { git = "https://github.com/gfx-rs/wgpu.git", rev = "fac4731288117d951d0944d96cf0b00fa006dd6c" }
# wgpu = { git = "https://github.com/cwfitzgerald/wgpu.git", rev = "bda861f77e0ca0b97697850ad19d19a8b8f1cc9c" }
# wgpu-core = { git = "https://github.com/cwfitzgerald/wgpu.git", rev = "bda861f77e0ca0b97697850ad19d19a8b8f1cc9c" }
# wgpu-hal = { git = "https://github.com/cwfitzgerald/wgpu.git", rev = "bda861f77e0ca0b97697850ad19d19a8b8f1cc9c" }
Expand All @@ -48,5 +48,7 @@ lto = "thin"
# wgpu-core = { path = "../wgpu/wgpu-core" }
# wgpu-hal = { path = "../wgpu/wgpu-hal" }
# wgpu-types = { path = "../wgpu/wgpu-types" }
naga = { git = "https://github.com/gfx-rs/naga.git", rev = "e98bd92" }
range-alloc = { git = "https://github.com/expenses/gfx.git", rev = "6afbeb6d9733e295404f4fe0ac936591e277a26e" }

gltf = { git = "https://github.com/gltf-rs/gltf.git", rev = "7031e7a8ec7c991b1b1d29eaf7c531c6f4842083" }
1 change: 0 additions & 1 deletion build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ case $1 in
echo "Subcommands:"
echo "help This message."
echo "web-bin [release] <BINARY> Builds BINARY as wasm, and runs wasm-bindgen on the result."
echo "shaders Calls glslc to build all glsl to spirv, and calls naga to create wgsl from it."
echo "serve Serve a web server from target/generated using simple-http-server."
esac
36 changes: 14 additions & 22 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ allow = [
"Apache-2.0",
"MIT",
"MPL-2.0",
"LicenseRef-UFL-1.0",
"Unlicense",
]
copyleft = "allow"
Expand All @@ -20,36 +21,27 @@ license-files = [
multiple-versions = "deny"
wildcards = "allow"
skip = [
# everything
{ name = "cfg-if", version = "0.1.10" },
{ name = "hashbrown", version = "0.11.2" }, # gpu-descriptor from wgpu-hal uses old version
{ name = "parking_lot", version = "0.11.2" }, # winit and imgui uses old version
{ name = "parking_lot_core", version = "0.8.5" }, # winit and imgui uses old version
# graphics
{ name = "core-foundation", version = "0.7.0" }, # winit uses old version
{ name = "core-foundation-sys", version = "0.7.0" }, # winit uses old version
{ name = "core-graphics", version = "0.19.2" }, # winit uses old version
# windows
{ name = "windows_aarch64_msvc", version = "0.32.0" },
{ name = "windows_i686_gnu", version = "0.32.0" },
{ name = "windows_i686_msvc", version = "0.32.0" },
{ name = "windows_x86_64_gnu", version = "0.32.0" },
{ name = "windows_x86_64_msvc", version = "0.32.0" },
# hashbrown
{ name = "ahash", version = "0.7.6" },
# gltf / reqwest
{ name = "base64", version = "0.13.1" },
# ddsfile
{ name = "num-traits", version = "0.1.43" },
# android
{ name = "env_logger", version = "0.8.4" },
# handlebars
{ name = "block-buffer", version = "0.7.3" },
{ name = "digest", version = "0.8.1" },
{ name = "generic-array", version = "0.12.4" },
{ name = "opaque-debug", version = "0.2.3" },
{ name = "raw-window-handle", version = "0.4.3" },
]
skip-tree = [
{ name = "windows", version = "0.39" },
{ name = "windows-sys", version = "0.36" },
# winit transitively included dupes
{ name = "winit", version = "0.27" },
]

[advisories]
vulnerability = "warn"
unmaintained = "warn"
ignore = [
# xml is unmaintained (wayland)
"RUSTSEC-2022-0048"
]

[sources]
Expand Down
12 changes: 6 additions & 6 deletions examples/animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.3.0"
authors = ["The rend3 Developers"]
edition = "2021"
publish = false
rust-version = "1.57"
rust-version = "1.65"

[lib]
crate-type = ["lib", "cdylib"]
Expand All @@ -16,9 +16,9 @@ path = "src/main.rs"

[dependencies]
# logging
env_logger = { version = "0.9", default-features = false, features = ["termcolor", "atty"] }
env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] }
# Linear algebra library
glam = "0.21.2"
glam = "0.22"
# std::time::Instant that works on wasm
instant = "0.1"
# block on async functions
Expand All @@ -34,19 +34,19 @@ rend3-anim = { version = "^0.3.0", path = "../../rend3-anim" }
# Import gltf models
rend3-gltf = { version = "^0.3.0", path = "../../rend3-gltf" }
# windowing
winit = "0.26"
winit = "0.27"
image = { version = "0.24", default-features = false, features = ["jpeg"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = "0.2"
console_error_panic_hook = "0.1"
js-sys = "0.3"
web-sys = "0.3"
wasm-bindgen = "=0.2.81"
wasm-bindgen = "=0.2.83"
wasm-bindgen-futures = "0.4"

[target.'cfg(target_os = "android")'.dependencies]
ndk-glue = { version = "0.5", features = ["logger"] }
ndk-glue = { version = "0.7", features = ["logger"] }

[package.metadata.android]
build_targets = ["aarch64-linux-android"]
Expand Down
22 changes: 15 additions & 7 deletions examples/animation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rend3::types::DirectionalLightHandle;
use std::{path::Path, sync::Arc};

use rend3::types::DirectionalLightHandle;

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

/// The application data, can only be obtained at `setup` time, so it's under an
Expand Down Expand Up @@ -42,6 +43,7 @@ impl rend3_framework::App for AnimationExample {

fn setup(
&mut self,
_event_loop: &winit::event_loop::EventLoop<rend3_framework::UserResizeEvent<()>>,
_window: &winit::window::Window,
renderer: &Arc<rend3::Renderer>,
_routines: &Arc<rend3_framework::DefaultRoutines>,
Expand All @@ -60,7 +62,7 @@ impl rend3_framework::App for AnimationExample {
// Load a gltf model with animation data
// Needs to be stored somewhere, otherwise all the data gets freed.
let path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/scene.gltf"));
let gltf_data = std::fs::read(&path).unwrap();
let gltf_data = std::fs::read(path).unwrap();
let parent_directory = path.parent().unwrap();
let (loaded_scene, loaded_instance) = pollster::block_on(rend3_gltf::load_gltf(
renderer,
Expand All @@ -79,6 +81,7 @@ impl rend3_framework::App for AnimationExample {
// Direction will be normalized
direction: glam::Vec3::new(-1.0, -4.0, 2.0),
distance: 400.0,
resolution: 2048,
});

self._directional_light_handle = Some(directional_light_handle);
Expand All @@ -92,7 +95,7 @@ impl rend3_framework::App for AnimationExample {
};

let path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/cube_3.gltf"));
let gltf_data = std::fs::read(&path).unwrap();
let gltf_data = std::fs::read(path).unwrap();
let parent_directory = path.parent().unwrap();
let (loaded_scene, loaded_instance) = pollster::block_on(rend3_gltf::load_gltf(
renderer,
Expand Down Expand Up @@ -146,9 +149,7 @@ impl rend3_framework::App for AnimationExample {
// Render!
rend3_framework::Event::RedrawRequested(_) => {
// Get a frame
let frame = rend3::util::output::OutputFrame::Surface {
surface: Arc::clone(surface.unwrap()),
};
let frame = surface.unwrap().get_current_texture().unwrap();
// Ready up the renderer
let (cmd_bufs, ready) = renderer.ready();

Expand All @@ -159,21 +160,28 @@ impl rend3_framework::App for AnimationExample {
// Build a rendergraph
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));
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
&ready,
&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
);

// Dispatch a render using the built up rendergraph!
graph.execute(renderer, frame, cmd_bufs, &ready);
graph.execute(renderer, cmd_bufs, &ready);

// Present the frame
frame.present();
}
// Other events we don't care about
_ => {}
Expand Down
10 changes: 5 additions & 5 deletions examples/cube-no-framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.3.0"
authors = ["The rend3 Developers"]
edition = "2021"
publish = false
rust-version = "1.57"
rust-version = "1.65"

[[bin]]
name = "cube-no-framework"
Expand All @@ -15,22 +15,22 @@ path = "src/main.rs"

[dependencies]
# logging
env_logger = { version = "0.9", default-features = false, features = ["termcolor", "atty"] }
env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] }
# Linear algebra library
glam = "0.21.2"
glam = "0.22"
# Renderer core
rend3 = { version = "^0.3.0", path = "../../rend3" }
# Programmable render list that dictates how the scene renders
rend3-routine = { version = "^0.3.0", path = "../../rend3-routine" }
# Provides `block_on` to wait for futures from sync code
pollster = "0.2"
# windowing
winit = "0.26"
winit = "0.27"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = "0.2"
console_error_panic_hook = "0.1"
js-sys = "0.3"
web-sys = "0.3"
wasm-bindgen = "=0.2.81"
wasm-bindgen = "=0.2.83"
wasm-bindgen-futures = "0.4"
22 changes: 14 additions & 8 deletions examples/cube-no-framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ fn main() {
// SAFETY: this surface _must_ not be used after the `window` dies. Both the
// event loop and the renderer are owned by the `run` closure passed to winit,
// so rendering work will stop after the window dies.
let surface = Arc::new(unsafe { iad.instance.create_surface(&window) });
let surface = Arc::new(unsafe { iad.instance.create_surface(&window) }.unwrap());
// Get the preferred format for the surface.
let formats = surface.get_supported_formats(&iad.adapter);
let preferred_format = formats[0];
let caps = surface.get_capabilities(&iad.adapter);
let preferred_format = caps.formats[0];

// Configure the surface to be ready for rendering.
rend3::configure_surface(
Expand Down Expand Up @@ -164,6 +164,7 @@ fn main() {
// Direction will be normalized
direction: glam::Vec3::new(-1.0, -4.0, 2.0),
distance: 400.0,
resolution: 2048,
});

let mut resolution = glam::UVec2::new(window_size.width, window_size.height);
Expand All @@ -188,38 +189,43 @@ fn main() {
&renderer.device,
preferred_format,
glam::UVec2::new(resolution.x, resolution.y),
rend3::types::PresentMode::Mailbox,
rend3::types::PresentMode::Fifo,
);
// Tell the renderer about the new aspect ratio.
renderer.set_aspect_ratio(resolution.x as f32 / resolution.y as f32);
}
// Render!
winit::event::Event::MainEventsCleared => {
// Get a frame
let frame = rend3::util::output::OutputFrame::Surface {
surface: Arc::clone(&surface),
};
let frame = surface.get_current_texture().unwrap();
// Ready up the renderer
let (cmd_bufs, ready) = renderer.ready();

// Build a rendergraph
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));
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
&ready,
&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
);

// Dispatch a render using the built up rendergraph!
graph.execute(&renderer, frame, cmd_bufs, &ready);
graph.execute(&renderer, cmd_bufs, &ready);

// Present the frame
frame.present();
}
// Other events we don't care about
_ => {}
Expand Down
12 changes: 6 additions & 6 deletions examples/cube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.3.0"
authors = ["The rend3 Developers"]
edition = "2021"
publish = false
rust-version = "1.57"
rust-version = "1.65"

[lib]
crate-type = ["lib", "cdylib"]
Expand All @@ -18,28 +18,28 @@ path = "src/main.rs"

[dependencies]
# logging
env_logger = { version = "0.9", default-features = false, features = ["termcolor", "atty"] }
env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] }
# Linear algebra library
glam = "0.21.2"
glam = "0.22"
# Renderer core
rend3 = { version = "^0.3.0", path = "../../rend3" }
# Programmable render list that dictates how the scene renders
rend3-routine = { version = "^0.3.0", path = "../../rend3-routine" }
# Framework that deals with the event loop, setting up the renderer, and platform differences.
rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" }
# windowing
winit = "0.26"
winit = "0.27"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = "0.2"
console_error_panic_hook = "0.1"
js-sys = "0.3"
web-sys = "0.3"
wasm-bindgen = "=0.2.81"
wasm-bindgen = "=0.2.83"
wasm-bindgen-futures = "0.4"

[target.'cfg(target_os = "android")'.dependencies]
ndk-glue = { version = "0.5", features = ["logger"] }
ndk-glue = { version = "0.7", features = ["logger"] }

[package.metadata.android]
build_targets = ["aarch64-linux-android"]
Expand Down
Loading

0 comments on commit 0fa5292

Please sign in to comment.