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.
This commit is contained in:
François Mockers 2024-06-26 05:08:23 +02:00 committed by GitHub
parent 8308ad08a2
commit 19d078c609
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 50 additions and 16 deletions

View file

@ -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"]

View file

@ -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

View file

@ -136,6 +136,14 @@ impl Plugin for Core3dPlugin {
.init_resource::<DrawFunctions<AlphaMask3dPrepass>>()
.init_resource::<DrawFunctions<Opaque3dDeferred>>()
.init_resource::<DrawFunctions<AlphaMask3dDeferred>>()
.init_resource::<ViewBinnedRenderPhases<Opaque3d>>()
.init_resource::<ViewBinnedRenderPhases<AlphaMask3d>>()
.init_resource::<ViewBinnedRenderPhases<Opaque3dPrepass>>()
.init_resource::<ViewBinnedRenderPhases<AlphaMask3dPrepass>>()
.init_resource::<ViewBinnedRenderPhases<Opaque3dDeferred>>()
.init_resource::<ViewBinnedRenderPhases<AlphaMask3dDeferred>>()
.init_resource::<ViewSortedRenderPhases<Transmissive3d>>()
.init_resource::<ViewSortedRenderPhases<Transparent3d>>()
.add_systems(ExtractSchedule, extract_core_3d_camera_phases)
.add_systems(ExtractSchedule, extract_camera_prepass_phase)
.add_systems(

View file

@ -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<Shader> = Handle::weak_from_u128(55594763423201);
@ -53,6 +53,7 @@ impl Plugin for SkyboxPlugin {
render_app
.init_resource::<SpecializedRenderPipelines<SkyboxPipeline>>()
.init_resource::<SpecializedRenderPipelines<SkyboxPrepassPipeline>>()
.init_resource::<PreviousViewUniforms>()
.add_systems(
Render,
(

View file

@ -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::<bevy_asset::Assets<Image>>()
.insert(SMAA_AREA_LUT_TEXTURE_HANDLE.id(), lut_placeholder());
#[cfg(not(feature = "smaa_luts"))]
app.world_mut()
.resource_mut::<bevy_asset::Assets<Image>>()
.insert(SMAA_SEARCH_LUT_TEXTURE_HANDLE.id(), lut_placeholder());
app.add_plugins(ExtractComponentPlugin::<SmaaSettings>::default())
.register_type::<SmaaSettings>();

View file

@ -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"]

View file

@ -102,8 +102,7 @@ where
)
.init_resource::<PrepassViewBindGroup>()
.init_resource::<SpecializedMeshPipelines<PrepassPipeline<M>>>()
.allow_ambiguous_resource::<SpecializedMeshPipelines<PrepassPipeline<M>>>()
.init_resource::<PreviousViewUniforms>();
.allow_ambiguous_resource::<SpecializedMeshPipelines<PrepassPipeline<M>>>();
}
fn finish(&self, app: &mut App) {

View file

@ -218,8 +218,6 @@ impl Plugin for MeshRenderPlugin {
);
};
let indirect_parameters_buffer = IndirectParametersBuffer::new();
let render_device = render_app.world().resource::<RenderDevice>();
if let Some(per_object_buffer_batch_size) =
GpuArrayBuffer::<MeshUniform>::batch_size(render_device)
@ -231,7 +229,6 @@ impl Plugin for MeshRenderPlugin {
}
render_app
.insert_resource(indirect_parameters_buffer)
.init_resource::<MeshPipelineViewLayouts>()
.init_resource::<MeshPipeline>();
}

View file

@ -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) {

View file

@ -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|