gallium/st: lower NV21 to R8_B8G8 instead of G8_B8R8

When NV21 lowering with hardware sampling and shader CSC was added, the
incorrect PIPE_FORMAT_G8_B8R8_UNORM was used. That format is supposed to
represent vulkan NV12 instead.

This commit introduces PIPE_FORMAT_R8_B8G8_UNORM, which correctly describes the
gallium mapping for YUV CSC, with R as Y, instead of G as Y.

Fixes: 26e3be513d ("gallium/st: add support for PIPE_FORMAT_NV21 and PIPE_FORMAT_G8_B8R8_420")
Signed-off-by: Italo Nicola <italonicola@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24266>
This commit is contained in:
Italo Nicola 2023-07-10 23:09:44 +00:00 committed by Marge Bot
parent 4eb0a98e5a
commit 2dc883eb37
10 changed files with 19 additions and 18 deletions

View file

@ -890,11 +890,11 @@ static const struct dri2_format_mapping r8_g8b8_mapping = {
{ 1, 1, 1, __DRI_IMAGE_FORMAT_GR88 } }
};
static const struct dri2_format_mapping g8_b8r8_mapping = {
static const struct dri2_format_mapping r8_b8g8_mapping = {
DRM_FORMAT_NV21,
__DRI_IMAGE_FORMAT_NONE,
__DRI_IMAGE_COMPONENTS_Y_UV,
PIPE_FORMAT_G8_B8R8_420_UNORM,
PIPE_FORMAT_R8_B8G8_420_UNORM,
2,
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_R8 },
{ 1, 1, 1, __DRI_IMAGE_FORMAT_GR88 } }
@ -959,7 +959,7 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
PIPE_BIND_SAMPLER_VIEW))
tex_usage |= PIPE_BIND_SAMPLER_VIEW;
/* For NV12, see if we have support for sampling r8_b8g8 */
/* For NV12, see if we have support for sampling r8_g8b8 */
if (!tex_usage && map->pipe_format == PIPE_FORMAT_NV12 &&
pscreen->is_format_supported(pscreen, PIPE_FORMAT_R8_G8B8_420_UNORM,
screen->target, 0, 0, PIPE_BIND_SAMPLER_VIEW)) {
@ -967,11 +967,11 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
tex_usage |= PIPE_BIND_SAMPLER_VIEW;
}
/* For NV21, see if we have support for sampling g8_b8r8 */
/* For NV21, see if we have support for sampling r8_b8g8 */
if (!tex_usage && map->pipe_format == PIPE_FORMAT_NV21 &&
pscreen->is_format_supported(pscreen, PIPE_FORMAT_G8_B8R8_420_UNORM,
pscreen->is_format_supported(pscreen, PIPE_FORMAT_R8_B8G8_420_UNORM,
screen->target, 0, 0, PIPE_BIND_SAMPLER_VIEW)) {
map = &g8_b8r8_mapping;
map = &r8_b8g8_mapping;
tex_usage |= PIPE_BIND_SAMPLER_VIEW;
}

View file

@ -270,7 +270,7 @@ update_shader_samplers(struct st_context *st,
break;
FALLTHROUGH;
case PIPE_FORMAT_NV21:
if (stObj->pt->format == PIPE_FORMAT_G8_B8R8_420_UNORM)
if (stObj->pt->format == PIPE_FORMAT_R8_B8G8_420_UNORM)
/* no additional views needed */
break;
FALLTHROUGH;

View file

@ -187,7 +187,7 @@ st_get_sampler_views(struct st_context *st,
pipe->create_sampler_view(pipe, stObj->pt->next, &tmpl);
break;
case PIPE_FORMAT_NV21:
if (stObj->pt->format == PIPE_FORMAT_G8_B8R8_420_UNORM)
if (stObj->pt->format == PIPE_FORMAT_R8_B8G8_420_UNORM)
/* no additional views needed */
break;

View file

@ -181,8 +181,8 @@ is_nv12_as_r8_g8b8_supported(struct pipe_screen *screen, struct st_egl_image *ou
}
if (out->format == PIPE_FORMAT_NV21 &&
out->texture->format == PIPE_FORMAT_G8_B8R8_420_UNORM &&
screen->is_format_supported(screen, PIPE_FORMAT_G8_B8R8_420_UNORM,
out->texture->format == PIPE_FORMAT_R8_B8G8_420_UNORM &&
screen->is_format_supported(screen, PIPE_FORMAT_R8_B8G8_420_UNORM,
PIPE_TEXTURE_2D,
out->texture->nr_samples,
out->texture->nr_storage_samples,
@ -366,10 +366,8 @@ st_bind_egl_image(struct gl_context *ctx,
switch (stimg->format) {
case PIPE_FORMAT_NV12:
case PIPE_FORMAT_NV21:
if (stimg->texture->format == PIPE_FORMAT_R8_G8B8_420_UNORM) {
texFormat = MESA_FORMAT_R8G8B8X8_UNORM;
texObj->RequiredTextureImageUnits = 1;
} else if (stimg->texture->format == PIPE_FORMAT_G8_B8R8_420_UNORM) {
if (stimg->texture->format == PIPE_FORMAT_R8_G8B8_420_UNORM ||
stimg->texture->format == PIPE_FORMAT_R8_B8G8_420_UNORM) {
texFormat = MESA_FORMAT_R8G8B8X8_UNORM;
texObj->RequiredTextureImageUnits = 1;
} else {

View file

@ -97,7 +97,7 @@ st_get_external_sampler_key(struct st_context *st, struct gl_program *prog)
key.lower_nv12 |= (1 << unit);
break;
case PIPE_FORMAT_NV21:
if (stObj->pt->format == PIPE_FORMAT_G8_B8R8_420_UNORM) {
if (stObj->pt->format == PIPE_FORMAT_R8_B8G8_420_UNORM) {
key.lower_yuv |= (1 << unit);
break;
}

View file

@ -387,8 +387,8 @@ st_get_sampler_view_format(const struct st_context *st,
}
FALLTHROUGH;
case PIPE_FORMAT_NV21:
if (texObj->pt->format == PIPE_FORMAT_G8_B8R8_420_UNORM) {
format = PIPE_FORMAT_G8_B8R8_420_UNORM;
if (texObj->pt->format == PIPE_FORMAT_R8_B8G8_420_UNORM) {
format = PIPE_FORMAT_R8_B8G8_420_UNORM;
break;
}
FALLTHROUGH;

View file

@ -193,7 +193,7 @@ const struct panfrost_format GENX(panfrost_pipe_format)[PIPE_FORMAT_COUNT] = {
FMT_YUV(R8B8_R8G8_UNORM, YUYV8, VYUA, NO_SWAP, CO_SITED, _T__),
FMT_YUV(B8R8_G8R8_UNORM, VYUY8, VUYA, SWAP, CO_SITED, _T__),
FMT_YUV(R8_G8B8_420_UNORM, Y8_UV8_420, YUVA, NO_SWAP, CO_SITED, _T__),
FMT_YUV(G8_B8R8_420_UNORM, Y8_UV8_420, YVUA, NO_SWAP, CO_SITED, _T__),
FMT_YUV(R8_B8G8_420_UNORM, Y8_UV8_420, YVUA, NO_SWAP, CO_SITED, _T__),
FMT_YUV(R8_G8_B8_420_UNORM, Y8_U8_V8_420, YUVA, NO_SWAP, CO_SITED, _T__),
FMT_YUV(R8_B8_G8_420_UNORM, Y8_U8_V8_420, YVUA, NO_SWAP, CO_SITED, _T__),
#endif

View file

@ -406,6 +406,7 @@ PIPE_FORMAT_Y8_400_UNORM , other , 1, 1, 1, un8, , , , x0
# RGB version of NV12 and YV12 for hardware that supports sampling from
# multiplane textures but needs color-space conversion in the shader.
PIPE_FORMAT_R8_G8B8_420_UNORM , planar2, 1, 1, 1, un8, , , , xyzw, rgb
PIPE_FORMAT_R8_B8G8_420_UNORM , planar2, 1, 1, 1, un8, , , , xyzw, rgb
PIPE_FORMAT_G8_B8R8_420_UNORM , planar2, 1, 1, 1, un8, , , , xyzw, rgb
PIPE_FORMAT_R8_G8_B8_420_UNORM , planar3, 1, 1, 1, un8, , , , xyzw, rgb
PIPE_FORMAT_R8_B8_G8_420_UNORM , planar3, 1, 1, 1, un8, , , , xyzw, rgb

Can't render this file because it contains an unexpected character in line 8 and column 3.

View file

@ -113,6 +113,7 @@ def has_access(format):
'y16_u16v16_422_unorm',
'y16_u16_v16_444_unorm',
'r8_g8b8_420_unorm',
'r8_b8g8_420_unorm',
'g8_b8r8_420_unorm',
'r8_g8_b8_420_unorm',
'r8_b8_g8_420_unorm',

View file

@ -511,6 +511,7 @@ enum pipe_format {
PIPE_FORMAT_XYUV,
PIPE_FORMAT_R8_G8B8_420_UNORM,
PIPE_FORMAT_R8_B8G8_420_UNORM,
PIPE_FORMAT_G8_B8R8_420_UNORM,
PIPE_FORMAT_R8_G8_B8_420_UNORM,
PIPE_FORMAT_R8_B8_G8_420_UNORM,