Skip to content

Commit 082c44e

Browse files
atlv24salixsalicaceaemate-hbeicauseIceSentry
authored
Remove ExtractedView::hdr, add ExtractedView::texture_format, move compositing_space to ExtractedCamera (#23734)
# Objective - Clean up our texture format handling. - Fix #23732 - Get us closer to #22563 - It makes no sense for views to talk about being hdr or not. They have a texture format, that's it. What does HDR shadows even mean lol - Same for compositing_space ## Solution - Remove ExtractedView::hdr - Add ExtractedView::texture_format - Move ExtractedView::compositing_space to ExtractedCamera::compositing_space - Add texture_format to a bunch of specialization keys instead of hdr bool - Convert VolumetricFogPipelineKey to not use flags and just use bool and texture format - Remove BevyDefault TextureFormat - Remove ViewTarget TEXTURE_FORMAT_HDR ## Testing - Pretty extensively test at this point This has a migration guide. --------- Co-authored-by: Willow Black <wmcblack@gmail.com> Co-authored-by: Máté Homolya <mate.homolya@gmail.com> Co-authored-by: Luo Zhihao <luo_zhihao@outlook.com> Co-authored-by: IceSentry <IceSentry@users.noreply.github.com>
1 parent c040d76 commit 082c44e

56 files changed

Lines changed: 644 additions & 540 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "Camera TextureFormat rework"
3+
pull_requests: [23734]
4+
---
5+
6+
`ExtractedView::hdr` has been moved to `ExtractedCamera::hdr`. Views do not have a notion
7+
of HDR, that is a camera-specific property.
8+
`TextureFormat::bevy_default()` and `ViewTargets::TEXTURE_FORMAT_HDR` are deprecated,
9+
please source your texture format from `ExtractedView::target_format` instead, and
10+
plumb it through your specialization keys.
11+
Similarly, `ViewTarget::is_hdr` was removed. Use `ExtractedCamera::hdr` to check this, as it is a property of a camera not a view target.

crates/bevy_anti_alias/src/contrast_adaptive_sharpening/mod.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use bevy_core_pipeline::{
77
FullscreenShader,
88
};
99
use bevy_ecs::{prelude::*, query::QueryItem};
10-
use bevy_image::BevyDefault as _;
1110
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1211
use bevy_render::{
1312
extract_component::{ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin},
@@ -17,7 +16,7 @@ use bevy_render::{
1716
},
1817
renderer::RenderDevice,
1918
sync_component::SyncComponent,
20-
view::{ExtractedView, ViewTarget},
19+
view::ExtractedView,
2120
Render, RenderApp, RenderStartup, RenderSystems,
2221
};
2322

@@ -179,7 +178,7 @@ pub fn init_cas_pipeline(
179178

180179
#[derive(PartialEq, Eq, Hash, Clone, Copy, SpecializerKey)]
181180
pub struct CasPipelineKey {
182-
texture_format: TextureFormat,
181+
target_format: TextureFormat,
183182
denoise: bool,
184183
}
185184

@@ -202,7 +201,7 @@ impl Specializer<RenderPipeline> for CasPipelineSpecializer {
202201
fragment.set_target(
203202
0,
204203
ColorTargetState {
205-
format: key.texture_format,
204+
format: key.target_format,
206205
blend: None,
207206
write_mask: ColorWrites::ALL,
208207
},
@@ -216,7 +215,7 @@ fn prepare_cas_pipelines(
216215
mut commands: Commands,
217216
pipeline_cache: Res<PipelineCache>,
218217
mut sharpening_pipeline: ResMut<CasPipeline>,
219-
views: Query<
218+
cameras: Query<
220219
(Entity, &ExtractedView, &DenoiseCas),
221220
Or<(Added<CasUniform>, Changed<DenoiseCas>)>,
222221
>,
@@ -226,16 +225,12 @@ fn prepare_cas_pipelines(
226225
commands.entity(entity).remove::<ViewCasPipeline>();
227226
}
228227

229-
for (entity, view, denoise_cas) in &views {
228+
for (entity, view, denoise_cas) in &cameras {
230229
let pipeline_id = sharpening_pipeline.variants.specialize(
231230
&pipeline_cache,
232231
CasPipelineKey {
233232
denoise: denoise_cas.0,
234-
texture_format: if view.hdr {
235-
ViewTarget::TEXTURE_FORMAT_HDR
236-
} else {
237-
TextureFormat::bevy_default()
238-
},
233+
target_format: view.target_format,
239234
},
240235
)?;
241236

crates/bevy_anti_alias/src/fxaa/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ use bevy_core_pipeline::{
77
FullscreenShader,
88
};
99
use bevy_ecs::prelude::*;
10-
use bevy_image::BevyDefault as _;
1110
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1211
use bevy_render::{
12+
camera::ExtractedCamera,
1313
extract_component::{ExtractComponent, ExtractComponentPlugin},
1414
render_resource::{
1515
binding_types::{sampler, texture_2d},
1616
*,
1717
},
1818
renderer::RenderDevice,
19-
view::{ExtractedView, ViewTarget},
19+
view::ExtractedView,
2020
GpuResourceAppExt, Render, RenderApp, RenderStartup, RenderSystems,
2121
};
2222
use bevy_shader::Shader;
@@ -159,7 +159,7 @@ pub struct CameraFxaaPipeline {
159159
pub struct FxaaPipelineKey {
160160
edge_threshold: Sensitivity,
161161
edge_threshold_min: Sensitivity,
162-
texture_format: TextureFormat,
162+
target_format: TextureFormat,
163163
}
164164

165165
impl SpecializedRenderPipeline for FxaaPipeline {
@@ -177,7 +177,7 @@ impl SpecializedRenderPipeline for FxaaPipeline {
177177
format!("EDGE_THRESH_MIN_{}", key.edge_threshold_min.get_str()).into(),
178178
],
179179
targets: vec![Some(ColorTargetState {
180-
format: key.texture_format,
180+
format: key.target_format,
181181
blend: None,
182182
write_mask: ColorWrites::ALL,
183183
})],
@@ -193,9 +193,9 @@ pub fn prepare_fxaa_pipelines(
193193
pipeline_cache: Res<PipelineCache>,
194194
mut pipelines: ResMut<SpecializedRenderPipelines<FxaaPipeline>>,
195195
fxaa_pipeline: Res<FxaaPipeline>,
196-
views: Query<(Entity, &ExtractedView, &Fxaa)>,
196+
cameras: Query<(Entity, &ExtractedView, &Fxaa), With<ExtractedCamera>>,
197197
) {
198-
for (entity, view, fxaa) in &views {
198+
for (entity, view, fxaa) in &cameras {
199199
if !fxaa.enabled {
200200
continue;
201201
}
@@ -205,11 +205,7 @@ pub fn prepare_fxaa_pipelines(
205205
FxaaPipelineKey {
206206
edge_threshold: fxaa.edge_threshold,
207207
edge_threshold_min: fxaa.edge_threshold_min,
208-
texture_format: if view.hdr {
209-
ViewTarget::TEXTURE_FORMAT_HDR
210-
} else {
211-
TextureFormat::bevy_default()
212-
},
208+
target_format: view.target_format,
213209
},
214210
);
215211

crates/bevy_anti_alias/src/smaa/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use bevy_ecs::{
4747
schedule::IntoScheduleConfigs as _,
4848
system::{Commands, Query, Res, ResMut},
4949
};
50-
use bevy_image::{BevyDefault, Image, ToExtents};
50+
use bevy_image::{Image, ToExtents};
5151
use bevy_math::{vec4, Vec4};
5252
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
5353
use bevy_render::{
@@ -177,7 +177,7 @@ struct SmaaNeighborhoodBlendingPipeline {
177177
#[derive(Clone, PartialEq, Eq, Hash)]
178178
pub struct SmaaNeighborhoodBlendingPipelineKey {
179179
/// The format of the framebuffer.
180-
texture_format: TextureFormat,
180+
target_format: TextureFormat,
181181
/// The quality preset.
182182
preset: SmaaPreset,
183183
}
@@ -566,7 +566,7 @@ impl SpecializedRenderPipeline for SmaaNeighborhoodBlendingPipeline {
566566
shader_defs,
567567
entry_point: Some("neighborhood_blending_fragment_main".into()),
568568
targets: vec![Some(ColorTargetState {
569-
format: key.texture_format,
569+
format: key.target_format,
570570
blend: None,
571571
write_mask: ColorWrites::ALL,
572572
})],
@@ -583,9 +583,9 @@ fn prepare_smaa_pipelines(
583583
pipeline_cache: Res<PipelineCache>,
584584
mut specialized_render_pipelines: ResMut<SmaaSpecializedRenderPipelines>,
585585
smaa_pipelines: Res<SmaaPipelines>,
586-
view_targets: Query<(Entity, &ExtractedView, &Smaa)>,
586+
cameras: Query<(Entity, &ExtractedView, &Smaa), With<ExtractedCamera>>,
587587
) {
588-
for (entity, view, smaa) in &view_targets {
588+
for (entity, view, smaa) in &cameras {
589589
let edge_detection_pipeline_id = specialized_render_pipelines.edge_detection.specialize(
590590
&pipeline_cache,
591591
&smaa_pipelines.edge_detection,
@@ -606,11 +606,7 @@ fn prepare_smaa_pipelines(
606606
&pipeline_cache,
607607
&smaa_pipelines.neighborhood_blending,
608608
SmaaNeighborhoodBlendingPipelineKey {
609-
texture_format: if view.hdr {
610-
ViewTarget::TEXTURE_FORMAT_HDR
611-
} else {
612-
TextureFormat::bevy_default()
613-
},
609+
target_format: view.target_format,
614610
preset: smaa.preset,
615611
},
616612
);

crates/bevy_anti_alias/src/taa/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bevy_ecs::{
1515
schedule::IntoScheduleConfigs,
1616
system::{Commands, Query, Res, ResMut},
1717
};
18-
use bevy_image::{BevyDefault as _, ToExtents};
18+
use bevy_image::ToExtents;
1919
use bevy_math::vec2;
2020
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
2121
use bevy_render::{
@@ -292,7 +292,8 @@ struct TaaPipelineSpecializer;
292292

293293
#[derive(PartialEq, Eq, Hash, Clone, SpecializerKey)]
294294
struct TaaPipelineKey {
295-
hdr: bool,
295+
target_format: TextureFormat,
296+
tonemap: bool,
296297
reset: bool,
297298
}
298299

@@ -305,19 +306,16 @@ impl Specializer<RenderPipeline> for TaaPipelineSpecializer {
305306
descriptor: &mut RenderPipelineDescriptor,
306307
) -> Result<Canonical<Self::Key>, BevyError> {
307308
let fragment = descriptor.fragment_mut()?;
308-
let format = if key.hdr {
309+
if key.tonemap {
309310
fragment.shader_defs.push("TONEMAP".into());
310-
ViewTarget::TEXTURE_FORMAT_HDR
311-
} else {
312-
TextureFormat::bevy_default()
313-
};
311+
}
314312

315313
if key.reset {
316314
fragment.shader_defs.push("RESET".into());
317315
}
318316

319317
let color_target_state = ColorTargetState {
320-
format,
318+
format: key.target_format,
321319
blend: None,
322320
write_mask: ColorWrites::ALL,
323321
};
@@ -395,21 +393,17 @@ fn prepare_taa_history_textures(
395393
mut texture_cache: ResMut<TextureCache>,
396394
render_device: Res<RenderDevice>,
397395
frame_count: Res<FrameCount>,
398-
views: Query<(Entity, &ExtractedCamera, &ExtractedView), With<TemporalAntiAliasing>>,
396+
cameras: Query<(Entity, &ExtractedView, &ExtractedCamera), With<TemporalAntiAliasing>>,
399397
) {
400-
for (entity, camera, view) in &views {
398+
for (entity, view, camera) in &cameras {
401399
if let Some(physical_target_size) = camera.physical_target_size {
402400
let mut texture_descriptor = TextureDescriptor {
403401
label: None,
404402
size: physical_target_size.to_extents(),
405403
mip_level_count: 1,
406404
sample_count: 1,
407405
dimension: TextureDimension::D2,
408-
format: if view.hdr {
409-
ViewTarget::TEXTURE_FORMAT_HDR
410-
} else {
411-
TextureFormat::bevy_default()
412-
},
406+
format: view.target_format,
413407
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::RENDER_ATTACHMENT,
414408
view_formats: &[],
415409
};
@@ -444,11 +438,17 @@ fn prepare_taa_pipelines(
444438
mut commands: Commands,
445439
pipeline_cache: Res<PipelineCache>,
446440
mut pipeline: ResMut<TaaPipeline>,
447-
views: Query<(Entity, &ExtractedView, &TemporalAntiAliasing)>,
441+
cameras: Query<(
442+
Entity,
443+
&ExtractedCamera,
444+
&ExtractedView,
445+
&TemporalAntiAliasing,
446+
)>,
448447
) -> Result<(), BevyError> {
449-
for (entity, view, taa_settings) in &views {
448+
for (entity, camera, view, taa_settings) in &cameras {
450449
let mut pipeline_key = TaaPipelineKey {
451-
hdr: view.hdr,
450+
target_format: view.target_format,
451+
tonemap: camera.hdr,
452452
reset: taa_settings.reset,
453453
};
454454
let pipeline_id = pipeline

crates/bevy_core_pipeline/src/blit/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl BlitPipeline {
8484

8585
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
8686
pub struct BlitPipelineKey {
87-
pub texture_format: TextureFormat,
87+
pub target_format: TextureFormat,
8888
pub blend_state: Option<BlendState>,
8989
pub samples: u32,
9090
/// Color space of the source texture. When `Some(Srgb)` or `Some(Oklab)`, the blit converts
@@ -111,7 +111,7 @@ impl SpecializedRenderPipeline for BlitPipeline {
111111
shader: self.fragment_shader.clone(),
112112
shader_defs,
113113
targets: vec![Some(ColorTargetState {
114-
format: key.texture_format,
114+
format: key.target_format,
115115
blend: key.blend_state,
116116
write_mask: ColorWrites::ALL,
117117
})],

0 commit comments

Comments
 (0)