From 1642b13696a037667e4a26c9f47f5b029a523c05 Mon Sep 17 00:00:00 2001 From: glasspangolin <23103433+glasspangolin@users.noreply.github.com> Date: Mon, 18 Nov 2024 18:04:14 +1100 Subject: [PATCH 1/2] - Updated bevy from 0.12 to 0.14.2 -- Type naming changes -- Some fairly large changes with separation of graphics world and game world. -- New colours. - WGPU became more fussy: -- Avoiding extreme float values NaN, Inf. -- had to change prim raster buffer packing arrangement 64 bytes to 32 bytes (Rgba32Float x 4 -> Rgba32Float x 1 + Rgba16Float x 2). -- Seems to be more strict about padding and format of textures. - Attempt to avoid type confusion between glam types and spir_v::glam, with conversion where necessary. - updated requirement to nightly-2024-04-24 for rust-gpu. -- Unfortunately, this results in a stubborn: error[E0658]: inline-const is experimental Which I found a work around to get a local version of bevy and add #![feature(inline_const)] to the crate root. --- .gitignore | 1 + Cargo.toml | 3 - bevy-strolle/Cargo.toml | 22 ++-- bevy-strolle/examples/_common.rs | 49 +++---- bevy-strolle/examples/cornell.rs | 5 +- bevy-strolle/examples/demo.rs | 62 +++++---- bevy-strolle/src/debug.rs | 3 +- bevy-strolle/src/graph.rs | 56 ++++---- bevy-strolle/src/lib.rs | 9 +- bevy-strolle/src/rendering_node.rs | 3 + bevy-strolle/src/stages.rs | 5 +- bevy-strolle/src/stages/extract.rs | 42 ++---- bevy-strolle/src/stages/prepare.rs | 79 +++++++----- bevy-strolle/src/state.rs | 1 - bevy-strolle/src/utils.rs | 12 +- rust-toolchain.toml | 4 +- strolle-gpu/Cargo.toml | 6 +- strolle-gpu/src/brdf.rs | 12 +- strolle-gpu/src/camera.rs | 7 +- strolle-gpu/src/gbuffer.rs | 107 +++++++--------- strolle-gpu/src/hit.rs | 4 +- strolle-gpu/src/light.rs | 49 ++++--- strolle-gpu/src/noise/white.rs | 6 +- strolle-gpu/src/ray.rs | 24 +++- strolle-gpu/src/reservoir/di.rs | 73 ++++++----- strolle-gpu/src/surface.rs | 17 ++- strolle-gpu/src/triangle.rs | 2 +- strolle-gpu/src/utils.rs | 25 +++- strolle-gpu/src/utils/f32_ext.rs | 2 +- strolle-shader-builder/Cargo.toml | 2 +- strolle-shaders/Cargo.toml | 2 +- strolle-shaders/src/di_resolving.rs | 21 ++- strolle-shaders/src/di_sampling.rs | 4 +- strolle-shaders/src/di_spatial_resampling.rs | 8 +- strolle-shaders/src/di_temporal_resampling.rs | 8 +- strolle-shaders/src/frame_composition.rs | 2 +- strolle-shaders/src/frame_denoising.rs | 12 +- strolle-shaders/src/frame_reprojection.rs | 10 +- strolle-shaders/src/gi_preview_resampling.rs | 11 +- strolle-shaders/src/gi_reprojection.rs | 2 +- strolle-shaders/src/gi_resolving.rs | 2 +- strolle-shaders/src/gi_sampling_a.rs | 2 +- strolle-shaders/src/gi_sampling_b.rs | 4 +- strolle-shaders/src/gi_spatial_resampling.rs | 2 +- strolle-shaders/src/gi_temporal_resampling.rs | 4 +- strolle-shaders/src/prim_raster.rs | 7 - strolle/Cargo.toml | 6 +- strolle/src/bvh/builder.rs | 11 +- strolle/src/bvh/serializer.rs | 4 +- strolle/src/camera.rs | 15 ++- strolle/src/camera_controller/buffers.rs | 64 ++++------ strolle/src/camera_controller/pass.rs | 4 +- .../camera_controller/passes/bvh_heatmap.rs | 3 +- .../camera_controller/passes/di_resolving.rs | 3 +- .../camera_controller/passes/di_sampling.rs | 3 +- .../passes/di_spatial_resampling.rs | 7 +- .../passes/di_temporal_resampling.rs | 3 +- .../passes/frame_composition.rs | 6 +- .../passes/frame_denoising.rs | 17 +-- .../passes/frame_reprojection.rs | 7 +- .../passes/gi_preview_resampling.rs | 5 +- .../passes/gi_reprojection.rs | 3 +- .../camera_controller/passes/gi_resolving.rs | 3 +- .../camera_controller/passes/gi_sampling.rs | 5 +- .../passes/gi_spatial_resampling.rs | 7 +- .../passes/gi_temporal_resampling.rs | 3 +- .../camera_controller/passes/prim_raster.rs | 36 ++---- .../camera_controller/passes/ref_shading.rs | 3 +- .../camera_controller/passes/ref_tracing.rs | 3 +- strolle/src/images.rs | 120 +++++++++++++++--- strolle/src/lib.rs | 4 +- strolle/src/light.rs | 9 +- strolle/src/material.rs | 9 +- strolle/src/mesh_triangle.rs | 21 +-- strolle/src/triangle.rs | 22 ++-- strolle/src/utils.rs | 4 + strolle/src/utils/bounding_box.rs | 2 +- strolle/src/utils/interface.rs | 58 +++++++++ 78 files changed, 745 insertions(+), 518 deletions(-) create mode 100644 strolle/src/utils/interface.rs diff --git a/.gitignore b/.gitignore index b555a1d6..f6433629 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target /bevy-strolle/assets/demo /bevy-strolle/examples/bench-* /bevy-strolle/examples/scene* +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index bc2d7549..5943300c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,3 @@ members = [ "strolle-shaders", ] -[patch."crates-io"] -# TODO https://github.com/gfx-rs/naga/issues/2373 -naga = { git = "https://github.com/Patryk27/naga", branch = "v0.13.0-strolle" } diff --git a/bevy-strolle/Cargo.toml b/bevy-strolle/Cargo.toml index 683388d2..5805823a 100644 --- a/bevy-strolle/Cargo.toml +++ b/bevy-strolle/Cargo.toml @@ -4,16 +4,20 @@ version = "0.1.0" edition = "2021" [dependencies] -bevy = "0.12.1" # TODO use default-features = false -bevy_egui = "0.24" +bevy = { version = "0.14.2", default-features = false, features = ["default"] } +bevy_egui = { version = "0.29.0" } +spirv-std = { git = "https://github.com/glasspangolin/rust-gpu.git" } log = "0.4.18" strolle = { path = "../strolle", features = ["metrics"] } -wgpu = "0.17.2" +wgpu = "0.20.1" [dev-dependencies] -bevy = { version = "0.12.1", features = ["jpeg"] } -bevy_mod_raycast = "0.16.0" -bevy_rapier3d = "0.23.0" -lazy_static = "1.4.0" -smooth-bevy-cameras = "0.10.0" -zip = { version = "0.6.6", default-features = false, features = ["deflate"] } +bevy = { version = "0.14.2", default-features = false, features = ["default", "jpeg"] } +bevy_mod_raycast = { version = "0.18.0" } +smooth-bevy-cameras = { version = "0.12.0"} +lazy_static = "1.5.0" +zip = { version = "2.2.0", default-features = false, features = ["deflate"] } + +[patch.crates-io] +bevy = { version = "0.14.2" } +bevy_render = {version = "0.14.2"} \ No newline at end of file diff --git a/bevy-strolle/examples/_common.rs b/bevy-strolle/examples/_common.rs index 6e0a9f82..f49b4d17 100644 --- a/bevy-strolle/examples/_common.rs +++ b/bevy-strolle/examples/_common.rs @@ -7,13 +7,14 @@ use std::env; use std::fs::File; use std::io::BufReader; use std::path::Path; - +use bevy::core_pipeline::core_3d::graph::Core3d; use bevy::prelude::*; use bevy::render::camera::CameraRenderGraph; use bevy::window::{CursorGrabMode, PrimaryWindow}; use bevy_strolle::prelude::*; use smooth_bevy_cameras::controllers::fps::FpsCameraController; use zip::ZipArchive; +use bevy_strolle::graph::StrolleGraph; pub fn extract_assets() { extract_asset("cornell"); @@ -48,7 +49,7 @@ fn extract_asset(name: &str) { // ----------------------------------------------------------------------------- pub fn handle_camera( - keys: Res>, + keys: Res>, mut window: Query<&mut Window, With>, mut camera: Query<( &Transform, @@ -64,8 +65,8 @@ pub fn handle_camera( mut fps_camera_controller, ) = camera.single_mut(); - if keys.just_pressed(KeyCode::Key1) { - camera_render_graph.set(bevy_strolle::graph::NAME); + if keys.just_pressed(KeyCode::Digit1) { + camera_render_graph.set(StrolleGraph); camera.mode = match camera.mode { st::CameraMode::Image { denoise } => { @@ -75,8 +76,8 @@ pub fn handle_camera( }; } - if keys.just_pressed(KeyCode::Key2) { - camera_render_graph.set(bevy_strolle::graph::NAME); + if keys.just_pressed(KeyCode::Digit2) { + camera_render_graph.set(StrolleGraph); camera.mode = match camera.mode { st::CameraMode::DiDiffuse { denoise } => { @@ -86,8 +87,8 @@ pub fn handle_camera( }; } - if keys.just_pressed(KeyCode::Key3) { - camera_render_graph.set(bevy_strolle::graph::NAME); + if keys.just_pressed(KeyCode::Digit3) { + camera_render_graph.set(StrolleGraph); camera.mode = match camera.mode { st::CameraMode::DiSpecular { denoise } => { @@ -97,8 +98,8 @@ pub fn handle_camera( }; } - if keys.just_pressed(KeyCode::Key4) { - camera_render_graph.set(bevy_strolle::graph::NAME); + if keys.just_pressed(KeyCode::Digit4) { + camera_render_graph.set(StrolleGraph); camera.mode = match camera.mode { st::CameraMode::GiDiffuse { denoise } => { @@ -108,8 +109,8 @@ pub fn handle_camera( }; } - if keys.just_pressed(KeyCode::Key5) { - camera_render_graph.set(bevy_strolle::graph::NAME); + if keys.just_pressed(KeyCode::Digit5) { + camera_render_graph.set(StrolleGraph); camera.mode = match camera.mode { st::CameraMode::GiSpecular { denoise } => { @@ -119,20 +120,20 @@ pub fn handle_camera( }; } - if keys.just_pressed(KeyCode::Key8) { - camera_render_graph.set(bevy_strolle::graph::NAME); + if keys.just_pressed(KeyCode::Digit8) { + camera_render_graph.set(StrolleGraph); camera.mode = st::CameraMode::BvhHeatmap; } - if keys.just_pressed(KeyCode::Key9) { - camera_render_graph.set(bevy_strolle::graph::NAME); + if keys.just_pressed(KeyCode::Digit9) { + camera_render_graph.set(StrolleGraph); camera.mode = st::CameraMode::Reference { depth: 1 }; } - if keys.just_pressed(KeyCode::Key0) { - camera_render_graph.set("core_3d"); + if keys.just_pressed(KeyCode::Digit0) { + camera_render_graph.set(Core3d); } if keys.just_pressed(KeyCode::Semicolon) { @@ -149,7 +150,7 @@ pub fn handle_camera( }; } - if keys.just_pressed(KeyCode::X) { + if keys.just_pressed(KeyCode::KeyX) { println!("{:?}", camera_xform.translation); } } @@ -173,20 +174,20 @@ impl Default for Sun { } } -pub fn handle_sun(keys: Res>, mut sun: ResMut) { - if keys.just_pressed(KeyCode::H) { +pub fn handle_sun(keys: Res>, mut sun: ResMut) { + if keys.just_pressed(KeyCode::KeyH) { sun.azimuth -= 0.05; } - if keys.just_pressed(KeyCode::J) { + if keys.just_pressed(KeyCode::KeyJ) { sun.altitude -= 0.05; } - if keys.just_pressed(KeyCode::K) { + if keys.just_pressed(KeyCode::KeyK) { sun.altitude += 0.05; } - if keys.just_pressed(KeyCode::L) { + if keys.just_pressed(KeyCode::KeyL) { sun.azimuth += 0.05; } } diff --git a/bevy-strolle/examples/cornell.rs b/bevy-strolle/examples/cornell.rs index 637665d4..bf2dfb3e 100644 --- a/bevy-strolle/examples/cornell.rs +++ b/bevy-strolle/examples/cornell.rs @@ -6,6 +6,7 @@ use bevy::math::vec3; use bevy::prelude::*; use bevy::render::camera::CameraRenderGraph; use bevy::window::WindowResolution; +use bevy_strolle::graph::StrolleGraph; use bevy_strolle::prelude::*; use smooth_bevy_cameras::controllers::orbit::{ OrbitCameraBundle, OrbitCameraController, OrbitCameraPlugin, @@ -56,14 +57,14 @@ fn setup(mut commands: Commands, assets: Res) { commands .spawn(Camera3dBundle { camera_render_graph: CameraRenderGraph::new( - bevy_strolle::graph::NAME, + StrolleGraph, ), camera: Camera { hdr: true, ..default() }, ..default() - }) + }).insert(StrolleCamera::default()) .insert(OrbitCameraBundle::new( { OrbitCameraController { diff --git a/bevy-strolle/examples/demo.rs b/bevy-strolle/examples/demo.rs index 5e71fa01..47d31c38 100644 --- a/bevy-strolle/examples/demo.rs +++ b/bevy-strolle/examples/demo.rs @@ -2,12 +2,14 @@ mod common; use std::f32::consts::PI; - -use bevy::core_pipeline::clear_color::ClearColorConfig; +use bevy::asset::AssetContainer; use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}; use bevy::math::{uvec2, vec3}; use bevy::prelude::*; use bevy::render::camera::{CameraRenderGraph, RenderTarget}; +use bevy::render::renderer::RenderDevice; +use bevy::render::RenderPlugin; +use bevy::render::settings::{RenderCreation, WgpuSettings}; use bevy::render::texture::ImageSampler; use bevy::window::{CursorGrabMode, PrimaryWindow, WindowResolution}; use bevy_strolle::prelude::*; @@ -15,10 +17,8 @@ use smooth_bevy_cameras::controllers::fps::{ FpsCameraBundle, FpsCameraController, FpsCameraPlugin, }; use smooth_bevy_cameras::LookTransformPlugin; -use wgpu::{ - Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, -}; - +use wgpu::{Extent3d, Limits, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages}; +use bevy_strolle::graph::StrolleGraph; use self::common::Sun; const VIEWPORT_SIZE: UVec2 = uvec2(640, 480); @@ -48,6 +48,7 @@ fn main() { .add_systems(Startup, setup_window) .add_systems(Startup, setup_camera) .add_systems(Startup, setup_scene) + .add_systems(Startup, check_gpu_limits) .add_systems(Update, adjust_materials) .add_systems(Update, handle_materials) .add_systems(Update, common::handle_camera) @@ -60,6 +61,21 @@ fn main() { .run(); } +fn check_gpu_limits(render_device: Res) { + let limits = render_device.limits(); + info!("GPU Limits:"); + info!(" max_color_attachment_bytes_per_sample: {}", + limits.max_color_attachment_bytes_per_sample); + info!(" max_texture_dimension_2d: {}", + limits.max_texture_dimension_2d); + info!(" max_storage_buffer_binding_size: {}", + limits.max_storage_buffer_binding_size); + info!(" max_bind_groups: {}", + limits.max_bind_groups); + info!(" max_bindings_per_bind_group: {}", + limits.max_bindings_per_bind_group); +} + fn setup_window(mut window: Query<&mut Window, With>) { let mut window = window.single_mut(); @@ -118,16 +134,13 @@ fn setup_camera( order: 1, ..default() }, - camera_2d: Camera2d { - clear_color: ClearColorConfig::None, - }, + camera_2d: Camera2d {}, ..default() }); - commands - .spawn(Camera3dBundle { + commands.spawn(Camera3dBundle { camera_render_graph: CameraRenderGraph::new( - bevy_strolle::graph::NAME, + StrolleGraph, ), camera: Camera { order: 0, @@ -136,8 +149,7 @@ fn setup_camera( ..default() }, ..default() - }) - .insert(StrolleCamera::default()) + }).insert(StrolleCamera::default()) .insert(FpsCameraBundle::new( { FpsCameraController { @@ -181,7 +193,7 @@ fn setup_scene( color: Color::WHITE, range: 35.0, radius: 0.15, - intensity: 5000.0, + intensity: 1000.0, shadows_enabled: true, ..default() }, @@ -203,10 +215,10 @@ fn setup_scene( commands .spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Torus::default())), + mesh: meshes.add(Mesh::from(Torus::default())), material: materials.add(StandardMaterial { base_color: color, - emissive: color * 10.0, + emissive: color.to_linear(), ..default() }), transform: Transform::from_translation(torus) @@ -214,7 +226,7 @@ fn setup_scene( .with_scale(Vec3::splat(0.5)), ..default() }) - .insert(Torus); + .insert(StrTorus); } // --- @@ -261,16 +273,16 @@ fn adjust_materials( } fn handle_materials( - keys: Res>, + keys: Res>, mut materials: ResMut>, ) { - if keys.just_pressed(KeyCode::T) { + if keys.just_pressed(KeyCode::KeyT) { for (_, material) in materials.iter_mut() { material.base_color_texture = None; } } - if keys.just_pressed(KeyCode::M) { + if keys.just_pressed(KeyCode::KeyM) { for (_, material) in materials.iter_mut() { if material.metallic == 0.0 { material.metallic = 1.0; @@ -291,13 +303,13 @@ struct Flashlight { } fn handle_flashlight( - keys: Res>, + keys: Res>, mut flashlight: Query<(&mut Flashlight, &mut SpotLight)>, mut lights: Query<&mut PointLight>, ) { let (mut flashlight, mut flashlight_spot) = flashlight.single_mut(); - if keys.just_pressed(KeyCode::F) { + if keys.just_pressed(KeyCode::KeyF) { flashlight.enabled = !flashlight.enabled; if flashlight.enabled { @@ -330,11 +342,11 @@ fn animate_flashlight( // ----------------------------------------------------------------------------- #[derive(Component)] -struct Torus; +struct StrTorus; fn animate_toruses( time: Res