From 0ae15fffefd66d78828902176da25d19ae652a0e Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 8 Sep 2026 10:15:13 +0900 Subject: [PATCH] vulkan_decode: do not bind the current picture twice when its slot is active When decoding the second field of a pair, the picture is already bound as an active reference at its DPB slot, since the first field made it one. Appending it again as an inactive slot duplicates the picture resource within the coding scope, which is not allowed (VUID-vkCmdBeginVideoCodingKHR-pPictureResource-07238). --- libavcodec/vulkan_decode.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 2ee78a3fba..961a62fbb7 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -460,12 +460,19 @@ int ff_vk_decode_frame(AVCodecContext *avctx, FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &ctx->exec_pool); - /* The current decoding reference has to be bound as an inactive reference */ - VkVideoReferenceSlotInfoKHR *cur_vk_ref; - cur_vk_ref = (void *)&decode_start.pReferenceSlots[decode_start.referenceSlotCount]; - cur_vk_ref[0] = vp->ref_slot; - cur_vk_ref[0].slotIndex = -1; - decode_start.referenceSlotCount++; + /* The current picture's resource has to be bound as an inactive + * reference, unless its slot is already bound as an active one, as when + * decoding the second field of a pair. */ + int cur_bound = 0; + for (int i = 0; i < decode_start.referenceSlotCount; i++) + cur_bound |= decode_start.pReferenceSlots[i].slotIndex == vp->ref_slot.slotIndex; + if (!cur_bound) { + VkVideoReferenceSlotInfoKHR *cur_vk_ref; + cur_vk_ref = (void *)&decode_start.pReferenceSlots[decode_start.referenceSlotCount]; + cur_vk_ref[0] = vp->ref_slot; + cur_vk_ref[0].slotIndex = -1; + decode_start.referenceSlotCount++; + } sd_buf = vp->slices_buf;