Commit f529e624 authored by Dave Airlie's avatar Dave Airlie
Browse files

make correct dpb handling the default

parent 8cd21873
Pipeline #751148 waiting for manual action with stages
......@@ -36,7 +36,6 @@
* when it should be allocated by the application. This define forces the driver
* to be spec compliant, but breaks the current userspaces.
*/
//#define CORRECT_DPB_HANDLING
#define NUM_H264_REFS 17
#define FB_BUFFER_OFFSET 0x1000
#define FB_BUFFER_SIZE 2048
......@@ -256,86 +255,6 @@ static unsigned calc_ctx_size_h265_main10(struct radv_video_session *vid)
return cm_buffer_size + db_left_tile_ctx_size + db_left_tile_pxl_size;
}
#ifndef CORRECT_DPB_HANDLING
/* calculate size of reference picture buffer */
static unsigned calc_dpb_size(struct radv_video_session *vid)
{
unsigned width_in_mb, height_in_mb, image_size, dpb_size;
// always align them to MB size for dpb calculation
unsigned width = align(vid->vk.max_coded.width, VL_MACROBLOCK_WIDTH);
unsigned height = align(vid->vk.max_coded.height, VL_MACROBLOCK_HEIGHT);
// always one more for currently decoded picture
unsigned max_references = vid->vk.max_dpb_slots + 1;
// aligned size of a single frame
image_size = align(width, 32) * height;
image_size += image_size / 2;
image_size = align(image_size, 1024);
// picture width & height in 16 pixel units
width_in_mb = width / VL_MACROBLOCK_WIDTH;
height_in_mb = align(height / VL_MACROBLOCK_HEIGHT, 2);
switch (vid->vk.op) {
case VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_EXT: {
unsigned fs_in_mb = width_in_mb * height_in_mb;
unsigned num_dpb_buffer;
switch (vid->h264_level) {
case 30:
num_dpb_buffer = 8100 / fs_in_mb;
break;
case 31:
num_dpb_buffer = 18000 / fs_in_mb;
break;
case 32:
num_dpb_buffer = 20480 / fs_in_mb;
break;
case 41:
num_dpb_buffer = 32768 / fs_in_mb;
break;
case 42:
num_dpb_buffer = 34816 / fs_in_mb;
break;
case 50:
num_dpb_buffer = 110400 / fs_in_mb;
break;
case 51:
num_dpb_buffer = 184320 / fs_in_mb;
break;
default:
num_dpb_buffer = 184320 / fs_in_mb;
break;
}
num_dpb_buffer++;
max_references = MAX2(MIN2(NUM_H264_REFS, num_dpb_buffer), max_references);
dpb_size = image_size * max_references;
break;
}
case VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_EXT: {
if (vid->vk.max_coded.width * vid->vk.max_coded.height >= 4096 * 2000)
max_references = MAX2(max_references, 8);
else
max_references = MAX2(max_references, 17);
width = align(width, 16);
height = align(height, 16);
if (vid->vk.h265.profile_idc == STD_VIDEO_H265_PROFILE_IDC_MAIN_10)
dpb_size = align((align(width, 64) * align(height, 64) * 9) / 4, 256) * max_references;
else
dpb_size = align((align(width, 32) * height * 3) / 2, 256) * max_references;
break;
}
default:
unreachable("unknown operation");
}
return dpb_size;
}
#endif
VkResult
radv_CreateVideoSessionKHR(VkDevice _device,
const VkVideoSessionCreateInfoKHR *pCreateInfo,
......@@ -390,9 +309,6 @@ radv_CreateVideoSessionKHR(VkDevice _device,
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;
#ifndef CORRECT_DPB_HANDLING
vid->dpb_size = calc_dpb_size(vid);
#endif
*pVideoSession = radv_video_session_to_handle(vid);
return VK_SUCCESS;
}
......@@ -482,12 +398,12 @@ radv_GetPhysicalDeviceVideoCapabilitiesKHR(VkPhysicalDevice physicalDevice,
pCapabilities->minCodedExtent.width = VL_MACROBLOCK_WIDTH;
pCapabilities->minCodedExtent.height = VL_MACROBLOCK_HEIGHT;
#ifdef CORRECT_DPB_HANDLING
struct VkVideoDecodeCapabilitiesKHR *dec_caps = (struct VkVideoDecodeCapabilitiesKHR *)
vk_find_struct(pCapabilities->pNext, VIDEO_DECODE_CAPABILITIES_KHR);
if (dec_caps)
dec_caps->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR;
#endif
switch (pVideoProfile->videoCodecOperation) {
case VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_EXT: {
struct VkVideoDecodeH264CapabilitiesEXT *ext = (struct VkVideoDecodeH264CapabilitiesEXT *)
......@@ -545,13 +461,13 @@ radv_GetPhysicalDeviceVideoFormatPropertiesKHR(VkPhysicalDevice physicalDevice,
VkVideoFormatPropertiesKHR *pVideoFormatProperties)
{
/* radv requires separate allocates for DPB and decode video. */
#ifdef CORRECT_DPB_HANDLING
if ((pVideoFormatInfo->imageUsage & (VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR |
VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR)) ==
(VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR |
VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR))
return VK_ERROR_FORMAT_NOT_SUPPORTED;
#endif
*pVideoFormatPropertyCount = 1;
if (!pVideoFormatProperties)
......@@ -566,7 +482,6 @@ radv_GetPhysicalDeviceVideoFormatPropertiesKHR(VkPhysicalDevice physicalDevice,
#define RADV_BIND_SESSION_CTX 0
#define RADV_BIND_H264_5_CTX 1
#define RADV_BIND_BROKEN_DPB 2
VkResult
radv_GetVideoSessionMemoryRequirementsKHR(VkDevice _device,
......@@ -580,9 +495,6 @@ radv_GetVideoSessionMemoryRequirementsKHR(VkDevice _device,
uint32_t num_memory_reqs = 0;
int idx = 0;
#ifndef CORRECT_DPB_HANDLING
num_memory_reqs = 1;
#endif
if (device->physical_device->rad_info.family >= CHIP_POLARIS10)
num_memory_reqs++;
......@@ -603,14 +515,6 @@ radv_GetVideoSessionMemoryRequirementsKHR(VkDevice _device,
pMemoryRequirements[idx].memoryRequirements.memoryTypeBits = memory_type_bits;
idx++;
}
#ifndef CORRECT_DPB_HANDLING
/* internal DPB? */
pMemoryRequirements[idx].memoryBindIndex = RADV_BIND_BROKEN_DPB;
pMemoryRequirements[idx].memoryRequirements.size = vid->dpb_size;
pMemoryRequirements[idx].memoryRequirements.alignment = 0;
pMemoryRequirements[idx].memoryRequirements.memoryTypeBits = memory_type_bits;
idx++;
#endif
if (vid->stream_type == RDECODE_CODEC_H264_PERF &&
device->physical_device->rad_info.family >= CHIP_POLARIS10) {
......@@ -669,11 +573,6 @@ radv_BindVideoSessionMemoryKHR(VkDevice _device,
case RADV_BIND_H264_5_CTX:
copy_bind(&vid->ctx, &pBindSessionMemoryInfos[i]);
break;
case RADV_BIND_BROKEN_DPB:
#ifndef CORRECT_DPB_HANDLING
copy_bind(&vid->dpb, &pBindSessionMemoryInfos[i]);
#endif
break;
default:
assert(0);
break;
......@@ -1024,10 +923,8 @@ static bool rvcn_dec_message_decode(struct radv_device *device,
unsigned sizes = 0, offset_decode, offset_codec;
struct radv_image_view *dst_iv = radv_image_view_from_handle(frame_info->dstPictureResource.imageViewBinding);
struct radv_image *img = dst_iv->image;
#ifdef CORRECT_DPB_HANDLING
struct radv_image_view *dpb_iv = radv_image_view_from_handle(frame_info->pSetupReferenceSlot->pPictureResource->imageViewBinding);
struct radv_image *dpb = dpb_iv->image;
#endif
struct radv_image_plane *luma = &img->planes[0];
struct radv_image_plane *chroma = &img->planes[1];
......@@ -1080,11 +977,7 @@ static bool rvcn_dec_message_decode(struct radv_device *device,
decode->bsd_size = frame_info->srcBufferRange;
#ifdef CORRECT_DPB_HANDLING
decode->dpb_size = (vid->dpb_type != DPB_DYNAMIC_TIER_2) ? dpb->size : 0;
#else
decode->dpb_size = (vid->dpb_type != DPB_DYNAMIC_TIER_2) ? vid->dpb.size : 0;
#endif
decode->dt_size = dst_iv->image->planes[0].surface.total_size +
dst_iv->image->planes[1].surface.total_size;
......@@ -1411,10 +1304,8 @@ static bool ruvd_dec_message_decode(struct radv_device *device,
struct radv_image *img = dst_iv->image;
struct radv_image_plane *luma = &img->planes[0];
struct radv_image_plane *chroma = &img->planes[1];
#ifdef CORRECT_DPB_HANDLING
struct radv_image_view *dpb_iv = radv_image_view_from_handle(frame_info->pSetupReferenceSlot->pPictureResource->imageViewBinding);
struct radv_image *dpb = dpb_iv->image;
#endif
memset(msg, 0, sizeof(struct ruvd_msg));
msg->size = sizeof(*msg);
......@@ -1427,11 +1318,7 @@ static bool ruvd_dec_message_decode(struct radv_device *device,
msg->body.decode.width_in_samples = frame_info->dstPictureResource.codedExtent.width;
msg->body.decode.height_in_samples = frame_info->dstPictureResource.codedExtent.height;
#ifdef CORRECT_DPB_HANDLING
msg->body.decode.dpb_size = (vid->dpb_type != DPB_DYNAMIC_TIER_2) ? dpb->size : 0;
#else
msg->body.decode.dpb_size = (vid->dpb_type != DPB_DYNAMIC_TIER_2) ? vid->dpb.size : 0;
#endif
msg->body.decode.bsd_size = frame_info->srcBufferRange;
msg->body.decode.db_pitch = align(frame_info->dstPictureResource.codedExtent.width, vid->db_alignment);
......@@ -1646,14 +1533,9 @@ radv_uvd_decode_video(struct radv_cmd_buffer *cmd_buffer,
send_cmd(cmd_buffer, RDECODE_CMD_MSG_BUFFER, msg_bo, out_offset);
if (vid->dpb_type != DPB_DYNAMIC_TIER_2) {
#ifdef CORRECT_DPB_HANDLING
struct radv_image_view *dpb_iv = radv_image_view_from_handle(frame_info->pSetupReferenceSlot->pPictureResource->imageViewBinding);
struct radv_image *dpb = dpb_iv->image;
send_cmd(cmd_buffer, RDECODE_CMD_DPB_BUFFER, dpb->bindings[0].bo, dpb->bindings[0].offset);
#else
if (vid->dpb.mem)
send_cmd(cmd_buffer, RDECODE_CMD_DPB_BUFFER, vid->dpb.mem->bo, vid->dpb.offset);
#endif
}
if (vid->ctx.mem)
......@@ -1722,14 +1604,9 @@ radv_vcn_decode_video(struct radv_cmd_buffer *cmd_buffer,
send_cmd(cmd_buffer, RDECODE_CMD_MSG_BUFFER, msg_bo, out_offset);
if (vid->dpb_type != DPB_DYNAMIC_TIER_2) {
#ifdef CORRECT_DPB_HANDLING
struct radv_image_view *dpb_iv = radv_image_view_from_handle(frame_info->pSetupReferenceSlot->pPictureResource->imageViewBinding);
struct radv_image *dpb = dpb_iv->image;
send_cmd(cmd_buffer, RDECODE_CMD_DPB_BUFFER, dpb->bindings[0].bo, dpb->bindings[0].offset);
#else
if (vid->dpb.mem)
send_cmd(cmd_buffer, RDECODE_CMD_DPB_BUFFER, vid->dpb.mem->bo, vid->dpb.offset);
#endif
}
if (vid->ctx.mem)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment