Module: Mesa Branch: main Commit: cfec9a55ea6a1cd535ea60aeff7f7bd85dd64bb5 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=cfec9a55ea6a1cd535ea60aeff7f7bd85dd64bb5
Author: Marek Olšák <[email protected]> Date: Fri Apr 1 21:43:42 2022 -0400 frontend/dri: allow swapped BGR->RGB channel order for MSAA color buffers This only applies to MSAA visuals. The MSAA channel order doesn't have to match the visual, but some drivers don't support MSAA with BGR. Reviewed-by: Adam Jackson <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16327> --- src/gallium/frontends/dri/dri2.c | 17 +++++++++++++++-- src/gallium/frontends/dri/dri_screen.c | 12 ++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c index 63ac9d5c0ee..3cbf15927b8 100644 --- a/src/gallium/frontends/dri/dri2.c +++ b/src/gallium/frontends/dri/dri2.c @@ -627,12 +627,26 @@ dri2_allocate_textures(struct dri_context *ctx, continue; if (drawable->textures[statt]) { + struct pipe_screen *screen = ctx->st->pipe->screen; + templ.format = drawable->textures[statt]->format; templ.bind = drawable->textures[statt]->bind & ~(PIPE_BIND_SCANOUT | PIPE_BIND_SHARED); templ.nr_samples = drawable->stvis.samples; templ.nr_storage_samples = drawable->stvis.samples; + /* The MSAA component order doesn't have to match the single-sample + * one. Allow the DRI frontend to swap channels for MSAA. + */ + if (!screen->is_format_supported(screen, templ.format, + PIPE_TEXTURE_2D, + templ.nr_samples, + templ.nr_storage_samples, + templ.bind)) { + templ.format = util_format_rgb_to_bgr(templ.format); + assert(templ.format); + } + /* Try to reuse the resource. * (the other resource parameters should be constant) */ @@ -643,8 +657,7 @@ dri2_allocate_textures(struct dri_context *ctx, pipe_resource_reference(&drawable->msaa_textures[statt], NULL); drawable->msaa_textures[statt] = - screen->base.screen->resource_create(screen->base.screen, - &templ); + screen->resource_create(screen, &templ); assert(drawable->msaa_textures[statt]); /* If there are any MSAA resources, we should initialize them diff --git a/src/gallium/frontends/dri/dri_screen.c b/src/gallium/frontends/dri/dri_screen.c index e68a8c19eec..b7e5e0f51fa 100644 --- a/src/gallium/frontends/dri/dri_screen.c +++ b/src/gallium/frontends/dri/dri_screen.c @@ -257,13 +257,21 @@ dri_fill_in_modes(struct dri_screen *screen) continue; for (i = 1; i <= msaa_samples_max; i++) { + /* The MSAA component order doesn't have to match the single-sample + * one. Allow the DRI frontend to swap channels for MSAA. + */ + enum pipe_format swapped_format = + util_format_rgb_to_bgr(pipe_formats[format]); int samples = i > 1 ? i : 0; if (p_screen->is_format_supported(p_screen, pipe_formats[format], PIPE_TEXTURE_2D, samples, samples, - PIPE_BIND_RENDER_TARGET)) { + PIPE_BIND_RENDER_TARGET) || + (swapped_format != PIPE_FORMAT_NONE && + p_screen->is_format_supported(p_screen, swapped_format, + PIPE_TEXTURE_2D, samples, samples, + PIPE_BIND_RENDER_TARGET))) msaa_modes[num_msaa_modes++] = samples; - } } if (num_msaa_modes) {
