st/mesa: Add NV12 lowering to PIPE_FORMAT_R8_G8B8_420_UNORM

Some GPUs can sample biplanar formats like NV12 natively, returning
the YUV values. Add a lowering type that uses that for sampling and
relies on existing colorspace conversions.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6693>
This commit is contained in:
Kristian H. Kristensen
2020-09-28 20:11:18 +00:00
committed by Marge Bot
parent e23bcb69c3
commit 826a10255f
9 changed files with 92 additions and 5 deletions

View File

@@ -726,6 +726,16 @@ dri2_update_tex_buffer(struct dri_drawable *drawable,
/* no-op */
}
static const struct dri2_format_mapping r8_g8b8_mapping = {
DRM_FORMAT_NV12,
__DRI_IMAGE_FORMAT_NONE,
__DRI_IMAGE_COMPONENTS_Y_UV,
PIPE_FORMAT_R8_G8B8_420_UNORM,
2,
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } }
};
static __DRIimage *
dri2_create_image_from_winsys(__DRIscreen *_screen,
int width, int height, const struct dri2_format_mapping *map,
@@ -748,6 +758,14 @@ 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 */
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)) {
map = &r8_g8b8_mapping;
tex_usage |= PIPE_BIND_SAMPLER_VIEW;
}
if (!tex_usage && util_format_is_yuv(map->pipe_format)) {
/* YUV format sampling can be emulated by the GL gallium frontend by
* using multiple samplers of varying formats.