summaryrefslogtreecommitdiff
path: root/libavutil/hwcontext_vulkan.c
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2020-03-12 18:03:43 +0000
committerLynne <dev@lynne.ee>2020-03-12 18:16:11 +0000
commitb31959d776e6da3ff8519121bafae9753f2be20f (patch)
tree464e833b7a38065eecf4d96773958a2a46d214ce /libavutil/hwcontext_vulkan.c
parent501bd57bdbc488db93c95d40682ef0b4f01ccec5 (diff)
hwcontext_vulkan: duplicate DMABUF objects before importing them
The specifications are very vague about who has ownership, and in this case, Vulkan takes ownership of all DMABUF FDs passed to it, causing errors to occur if someone gave us images for mapping which were meant to be kept. The old behavior worked with one-way VAAPI and DMABUF imports, but was broken with clients like wlroots' dmabuf-capture.
Diffstat (limited to 'libavutil/hwcontext_vulkan.c')
-rw-r--r--libavutil/hwcontext_vulkan.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 6c2372f7fb..626b3ab5b7 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1699,15 +1699,16 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
VkImportMemoryFdInfoKHR idesc = {
.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
.handleType = htype,
- .fd = desc->objects[i].fd,
+ .fd = dup(desc->objects[i].fd),
};
ret = pfn_vkGetMemoryFdPropertiesKHR(hwctx->act_dev, htype,
- desc->objects[i].fd, &fdmp);
+ idesc.fd, &fdmp);
if (ret != VK_SUCCESS) {
av_log(hwfc, AV_LOG_ERROR, "Failed to get FD properties: %s\n",
vk_ret2str(ret));
err = AVERROR_EXTERNAL;
+ close(idesc.fd);
goto fail;
}
@@ -1715,8 +1716,10 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
err = alloc_mem(ctx, &req, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
&idesc, &f->flags, &f->mem[i]);
- if (err)
+ if (err) {
+ close(idesc.fd);
return err;
+ }
f->size[i] = desc->objects[i].size;
}