diff mbox series

[FFmpeg-devel,3/3] lavu/hwcontext_[vaapi|vulkan]: support mapping VUYA, P012, and Y412

Message ID 20220816050256.32149-4-philipl@overt.org
State New
Headers show
Series V4: VAAPI: Add high bit depth encode/decode support | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Philip Langdale Aug. 16, 2022, 5:02 a.m. UTC
These two of the Microsoft formats used by Intel VAAPI are sufficiently
conventional that we can add simple mappings for them in the hwcontexts
to enable back and forth mapping so that Vulkan filters can be used
with vaapi decoding/encoding of these formats.

Note that as with P010, we have to map to full 16bit Vulkan formats and
so technically lose some information with P012 and Y412. The most
significant consequence of this is that when mapping form Vulkan back
to VAAPI, the underlying DRM format will actually be Y416 and so we
need a mapping entry for it, even though we haven't added that as a
pixel format.

Signed-off-by: Philip Langdale <philipl@overt.org>
---
 libavutil/hwcontext_vaapi.c  |  9 +++++++++
 libavutil/hwcontext_vulkan.c | 10 ++++++++++
 2 files changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 6c057aa5fd..15fea62a34 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1010,6 +1010,9 @@  static const struct {
     DRM_MAP(NV12, 1, DRM_FORMAT_NV12),
 #if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16)
     DRM_MAP(P010, 2, DRM_FORMAT_R16, DRM_FORMAT_RG1616),
+#endif
+#if defined(VA_FOURCC_P012) && defined(DRM_FORMAT_R16)
+    DRM_MAP(P012, 2, DRM_FORMAT_R16, DRM_FORMAT_RG1616),
 #endif
     DRM_MAP(BGRA, 1, DRM_FORMAT_ARGB8888),
     DRM_MAP(BGRX, 1, DRM_FORMAT_XRGB8888),
@@ -1021,6 +1024,12 @@  static const struct {
 #endif
     DRM_MAP(ARGB, 1, DRM_FORMAT_BGRA8888),
     DRM_MAP(XRGB, 1, DRM_FORMAT_BGRX8888),
+#ifdef VA_FOURCC_AYUV
+    DRM_MAP(AYUV, 1, DRM_FORMAT_AYUV),
+#endif
+#ifdef VA_FOURCC_Y412
+    DRM_MAP(Y412, 1, DRM_FORMAT_Y412),
+#endif
 };
 #undef DRM_MAP
 
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 237caa4bc0..62db2633fa 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -173,6 +173,7 @@  static const struct {
     { AV_PIX_FMT_NV12, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8G8_UNORM } },
     { AV_PIX_FMT_NV21, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8G8_UNORM } },
     { AV_PIX_FMT_P010, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16G16_UNORM } },
+    { AV_PIX_FMT_P012, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16G16_UNORM } },
     { AV_PIX_FMT_P016, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16G16_UNORM } },
 
     { AV_PIX_FMT_NV16, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8G8_UNORM } },
@@ -210,6 +211,9 @@  static const struct {
     { AV_PIX_FMT_YUVA444P12, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
     { AV_PIX_FMT_YUVA444P16, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
 
+    { AV_PIX_FMT_VUYA,   { VK_FORMAT_R8G8B8A8_UNORM } },
+    { AV_PIX_FMT_Y412,   { VK_FORMAT_R16G16B16A16_UNORM } },
+
     { AV_PIX_FMT_BGRA,   { VK_FORMAT_B8G8R8A8_UNORM } },
     { AV_PIX_FMT_RGBA,   { VK_FORMAT_R8G8B8A8_UNORM } },
     { AV_PIX_FMT_RGB24,  { VK_FORMAT_R8G8B8_UNORM } },
@@ -2629,6 +2633,12 @@  static const struct {
     { DRM_FORMAT_XRGB8888, VK_FORMAT_B8G8R8A8_UNORM },
     { DRM_FORMAT_ABGR8888, VK_FORMAT_R8G8B8A8_UNORM },
     { DRM_FORMAT_XBGR8888, VK_FORMAT_R8G8B8A8_UNORM },
+
+    { DRM_FORMAT_AYUV,     VK_FORMAT_R8G8B8A8_UNORM     },
+    { DRM_FORMAT_Y412,     VK_FORMAT_R16G16B16A16_UNORM },
+    // As we had to map Y412 to a 16bit Vulkan format, reverse mapping will
+    // end up yielding Y416 as the DRM format, so we need to recognise it.
+    { DRM_FORMAT_Y416,     VK_FORMAT_R16G16B16A16_UNORM },
 };
 
 static inline VkFormat drm_to_vulkan_fmt(uint32_t drm_fourcc)