From 41cee21f6205405b5fe34c14ff67279578a5ed9a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 12 Sep 2023 12:24:54 +1000 Subject: [PATCH] radv/video: take db alignment into account when allocating images. Make sure to take the db alignment into account when sizing the underlying images. Fixes a 360p sample from Lynne. Cc: mesa-stable Acked-by: Bas Nieuwenhuizen Reviewed-by: Lynne Part-of: (cherry picked from commit 3740b6f599b098b1cd3fddaec9938af681e8378c) --- .pick_status.json | 2 +- src/amd/vulkan/radv_image.c | 2 +- src/amd/vulkan/radv_private.h | 4 +++- src/amd/vulkan/radv_video.c | 36 ++++++++++++++++++++++++++++++----- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index cf3ebbe5b6f..49085770f3c 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3064,7 +3064,7 @@ "description": "radv/video: take db alignment into account when allocating images.", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c index e46c5bab1c3..d7498a85306 100644 --- a/src/amd/vulkan/radv_image.c +++ b/src/amd/vulkan/radv_image.c @@ -1720,7 +1720,7 @@ radv_image_create_layout(struct radv_device *device, struct radv_image_create_in if (image->vk.usage & (VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR)) { assert(profile_list); uint32_t width_align, height_align; - vk_video_get_profile_alignments(profile_list, &width_align, &height_align); + radv_video_get_profile_alignments(device->physical_device, profile_list, &width_align, &height_align); image_info.width = align(image_info.width, width_align); image_info.height = align(image_info.height, height_align); } diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 1c59d04d84f..c50c6e03ad1 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -3597,7 +3597,9 @@ radv_queue_ring(const struct radv_queue *queue) /* radv_video */ void radv_init_physical_device_decoder(struct radv_physical_device *pdevice); - +void radv_video_get_profile_alignments(struct radv_physical_device *pdevice, + const VkVideoProfileListInfoKHR *profile_list, uint32_t *width_align_out, + uint32_t *height_align_out); /** * Helper used for debugging compiler issues by enabling/disabling LLVM for a * specific shader stage (developers only). diff --git a/src/amd/vulkan/radv_video.c b/src/amd/vulkan/radv_video.c index 0d729b9ccb2..7297907f0c6 100644 --- a/src/amd/vulkan/radv_video.c +++ b/src/amd/vulkan/radv_video.c @@ -57,6 +57,14 @@ radv_enable_tier2(struct radv_physical_device *pdevice) return false; } +static uint32_t +radv_video_get_db_alignment(struct radv_physical_device *pdevice, int width, bool is_h265_main_10) +{ + if (pdevice->rad_info.family >= CHIP_RENOIR && width > 32 && is_h265_main_10) + return 64; + return 32; +} + static bool radv_vid_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer, unsigned size, unsigned *out_offset, void **ptr) { @@ -305,11 +313,9 @@ radv_CreateVideoSessionKHR(VkDevice _device, const VkVideoSessionCreateInfoKHR * vid->stream_handle = si_vid_alloc_stream_handle(device->physical_device); vid->dbg_frame_cnt = 0; - vid->db_alignment = - (device->physical_device->rad_info.family >= CHIP_RENOIR && vid->vk.max_coded.width > 32 && - (vid->stream_type == RDECODE_CODEC_H265 && vid->vk.h265.profile_idc == STD_VIDEO_H265_PROFILE_IDC_MAIN_10)) - ? 64 - : 32; + vid->db_alignment = radv_video_get_db_alignment( + device->physical_device, vid->vk.max_coded.width, + vid->stream_type == RDECODE_CODEC_H265 && vid->vk.h265.profile_idc == STD_VIDEO_H265_PROFILE_IDC_MAIN_10); *pVideoSession = radv_video_session_to_handle(vid); return VK_SUCCESS; @@ -1877,3 +1883,23 @@ radv_CmdDecodeVideoKHR(VkCommandBuffer commandBuffer, const VkVideoDecodeInfoKHR else radv_vcn_decode_video(cmd_buffer, frame_info); } + +void +radv_video_get_profile_alignments(struct radv_physical_device *pdevice, const VkVideoProfileListInfoKHR *profile_list, + uint32_t *width_align_out, uint32_t *height_align_out) +{ + vk_video_get_profile_alignments(profile_list, width_align_out, height_align_out); + bool is_h265_main_10 = false; + for (unsigned i = 0; i < profile_list->profileCount; i++) { + if (profile_list->pProfiles[i].videoCodecOperation == VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR) { + const struct VkVideoDecodeH265ProfileInfoKHR *h265_profile = + vk_find_struct_const(profile_list->pProfiles[i].pNext, VIDEO_DECODE_H265_PROFILE_INFO_KHR); + if (h265_profile->stdProfileIdc == STD_VIDEO_H265_PROFILE_IDC_MAIN_10) + is_h265_main_10 = true; + } + } + + uint32_t db_alignment = radv_video_get_db_alignment(pdevice, 64, is_h265_main_10); + *width_align_out = MAX2(*width_align_out, db_alignment); + *height_align_out = MAX2(*height_align_out, db_alignment); +}