zink: split out luminance/alpha clear conversion code for reuse

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22025>
This commit is contained in:
Mike Blumenkrantz
2023-03-20 08:50:29 -04:00
committed by Marge Bot
parent 84762bb1cf
commit 600b8ba75c

View File

@@ -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