Re: [FFmpeg-devel] [PATCH v4 2/2] lavc/vulkan_av1: port to the new stable API

2024-02-12 Thread Benjamin Cheng via ffmpeg-devel
On Sun Feb 11, 2024 at 10:15 AM EST, Lynne wrote:
> From: Lynne 
> Date: Fri, 19 Jan 2024 10:49:02 +1000
> Subject: [PATCH v4 2/2] lavc/vulkan_av1: port to the new stable API
> 
> Most of this patch was written by Dave Airlie ,
> with some additions by me.
> ---
>  configure |   4 +-
>  libavcodec/Makefile   |   3 +-
>  libavcodec/av1.h  |   2 +
>  libavcodec/vulkan_av1.c   | 477 ++
>  libavcodec/vulkan_decode.c|  24 +-
>  libavcodec/vulkan_decode.h|   2 +-
>  libavcodec/vulkan_video.c |   2 +-
>  libavcodec/vulkan_video.h |   2 -
>  libavcodec/vulkan_video_codec_av1std.h| 403 ---
>  libavcodec/vulkan_video_codec_av1std_decode.h |  36 --
>  libavutil/hwcontext_vulkan.c  |   2 +-
>  libavutil/vulkan_functions.h  |   2 +-
>  libavutil/vulkan_loader.h |   2 +-
>  13 files changed, 277 insertions(+), 684 deletions(-)
>  delete mode 100644 libavcodec/vulkan_video_codec_av1std.h
>  delete mode 100644 libavcodec/vulkan_video_codec_av1std_decode.h
> 
> diff --git a/configure b/configure
> index f72533b7d2..9a3a451115 100755
> --- a/configure
> +++ b/configure
> @@ -7225,8 +7225,8 @@ enabled crystalhd && check_lib crystalhd "stdint.h 
> libcrystalhd/libcrystalhd_if.
>   "in maintaining it."
>  
>  if enabled vulkan; then
> -check_pkg_config_header_only vulkan "vulkan >= 1.3.255" 
> "vulkan/vulkan.h" "defined VK_VERSION_1_3" ||
> -check_cpp_condition vulkan "vulkan/vulkan.h" 
> "defined(VK_VERSION_1_4) || (defined(VK_VERSION_1_3) && VK_HEADER_VERSION >= 
> 255)"
> +check_pkg_config_header_only vulkan "vulkan >= 1.3.277" 
> "vulkan/vulkan.h" "defined VK_VERSION_1_3" ||
> +check_cpp_condition vulkan "vulkan/vulkan.h" 
> "defined(VK_VERSION_1_4) || (defined(VK_VERSION_1_3) && VK_HEADER_VERSION >= 
> 277)"
>  fi
>  
>  if disabled vulkan; then
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 470d7cb9b1..581415f3b7 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1262,7 +1262,6 @@ SKIPHEADERS+= %_tablegen.h  
> \
>aacenc_quantization.h \
>aacenc_quantization_misc.h\
>bitstream_template.h  \
> -  vulkan_video_codec_av1std.h   \
>$(ARCH)/vpx_arith.h  \
>  
>  SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h
> @@ -1285,7 +1284,7 @@ SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h
>  SKIPHEADERS-$(CONFIG_VAAPI)+= vaapi_decode.h vaapi_hevc.h 
> vaapi_encode.h
>  SKIPHEADERS-$(CONFIG_VDPAU)+= vdpau.h vdpau_internal.h
>  SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX) += videotoolbox.h vt_internal.h
> -SKIPHEADERS-$(CONFIG_VULKAN)   += vulkan.h vulkan_video.h 
> vulkan_decode.h vulkan_video_codec_av1std_decode.h
> +SKIPHEADERS-$(CONFIG_VULKAN)   += vulkan.h vulkan_video.h 
> vulkan_decode.h
>  SKIPHEADERS-$(CONFIG_V4L2_M2M) += v4l2_buffers.h v4l2_context.h 
> v4l2_m2m.h
>  SKIPHEADERS-$(CONFIG_ZLIB) += zlib_wrapper.h
>  
> diff --git a/libavcodec/av1.h b/libavcodec/av1.h
> index 8704bc41c1..18d5fa9e7f 100644
> --- a/libavcodec/av1.h
> +++ b/libavcodec/av1.h
> @@ -121,6 +121,8 @@ enum {
>  AV1_DIV_LUT_NUM   = 257,
>  
>  AV1_MAX_LOOP_FILTER = 63,
> +
> +AV1_RESTORATION_TILESIZE_MAX = 256,
>  };
>  
>  
> diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
> index 9730e4b08d..641ee3e4bf 100644
> --- a/libavcodec/vulkan_av1.c
> +++ b/libavcodec/vulkan_av1.c
> @@ -31,22 +31,36 @@ const VkExtensionProperties ff_vk_dec_av1_ext = {
>  typedef struct AV1VulkanDecodePicture {
>  FFVulkanDecodePicture   vp;
>  
> -/* Workaround for a spec issue.
> - *Can be removed once no longer needed, and threading can be enabled. */
> +/* TODO: investigate if this can be removed to make decoding completely
> + * independent. */
>  FFVulkanDecodeContext  *dec;
>  
> -StdVideoAV1MESATiletiles[MAX_TILES];
> -StdVideoAV1MESATileListtile_list;
> -const uint32_t*tile_offsets;
> +uint32_t tile_count;
> +uint32_t tile_sizes[MAX_TILES];
> +const uint32_t *tile_offsets;
>  
>  /* Current picture */
> -VkVideoDecodeAV1DpbSlotInfoMESAvkav1_ref;
> -StdVideoAV1MESAFrameHeader av1_frame_header;
> -VkVideoDecodeAV1PictureInfoMESAav1_pic_info;
> +StdVideoDecodeAV1ReferenceInfo std_ref;
> +VkVideoDecodeAV1DpbSlotInfoKHR vkav1_ref;
> +uint16_t width_in_sbs_minus1[64];
> +uint16_t height_in_sbs_minus1[64];
> +

Re: [FFmpeg-devel] [PATCH] libavcodec/dxva2.c: fix dxva2 does not support H264 baseline profile

2023-10-14 Thread Benjamin Cheng via ffmpeg-devel
On Fri Oct 13, 2023 at 11:59 PM EDT, xyz1001 wrote:
> dxva2 fail to init when decode h264 with baseline profile becase 
> `prof_h264_high` does not contains `AV_PROFILE_H264_BASELINE` and 
> `dxva_check_codec_compatibility` will return error

prof_h264_high uses either DXVA2_ModeH264_E or DXVA2_ModeH264_F, which
only supports up to H.264 High, and H.264 Baseline has features that are
not in High. You have to use a different DXVA profile for Baseline.

> ---
>  libavcodec/dxva2.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
> index d7bc587562..e6b83f89cc 100644
> --- a/libavcodec/dxva2.c
> +++ b/libavcodec/dxva2.c
> @@ -61,7 +61,8 @@ typedef struct dxva_mode {
>  static const int prof_mpeg2_main[]   = {AV_PROFILE_MPEG2_SIMPLE,
>  AV_PROFILE_MPEG2_MAIN,
>  AV_PROFILE_UNKNOWN};
> -static const int prof_h264_high[]= {AV_PROFILE_H264_CONSTRAINED_BASELINE,
> +static const int prof_h264_high[]= {AV_PROFILE_H264_BASELINE,
> +AV_PROFILE_H264_CONSTRAINED_BASELINE,
>  AV_PROFILE_H264_MAIN,
>  AV_PROFILE_H264_HIGH,
>  AV_PROFILE_UNKNOWN};

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v2] vulkan_h264: fix long-term ref handling

2023-10-13 Thread Benjamin Cheng via ffmpeg-devel
h->long_ref isn't guaranteed to be contiguously filled. Use the approach
from both vaapi_h264 and vdpau_h264 which goes through the 16 frames in
h->long_ref to find the LTR entries.

Fixes MR2_MW_A.264 from JVT-AVC_V1.

---
 libavcodec/vulkan_h264.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c
index 32ef32d640..1bbef7b0e8 100644
--- a/libavcodec/vulkan_h264.c
+++ b/libavcodec/vulkan_h264.c
@@ -406,10 +406,14 @@ static int vk_h264_start_frame(AVCodecContext  
*avctx,
 }
 
 /* Fill in long-term refs */
-for (int r = 0, i = h->short_ref_count; i < h->short_ref_count + 
h->long_ref_count; i++, r++) {
+for (int r = 0, i = h->short_ref_count; r < H264_MAX_DPB_FRAMES &&
+ i < h->short_ref_count + h->long_ref_count; r++) {
+if (!h->long_ref[r])
+continue;
+
 dpb_slot_index = 0;
-for (unsigned slot = 0; slot < H264_MAX_PICTURE_COUNT; slot++) {
-if (h->long_ref[i] == >DPB[slot]) {
+for (unsigned slot = 0; slot < 16; slot++) {
+if (h->long_ref[r] == >DPB[slot]) {
 dpb_slot_index = slot;
 break;
 }
@@ -422,6 +426,7 @@ static int vk_h264_start_frame(AVCodecContext  
*avctx,
 dpb_slot_index);
 if (err < 0)
 return err;
+i++;
 }
 
 hp->h264pic = (StdVideoDecodeH264PictureInfo) {
-- 
2.42.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] vulkan_hevc: handle non-contiguous SPS/PPS/VPS ids

2023-09-30 Thread Benjamin Cheng via ffmpeg-devel
Some clips (i.e. SLIST_B_Sony_9) will use PPS 0 and 8, before PPS 1-7.
vulkan_hevc expects {sps,pps,vps}_list to be filled in order, which
causes PPS 8 to not be added to the Vulkan session params when it is
being used by a picture.

This removes the expectation that these lists are filled in order. The
indicies into vps_list are saved since there are multiple usages of it.

This also fixes a bug with some clips (i.e. PPS_A_qualcomm_7) which use
all 64 available PPS slots, causing the old loop to think there are more
than 64 PPS-es.
---
 libavcodec/vulkan_hevc.c | 46 +++-
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index 52f223ceb2..9685ec14c8 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -70,6 +70,7 @@ typedef struct HEVCHeaderSet {
 
 static int alloc_hevc_header_structs(FFVulkanDecodeContext *s,
  int nb_vps,
+ const int 
vps_list_idx[HEVC_MAX_VPS_COUNT],
  AVBufferRef * const 
vps_list[HEVC_MAX_VPS_COUNT])
 {
 uint8_t *data_ptr;
@@ -77,7 +78,7 @@ static int alloc_hevc_header_structs(FFVulkanDecodeContext *s,
 
 size_t buf_size = sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS);
 for (int i = 0; i < nb_vps; i++) {
-const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data;
+const HEVCVPS *vps = (const HEVCVPS *)vps_list[vps_list_idx[i]]->data;
 buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters;
 }
 
@@ -96,7 +97,7 @@ static int alloc_hevc_header_structs(FFVulkanDecodeContext *s,
 hdr->hvps = (HEVCHeaderVPS *)(data_ptr + sizeof(HEVCHeaderSet));
 data_ptr += sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS);
 for (int i = 0; i < nb_vps; i++) {
-const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data;
+const HEVCVPS *vps = (const HEVCVPS *)vps_list[vps_list_idx[i]]->data;
 hdr->hvps[i].sls = (HEVCHeaderVPSSet *)data_ptr;
 data_ptr += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters;
 }
@@ -655,13 +656,15 @@ static int vk_hevc_create_params(AVCodecContext *avctx, 
AVBufferRef **buf)
 .videoSessionParametersTemplate = NULL,
 };
 
-int nb_vps = 0;
 HEVCHeaderSet *hdr;
+int nb_vps = 0;
+int vps_list_idx[HEVC_MAX_VPS_COUNT];
 
-for (int i = 0; h->ps.vps_list[i]; i++)
-nb_vps++;
+for (int i = 0; i < HEVC_MAX_VPS_COUNT; i++)
+if (h->ps.vps_list[i])
+vps_list_idx[nb_vps++] = i;
 
-err = alloc_hevc_header_structs(dec, nb_vps, h->ps.vps_list);
+err = alloc_hevc_header_structs(dec, nb_vps, vps_list_idx, h->ps.vps_list);
 if (err < 0)
 return err;
 
@@ -672,26 +675,31 @@ static int vk_hevc_create_params(AVCodecContext *avctx, 
AVBufferRef **buf)
 h265_params_info.pStdVPSs = hdr->vps;
 
 /* SPS list */
-for (int i = 0; h->ps.sps_list[i]; i++) {
-const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data;
-set_sps(sps_l, i, >hsps[i].scaling, >hsps[i].vui_header,
->hsps[i].vui, >sps[i], hdr->hsps[i].nal_hdr,
-hdr->hsps[i].vcl_hdr, >hsps[i].ptl, >hsps[i].dpbm,
->hsps[i].pal, hdr->hsps[i].str, >hsps[i].ltr);
-h265_params_info.stdSPSCount++;
+for (int i = 0; i < HEVC_MAX_SPS_COUNT; i++) {
+if (h->ps.sps_list[i]) {
+const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data;
+int idx = h265_params_info.stdSPSCount++;
+set_sps(sps_l, i, >hsps[idx].scaling, 
>hsps[idx].vui_header,
+>hsps[idx].vui, >sps[idx], 
hdr->hsps[idx].nal_hdr,
+hdr->hsps[idx].vcl_hdr, >hsps[idx].ptl, 
>hsps[idx].dpbm,
+>hsps[idx].pal, hdr->hsps[idx].str, 
>hsps[idx].ltr);
+}
 }
 
 /* PPS list */
-for (int i = 0; h->ps.pps_list[i]; i++) {
-const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data;
-const HEVCSPS *sps_l = (const HEVCSPS 
*)h->ps.sps_list[pps_l->sps_id]->data;
-set_pps(pps_l, sps_l, >hpps[i].scaling, >pps[i], 
>hpps[i].pal);
-h265_params_info.stdPPSCount++;
+for (int i = 0; i < HEVC_MAX_PPS_COUNT; i++) {
+if (h->ps.pps_list[i]) {
+const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data;
+const HEVCSPS *sps_l = (const HEVCSPS 
*)h->ps.sps_list[pps_l->sps_id]->data;
+int idx = h265_params_info.stdPPSCount++;
+set_pps(pps_l, sps_l, >hpps[idx].scaling,
+>pps[idx], >hpps[idx].pal);
+}
 }
 
 /* VPS list */
 for (int i = 0; i < nb_vps; i++) {
-const HEVCVPS *vps_l = (const HEVCVPS *)h->ps.vps_list[i]->data;
+const HEVCVPS *vps_l = (const HEVCVPS 
*)h->ps.vps_list[vps_list_idx[i]]->data;
 set_vps(vps_l, >vps[i], >hvps[i].ptl, 

[FFmpeg-devel] [PATCH] vulkan_hevc: handle non-contiguous SPS/PPS/VPS ids

2023-09-30 Thread Benjamin Cheng via ffmpeg-devel
Some clips (i.e. SLIST_B_Sony_9) will use PPS 0 and 8, before PPS 1-7.
vulkan_hevc expects {sps,pps,vps}_list to be filled in order, which
causes PPS 8 to not be added to the Vulkan session params when it is
being used by a picture.

This removes the expectation that these lists are filled in order. The
indicies into vps_list are saved since there are multiple usages of it.

This also fixes a bug with some clips (i.e. PPS_A_qualcomm_7) which use
all 64 available PPS slots, causing the old loop to think there are more
than 64 PPS-es.
---
 libavcodec/vulkan_hevc.c | 47 +++-
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index 52f223ceb2..a8265acf32 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -70,6 +70,7 @@ typedef struct HEVCHeaderSet {
 
 static int alloc_hevc_header_structs(FFVulkanDecodeContext *s,
  int nb_vps,
+ const int 
vps_list_idx[HEVC_MAX_VPS_COUNT],
  AVBufferRef * const 
vps_list[HEVC_MAX_VPS_COUNT])
 {
 uint8_t *data_ptr;
@@ -77,7 +78,7 @@ static int alloc_hevc_header_structs(FFVulkanDecodeContext *s,
 
 size_t buf_size = sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS);
 for (int i = 0; i < nb_vps; i++) {
-const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data;
+const HEVCVPS *vps = (const HEVCVPS *)vps_list[vps_list_idx[i]]->data;
 buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters;
 }
 
@@ -96,7 +97,7 @@ static int alloc_hevc_header_structs(FFVulkanDecodeContext *s,
 hdr->hvps = (HEVCHeaderVPS *)(data_ptr + sizeof(HEVCHeaderSet));
 data_ptr += sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS);
 for (int i = 0; i < nb_vps; i++) {
-const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data;
+const HEVCVPS *vps = (const HEVCVPS *)vps_list[vps_list_idx[i]]->data;
 hdr->hvps[i].sls = (HEVCHeaderVPSSet *)data_ptr;
 data_ptr += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters;
 }
@@ -655,13 +656,15 @@ static int vk_hevc_create_params(AVCodecContext *avctx, 
AVBufferRef **buf)
 .videoSessionParametersTemplate = NULL,
 };
 
-int nb_vps = 0;
 HEVCHeaderSet *hdr;
+int nb_vps = 0;
+int vps_list_idx[HEVC_MAX_VPS_COUNT];
 
-for (int i = 0; h->ps.vps_list[i]; i++)
-nb_vps++;
+for (int i = 0; i < HEVC_MAX_VPS_COUNT; i++)
+if (h->ps.vps_list[i])
+vps_list_idx[nb_vps++] = i;
 
-err = alloc_hevc_header_structs(dec, nb_vps, h->ps.vps_list);
+err = alloc_hevc_header_structs(dec, nb_vps, vps_list_idx, h->ps.vps_list);
 if (err < 0)
 return err;
 
@@ -672,29 +675,33 @@ static int vk_hevc_create_params(AVCodecContext *avctx, 
AVBufferRef **buf)
 h265_params_info.pStdVPSs = hdr->vps;
 
 /* SPS list */
-for (int i = 0; h->ps.sps_list[i]; i++) {
-const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data;
-set_sps(sps_l, i, >hsps[i].scaling, >hsps[i].vui_header,
->hsps[i].vui, >sps[i], hdr->hsps[i].nal_hdr,
-hdr->hsps[i].vcl_hdr, >hsps[i].ptl, >hsps[i].dpbm,
->hsps[i].pal, hdr->hsps[i].str, >hsps[i].ltr);
-h265_params_info.stdSPSCount++;
+for (int i = 0; i < HEVC_MAX_SPS_COUNT; i++) {
+if (h->ps.sps_list[i]) {
+const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data;
+int idx = h265_params_info.stdSPSCount++;
+set_sps(sps_l, i, >hsps[idx].scaling, 
>hsps[idx].vui_header,
+>hsps[idx].vui, >sps[idx], 
hdr->hsps[idx].nal_hdr,
+hdr->hsps[idx].vcl_hdr, >hsps[idx].ptl, 
>hsps[idx].dpbm,
+>hsps[idx].pal, hdr->hsps[idx].str, 
>hsps[idx].ltr);
+}
 }
 
 /* PPS list */
-for (int i = 0; h->ps.pps_list[i]; i++) {
-const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data;
-const HEVCSPS *sps_l = (const HEVCSPS 
*)h->ps.sps_list[pps_l->sps_id]->data;
-set_pps(pps_l, sps_l, >hpps[i].scaling, >pps[i], 
>hpps[i].pal);
-h265_params_info.stdPPSCount++;
+for (int i = 0; i < HEVC_MAX_PPS_COUNT; i++) {
+if (h->ps.pps_list[i]) {
+const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data;
+const HEVCSPS *sps_l = (const HEVCSPS 
*)h->ps.sps_list[pps_l->sps_id]->data;
+int idx = h265_params_info.stdPPSCount++;
+set_pps(pps_l, sps_l, >hpps[idx].scaling,
+>pps[idx], >hpps[idx].pal);
+}
 }
 
 /* VPS list */
 for (int i = 0; i < nb_vps; i++) {
-const HEVCVPS *vps_l = (const HEVCVPS *)h->ps.vps_list[i]->data;
+const HEVCVPS *vps_l = (const HEVCVPS 
*)h->ps.vps_list[vps_list_idx[i]]->data;
 set_vps(vps_l, >vps[i], >hvps[i].ptl, 

[FFmpeg-devel] [PATCH] vulkan_h264: fix long-term ref handling

2023-09-22 Thread Benjamin Cheng via ffmpeg-devel
h->long_ref isn't guaranteed to be contiguously filled. Use the approach
from both vaapi_h264 and vdpau_h264 which goes through the 16 frames in
h->long_ref to find the LTR entries.

Fixes MR2_MW_A.264 from JVT-AVC_V1.
---
 libavcodec/vulkan_h264.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c
index 32ef32d640..4135188e7a 100644
--- a/libavcodec/vulkan_h264.c
+++ b/libavcodec/vulkan_h264.c
@@ -406,10 +406,14 @@ static int vk_h264_start_frame(AVCodecContext  
*avctx,
 }
 
 /* Fill in long-term refs */
-for (int r = 0, i = h->short_ref_count; i < h->short_ref_count + 
h->long_ref_count; i++, r++) {
+for (int r = 0, i = h->short_ref_count; r < H264_MAX_DPB_FRAMES &&
+ i < h->short_ref_count + h->long_ref_count; r++) {
+   if (!h->long_ref[r])
+   continue;
+
 dpb_slot_index = 0;
-for (unsigned slot = 0; slot < H264_MAX_PICTURE_COUNT; slot++) {
-if (h->long_ref[i] == >DPB[slot]) {
+for (unsigned slot = 0; slot < 16; slot++) {
+if (h->long_ref[r] == >DPB[slot]) {
 dpb_slot_index = slot;
 break;
 }
@@ -422,6 +426,7 @@ static int vk_h264_start_frame(AVCodecContext  
*avctx,
 dpb_slot_index);
 if (err < 0)
 return err;
+   i++;
 }
 
 hp->h264pic = (StdVideoDecodeH264PictureInfo) {
-- 
2.42.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] hwcontext_vulkan: guard unistd.h include

2023-09-22 Thread Benjamin Cheng via ffmpeg-devel
win32 typically doesn't have unistd.h, so always including it will break
MSVC builds. The usage of those POSIX functions are already guarded by
_WIN32, so use that to guard unistd.h include as well.
---
 libavutil/hwcontext_vulkan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index c676f4fc57..6c573abb8b 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -27,10 +27,10 @@
 #include "compat/w32dlfcn.h"
 #else
 #include 
+#include 
 #endif
 
 #include "thread.h"
-#include 
 
 #include "config.h"
 #include "pixdesc.h"
-- 
2.42.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] vulkan_h264: send scaling lists in zig-zag order

2023-08-21 Thread Benjamin Cheng via ffmpeg-devel
h264_ps turns the scaling lists into matrices with a raster scan order,
but Vulkan wants the scaling lists as originally defined.
---
 libavcodec/vulkan_h264.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c
index f38bb9057b..9fe0d194f5 100644
--- a/libavcodec/vulkan_h264.c
+++ b/libavcodec/vulkan_h264.c
@@ -145,12 +145,13 @@ static void set_sps(const SPS *sps,
 };
 
 for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_4X4_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList4x4[i], sps->scaling_matrix4[i],
-   STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix4));
+for (int j = 0; j < STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS; j++)
+vksps_scaling->ScalingList4x4[i][j] = 
sps->scaling_matrix4[i][ff_zigzag_scan[j]];
 
 for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList8x8[i], 
sps->scaling_matrix8[h264_scaling_list8_order[i]],
-   STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix8));
+for (int j = 0; j < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS; j++)
+vksps_scaling->ScalingList8x8[i][j] =
+
sps->scaling_matrix8[h264_scaling_list8_order[i]][ff_zigzag_direct[j]];
 
 *vksps_vui_header = (StdVideoH264HrdParameters) {
 .cpb_cnt_minus1 = sps->cpb_cnt - 1,
@@ -250,12 +251,13 @@ static void set_pps(const PPS *pps, const SPS *sps,
 };
 
 for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_4X4_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList4x4[i], pps->scaling_matrix4[i],
-   STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix4));
+for (int j = 0; j < STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS; j++)
+vkpps_scaling->ScalingList4x4[i][j] = 
pps->scaling_matrix4[i][ff_zigzag_scan[j]];
 
 for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList8x8[i], 
pps->scaling_matrix8[h264_scaling_list8_order[i]],
-   STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix8));
+for (int j = 0; j < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS; j++)
+vkpps_scaling->ScalingList8x8[i][j] =
+
pps->scaling_matrix8[h264_scaling_list8_order[i]][ff_zigzag_direct[j]];
 
 *vkpps = (StdVideoH264PictureParameterSet) {
 .seq_parameter_set_id = pps->sps_id,
-- 
2.41.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3] vulkan_h264: fill correct ScalingList8x8 entries

2023-08-01 Thread Benjamin Cheng
The Vulkan spec wants ScalingList8x8 as defined by ITU spec, which is in
a different order from how ffmpeg parses it.

v2: generalize for 444 case
v3: fix whitespace
---
 libavcodec/vulkan_h264.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c
index 84bcef7933..20e03dd26a 100644
--- a/libavcodec/vulkan_h264.c
+++ b/libavcodec/vulkan_h264.c
@@ -43,6 +43,8 @@ typedef struct H264VulkanDecodePicture {
 VkVideoDecodeH264PictureInfoKHR h264_pic_info;
 } H264VulkanDecodePicture;
 
+const static int h264_scaling_list8_order[] = { 0, 3, 1, 4, 2, 5 };
+
 static int vk_h264_fill_pict(AVCodecContext *avctx, H264Picture **ref_src,
  VkVideoReferenceSlotInfoKHR *ref_slot,   /* 
Main structure */
  VkVideoPictureResourceInfoKHR *ref,  /* 
Goes in ^ */
@@ -147,7 +149,7 @@ static void set_sps(const SPS *sps,
STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix4));
 
 for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList8x8[i], sps->scaling_matrix8[i],
+memcpy(vksps_scaling->ScalingList8x8[i], 
sps->scaling_matrix8[h264_scaling_list8_order[i]],
STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix8));
 
 *vksps_vui_header = (StdVideoH264HrdParameters) {
@@ -252,7 +254,7 @@ static void set_pps(const PPS *pps, const SPS *sps,
STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix4));
 
 for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList8x8[i], pps->scaling_matrix8[i],
+memcpy(vkpps_scaling->ScalingList8x8[i], 
pps->scaling_matrix8[h264_scaling_list8_order[i]],
STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix8));
 
 *vkpps = (StdVideoH264PictureParameterSet) {
-- 
2.41.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] vulkan_h264: fill correct ScalingList8x8 entries

2023-08-01 Thread Benjamin Cheng
The Vulkan spec wants ScalingList8x8 as defined by ITU spec, which is in
a different order from how ffmpeg parses it.
---
 libavcodec/vulkan_h264.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c
index 84bcef7933..9d4ffa1f9d 100644
--- a/libavcodec/vulkan_h264.c
+++ b/libavcodec/vulkan_h264.c
@@ -43,6 +43,9 @@ typedef struct H264VulkanDecodePicture {
 VkVideoDecodeH264PictureInfoKHR h264_pic_info;
 } H264VulkanDecodePicture;
 
+const static int h264_scaling_list8_order[] = { 0, 3, 1, 4, 2, 5 };
+
+
 static int vk_h264_fill_pict(AVCodecContext *avctx, H264Picture **ref_src,
  VkVideoReferenceSlotInfoKHR *ref_slot,   /* 
Main structure */
  VkVideoPictureResourceInfoKHR *ref,  /* 
Goes in ^ */
@@ -147,9 +150,9 @@ static void set_sps(const SPS *sps,
STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix4));
 
 for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList8x8[i], sps->scaling_matrix8[i],
+memcpy(vksps_scaling->ScalingList8x8[i], 
sps->scaling_matrix8[h264_scaling_list8_order[i]],
STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix8));
-
+
 *vksps_vui_header = (StdVideoH264HrdParameters) {
 .cpb_cnt_minus1 = sps->cpb_cnt - 1,
 .bit_rate_scale = sps->bit_rate_scale,
@@ -252,7 +255,7 @@ static void set_pps(const PPS *pps, const SPS *sps,
STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix4));
 
 for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList8x8[i], pps->scaling_matrix8[i],
+memcpy(vkpps_scaling->ScalingList8x8[i], 
pps->scaling_matrix8[h264_scaling_list8_order[i]],
STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix8));
 
 *vkpps = (StdVideoH264PictureParameterSet) {
-- 
2.41.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] vulkan_h264: fill correct ScalingList8x8 entries

2023-07-31 Thread Benjamin Cheng
The Vulkan spec wants ScalingList8x8 as defined by ITU spec. The latter
only defines ScalingList8x8[0] and ScalingList8x8[1] when
chroma_format_idc != 3.
---
 libavcodec/vulkan_h264.c | 24 
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c
index 84bcef7933..0d81ae8a3c 100644
--- a/libavcodec/vulkan_h264.c
+++ b/libavcodec/vulkan_h264.c
@@ -146,9 +146,17 @@ static void set_sps(const SPS *sps,
 memcpy(vksps_scaling->ScalingList4x4[i], sps->scaling_matrix4[i],
STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix4));
 
-for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList8x8[i], sps->scaling_matrix8[i],
+if (sps->chroma_format_idc == 3 /* yuv444 */) {
+for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
+memcpy(vksps_scaling->ScalingList8x8[i], sps->scaling_matrix8[i],
+   STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix8));
+} else {
+/* All other chroma formats have only 2 scaling 8x8 matrices. */
+memcpy(vksps_scaling->ScalingList8x8[0], sps->scaling_matrix8[0],
STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix8));
+memcpy(vksps_scaling->ScalingList8x8[1], sps->scaling_matrix8[3],
+   STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**sps->scaling_matrix8));
+}
 
 *vksps_vui_header = (StdVideoH264HrdParameters) {
 .cpb_cnt_minus1 = sps->cpb_cnt - 1,
@@ -251,9 +259,17 @@ static void set_pps(const PPS *pps, const SPS *sps,
 memcpy(vkpps_scaling->ScalingList4x4[i], pps->scaling_matrix4[i],
STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix4));
 
-for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList8x8[i], pps->scaling_matrix8[i],
+if (sps->chroma_format_idc == 3 /* yuv444 */) {
+for (int i = 0; i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS; i++)
+memcpy(vkpps_scaling->ScalingList8x8[i], pps->scaling_matrix8[i],
+   STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix8));
+} else {
+/* All other chroma formats have only 2 scaling 8x8 matrices. */
+memcpy(vkpps_scaling->ScalingList8x8[0], pps->scaling_matrix8[0],
STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix8));
+memcpy(vkpps_scaling->ScalingList8x8[1], pps->scaling_matrix8[3],
+   STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**pps->scaling_matrix8));
+}
 
 *vkpps = (StdVideoH264PictureParameterSet) {
 .seq_parameter_set_id = pps->sps_id,
-- 
2.41.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] vulkan_hevc: use diagonal scan order for scaling lists

2023-07-27 Thread Benjamin Cheng
The hevc parser parses the diagonal scan order in bitstream into raster
scan order. However, the Vulkan spec wants it as specified in H265 spec,
which is diagonal scan order.

Tested on RADV.

v2: fix copy-paste typo with PPS.
---
 libavcodec/vulkan_hevc.c | 83 
 1 file changed, 41 insertions(+), 42 deletions(-)

diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index ab0f6b96d0..1f157faf87 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -17,6 +17,7 @@
  */
 
 #include "hevcdec.h"
+#include "hevc_data.h"
 #include "hevc_ps.h"
 
 #include "vulkan_decode.h"
@@ -205,6 +206,44 @@ static StdVideoH265LevelIdc convert_to_vk_level_idc(int 
level_idc)
 }
 }
 
+static void copy_scaling_list(const ScalingList *sl,
+StdVideoH265ScalingLists *vksl)
+{
+for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS; i++) {
+for (int j = 0; j < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS; j++) 
{
+uint8_t pos = 4 * ff_hevc_diag_scan4x4_y[j] + 
ff_hevc_diag_scan4x4_x[j];
+vksl->ScalingList4x4[i][j] = sl->sl[0][i][pos];
+}
+}
+
+for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS; i++) {
+for (int j = 0; j < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_ELEMENTS; j++) 
{
+uint8_t pos = 8 * ff_hevc_diag_scan8x8_y[j] + 
ff_hevc_diag_scan8x8_x[j];
+vksl->ScalingList8x8[i][j] = sl->sl[1][i][pos];
+}
+}
+
+for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS; i++) {
+for (int j = 0; j < STD_VIDEO_H265_SCALING_LIST_16X16_NUM_ELEMENTS; 
j++) {
+uint8_t pos = 8 * ff_hevc_diag_scan8x8_y[j] + 
ff_hevc_diag_scan8x8_x[j];
+vksl->ScalingList16x16[i][j] = sl->sl[2][i][pos];
+}
+}
+
+for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++) {
+for (int j = 0; j < STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS; 
j++) {
+uint8_t pos = 8 * ff_hevc_diag_scan8x8_y[j] + 
ff_hevc_diag_scan8x8_x[j];
+vksl->ScalingList32x32[i][j] = sl->sl[3][i * 3][pos];
+}
+}
+
+memcpy(vksl->ScalingListDCCoef16x16, sl->sl_dc[0],
+STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS * 
sizeof(*vksl->ScalingListDCCoef16x16));
+
+for (int i = 0; i <  STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++)
+vksl->ScalingListDCCoef32x32[i] = sl->sl_dc[1][i * 3];
+}
+
 static void set_sps(const HEVCSPS *sps, int sps_idx,
 StdVideoH265ScalingLists *vksps_scaling,
 StdVideoH265HrdParameters *vksps_vui_header,
@@ -218,27 +257,7 @@ static void set_sps(const HEVCSPS *sps, int sps_idx,
 StdVideoH265ShortTermRefPicSet *str,
 StdVideoH265LongTermRefPicsSps *ltr)
 {
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList4x4[i], sps->scaling_list.sl[0][i],
-   STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**vksps_scaling->ScalingList4x4));
-
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList8x8[i], sps->scaling_list.sl[1][i],
-   STD_VIDEO_H265_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**vksps_scaling->ScalingList8x8));
-
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList16x16[i], sps->scaling_list.sl[2][i],
-   STD_VIDEO_H265_SCALING_LIST_16X16_NUM_ELEMENTS * 
sizeof(**vksps_scaling->ScalingList16x16));
-
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList32x32[i], sps->scaling_list.sl[3][i * 
3],
-   STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS * 
sizeof(**vksps_scaling->ScalingList32x32));
-
-memcpy(vksps_scaling->ScalingListDCCoef16x16, sps->scaling_list.sl_dc[0],
-   STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS * 
sizeof(*vksps_scaling->ScalingListDCCoef16x16));
-
-for (int i = 0; i <  STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++)
-vksps_scaling->ScalingListDCCoef32x32[i] = 
sps->scaling_list.sl_dc[1][i * 3];
+copy_scaling_list(>scaling_list, vksps_scaling);
 
 *vksps_vui_header = (StdVideoH265HrdParameters) {
 .flags = (StdVideoH265HrdFlags) {
@@ -464,27 +483,7 @@ static void set_pps(const HEVCPPS *pps, const HEVCSPS *sps,
 StdVideoH265PictureParameterSet *vkpps,
 StdVideoH265PredictorPaletteEntries *pal)
 {
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList4x4[i], pps->scaling_list.sl[0][i],
-   STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**vkpps_scaling->ScalingList4x4));
-
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList8x8[i], 

[FFmpeg-devel] [PATCH] vulkan_hevc: use diagonal scan order for scaling lists

2023-07-27 Thread Benjamin Cheng
The hevc parser parses the diagonal scan order in bitstream into raster
scan order. However, the Vulkan spec wants it as specified in H265 spec,
which is diagonal scan order.

Tested on RADV.
---
 libavcodec/vulkan_hevc.c | 83 
 1 file changed, 41 insertions(+), 42 deletions(-)

diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index ab0f6b96d0..15f2c3aa82 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -17,6 +17,7 @@
  */
 
 #include "hevcdec.h"
+#include "hevc_data.h"
 #include "hevc_ps.h"
 
 #include "vulkan_decode.h"
@@ -205,6 +206,44 @@ static StdVideoH265LevelIdc convert_to_vk_level_idc(int 
level_idc)
 }
 }
 
