Skip to content

Commit

Permalink
Bunch of Small Touchups (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald authored Dec 11, 2023
1 parent e1cfe1b commit ccbcf3e
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 111 deletions.
50 changes: 2 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ integration crates
There are extension crates that are not required, but provide pre-made bits
of useful code that I would recommend using.

- `rend3-anim`: Skeletal animation playback utilities. Currently tied to rend3-gltf.
- `rend3-framework`: Vastly simplifies correct handling of the window and
surface across platforms.
- `rend3-gltf`: Modular gltf file and scene loader.
Expand All @@ -61,54 +60,9 @@ Integration with other external libraries are also offered. Due to external
dependencies, the versions of these may increase at a much higher rate than
the rest of the ecosystem.

- `rend3-anim`: Skeletal animation playback utilities. Currently tied to rend3-gltf.
- `rend3-egui`: Integration with the [egui](https://github.com/emilk/egui)
immediate mode gui.
- `rend3-imgui`: Integration with the [imgui](https://github.com/ocornut/imgui)
immediate mode gui.

## Features and Platform Support

rend3 supports two different rendering profiles one for speed and one for
compatibility.

#### Profile Features

The modern profile not only offloads a lot more work to the gpu, it can do more
aggressive performance optimizations including only drawing exactly the triangles that are needed

| Profile | Texture Access | Object Culling | Triangle Culling | Draw Calls |
|:----------|----------------|----------------|------------------|---------------------|
| GpuDriven | Bindless | On GPU | On GPU | Merged Indirect |
| CpuDriven | Bound | On CPU || Instanced Direct |

#### Profile Support

The following table shows support of various profiles on various apis/platforms. This will
hopefully help you judge what your target demographic supports.

| OS | API | GPU | GpuDriven | CpuDriven |
|----------------------|--------|--------------------------------------------|:---------:|:---------:|
| Windows 7+ | Vulkan | AMD / NVIDIA |||
| | Vulkan | Intel 6XXX+ |||
| | Dx11 | Intel 2XXX+ || 🚧 |
| Windows 10+ | Dx12 | Intel 6XXX+ / AMD GCN 2+ / NVIDIA 6XX+ | 🚧 ||
| MacOS 10.13+ iOS 11+ | Metal | Intel / Apple A13+ / M1+ |||
| | | Apple A9+ |||
| Linux | Vulkan | Intel 6XXX+ / AMD GCN 2+ / NVIDIA 6XX+ |||
| | | Intel 4XXX+ |||
| Android | Vulkan | All |||

Footnotes:
- ✅ Supported
- 🚧 In Progress
- ❌ Unsupported
- — Modern Profile Used
- Intel 6XXX = Skylake
- Intel 4XXX = Haswell
- Intel 2XXX = Sandy Bridge
- AMD GCN 2 = Rx 200+, RX 5000+
- Apple A9 = iPhone 6S, iPad 5th Gen
- Apple A13 = iPhone 11, iPad 9th Gen

## Purpose

Expand All @@ -122,7 +76,7 @@ Footnotes:
advanced game or simulation nor care how you structure your program.
If you want a very basic framework to deal with windowing and event loop management,
`rend3-framework` can help you. This will always be optional and is just there to help
with the limited set of cases it canhelp
with the limited set of cases it can help.

## Future Plans

Expand Down
6 changes: 6 additions & 0 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ case $1 in
RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown --workspace --exclude rend3-imgui --exclude rend3-imgui-example
cargo deny --all-features check
;;
update-readme)
cd rend3
cargo install cargo-readme
cargo readme -t ../README.tpl -o ../README.md
;;
help | *)
set +x
echo "rend3 build script"
Expand All @@ -40,6 +45,7 @@ case $1 in
echo ""
echo "Subcommands:"
echo "help This message."
echo "update-readme Rebuilds the README.md file from the rend3 crate docs."
echo "web-bin [release] <BINARY> Builds BINARY as wasm, and runs wasm-bindgen on the result."
echo "serve Serve a web server from target/generated using simple-http-server."
esac
4 changes: 2 additions & 2 deletions examples/animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ path = "src/main.rs"
env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] }
# Linear algebra library
glam = "0.24"
# std::time::Instant that works on wasm
instant = "0.1"
# block on async functions
pollster = "0.3"
# Renderer core
Expand All @@ -33,6 +31,8 @@ rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" }
rend3-anim = { version = "^0.3.0", path = "../../rend3-anim" }
# Import gltf models
rend3-gltf = { version = "^0.3.0", path = "../../rend3-gltf" }
# std::time::Instant that works on wasm
web-time = "0.2"
# windowing
winit = "0.28"
image = { version = "0.24", default-features = false, features = ["jpeg"] }
Expand Down
8 changes: 4 additions & 4 deletions examples/animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct AnimatedObject {
loaded_instance: rend3_gltf::GltfSceneInstance,
animation_data: rend3_anim::AnimationData,
animation_time: f32,
last_frame_time: instant::Instant,
last_frame_time: web_time::Instant,
}

