[FFmpeg-cvslog] ffv1enc_vulkan: support 8 and 16-bit 2-plane YUV formats

Lynne git at videolan.org
Thu May 1 10:35:02 EEST 2025


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Tue Apr 29 10:01:21 2025 +0200| [707c04fe0613ec9daa91361b889d5f9eedf93c5c] | committer: Lynne

ffv1enc_vulkan: support 8 and 16-bit 2-plane YUV formats

This adds support for all 8-bit and 16-bit 2-plane formats.
P010 and others require more work as the data's LSB-padded.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=707c04fe0613ec9daa91361b889d5f9eedf93c5c
---

 libavcodec/ffv1enc.c            |  6 ++++++
 libavcodec/ffv1enc_vulkan.c     |  8 ++++++--
 libavcodec/vulkan/ffv1_enc.comp | 21 ++++++++++++++-------
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 6ab648fd80..40209f9935 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -839,6 +839,9 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
             s->bits_per_raw_sample = 14;
         s->packed_at_lsb = 1;
     case AV_PIX_FMT_GRAY16:
+    case AV_PIX_FMT_P016:
+    case AV_PIX_FMT_P216:
+    case AV_PIX_FMT_P416:
     case AV_PIX_FMT_YUV444P16:
     case AV_PIX_FMT_YUV422P16:
     case AV_PIX_FMT_YUV420P16:
@@ -859,6 +862,9 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
         s->version = FFMAX(s->version, 1);
     case AV_PIX_FMT_GRAY8:
     case AV_PIX_FMT_YA8:
+    case AV_PIX_FMT_NV12:
+    case AV_PIX_FMT_NV16:
+    case AV_PIX_FMT_NV24:
     case AV_PIX_FMT_YUV444P:
     case AV_PIX_FMT_YUV440P:
     case AV_PIX_FMT_YUV422P:
diff --git a/libavcodec/ffv1enc_vulkan.c b/libavcodec/ffv1enc_vulkan.c
index 688c14fb81..42a98a5efa 100644
--- a/libavcodec/ffv1enc_vulkan.c
+++ b/libavcodec/ffv1enc_vulkan.c
@@ -141,6 +141,7 @@ typedef struct FFv1VkParameters {
     uint8_t micro_version;
     uint8_t force_pcm;
     uint8_t key_frame;
+    uint8_t components;
     uint8_t planes;
     uint8_t codec_planes;
     uint8_t transparency;
@@ -149,7 +150,7 @@ typedef struct FFv1VkParameters {
     uint8_t ec;
     uint8_t ppi;
     uint8_t chunks;
-    uint8_t padding[2];
+    uint8_t padding[1];
 } FFv1VkParameters;
 
 static void add_push_data(FFVulkanShader *shd)
@@ -173,6 +174,7 @@ static void add_push_data(FFVulkanShader *shd)
     GLSLC(1,    uint8_t micro_version;                                        );
     GLSLC(1,    uint8_t force_pcm;                                            );
     GLSLC(1,    uint8_t key_frame;                                            );
+    GLSLC(1,    uint8_t components;                                           );
     GLSLC(1,    uint8_t planes;                                               );
     GLSLC(1,    uint8_t codec_planes;                                         );
     GLSLC(1,    uint8_t transparency;                                         );
@@ -181,7 +183,7 @@ static void add_push_data(FFVulkanShader *shd)
     GLSLC(1,    uint8_t ec;                                                   );
     GLSLC(1,    uint8_t ppi;                                                  );
     GLSLC(1,    uint8_t chunks;                                               );
-    GLSLC(1,    uint8_t padding[2];                                           );
+    GLSLC(1,    uint8_t padding[1];                                           );
     GLSLC(0, };                                                               );
     ff_vk_shader_add_push_const(shd, 0, sizeof(FFv1VkParameters),
                                 VK_SHADER_STAGE_COMPUTE_BIT);
@@ -326,6 +328,7 @@ static int vulkan_encode_ffv1_submit_frame(AVCodecContext *avctx,
 
     int has_inter = avctx->gop_size > 1;
     uint32_t context_count = f->context_count[f->context_model];
+    const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
 
     VkImageView in_views[AV_NUM_DATA_POINTERS];
     VkImageView intermediate_views[AV_NUM_DATA_POINTERS];
@@ -498,6 +501,7 @@ static int vulkan_encode_ffv1_submit_frame(AVCodecContext *avctx,
         .micro_version = f->micro_version,
         .force_pcm = fv->force_pcm,
         .key_frame = f->key_frame,
+        .components = fmt_desc->nb_components,
         .planes = av_pix_fmt_count_planes(avctx->sw_pix_fmt),
         .codec_planes = f->plane_count,
         .transparency = f->transparency,
diff --git a/libavcodec/vulkan/ffv1_enc.comp b/libavcodec/vulkan/ffv1_enc.comp
index 880d3a37f0..4b851fd711 100644
--- a/libavcodec/vulkan/ffv1_enc.comp
+++ b/libavcodec/vulkan/ffv1_enc.comp
@@ -26,14 +26,18 @@ void encode_slice(inout SliceContext sc, const uint slice_idx)
 
 #ifndef GOLOMB
     if (sc.slice_coding_mode == 1) {
-        for (int p = 0; p < planes; p++) {
+        for (int c = 0; c < components; c++) {
 
             int h = sc.slice_dim.y;
-            if (p > 0 && p < 3)
+            if (c > 0 && c < 3)
                 h >>= chroma_shift.y;
 
+            /* Takes into account dual-plane YUV formats */
+            int p = min(c, planes - 1);
+            int comp = c - p;
+
             for (int y = 0; y < h; y++)
-                encode_line_pcm(sc, y, p, 0, bits);
+                encode_line_pcm(sc, y, p, comp, bits);
         }
     } else
 #endif
@@ -41,18 +45,21 @@ void encode_slice(inout SliceContext sc, const uint slice_idx)
         uint64_t slice_state_off = uint64_t(slice_state) +
                                    slice_idx*plane_state_size*codec_planes;
 
-        for (int p = 0; p < planes; p++) {
+        for (int c = 0; c < components; c++) {
             int run_index = 0;
 
             int h = sc.slice_dim.y;
-            if (p > 0 && p < 3)
+            if (c > 0 && c < 3)
                 h >>= chroma_shift.y;
 
+            int p = min(c, planes - 1);
+            int comp = c - p;
+
             for (int y = 0; y < h; y++)
-                encode_line(sc, slice_state_off, y, p, 0, bits, run_index);
+                encode_line(sc, slice_state_off, y, p, comp, bits, run_index);
 
             /* For the second chroma plane, reuse the first plane's state */
-            if (p != 1)
+            if (c != 1)
                 slice_state_off += plane_state_size;
         }
     }



More information about the ffmpeg-cvslog mailing list