Skip to content

Commit

Permalink
Specialize UI pipeline on "hdr-ness" (#6459)
Browse files Browse the repository at this point in the history
# 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).
  • Loading branch information
cart committed Nov 3, 2022
1 parent fc56c68 commit e6a0164
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 7 additions & 3 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub fn queue_uinodes(
mut image_bind_groups: ResMut<UiImageBindGroups>,
gpu_images: Res<RenderAssets<Image>>,
ui_batches: Query<(Entity, &UiBatch)>,
mut views: Query<&mut RenderPhase<TransparentUi>>,
mut views: Query<(&ExtractedView, &mut RenderPhase<TransparentUi>)>,
events: Res<SpriteAssetEvents>,
) {
// If an image has changed, the GpuImage has (probably) changed
Expand All @@ -586,8 +586,12 @@ pub fn queue_uinodes(
layout: &ui_pipeline.view_layout,
}));
let draw_ui_function = draw_functions.read().get_id::<DrawUi>().unwrap();
let pipeline = pipelines.specialize(&mut pipeline_cache, &ui_pipeline, UiPipelineKey {});
for mut transparent_phase in &mut views {
for (view, mut transparent_phase) in &mut views {
let pipeline = pipelines.specialize(
&mut pipeline_cache,
&ui_pipeline,
UiPipelineKey { hdr: view.hdr },
);
for (entity, batch) in &ui_batches {
image_bind_groups
.values
Expand Down
19 changes: 14 additions & 5 deletions crates/bevy_ui/src/render/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use bevy_ecs::prelude::*;
use bevy_render::{
render_resource::*, renderer::RenderDevice, texture::BevyDefault, view::ViewUniform,
render_resource::*,
renderer::RenderDevice,
texture::BevyDefault,
view::{ViewTarget, ViewUniform},
};

#[derive(Resource)]
Expand Down Expand Up @@ -57,12 +60,14 @@ impl FromWorld for UiPipeline {
}

#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct UiPipelineKey {}
pub struct UiPipelineKey {
pub hdr: bool,
}

impl SpecializedRenderPipeline for UiPipeline {
type Key = UiPipelineKey;
/// FIXME: there are no specialization for now, should this be removed?
fn specialize(&self, _key: Self::Key) -> RenderPipelineDescriptor {

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
let vertex_layout = VertexBufferLayout::from_vertex_formats(
VertexStepMode::Vertex,
vec![
Expand All @@ -88,7 +93,11 @@ impl SpecializedRenderPipeline for UiPipeline {
shader_defs,
entry_point: "fragment".into(),
targets: vec![Some(ColorTargetState {
format: TextureFormat::bevy_default(),
format: if key.hdr {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
},
blend: Some(BlendState::ALPHA_BLENDING),
write_mask: ColorWrites::ALL,
})],
Expand Down

0 comments on commit e6a0164

Please sign in to comment.