+static void copy_scaling_list(const ScalingList *sl,
+   StdVideoH265ScalingLists *vksl)
+{
+for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS; i++) {
+for (int j = 0; j < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS; j++) 
{
+uint8_t pos = 4 * ff_hevc_diag_scan4x4_y[j] + 
ff_hevc_diag_scan4x4_x[j];
+vksl->ScalingList4x4[i][j] = sl->sl[0][i][pos];
+}
+}
+
+for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS; i++) {
+for (int j = 0; j < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_ELEMENTS; j++) 
{
+uint8_t pos = 8 * ff_hevc_diag_scan8x8_y[j] + 
ff_hevc_diag_scan8x8_x[j];
+vksl->ScalingList8x8[i][j] = sl->sl[1][i][pos];
+}
+}
+
+for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS; i++) {
+for (int j = 0; j < STD_VIDEO_H265_SCALING_LIST_16X16_NUM_ELEMENTS; 
j++) {
+uint8_t pos = 8 * ff_hevc_diag_scan8x8_y[j] + 
ff_hevc_diag_scan8x8_x[j];
+vksl->ScalingList16x16[i][j] = sl->sl[2][i][pos];
+}
+}
+
+for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++) {
+for (int j = 0; j < STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS; 
j++) {
+uint8_t pos = 8 * ff_hevc_diag_scan8x8_y[j] + 
ff_hevc_diag_scan8x8_x[j];
+vksl->ScalingList32x32[i][j] = sl->sl[3][i * 3][pos];
+}
+}
+
+memcpy(vksl->ScalingListDCCoef16x16, sl->sl_dc[0],
+STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS * 
sizeof(*vksl->ScalingListDCCoef16x16));
+
+for (int i = 0; i <  STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++)
+vksl->ScalingListDCCoef32x32[i] = sl->sl_dc[1][i * 3];
+}
+
 static void set_sps(const HEVCSPS *sps, int sps_idx,
 StdVideoH265ScalingLists *vksps_scaling,
 StdVideoH265HrdParameters *vksps_vui_header,
@@ -218,27 +257,7 @@ static void set_sps(const HEVCSPS *sps, int sps_idx,
 StdVideoH265ShortTermRefPicSet *str,
 StdVideoH265LongTermRefPicsSps *ltr)
 {
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList4x4[i], sps->scaling_list.sl[0][i],
-   STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**vksps_scaling->ScalingList4x4));
-
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList8x8[i], sps->scaling_list.sl[1][i],
-   STD_VIDEO_H265_SCALING_LIST_8X8_NUM_ELEMENTS * 
sizeof(**vksps_scaling->ScalingList8x8));
-
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList16x16[i], sps->scaling_list.sl[2][i],
-   STD_VIDEO_H265_SCALING_LIST_16X16_NUM_ELEMENTS * 
sizeof(**vksps_scaling->ScalingList16x16));
-
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++)
-memcpy(vksps_scaling->ScalingList32x32[i], sps->scaling_list.sl[3][i * 
3],
-   STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS * 
sizeof(**vksps_scaling->ScalingList32x32));
-
-memcpy(vksps_scaling->ScalingListDCCoef16x16, sps->scaling_list.sl_dc[0],
-   STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS * 
sizeof(*vksps_scaling->ScalingListDCCoef16x16));
-
-for (int i = 0; i <  STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++)
-vksps_scaling->ScalingListDCCoef32x32[i] = 
sps->scaling_list.sl_dc[1][i * 3];
+copy_scaling_list(>scaling_list, vksps_scaling);
 
 *vksps_vui_header = (StdVideoH265HrdParameters) {
 .flags = (StdVideoH265HrdFlags) {
@@ -464,27 +483,7 @@ static void set_pps(const HEVCPPS *pps, const HEVCSPS *sps,
 StdVideoH265PictureParameterSet *vkpps,
 StdVideoH265PredictorPaletteEntries *pal)
 {
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList4x4[i], pps->scaling_list.sl[0][i],
-   STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * 
sizeof(**vkpps_scaling->ScalingList4x4));
-
-for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS; i++)
-memcpy(vkpps_scaling->ScalingList8x8[i], pps->scaling_list.sl[1][i],
-