* [FFmpeg-devel] [PATCH] vulkan_decode: don't call get_proc_addr on every frame's destruction
@ 2023-09-15 0:26 Lynne
0 siblings, 0 replies; only message in thread
From: Lynne @ 2023-09-15 0:26 UTC (permalink / raw)
To: Ffmpeg Devel
[-- Attachment #1: Type: text/plain, Size: 386 bytes --]
The issue is that we cannot rely on any context existing when we free
frames, due to threading. 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.
Patch attached.
[-- Attachment #2: 0001-vulkan_decode-don-t-call-get_proc_addr-on-every-fram.patch --]
[-- Type: text/x-diff, Size: 4069 bytes --]
From dea92e37d06d6465df3cef645a0b8f63cf222c82 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Fri, 15 Sep 2023 02:22:00 +0200
Subject: [PATCH] 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.
---
libavcodec/vulkan_decode.c | 18 +++++++-----------
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..4788619ada 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 destruction functions, as no other context is guaranteed to exist */
+ PFN_vkDestroyImageView destroy_image_view;
+ PFN_vkWaitSemaphores wait_semaphores;
} FFVulkanDecodePicture;
/**
--
2.40.1
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-15 0:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-15 0:26 [FFmpeg-devel] [PATCH] vulkan_decode: don't call get_proc_addr on every frame's destruction Lynne
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git