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.
This commit is contained in:
Lynne 2020-03-12 18:03:43 +00:00
parent 501bd57bdb
commit b31959d776
1 changed files with 6 additions and 3 deletions

View File

@ -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;
}