From 2e9e8e9a3667c0669bce34df2f9e29e313caf0ac Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 6 May 2026 15:32:46 -0400 Subject: [PATCH] lavapipe: fix setting colormasks when attachments get remapped this requires blend state updates cc: mesa-stable Part-of: --- src/gallium/frontends/lavapipe/lvp_execute.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index d6d72702e06..c0fcdd7ae41 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -123,6 +123,7 @@ struct rendering_state { struct pipe_grid_info trace_rays_info; struct pipe_framebuffer_state framebuffer; int fb_map[PIPE_MAX_COLOR_BUFS]; + unsigned fb_max_cbufs; bool fb_remapped; struct pipe_blend_state blend_state; @@ -395,6 +396,7 @@ emit_fb_state(struct rendering_state *state) fb.nr_cbufs = MAX2(fb.nr_cbufs, state->fb_map[i] + 1); } } + state->fb_max_cbufs = fb.nr_cbufs; state->pctx->set_framebuffer_state(state->pctx, &fb); } else { state->pctx->set_framebuffer_state(state->pctx, &state->framebuffer); @@ -523,7 +525,7 @@ static void emit_state(struct rendering_state *state) } if (state->fb_remapped) { struct pipe_blend_state blend = state->blend_state; - for (unsigned i = 0; i < state->framebuffer.nr_cbufs; i++) { + for (unsigned i = 0; i < state->fb_max_cbufs; i++) { if (state->fb_map[i] < PIPE_MAX_COLOR_BUFS) { blend.rt[state->fb_map[i]] = state->blend_state.rt[i]; } @@ -1909,6 +1911,7 @@ handle_begin_rendering(struct vk_cmd_queue_entry *cmd, bool suspending = (info->flags & VK_RENDERING_SUSPENDING_BIT) == VK_RENDERING_SUSPENDING_BIT; state->fb_remapped = false; + state->fb_max_cbufs = 0; for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; i++) state->fb_map[i] = i; @@ -2007,6 +2010,7 @@ static void handle_end_rendering(struct vk_cmd_queue_entry *cmd, /* ensure that textures are correctly framebuffer-referenced in llvmpipe */ if (state->fb_remapped) { state->fb_remapped = false; + state->fb_max_cbufs = 0; emit_fb_state(state); } @@ -2062,6 +2066,7 @@ handle_rendering_attachment_locations(struct vk_cmd_queue_entry *cmd, struct ren { VkRenderingAttachmentLocationInfoKHR *set = cmd->u.set_rendering_attachment_locations.location_info; state->fb_remapped = !!set->pColorAttachmentLocations; + state->fb_max_cbufs = 0; memset(state->fb_map, PIPE_MAX_COLOR_BUFS, sizeof(state->fb_map)); assert(state->color_att_count == set->colorAttachmentCount); if (set->pColorAttachmentLocations) { @@ -2071,6 +2076,8 @@ handle_rendering_attachment_locations(struct vk_cmd_queue_entry *cmd, struct ren state->fb_map[i] = set->pColorAttachmentLocations[i]; } } + /* force re-emitting colormasks */ + state->blend_dirty = true; emit_fb_state(state); }