Skip to content

Commit 6f8089d

Browse files
authored
Fix UI corruption for AMD gpus with Vulkan (#9169)
# Objective Fixes #8894 Fixes #7944 ## Solution The UI pipeline's `MultisampleState::count` is set to 1 whereas the `MultisampleState::count` for the camera's ViewTarget is taken from the `Msaa` resource, and corruption occurs when these two values are different. This PR solves the problem by setting `MultisampleState::count` for the UI pipeline to the value from the Msaa resource too. I don't know much about Bevy's rendering internals or graphics hardware, so maybe there is a better solution than this. UI MSAA was probably disabled for a good reason (performance?). ## Changelog * Enabled multisampling for the UI pipeline.
1 parent 7fe0853 commit 6f8089d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

crates/bevy_ui/src/render/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod render_pass;
33

44
use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d};
55
use bevy_hierarchy::Parent;
6+
use bevy_render::view::Msaa;
67
use bevy_render::{ExtractSchedule, Render};
78
use bevy_window::{PrimaryWindow, Window};
89
pub use pipeline::*;
@@ -801,6 +802,7 @@ pub fn queue_uinodes(
801802
ui_batches: Query<(Entity, &UiBatch)>,
802803
mut views: Query<(&ExtractedView, &mut RenderPhase<TransparentUi>)>,
803804
events: Res<SpriteAssetEvents>,
805+
msaa: Res<Msaa>,
804806
) {
805807
// If an image has changed, the GpuImage has (probably) changed
806808
for event in &events.images {
@@ -826,7 +828,10 @@ pub fn queue_uinodes(
826828
let pipeline = pipelines.specialize(
827829
&pipeline_cache,
828830
&ui_pipeline,
829-
UiPipelineKey { hdr: view.hdr },
831+
UiPipelineKey {
832+
hdr: view.hdr,
833+
msaa_samples: msaa.samples(),
834+
},
830835
);
831836
for (entity, batch) in &ui_batches {
832837
image_bind_groups

crates/bevy_ui/src/render/pipeline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl FromWorld for UiPipeline {
6262
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
6363
pub struct UiPipelineKey {
6464
pub hdr: bool,
65+
pub msaa_samples: u32,
6566
}
6667

6768
impl SpecializedRenderPipeline for UiPipeline {
@@ -117,7 +118,7 @@ impl SpecializedRenderPipeline for UiPipeline {
117118
},
118119
depth_stencil: None,
119120
multisample: MultisampleState {
120-
count: 1,
121+
count: key.msaa_samples,
121122
mask: !0,
122123
alpha_to_coverage_enabled: false,
123124
},

crates/bevy_ui/src/render/render_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Node for UiPassNode {
7272
};
7373
let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
7474
label: Some("ui_pass"),
75-
color_attachments: &[Some(target.get_unsampled_color_attachment(Operations {
75+
color_attachments: &[Some(target.get_color_attachment(Operations {
7676
load: LoadOp::Load,
7777
store: true,
7878
}))],

0 commit comments

Comments
 (0)