From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id EAAE14BCA4
	for <ffmpegdev@gitmailbox.com>; Mon, 31 Mar 2025 02:38:32 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 75CD7687B0C;
	Mon, 31 Mar 2025 05:38:05 +0300 (EEST)
Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CDAFA687CA7
 for <ffmpeg-devel@ffmpeg.org>; Mon, 31 Mar 2025 05:37:56 +0300 (EEST)
DKIM-Signature: v=1; a=rsa-sha256; s=202405r; d=lynne.ee; c=relaxed/relaxed;
 h=Message-ID:Date:Subject:To:From; t=1743388675; bh=0gjv44KL//DdzBetvOphiHO
 9UIp42+s0uLByal8gE0E=; b=crYFLt5gvqZ8Im41T54rJREX7cJ1j9qBuO8/2tZvMdswRbahAS
 s110Pm+J9rUQT85uRgVzP+rG5QbO7EOivmc4bIgXnRFMauK0MH2Aw38eObf5fbZtd7EptKWQFMs
 7yBsCSmG+rapW2VdA23ERKOkHfGyDjxYqzBlin6PrOm8ahBG9Kve1ZId2UFi0BUySDRQFDbOsyy
 qYSNwQX27W3PDbtgPhgFXflmqzaz3njjR3uhgABvBD+itJcNTwA8xf2DebxHNgcooZ6Y3OXp0xp
 IzI5br5Yi0FyNgJ+YJxjO9Ml6c+tdZvlN2MdEINiE9kB2QU/D5oVFlMuPIVoVemNwIQ==;
DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed;
 h=Message-ID:Date:Subject:To:From; t=1743388675; bh=0gjv44KL//DdzBetvOphiHO
 9UIp42+s0uLByal8gE0E=; b=Kr36gzSLMlE60eSE4W37IpFpqUZnZN7ZIlnWFn4PIggjrvnGKT
 9/xut16+twSUjenp5FeiKFf/RDekqDGXpeAg==;
From: Lynne <dev@lynne.ee>
To: ffmpeg-devel@ffmpeg.org
Date: Mon, 31 Mar 2025 04:37:40 +0200
Message-ID: <20250331023753.285499-4-dev@lynne.ee>
X-Mailer: git-send-email 2.49.0
In-Reply-To: <20250331023753.285499-1-dev@lynne.ee>
References: <20250331023753.285499-1-dev@lynne.ee>
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH 4/6] vulkan_decode: add a generic start_frame
 function
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Lynne <dev@lynne.ee>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250331023753.285499-4-dev@lynne.ee/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

---
 libavcodec/vulkan_decode.c | 38 ++++++++++++++++++++++++++++++++++----
 libavcodec/vulkan_decode.h |  6 ++++++
 2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 058efe3037..893f8fca3d 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -151,8 +151,6 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic,
     int err;
     FFVulkanDecodeShared *ctx = dec->shared_ctx;
 
-    vkpic->slices_size = 0;
-
     /* If the decoder made a blank frame to make up for a missing ref, or the
      * frame is the current frame so it's missing one, create a re-representation */
     if (vkpic->view.ref[0])
@@ -209,8 +207,6 @@ int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic,
     FFVulkanDecodeShared *ctx = dec->shared_ctx;
     AVHWFramesContext *frames = (AVHWFramesContext *)pic->hw_frames_ctx->data;
 
-    vkpic->slices_size = 0;
-
     if (vkpic->view.ref[0])
         return 0;
 
@@ -248,6 +244,31 @@ int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic,
     return 0;
 }
 
+int ff_vk_decode_start_frame(AVCodecContext *avctx, FFVulkanDecodePicture *vp,
+                             const AVBufferRef *buffer_ref, int complete)
+{
+    int err;
+    FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
+    FFVulkanDecodeShared *ctx = dec->shared_ctx;
+
+    vp->nb_slices = 0;
+    vp->slices_size = 0;
+
+    /* Host map the input slices data if supported */
+    if (complete && ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY) {
+        err = ff_vk_host_map_buffer(&ctx->s, &vp->slices_buf, buffer_ref->data,
+                                    buffer_ref,
+                                    DECODER_IS_SDR(avctx->codec_id) ?
+                                    (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
+                                     VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) :
+                                    VK_BUFFER_USAGE_VIDEO_DECODE_SRC_BIT_KHR);
+        if (err < 0)
+            return err;
+    }
+
+    return 0;
+}
+
 int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp,
                            const uint8_t *data, size_t size, int add_startcode)
 {
@@ -268,6 +289,15 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp,
         return AVERROR(EINVAL);
 
     vkbuf = vp->slices_buf ? (FFVkBuffer *)vp->slices_buf->data : NULL;
+
+    /* Buffer exists, and is a single complete host-mapped buffer. */
+    if (vkbuf && vkbuf->host_ref) {
+        vp->slice_offsets[vp->nb_slices] = vp->slices_size;
+        vp->nb_slices = vp->nb_slices + 1;
+        vp->slices_size += startcode_len + size;
+        return 0;
+    }
+
     if (!vkbuf || vkbuf->size < new_size) {
         int err;
         AVBufferRef *new_ref;
diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h
index 6c3e1486b0..103be09943 100644
--- a/libavcodec/vulkan_decode.h
+++ b/libavcodec/vulkan_decode.h
@@ -145,6 +145,12 @@ int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic,
                                    FFVulkanDecodePicture *vkpic, int is_current,
                                    enum FFVkShaderRepFormat rep_fmt, int alloc_dpb);
 
+/**
+ * Generic start_frame function.
+ */
+int ff_vk_decode_start_frame(AVCodecContext *avctx, FFVulkanDecodePicture *vp,
+                             const AVBufferRef *buffer_ref, int complete);
+
 /**
  * Add slice data to frame.
  */
-- 
2.49.0
_______________________________________________
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".