[FFmpeg-devel] [PATCH] vulkan_vp9: Fix frame threading (PR #20176)
bcheng
code at ffmpeg.org
Fri Aug 8 15:48:13 EEST 2025
PR #20176 opened by bcheng
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20176
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20176.patch
The original cleanup of frame_id_alloc_mask was done in free_frame_priv
which may be called after the start_frame for the next few frames,
causing the frame_id slots to be exhausted. Instead, decide the in-use
frame_id slots by checking the frame_id present in the DPB as we need it.
From 04147adb519fd4ac9edba14628647a62fed56a00 Mon Sep 17 00:00:00 2001
From: Benjamin Cheng <ben at bcheng.me>
Date: Fri, 8 Aug 2025 08:42:57 -0400
Subject: [PATCH] vulkan_vp9: Fix frame threading
The original cleanup of frame_id_alloc_mask was done in free_frame_priv
which may be called after the start_frame for the next few frames,
causing the frame_id slots to be exhausted. Instead, decide the in-use
frame_id slots by checking the frame_id present in the DPB as we need it.
---
libavcodec/vulkan_vp9.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/libavcodec/vulkan_vp9.c b/libavcodec/vulkan_vp9.c
index 82e26cede9..f8ce73dc90 100644
--- a/libavcodec/vulkan_vp9.c
+++ b/libavcodec/vulkan_vp9.c
@@ -110,6 +110,7 @@ static int vk_vp9_start_frame(AVCodecContext *avctx,
int err;
int ref_count = 0;
const VP9SharedContext *s = avctx->priv_data;
+ uint32_t frame_id_alloc_mask = 0;
const VP9Frame *pic = &s->frames[CUR_FRAME];
FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
@@ -118,17 +119,24 @@ static int vk_vp9_start_frame(AVCodecContext *avctx,
VP9VulkanDecodePicture *ap = pic->hwaccel_picture_private;
FFVulkanDecodePicture *vp = &ap->vp;
+ /* Use the current frame_ids in ref_frames[] to decide occupied frame_ids */
+ for (int i = 0; i < STD_VIDEO_VP9_NUM_REF_FRAMES; i++) {
+ const VP9VulkanDecodePicture* rp = s->ref_frames[i].hwaccel_picture_private;
+ if (rp)
+ frame_id_alloc_mask |= 1 << rp->frame_id;
+ }
+
if (!ap->frame_id_set) {
unsigned slot_idx = 0;
for (unsigned i = 0; i < 32; i++) {
- if (!(dec->frame_id_alloc_mask & (1 << i))) {
+ if (!(frame_id_alloc_mask & (1 << i))) {
slot_idx = i;
break;
}
}
ap->frame_id = slot_idx;
ap->frame_id_set = 1;
- dec->frame_id_alloc_mask |= (1 << slot_idx);
+ frame_id_alloc_mask |= (1 << slot_idx);
}
for (int i = 0; i < STD_VIDEO_VP9_REFS_PER_FRAME; i++) {
@@ -338,10 +346,6 @@ static void vk_vp9_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
AVHWDeviceContext *hwctx = _hwctx.nc;
VP9VulkanDecodePicture *ap = data;
- /* Workaround for a spec issue. */
- if (ap->frame_id_set)
- ap->dec->frame_id_alloc_mask &= ~(1 << ap->frame_id);
-
/* Free frame resources, this also destroys the session parameters. */
ff_vk_decode_free_frame(hwctx, &ap->vp);
}
--
2.49.1
More information about the ffmpeg-devel
mailing list