From 600b8ba75c5000b1908c3894ca0f222bebb78f0d Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 20 Mar 2023 08:50:29 -0400 Subject: [PATCH] zink: split out luminance/alpha clear conversion code for reuse Part-of: --- src/gallium/drivers/zink/zink_clear.c | 61 +++++++++++++++------------ 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/gallium/drivers/zink/zink_clear.c b/src/gallium/drivers/zink/zink_clear.c index 5c816122714..64f8b194e72 100644 --- a/src/gallium/drivers/zink/zink_clear.c +++ b/src/gallium/drivers/zink/zink_clear.c @@ -142,6 +142,37 @@ get_clear_data(struct zink_context *ctx, struct zink_framebuffer_clear *fb_clear return add_new_clear(fb_clear); } +static void +convert_color(struct pipe_surface *psurf, union pipe_color_union *color) +{ + const struct util_format_description *desc = util_format_description(psurf->format); + union pipe_color_union tmp = *color; + + if (zink_format_is_emulated_alpha(psurf->format)) { + if (util_format_is_alpha(psurf->format)) { + tmp.ui[0] = tmp.ui[3]; + tmp.ui[1] = 0; + tmp.ui[2] = 0; + tmp.ui[3] = 0; + } else if (util_format_is_luminance(psurf->format)) { + tmp.ui[1] = 0; + tmp.ui[2] = 0; + tmp.f[3] = 1.0; + } else if (util_format_is_luminance_alpha(psurf->format)) { + tmp.ui[1] = tmp.ui[3]; + tmp.ui[2] = 0; + tmp.f[3] = 1.0; + } else /* zink_format_is_red_alpha */ { + tmp.ui[1] = tmp.ui[3]; + tmp.ui[2] = 0; + tmp.ui[3] = 0; + } + memcpy(color, &tmp, sizeof(union pipe_color_union)); + } + for (unsigned i = 0; i < 4; i++) + zink_format_clamp_channel_color(desc, color, &tmp, i); +} + void zink_clear(struct pipe_context *pctx, unsigned buffers, @@ -247,42 +278,16 @@ zink_clear(struct pipe_context *pctx, for (unsigned i = 0; i < fb->nr_cbufs; i++) { if ((buffers & (PIPE_CLEAR_COLOR0 << i)) && fb->cbufs[i]) { struct pipe_surface *psurf = fb->cbufs[i]; - bool emulated_alpha = zink_format_is_emulated_alpha(psurf->format); - const struct util_format_description *desc = util_format_description(psurf->format); struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[i]; struct zink_framebuffer_clear_data *clear = get_clear_data(ctx, fb_clear, needs_rp ? scissor_state : NULL); - const union pipe_color_union *color = pcolor; - union pipe_color_union tmp; ctx->clears_enabled |= PIPE_CLEAR_COLOR0 << i; clear->conditional = ctx->render_condition_active; clear->has_scissor = needs_rp; + memcpy(&clear->color, pcolor, sizeof(union pipe_color_union)); + convert_color(psurf, &clear->color); if (scissor_state && needs_rp) clear->scissor = *scissor_state; - if (emulated_alpha) { - tmp = *pcolor; - if (util_format_is_alpha(psurf->format)) { - tmp.ui[0] = tmp.ui[3]; - tmp.ui[1] = 0; - tmp.ui[2] = 0; - tmp.ui[3] = 0; - } else if (util_format_is_luminance(psurf->format)) { - tmp.ui[1] = 0; - tmp.ui[2] = 0; - tmp.f[3] = 1.0; - } else if (util_format_is_luminance_alpha(psurf->format)) { - tmp.ui[1] = tmp.ui[3]; - tmp.ui[2] = 0; - tmp.f[3] = 1.0; - } else /* zink_format_is_red_alpha */ { - tmp.ui[1] = tmp.ui[3]; - tmp.ui[2] = 0; - tmp.ui[3] = 0; - } - color = &tmp; - } - for (unsigned i = 0; i < 4; i++) - zink_format_clamp_channel_color(desc, &clear->color, color, i); if (zink_fb_clear_first_needs_explicit(fb_clear)) ctx->rp_clears_enabled &= ~(PIPE_CLEAR_COLOR0 << i); else