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

Benjamin Cheng ben at bcheng.me
Tue Aug 1 01:53:14 EEST 2023


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



More information about the ffmpeg-devel mailing list