Skip to content

Commit 34dd5e0

Browse files
committed
Merge pull request godotengine#97217 from stuartcarnie/97185_subpixel_rendering
Metal: Fix subpixel blending; fix inconsistent blend state
2 parents 25c4caa + e826ab9 commit 34dd5e0

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

drivers/metal/metal_objects.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDCommandBuffer {
318318
dirty.set_flag(DirtyFlag::DIRTY_UNIFORMS);
319319
}
320320

321+
_FORCE_INLINE_ void mark_blend_dirty() {
322+
if (!blend_constants.has_value()) {
323+
return;
324+
}
325+
dirty.set_flag(DirtyFlag::DIRTY_BLEND);
326+
}
327+
321328
MTLScissorRect clip_to_render_area(MTLScissorRect p_rect) const {
322329
uint32_t raLeft = render_area.position.x;
323330
uint32_t raRight = raLeft + render_area.size.width;

drivers/metal/metal_objects.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@
143143
if (render.pipeline != nullptr && render.pipeline->depth_stencil != rp->depth_stencil) {
144144
render.dirty.set_flag(RenderState::DIRTY_DEPTH);
145145
}
146+
if (rp->raster_state.blend.enabled) {
147+
render.dirty.set_flag(RenderState::DIRTY_BLEND);
148+
}
146149
render.pipeline = rp;
147150
}
148151
} else if (p->type == MDPipelineType::Compute) {
@@ -301,6 +304,7 @@
301304
render.mark_viewport_dirty();
302305
render.mark_scissors_dirty();
303306
render.mark_vertex_dirty();
307+
render.mark_blend_dirty();
304308
}
305309

306310
void MDCommandBuffer::_render_set_dirty_state() {

servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
24792479
r_current_batch = _new_batch(r_batch_broken);
24802480
r_current_batch->command_type = Item::Command::TYPE_NINEPATCH;
24812481
r_current_batch->command = c;
2482+
r_current_batch->has_blend = false;
24822483
r_current_batch->pipeline_variant = PipelineVariant::PIPELINE_VARIANT_NINEPATCH;
24832484
}
24842485

@@ -2548,6 +2549,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
25482549
r_current_batch = _new_batch(r_batch_broken);
25492550

25502551
r_current_batch->command_type = Item::Command::TYPE_POLYGON;
2552+
r_current_batch->has_blend = false;
25512553
r_current_batch->command = c;
25522554

25532555
TextureState tex_state(polygon->texture, texture_filter, texture_repeat, false, use_linear_colors);
@@ -2585,6 +2587,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
25852587
if (primitive->point_count != r_current_batch->primitive_points || r_current_batch->command_type != Item::Command::TYPE_PRIMITIVE) {
25862588
r_current_batch = _new_batch(r_batch_broken);
25872589
r_current_batch->command_type = Item::Command::TYPE_PRIMITIVE;
2590+
r_current_batch->has_blend = false;
25882591
r_current_batch->command = c;
25892592
r_current_batch->primitive_points = primitive->point_count;
25902593

@@ -2646,6 +2649,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
26462649
r_current_batch = _new_batch(r_batch_broken);
26472650
r_current_batch->command = c;
26482651
r_current_batch->command_type = c->type;
2652+
r_current_batch->has_blend = false;
26492653

26502654
InstanceData *instance_data = nullptr;
26512655

@@ -2799,6 +2803,7 @@ void RendererCanvasRenderRD::_render_batch(RD::DrawListID p_draw_list, PipelineV
27992803
RID pipeline = p_pipeline_variants->variants[p_batch->light_mode][p_batch->pipeline_variant].get_render_pipeline(RD::INVALID_ID, p_framebuffer_format);
28002804
RD::get_singleton()->draw_list_bind_render_pipeline(p_draw_list, pipeline);
28012805
if (p_batch->has_blend) {
2806+
DEV_ASSERT(p_batch->pipeline_variant == PIPELINE_VARIANT_QUAD_LCD_BLEND);
28022807
RD::get_singleton()->draw_list_set_blend_constants(p_draw_list, p_batch->modulate);
28032808
}
28042809

0 commit comments

Comments
 (0)