Skip to content

Commit e6a0164

Browse files
committed
Specialize UI pipeline on "hdr-ness" (#6459)
# Objective The UI pass in HDR breaks currently because the color attachment format does not match the HDR ViewTarget. ## Solution Specialize the UI pipeline on "hdr-ness" and select the appropriate format (like we do in the other built in pipelines).
1 parent fc56c68 commit e6a0164

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

crates/bevy_ui/src/render/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ pub fn queue_uinodes(
563563
mut image_bind_groups: ResMut<UiImageBindGroups>,
564564
gpu_images: Res<RenderAssets<Image>>,
565565
ui_batches: Query<(Entity, &UiBatch)>,
566-
mut views: Query<&mut RenderPhase<TransparentUi>>,
566+
mut views: Query<(&ExtractedView, &mut RenderPhase<TransparentUi>)>,
567567
events: Res<SpriteAssetEvents>,
568568
) {
569569
// If an image has changed, the GpuImage has (probably) changed
@@ -586,8 +586,12 @@ pub fn queue_uinodes(
586586
layout: &ui_pipeline.view_layout,
587587
}));
588588
let draw_ui_function = draw_functions.read().get_id::<DrawUi>().unwrap();
589-
let pipeline = pipelines.specialize(&mut pipeline_cache, &ui_pipeline, UiPipelineKey {});
590-
for mut transparent_phase in &mut views {
589+
for (view, mut transparent_phase) in &mut views {
590+
let pipeline = pipelines.specialize(
591+
&mut pipeline_cache,
592+
&ui_pipeline,
593+
UiPipelineKey { hdr: view.hdr },
594+
);
591595
for (entity, batch) in &ui_batches {
592596
image_bind_groups
593597
.values

crates/bevy_ui/src/render/pipeline.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use bevy_ecs::prelude::*;
22
use bevy_render::{
3-
render_resource::*, renderer::RenderDevice, texture::BevyDefault, view::ViewUniform,
3+
render_resource::*,
4+
renderer::RenderDevice,
5+
texture::BevyDefault,
6+
view::{ViewTarget, ViewUniform},
47
};
58

69
#[derive(Resource)]
@@ -57,12 +60,14 @@ impl FromWorld for UiPipeline {
5760
}
5861

5962
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
60-
pub struct UiPipelineKey {}
63+
pub struct UiPipelineKey {
64+
pub hdr: bool,
65+
}
6166

6267
impl SpecializedRenderPipeline for UiPipeline {
6368
type Key = UiPipelineKey;
64-
/// FIXME: there are no specialization for now, should this be removed?
65-
fn specialize(&self, _key: Self::Key) -> RenderPipelineDescriptor {
69+
70+
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
6671
let vertex_layout = VertexBufferLayout::from_vertex_formats(
6772
VertexStepMode::Vertex,
6873
vec![
@@ -88,7 +93,11 @@ impl SpecializedRenderPipeline for UiPipeline {
8893
shader_defs,
8994
entry_point: "fragment".into(),
9095
targets: vec![Some(ColorTargetState {
91-
format: TextureFormat::bevy_default(),
96+
format: if key.hdr {
97+
ViewTarget::TEXTURE_FORMAT_HDR
98+
} else {
99+
TextureFormat::bevy_default()
100+
},
92101
blend: Some(BlendState::ALPHA_BLENDING),
93102
write_mask: ColorWrites::ALL,
94103
})],

0 commit comments

Comments
 (0)