1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

hwcontext_vulkan: support PREP_MODE_DECODING in prepare_frame()

This commit is contained in:
Lynne 2022-11-23 15:18:21 +01:00
parent 6dfa29a58d
commit d4cb48dd00
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464

View File

@ -2030,7 +2030,9 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, AVVkFrame *f,
enum PrepMode { enum PrepMode {
PREP_MODE_WRITE, PREP_MODE_WRITE,
PREP_MODE_EXTERNAL_EXPORT, PREP_MODE_EXTERNAL_EXPORT,
PREP_MODE_EXTERNAL_IMPORT PREP_MODE_EXTERNAL_IMPORT,
PREP_MODE_DECODING_DST,
PREP_MODE_DECODING_DPB,
}; };
static int prepare_frame(AVHWFramesContext *hwfc, VulkanExecCtx *ectx, static int prepare_frame(AVHWFramesContext *hwfc, VulkanExecCtx *ectx,
@ -2039,7 +2041,7 @@ static int prepare_frame(AVHWFramesContext *hwfc, VulkanExecCtx *ectx,
int err; int err;
uint32_t src_qf, dst_qf; uint32_t src_qf, dst_qf;
VkImageLayout new_layout; VkImageLayout new_layout;
VkAccessFlags new_access; VkAccessFlags2 new_access;
AVVulkanFramesContext *vkfc = hwfc->hwctx; AVVulkanFramesContext *vkfc = hwfc->hwctx;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format); const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
VulkanDevicePriv *p = hwfc->device_ctx->internal->priv; VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
@ -2047,7 +2049,8 @@ static int prepare_frame(AVHWFramesContext *hwfc, VulkanExecCtx *ectx,
AVFrame tmp = { .data[0] = (uint8_t *)frame }; AVFrame tmp = { .data[0] = (uint8_t *)frame };
uint64_t sem_sig_val[AV_NUM_DATA_POINTERS]; uint64_t sem_sig_val[AV_NUM_DATA_POINTERS];
VkImageMemoryBarrier img_bar[AV_NUM_DATA_POINTERS] = { 0 }; VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS] = { 0 };
VkDependencyInfo dep_info;
VkTimelineSemaphoreSubmitInfo s_timeline_sem_info = { VkTimelineSemaphoreSubmitInfo s_timeline_sem_info = {
.sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO, .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO,
@ -2103,32 +2106,52 @@ static int prepare_frame(AVHWFramesContext *hwfc, VulkanExecCtx *ectx,
s_info.pWaitDstStageMask = wait_st; s_info.pWaitDstStageMask = wait_st;
s_info.waitSemaphoreCount = planes; s_info.waitSemaphoreCount = planes;
break; break;
case PREP_MODE_DECODING_DST:
new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR;
new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
src_qf = VK_QUEUE_FAMILY_IGNORED;
dst_qf = VK_QUEUE_FAMILY_IGNORED;
break;
case PREP_MODE_DECODING_DPB:
new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR;
new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
src_qf = VK_QUEUE_FAMILY_IGNORED;
dst_qf = VK_QUEUE_FAMILY_IGNORED;
break;
} }
/* Change the image layout to something more optimal for writes. /* Change the image layout to something more optimal for writes.
* This also signals the newly created semaphore, making it usable * This also signals the newly created semaphore, making it usable
* for synchronization */ * for synchronization */
for (int i = 0; i < planes; i++) { for (int i = 0; i < planes; i++) {
img_bar[i].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; img_bar[i] = (VkImageMemoryBarrier2) {
img_bar[i].srcAccessMask = 0x0; .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
img_bar[i].dstAccessMask = new_access; .pNext = NULL,
img_bar[i].oldLayout = frame->layout[i]; .srcStageMask = VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT,
img_bar[i].newLayout = new_layout; .srcAccessMask = 0x0,
img_bar[i].srcQueueFamilyIndex = src_qf; .dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT,
img_bar[i].dstQueueFamilyIndex = dst_qf; .dstAccessMask = new_access,
img_bar[i].image = frame->img[i]; .oldLayout = frame->layout[i],
img_bar[i].subresourceRange.levelCount = 1; .newLayout = new_layout,
img_bar[i].subresourceRange.layerCount = 1; .srcQueueFamilyIndex = src_qf,
img_bar[i].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; .dstQueueFamilyIndex = dst_qf,
.image = frame->img[i],
.subresourceRange = (VkImageSubresourceRange) {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
},
};
frame->layout[i] = img_bar[i].newLayout; frame->layout[i] = img_bar[i].newLayout;
frame->access[i] = img_bar[i].dstAccessMask; frame->access[i] = img_bar[i].dstAccessMask;
} }
vk->CmdPipelineBarrier(get_buf_exec_ctx(hwfc, ectx), vk->CmdPipelineBarrier2(get_buf_exec_ctx(hwfc, ectx), &(VkDependencyInfo) {
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
VK_PIPELINE_STAGE_TRANSFER_BIT, .pImageMemoryBarriers = img_bar,
0, 0, NULL, 0, NULL, planes, img_bar); .imageMemoryBarrierCount = planes,
});
err = submit_exec_ctx(hwfc, ectx, &s_info, frame, 0); err = submit_exec_ctx(hwfc, ectx, &s_info, frame, 0);
vkfc->unlock_frame(hwfc, frame); vkfc->unlock_frame(hwfc, frame);
@ -2369,7 +2392,13 @@ static AVBufferRef *vulkan_pool_alloc(void *opaque, size_t size)
if (err) if (err)
goto fail; goto fail;
err = prepare_frame(hwfc, &fp->conv_ctx, f, PREP_MODE_WRITE); if ( (hwctx->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR) &&
!(hwctx->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR))
err = prepare_frame(hwfc, &fp->conv_ctx, f, PREP_MODE_DECODING_DPB);
else if (hwctx->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR)
err = prepare_frame(hwfc, &fp->conv_ctx, f, PREP_MODE_DECODING_DST);
else
err = prepare_frame(hwfc, &fp->conv_ctx, f, PREP_MODE_WRITE);
if (err) if (err)
goto fail; goto fail;