#[derive(Default)]
Expand Down Expand Up @@ -91,7 +91,7 @@ impl rend3_framework::App for AnimationExample {
loaded_scene,
loaded_instance,
animation_time: 0.0,
last_frame_time: instant::Instant::now(),
last_frame_time: web_time::Instant::now(),
};

let path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/cube_3.gltf"));
Expand All @@ -110,7 +110,7 @@ impl rend3_framework::App for AnimationExample {
loaded_scene,
loaded_instance,
animation_time: 0.0,
last_frame_time: instant::Instant::now(),
last_frame_time: web_time::Instant::now(),
};

self.animated_objects = vec![animated_object, animated_object2];
Expand All @@ -136,7 +136,7 @@ impl rend3_framework::App for AnimationExample {
control_flow(winit::event_loop::ControlFlow::Exit);
}
rend3_framework::Event::MainEventsCleared => {
let now = instant::Instant::now();
let now = web_time::Instant::now();

self.animated_objects.iter_mut().for_each(|animated_object| {
let delta = now.duration_since(animated_object.last_frame_time).as_secs_f32();
Expand Down
2 changes: 0 additions & 2 deletions examples/egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ env_logger = { version = "0.10", default-features = false, features = ["auto-col
glam = "0.24"
# Importing png's
image = { version = "0.24.3", default-features = false, features = ["png"] }
# Portable implementation of Instant.
instant = { version = "0.1", features = ["wasm-bindgen"] }
# Renderer core
rend3 = { version = "^0.3.0",path = "../../rend3" }
# Egui renderer integration
Expand Down
2 changes: 1 addition & 1 deletion examples/scene-viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ image = { version = "0.24", default-features = false, features = [
"tiff",
] }
indoc = "2"
instant = { version = "0.1", features = ["wasm-bindgen"] }
log = "0.4"
pico-args = "0.5"
pollster = "0.3"
Expand All @@ -62,6 +61,7 @@ rend3-routine = { version = "^0.3.0", path = "../../rend3-routine" }
rustc-hash = "1"
smallvec = "1"
tracy-client = { version = "0.16", optional = true }
web-time = "0.2"
wgpu = "0.18.0"
wgpu-profiler = "0.15.0"
winit = "0.28"
Expand Down
2 changes: 1 addition & 1 deletion examples/scene-viewer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{collections::HashMap, future::Future, hash::BuildHasher, path::Path, sync::Arc, time::Duration};

use glam::{DVec2, Mat3A, Mat4, UVec2, Vec3, Vec3A};
use instant::Instant;
use pico_args::Arguments;
use rend3::{
types::{
Expand All @@ -14,6 +13,7 @@ use rend3::{
use rend3_framework::{lock, AssetPath, Mutex};
use rend3_gltf::GltfSceneInstance;
use rend3_routine::{base::BaseRenderGraph, pbr::NormalTextureYDirection, skybox::SkyboxRoutine};
use web_time::Instant;
use wgpu_profiler::GpuTimerScopeResult;
use winit::{
event::{DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, WindowEvent},
Expand Down
5 changes: 4 additions & 1 deletion rend3-framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ pub trait App<T: 'static = ()> {
console_log::init().unwrap();

#[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))]
env_logger::init();
env_logger::builder()
.filter_module("rend3", log::LevelFilter::Info)
.parse_default_env()
.init();
}

fn register_panic_hook(&mut self) {
Expand Down
48 changes: 1 addition & 47 deletions rend3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,52 +54,6 @@
//! - `rend3-anim`: Skeletal animation playback utilities. Currently tied to rend3-gltf.
//! - `rend3-egui`: Integration with the [egui](https://github.com/emilk/egui)
//! immediate mode gui.
//! - `rend3-imgui`: Integration with the [imgui](https://github.com/ocornut/imgui)
//! immediate mode gui.
//!
//! # Features and Platform Support
//!
//! rend3 supports two different rendering profiles one for speed and one for
//! compatibility.
//!
//! ### Profile Features
//!
//! The modern profile not only offloads a lot more work to the gpu, it can do more
//! aggressive performance optimizations including only drawing exactly the triangles that are needed
//!
//! | Profile | Texture Access | Object Culling | Triangle Culling | Draw Calls |
//! |:----------|----------------|----------------|------------------|---------------------|
//! | GpuDriven | Bindless | On GPU | On GPU | Merged Indirect |
//! | CpuDriven | Bound | On CPU | ❌ | Instanced Direct |
//!
//! ### Profile Support
//!
//! The following table shows support of various profiles on various apis/platforms. This will
//! hopefully help you judge what your target demographic supports.
//!
//! | OS | API | GPU | GpuDriven | CpuDriven |
//! |----------------------|--------|--------------------------------------------|:---------:|:---------:|
//! | Windows 7+ | Vulkan | AMD / NVIDIA | ✅ | — |
//! | | Vulkan | Intel 6XXX+ | ❌ | ✅ |
//! | | Dx11 | Intel 2XXX+ | ❌ | 🚧 |
//! | Windows 10+ | Dx12 | Intel 6XXX+ / AMD GCN 2+ / NVIDIA 6XX+ | 🚧 | ✅ |
//! | MacOS 10.13+ iOS 11+ | Metal | Intel / Apple A13+ / M1+ | ✅ | — |
//! | | | Apple A9+ | ❌ | ✅ |
//! | Linux | Vulkan | Intel 6XXX+ / AMD GCN 2+ / NVIDIA 6XX+ | ✅ | — |
//! | | | Intel 4XXX+ | ❌ | ✅ |
//! | Android | Vulkan | All | ❌ | ✅ |
//!
//! Footnotes:
//! - ✅ Supported
//! - 🚧 In Progress
//! - ❌ Unsupported
//! - — Modern Profile Used
//! - Intel 6XXX = Skylake
//! - Intel 4XXX = Haswell
//! - Intel 2XXX = Sandy Bridge
//! - AMD GCN 2 = Rx 200+, RX 5000+
//! - Apple A9 = iPhone 6S, iPad 5th Gen
//! - Apple A13 = iPhone 11, iPad 9th Gen
//!
//! # Purpose
//!
Expand All @@ -113,7 +67,7 @@
//! advanced game or simulation nor care how you structure your program.
//! If you want a very basic framework to deal with windowing and event loop management,
//! `rend3-framework` can help you. This will always be optional and is just there to help
//! with the limited set of cases it canhelp
//! with the limited set of cases it can help.
//!
//! # Future Plans
//!
Expand Down
28 changes: 23 additions & 5 deletions rend3/src/util/error_scope.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Helpers for working with wgpu error scopes.
use std::{
future::Future,
pin::Pin,
Expand All @@ -6,33 +8,49 @@ use std::{

use wgpu::Device;

/// Helper for working with allocation failure error scopes.
///
/// Because WebGPU uses asynchronous allocation, we cannot handle allocation failures
/// on WebGPU. This will always return success on WebGPU.
#[must_use = "All error scopes must end in a call to `end`"]
pub struct AllocationErrorScope<'a> {
device: &'a Device,
/// Used to communicate with the destructor if `end` was called on this or not.
ended: bool,
}

impl<'a> AllocationErrorScope<'a> {
/// Create a new AllocationErrorScope on this device.
pub fn new(device: &'a Device) -> Self {
device.push_error_scope(wgpu::ErrorFilter::OutOfMemory);
Self { device }
Self { device, ended: false }
}

pub fn end(self) -> Result<(), wgpu::Error> {
pub fn end(mut self) -> Result<(), wgpu::Error> {
// End has been called, no need to error.
self.ended = true;

// The future we get from wgpu will always be immedately ready on webgl/native. We can't
// reasonably handle failures on webgpu. As such we don't want to wait
// for the future to complete, just manually poll it once.

let mut future = self.device.pop_error_scope();
let pin = Pin::new(&mut future);
match pin.poll(&mut Context::from_waker(&noop_waker::noop_waker())) {
// We got an error, so return an error.
Poll::Ready(Some(error)) => Err(error),
// We got no error, so return nothing.
// We got no error, so return success.
Poll::Ready(None) => Ok(()),
// We're on webgpu, pretend everythign always works.
// We're on webgpu, pretend everything always works.
Poll::Pending => Ok(()),
}
}
}

impl<'a> Drop for AllocationErrorScope<'a> {
fn drop(&mut self) {
log::error!("AllocationErrorScope dropped without calling `end`");
if !self.ended {
log::error!("AllocationErrorScope dropped without calling `end`");
}
}
}

0 comments on commit ccbcf3e

Please sign in to comment.