diff options
author | Lynne <dev@lynne.ee> | 2023-09-15 02:22:00 +0200 |
---|---|---|
committer | Lynne <dev@lynne.ee> | 2023-09-15 17:35:22 +0200 |
commit | 9310ffc809d02d7bbc767555c2ed16311623ffe2 (patch) | |
tree | 0d6cd2e5d4a7428ce5fa853ba95ed6764f3625c3 | |
parent | 552a5fa496933c2679cac6774e483bee3f5c2c53 (diff) | |
download | ffmpeg-9310ffc809d02d7bbc767555c2ed16311623ffe2.tar.gz |
vulkan_decode: don't call get_proc_addr on every frame's destruction
The issue is that we cannot rely on any context existing when we free
frames. The Vulkan functions are loaded in each context separately,
so until now, we've just been loading them on every frame's destruction.
Rather than do this, just save the function pointers we need in each
frame. The function pointers are guaranteed to not change and exist.
-rw-r--r-- | libavcodec/vulkan_decode.c | 18 | ||||
-rw-r--r-- | libavcodec/vulkan_decode.h | 4 |
2 files changed, 11 insertions, 11 deletions
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 21bebb1677..ef4a1c3809 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -176,6 +176,7 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, { int err; FFVulkanDecodeShared *ctx = (FFVulkanDecodeShared *)dec->shared_ref->data; + FFVulkanFunctions *vk = &ctx->s.vkfn; vkpic->slices_size = 0; @@ -189,6 +190,9 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, vkpic->img_view_out = NULL; vkpic->img_view_dest = NULL; + vkpic->destroy_image_view = vk->DestroyImageView; + vkpic->wait_semaphores = vk->WaitSemaphores; + if (dec->layered_dpb && alloc_dpb) { vkpic->img_view_ref = ctx->layered_view; vkpic->img_aspect_ref = ctx->layered_aspect; @@ -554,9 +558,6 @@ int ff_vk_decode_frame(AVCodecContext *avctx, void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *vp) { AVVulkanDeviceContext *hwctx = dev_ctx->hwctx; - PFN_vkGetDeviceProcAddr device_proc_addr; - PFN_vkWaitSemaphores wait_semaphores; - PFN_vkDestroyImageView destroy_image_view; VkSemaphoreWaitInfo sem_wait = (VkSemaphoreWaitInfo) { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO, @@ -565,27 +566,22 @@ void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture * .semaphoreCount = 1, }; - /* Guaranteed to exist */ - device_proc_addr = (PFN_vkGetDeviceProcAddr)hwctx->get_proc_addr(hwctx->inst, "vkGetDeviceProcAddr"); - destroy_image_view = (PFN_vkDestroyImageView)device_proc_addr(hwctx->act_dev, "vkDestroyImageView"); - wait_semaphores = (PFN_vkWaitSemaphores)device_proc_addr(hwctx->act_dev, "vkWaitSemaphores"); - /* We do not have to lock the frame here because we're not interested * in the actual current semaphore value, but only that it's later than * the time we submitted the image for decoding. */ if (vp->sem) - wait_semaphores(hwctx->act_dev, &sem_wait, UINT64_MAX); + vp->wait_semaphores(hwctx->act_dev, &sem_wait, UINT64_MAX); /* Free slices data */ av_buffer_unref(&vp->slices_buf); /* Destroy image view (out) */ if (vp->img_view_out && vp->img_view_out != vp->img_view_dest) - destroy_image_view(hwctx->act_dev, vp->img_view_out, hwctx->alloc); + vp->destroy_image_view(hwctx->act_dev, vp->img_view_out, hwctx->alloc); /* Destroy image view (ref, unlayered) */ if (vp->img_view_dest) - destroy_image_view(hwctx->act_dev, vp->img_view_dest, hwctx->alloc); + vp->destroy_image_view(hwctx->act_dev, vp->img_view_dest, hwctx->alloc); av_frame_free(&vp->dpb_frame); } diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h index 71ba3dbd84..c983b44029 100644 --- a/libavcodec/vulkan_decode.h +++ b/libavcodec/vulkan_decode.h @@ -97,6 +97,10 @@ typedef struct FFVulkanDecodePicture { /* Slice data */ AVBufferRef *slices_buf; size_t slices_size; + + /* Vulkan functions needed for destruction, as no other context is guaranteed to exist */ + PFN_vkWaitSemaphores wait_semaphores; + PFN_vkDestroyImageView destroy_image_view; } FFVulkanDecodePicture; /** |