Commit 8db0d5b004 for ffmpeg

commit 8db0d5b0046bbb6f33eab4554c42a0d7ab82dc56
Author: Uraza Aru <271304759+urzaru@users.noreply.github.com>
Date:   Wed Oct 14 02:14:02 2026 +0500

    avcodec/vulkan_encode_av1: name the second P reference consistently

    For P frames with two references, ref_frame_idx[] puts the older
    reference under GOLDEN and points every other name, LAST2 included, at
    the newest one. set_name_slot() however gives the older reference the
    first free allowed name, LAST2, in referenceNameSlotIndices. The
    encoder then predicts LAST2 blocks from the older picture while
    decoders, following the frame header, use the newer one, and the
    picture drifts: on an RTX 4090, 1280x720 CBR 10 Mbit/s without B-frames
    fell from 44.8 dB PSNR on the key frame to 12.8 dB by frame 299.

    Index ref_frame_idx[] with the name set_name_slot() returns, so both
    mappings agree. The B-frame branch already keeps them in step.

    Fixes #25046.

    Assisted-by: Claude Opus 5.5
    Signed-off-by: Uraza Aru <271304759+urzaru@users.noreply.github.com>

diff --git a/libavcodec/vulkan_encode_av1.c b/libavcodec/vulkan_encode_av1.c
index 379b9f2eb9..9f864732df 100644
--- a/libavcodec/vulkan_encode_av1.c
+++ b/libavcodec/vulkan_encode_av1.c
@@ -188,6 +188,7 @@ static int init_pic_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic,

     uint32_t ref_name_mask = 0x0;
     int name_slots[STD_VIDEO_AV1_REFS_PER_FRAME];
+    int name;

     StdVideoAV1Segmentation *segmentation = &ap->segmentation;
     StdVideoAV1LoopFilter  *loop_filter = &ap->loop_filter;
@@ -397,10 +398,10 @@ static int init_pic_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic,
             }
             ref = pic->refs[0][pic->nb_refs[0] - 2];
             ap_ref = ref->codec_priv;
-            ap->av1pic_info.ref_frame_idx[3] = ap_ref->slot;
             ap->av1pic_info.ref_order_hint[ap_ref->slot] = ref->display_order - ap_ref->last_idr_frame;
-//            vpic->ref_frame_ctrl_l0.fields.search_idx1 = AV1_REF_FRAME_GOLDEN;
-            set_name_slot(ap_ref->av1pic_info.current_frame_id, name_slots, ref_name_mask, 0);
+            /* The header must name the same reference the encoder uses for it. */
+            name = set_name_slot(ap_ref->av1pic_info.current_frame_id, name_slots, ref_name_mask, 0);
+            ap->av1pic_info.ref_frame_idx[name] = ap_ref->slot;
         }
         break;
     case FF_HW_PICTURE_TYPE_B: