Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Specialize UI pipeline on "hdr-ness" #6459

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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