Module: Mesa Branch: main Commit: e36c49b69a82df98fef171a36367401b53109b4a URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e36c49b69a82df98fef171a36367401b53109b4a
Author: Karol Herbst <[email protected]> Date: Tue Sep 19 14:44:26 2023 +0200 zink: fix RA textures Signed-off-by: Karol Herbst <[email protected]> Reviewed-by: Mike Blumenkrantz <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24839> --- src/gallium/drivers/zink/zink_context.c | 6 ++++++ src/util/format/u_format.c | 33 +++++++++++++++++++++++++++++++++ src/util/format/u_format.h | 5 +++++ 3 files changed, 44 insertions(+) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 07496013da8..82db90a911e 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -55,6 +55,8 @@ #include "nir.h" #include "nir_builder.h" +#include "vk_format.h" + #include "driver_trace/tr_context.h" #include "util/u_memory.h" @@ -1161,6 +1163,10 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres, } else assert(state->format == linear); } + } else if (util_format_is_red_alpha(pres->format)) { + /* RA formats are mapped to RG with adjusted swizzle */ + assert(util_format_is_red_green(vk_format_to_pipe_format(ivci.format))); + swizzle[3] = PIPE_SWIZZLE_Y; } ivci.components.r = zink_component_mapping(swizzle[0]); diff --git a/src/util/format/u_format.c b/src/util/format/u_format.c index 920d217088e..30dd65e8428 100644 --- a/src/util/format/u_format.c +++ b/src/util/format/u_format.c @@ -299,6 +299,39 @@ util_format_is_luminance_alpha(enum pipe_format format) return false; } +bool +util_format_is_red_alpha(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + if ((desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) && + desc->swizzle[0] == PIPE_SWIZZLE_X && + desc->swizzle[1] == PIPE_SWIZZLE_0 && + desc->swizzle[2] == PIPE_SWIZZLE_0 && + desc->swizzle[3] == PIPE_SWIZZLE_Y) { + return true; + } + return false; +} + +bool +util_format_is_red_green(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + if ((desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) && + desc->swizzle[0] == PIPE_SWIZZLE_X && + desc->swizzle[1] == PIPE_SWIZZLE_Y && + desc->swizzle[2] == PIPE_SWIZZLE_0 && + desc->swizzle[3] == PIPE_SWIZZLE_1) { + return true; + } + return false; +} bool util_format_is_intensity(enum pipe_format format) diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h index 93de204bd3e..8c42adf5b2d 100644 --- a/src/util/format/u_format.h +++ b/src/util/format/u_format.h @@ -751,6 +751,11 @@ util_format_is_alpha(enum pipe_format format) ATTRIBUTE_CONST; bool util_format_is_luminance_alpha(enum pipe_format format) ATTRIBUTE_CONST; +bool +util_format_is_red_alpha(enum pipe_format format) ATTRIBUTE_CONST; + +bool +util_format_is_red_green(enum pipe_format format) ATTRIBUTE_CONST; bool util_format_is_intensity(enum pipe_format format) ATTRIBUTE_CONST;
