From 19d078c60953858d5cb7e006c5d90110712280a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Wed, 26 Jun 2024 05:08:23 +0200 Subject: [PATCH] don't crash without features `bevy_pbr`, `ktx2`, `zstd` (#14020) # Objective - Fixes #13728 ## Solution - add a new feature `smaa_luts`. if enables, it also enables `ktx2` and `zstd`. if not, it doesn't load the files but use placeholders instead - adds all the resources needed in the same places that system that uses them are added. --- Cargo.toml | 4 +++ crates/bevy_core_pipeline/Cargo.toml | 1 + crates/bevy_core_pipeline/src/core_3d/mod.rs | 8 +++++ crates/bevy_core_pipeline/src/skybox/mod.rs | 3 +- crates/bevy_core_pipeline/src/smaa/mod.rs | 30 +++++++++++++++---- crates/bevy_internal/Cargo.toml | 3 ++ crates/bevy_pbr/src/prepass/mod.rs | 3 +- crates/bevy_pbr/src/render/mesh.rs | 3 -- .../src/batching/gpu_preprocessing.rs | 10 ++++--- docs/cargo_features.md | 1 + 10 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8211f56657..64bc15ad0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,6 +77,7 @@ default = [ "bevy_gizmos", "android_shared_stdcxx", "tonemapping_luts", + "smaa_luts", "default_font", "webgl2", "sysinfo_plugin", @@ -286,6 +287,9 @@ detailed_trace = ["bevy_internal/detailed_trace"] # Include tonemapping Look Up Tables KTX2 files. If everything is pink, you need to enable this feature or change the `Tonemapping` method on your `Camera2dBundle` or `Camera3dBundle`. tonemapping_luts = ["bevy_internal/tonemapping_luts", "ktx2", "zstd"] +# Include SMAA Look Up Tables KTX2 Files +smaa_luts = ["bevy_internal/smaa_luts"] + # Enable AccessKit on Unix backends (currently only works with experimental screen readers and forks.) accesskit_unix = ["bevy_internal/accesskit_unix"] diff --git a/crates/bevy_core_pipeline/Cargo.toml b/crates/bevy_core_pipeline/Cargo.toml index 1b13d9b228..0c1a3ead54 100644 --- a/crates/bevy_core_pipeline/Cargo.toml +++ b/crates/bevy_core_pipeline/Cargo.toml @@ -18,6 +18,7 @@ trace = [] webgl = [] webgpu = [] tonemapping_luts = ["bevy_render/ktx2", "bevy_render/zstd"] +smaa_luts = ["bevy_render/ktx2", "bevy_render/zstd"] [dependencies] # bevy diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index a847607911..63696adcbf 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -136,6 +136,14 @@ impl Plugin for Core3dPlugin { .init_resource::>() .init_resource::>() .init_resource::>() + .init_resource::>() + .init_resource::>() + .init_resource::>() + .init_resource::>() + .init_resource::>() + .init_resource::>() + .init_resource::>() + .init_resource::>() .add_systems(ExtractSchedule, extract_core_3d_camera_phases) .add_systems(ExtractSchedule, extract_camera_prepass_phase) .add_systems( diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index 4ff5eccc51..ed700bddb4 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -24,7 +24,7 @@ use bevy_render::{ }; use prepass::{SkyboxPrepassPipeline, SKYBOX_PREPASS_SHADER_HANDLE}; -use crate::core_3d::CORE_3D_DEPTH_FORMAT; +use crate::{core_3d::CORE_3D_DEPTH_FORMAT, prepass::PreviousViewUniforms}; const SKYBOX_SHADER_HANDLE: Handle = Handle::weak_from_u128(55594763423201); @@ -53,6 +53,7 @@ impl Plugin for SkyboxPlugin { render_app .init_resource::>() .init_resource::>() + .init_resource::() .add_systems( Render, ( diff --git a/crates/bevy_core_pipeline/src/smaa/mod.rs b/crates/bevy_core_pipeline/src/smaa/mod.rs index 96721abdd9..1da7f36c18 100644 --- a/crates/bevy_core_pipeline/src/smaa/mod.rs +++ b/crates/bevy_core_pipeline/src/smaa/mod.rs @@ -31,7 +31,9 @@ //! [SMAA]: https://www.iryoku.com/smaa/ use bevy_app::{App, Plugin}; -use bevy_asset::{load_internal_asset, load_internal_binary_asset, Handle}; +#[cfg(feature = "smaa_luts")] +use bevy_asset::load_internal_binary_asset; +use bevy_asset::{load_internal_asset, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ component::Component, @@ -47,7 +49,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::{ camera::ExtractedCamera, extract_component::{ExtractComponent, ExtractComponentPlugin}, - render_asset::{RenderAssetUsages, RenderAssets}, + render_asset::RenderAssets, render_graph::{ NodeRunError, RenderGraphApp as _, RenderGraphContext, ViewNode, ViewNodeRunner, }, @@ -65,15 +67,19 @@ use bevy_render::{ VertexState, }, renderer::{RenderContext, RenderDevice, RenderQueue}, - texture::{ - BevyDefault, CachedTexture, CompressedImageFormats, GpuImage, Image, ImageFormat, - ImageSampler, ImageType, TextureCache, - }, + texture::{BevyDefault, CachedTexture, GpuImage, Image, TextureCache}, view::{ExtractedView, ViewTarget}, Render, RenderApp, RenderSet, }; +#[cfg(feature = "smaa_luts")] +use bevy_render::{ + render_asset::RenderAssetUsages, + texture::{CompressedImageFormats, ImageFormat, ImageSampler, ImageType}, +}; use bevy_utils::prelude::default; +#[cfg(not(feature = "smaa_luts"))] +use crate::tonemapping::lut_placeholder; use crate::{ core_2d::graph::{Core2d, Node2d}, core_3d::graph::{Core3d, Node3d}, @@ -287,6 +293,7 @@ impl Plugin for SmaaPlugin { // Load the two lookup textures. These are compressed textures in KTX2 // format. + #[cfg(feature = "smaa_luts")] load_internal_binary_asset!( app, SMAA_AREA_LUT_TEXTURE_HANDLE, @@ -304,6 +311,7 @@ impl Plugin for SmaaPlugin { .expect("Failed to load SMAA area LUT") ); + #[cfg(feature = "smaa_luts")] load_internal_binary_asset!( app, SMAA_SEARCH_LUT_TEXTURE_HANDLE, @@ -321,6 +329,16 @@ impl Plugin for SmaaPlugin { .expect("Failed to load SMAA search LUT") ); + #[cfg(not(feature = "smaa_luts"))] + app.world_mut() + .resource_mut::>() + .insert(SMAA_AREA_LUT_TEXTURE_HANDLE.id(), lut_placeholder()); + + #[cfg(not(feature = "smaa_luts"))] + app.world_mut() + .resource_mut::>() + .insert(SMAA_SEARCH_LUT_TEXTURE_HANDLE.id(), lut_placeholder()); + app.add_plugins(ExtractComponentPlugin::::default()) .register_type::(); diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 36f3597fbf..1dd13530f9 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -48,6 +48,9 @@ zstd = ["bevy_render/zstd"] # Include tonemapping LUT KTX2 files. tonemapping_luts = ["bevy_core_pipeline/tonemapping_luts"] +# Include SMAA LUT KTX2 Files +smaa_luts = ["bevy_core_pipeline/smaa_luts"] + # Audio format support (vorbis is enabled by default) flac = ["bevy_audio/flac"] mp3 = ["bevy_audio/mp3"] diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 9189830e74..1f728571bd 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -102,8 +102,7 @@ where ) .init_resource::() .init_resource::>>() - .allow_ambiguous_resource::>>() - .init_resource::(); + .allow_ambiguous_resource::>>(); } fn finish(&self, app: &mut App) { diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 299b719f7b..76ddbdb653 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -218,8 +218,6 @@ impl Plugin for MeshRenderPlugin { ); }; - let indirect_parameters_buffer = IndirectParametersBuffer::new(); - let render_device = render_app.world().resource::(); if let Some(per_object_buffer_batch_size) = GpuArrayBuffer::::batch_size(render_device) @@ -231,7 +229,6 @@ impl Plugin for MeshRenderPlugin { } render_app - .insert_resource(indirect_parameters_buffer) .init_resource::() .init_resource::(); } diff --git a/crates/bevy_render/src/batching/gpu_preprocessing.rs b/crates/bevy_render/src/batching/gpu_preprocessing.rs index dcb396a841..14e2c5e594 100644 --- a/crates/bevy_render/src/batching/gpu_preprocessing.rs +++ b/crates/bevy_render/src/batching/gpu_preprocessing.rs @@ -38,10 +38,12 @@ impl Plugin for BatchingPlugin { return; }; - render_app.add_systems( - Render, - write_indirect_parameters_buffer.in_set(RenderSet::PrepareResourcesFlush), - ); + render_app + .insert_resource(IndirectParametersBuffer::new()) + .add_systems( + Render, + write_indirect_parameters_buffer.in_set(RenderSet::PrepareResourcesFlush), + ); } fn finish(&self, app: &mut App) { diff --git a/docs/cargo_features.md b/docs/cargo_features.md index 8674294ec3..7778f0d18b 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -35,6 +35,7 @@ The default feature set enables most of the expected features of a game engine, |ktx2|KTX2 compressed texture support| |multi_threaded|Enables multithreaded parallelism in the engine. Disabling it forces all engine tasks to run on a single thread.| |png|PNG image format support| +|smaa_luts|Include SMAA Look Up Tables KTX2 Files| |sysinfo_plugin|Enables system information diagnostic plugin| |tonemapping_luts|Include tonemapping Look Up Tables KTX2 files. If everything is pink, you need to enable this feature or change the `Tonemapping` method on your `Camera2dBundle` or `Camera3dBundle`.| |vorbis|OGG/VORBIS audio format support|