Module: Mesa Branch: master Commit: 11ea1d177789f288b0538b27853e112e0b321ef4 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=11ea1d177789f288b0538b27853e112e0b321ef4
Author: Mike Blumenkrantz <[email protected]> Date: Thu Mar 18 15:42:43 2021 -0400 zink: unify clear color conversion code at some point this will get fixed to work for format conversions Reviewed-by: Dave Airlie <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9712> --- src/gallium/drivers/zink/zink_clear.c | 30 +++++++++++++++++++++--------- src/gallium/drivers/zink/zink_clear.h | 3 +++ src/gallium/drivers/zink/zink_context.c | 11 +---------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/gallium/drivers/zink/zink_clear.c b/src/gallium/drivers/zink/zink_clear.c index e5aa63b76ed..eec976758cb 100644 --- a/src/gallium/drivers/zink/zink_clear.c +++ b/src/gallium/drivers/zink/zink_clear.c @@ -424,6 +424,25 @@ zink_fb_clear_first_needs_explicit(struct zink_framebuffer_clear *fb_clear) return zink_fb_clear_element_needs_explicit(zink_fb_clear_element(fb_clear, 0)); } +void +zink_fb_clear_util_unpack_clear_color(struct zink_framebuffer_clear_data *clear, enum pipe_format format, union pipe_color_union *color) +{ + const struct util_format_description *desc = util_format_description(format); + if (clear->color.srgb) { + /* if SRGB mode is disabled for the fb with a backing srgb image then we have to + * convert this to srgb color + */ + for (unsigned j = 0; j < MIN2(3, desc->nr_channels); j++) { + assert(desc->channel[j].normalized); + color->f[j] = util_format_srgb_to_linear_float(clear->color.color.f[j]); + } + color->f[3] = clear->color.color.f[3]; + } else { + for (unsigned i = 0; i < 4; i++) + color->f[i] = clear->color.color.f[i]; + } +} + static void fb_clears_apply_internal(struct zink_context *ctx, struct pipe_resource *pres, int i) { @@ -439,15 +458,8 @@ fb_clears_apply_internal(struct zink_context *ctx, struct pipe_resource *pres, i else { struct pipe_surface *psurf = ctx->fb_state.cbufs[i]; struct zink_framebuffer_clear_data *clear = zink_fb_clear_element(fb_clear, 0); - union pipe_color_union color = clear->color.color; - if (clear->color.srgb) { - /* if SRGB mode is disabled for the fb with a backing srgb image then we have to - * convert this to srgb color - */ - color.f[0] = util_format_srgb_to_linear_float(clear->color.color.f[0]); - color.f[1] = util_format_srgb_to_linear_float(clear->color.color.f[1]); - color.f[2] = util_format_srgb_to_linear_float(clear->color.color.f[2]); - } + union pipe_color_union color; + zink_fb_clear_util_unpack_clear_color(clear, psurf->format, &color); clear_color_no_rp(ctx, zink_resource(pres), &color, psurf->u.tex.level, psurf->u.tex.first_layer, diff --git a/src/gallium/drivers/zink/zink_clear.h b/src/gallium/drivers/zink/zink_clear.h index ca5547ff73a..d024fcdd378 100644 --- a/src/gallium/drivers/zink/zink_clear.h +++ b/src/gallium/drivers/zink/zink_clear.h @@ -115,3 +115,6 @@ zink_fb_clears_apply_or_discard(struct zink_context *ctx, struct pipe_resource * void zink_fb_clears_apply_region(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region); + +void +zink_fb_clear_util_unpack_clear_color(struct zink_framebuffer_clear_data *clear, enum pipe_format format, union pipe_color_union *color); diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index fc763a37fd9..94dcaa9fcd8 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -1247,16 +1247,7 @@ zink_begin_render_pass(struct zink_context *ctx, struct zink_batch *batch) continue; } /* we now know there's one clear that can be done here */ - if (clear->color.srgb) { - clears[i].color.float32[0] = util_format_srgb_to_linear_float(clear->color.color.f[0]); - clears[i].color.float32[1] = util_format_srgb_to_linear_float(clear->color.color.f[1]); - clears[i].color.float32[2] = util_format_srgb_to_linear_float(clear->color.color.f[2]); - } else { - clears[i].color.float32[0] = clear->color.color.f[0]; - clears[i].color.float32[1] = clear->color.color.f[1]; - clears[i].color.float32[2] = clear->color.color.f[2]; - } - clears[i].color.float32[3] = clear->color.color.f[3]; + zink_fb_clear_util_unpack_clear_color(clear, fb_state->cbufs[i]->format, (void*)&clears[i].color); rpbi.clearValueCount = i + 1; clear_validate |= BITFIELD_BIT(i); assert(ctx->framebuffer->rp->state.clears); _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
