From 16dea12dae0bf3207741049c5a6dc6d4076507c0 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 5 May 2023 13:36:00 +0200 Subject: render/vulkan: add more YCbCr formats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Vulkan spec states: > For the purposes of range expansion and Y′CBCR model conversion, > the R and B components contain color difference (chroma) values > and the G component contains luma. The equations below that sentence also help understand the mapping. --- render/vulkan/pixel_format.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'render') diff --git a/render/vulkan/pixel_format.c b/render/vulkan/pixel_format.c index 01d69db3..e633c5c1 100644 --- a/render/vulkan/pixel_format.c +++ b/render/vulkan/pixel_format.c @@ -145,11 +145,46 @@ static const struct wlr_vk_format formats[] = { #endif // YCbCr formats + // R -> V, G -> Y, B -> U + // 420 -> 2x2 subsampled, 422 -> 2x1 subsampled, 444 -> non-subsampled + { + .drm = DRM_FORMAT_UYVY, + .vk = VK_FORMAT_B8G8R8G8_422_UNORM, + .is_ycbcr = true, + }, + { + .drm = DRM_FORMAT_YUYV, + .vk = VK_FORMAT_G8B8G8R8_422_UNORM, + .is_ycbcr = true, + }, { .drm = DRM_FORMAT_NV12, .vk = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, .is_ycbcr = true, }, + { + .drm = DRM_FORMAT_NV16, + .vk = VK_FORMAT_G8_B8R8_2PLANE_422_UNORM, + .is_ycbcr = true, + }, + { + .drm = DRM_FORMAT_YUV420, + .vk = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, + .is_ycbcr = true, + }, + { + .drm = DRM_FORMAT_YUV422, + .vk = VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM, + .is_ycbcr = true, + }, + { + .drm = DRM_FORMAT_YUV444, + .vk = VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM, + .is_ycbcr = true, + }, + // TODO: add 10, 12 and 16 bit formats + // TODO: add DRM_FORMAT_NV24/VK_FORMAT_G8_B8R8_2PLANE_444_UNORM (requires + // Vulkan 1.3 or VK_EXT_ycbcr_2plane_444_formats) }; const struct wlr_vk_format *vulkan_get_format_list(size_t *len) { -- cgit v1.2.3