Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Lynne <dev@lynne.ee>
To: ffmpeg-devel@ffmpeg.org
Cc: Lynne <dev@lynne.ee>
Subject: [FFmpeg-devel] [PATCH 2/2] ffv1enc_vulkan: support 2-plane YUV formats
Date: Tue, 29 Apr 2025 10:07:52 +0200
Message-ID: <20250429080759.319563-2-dev@lynne.ee> (raw)
In-Reply-To: <20250429080759.319563-1-dev@lynne.ee>

This adds support for NV12 and P010.
More will be added later.
---
 libavcodec/ffv1enc.c            |  2 ++
 libavcodec/ffv1enc_vulkan.c     |  8 ++++++--
 libavcodec/vulkan/ffv1_enc.comp | 21 ++++++++++++++-------
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 6ab648fd80..e215ab20a4 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -813,6 +813,7 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
         if (!avctx->bits_per_raw_sample)
             s->bits_per_raw_sample = 9;
     case AV_PIX_FMT_GRAY10:
+    case AV_PIX_FMT_P010:
     case AV_PIX_FMT_YUV444P10:
     case AV_PIX_FMT_YUV440P10:
     case AV_PIX_FMT_YUV420P10:
@@ -859,6 +860,7 @@ 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_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;
         }
     }
-- 
2.49.0.395.g12beb8f557c
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

      reply	other threads:[~2025-04-29  8:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-29  8:07 [FFmpeg-devel] [PATCH 1/2] hwcontext_vulkan: support AV_PIX_FMT_GBRP Lynne
2025-04-29  8:07 ` Lynne [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250429080759.319563-2-dev@lynne.ee \
    --to=dev@lynne.ee \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git