PR #26078 opened by Forgejo_Fairy URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26078 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26078.patch
Vulkan-to-DRM mapping replaces a caller-supplied DRM frames context with the Vulkan source context, leaking the original reference and causing hwdownload to reject the mapped frame. Preserve the destination context; ff_hwframe_map_create() already retains the source frame and context for the mapping lifetime. Also reject images without VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT before preparing them for export. The exporter unconditionally queries a DRM modifier, which is invalid for ordinary optimal-tiling hwupload images. Those allocations may enable only OPAQUE_FD export, making the subsequent DMA_BUF request invalid as well. Return ENOSYS before either call. This partially addresses #26021. It does not fix re-export of DRM-imported memory allocated without VkExportMemoryAllocateInfo, and should not close the issue. Validation on master bcbc1832649, x86-64 Linux, NVIDIA RTX 5090 / 595.99.02: - The generated NV12 hwupload → DRM hwmap command reproduces VUIDs 02272 and 00671 before the patch. Afterward it returns ENOSYS without those diagnostics. - A controlled ownership harness uses a real modifier-backed Vulkan frame, substitutes memory-FD export with /dev/null, and selects the CPU-wait fallback. Before the patch it observes context replacement and one leaked destination reference; afterward it preserves supplied and NULL destination contexts and restores baseline reference counts. This is not a real DMA-BUF interoperability test. - The same controlled test verifies the ownership regression at 25e187f84949 against its immediate parent 492e6e68dcd5. - All 73 enabled libavutil FATE tests passed after the context fix. Both commits build and pass whitespace checks; ownership tests were rerun with both applied. - Direct Vulkan upload/download produces the same frame checksum as software for the generated NV12 input. Actual Intel VAAPI import/re-export and end-to-end DRM hwdownload remain untested here: the available container cannot open the DRM render node or export real DMA-BUFs. Reproduction commands, harness, substitutions and results are preserved in tools/issue26021/ on fairy/issue26021-tooling. From 3547beae77bdefa9cd223f7d97796bff6f8ceff8 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Sun, 15 Nov 2026 09:24:31 +0000 Subject: [PATCH 1/2] avutil/hwcontext_vulkan: preserve the DRM mapping destination context The caller can supply a DRM frames context to av_hwframe_map(). Replacing it with a reference to the Vulkan source context both leaks the original reference and makes hwdownload reject the mapped frame. Leave the destination context alone. ff_hwframe_map_create() already retains the source frame and its frames context for the mapping lifetime. This also preserves a NULL destination context for direct DRM exports and the temporary DRM frame used by vulkan_map_to_vaapi(). Fixes the context replacement part of issue #26021. Fixes: 25e187f8494966377a4b9d077260ce7b501a911c Assisted-by: Fairy --- libavutil/hwcontext_vulkan.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 023b11224ea..d9d4eb41ad0 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -4668,7 +4668,6 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst, dst->width = src->width; dst->height = src->height; dst->data[0] = (uint8_t *)drm_desc; - dst->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx); if (sync_fd >= 0) close(sync_fd); -- 2.54.0 From f64da11d671abd5695be1f827562486cb6f8faac Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Sun, 15 Nov 2026 09:25:03 +0000 Subject: [PATCH 2/2] avutil/hwcontext_vulkan: reject DRM export of non-modifier images vulkan_map_to_drm() unconditionally queries the image's DRM modifier, which requires VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT. In particular, ordinary hwupload pools use optimal tiling and allocate for opaque-FD export, so mapping them to DRM also requests a DMA-BUF handle type that was not enabled at allocation. Return ENOSYS before changing image ownership or calling Vulkan when the image has no DRM modifier tiling. This prevents VUID 02272 and the ensuing 00671 on the software-upload reproducer in issue #26021. It does not make DRM-imported memory re-exportable; that is a separate allocation issue. Assisted-by: Fairy --- libavutil/hwcontext_vulkan.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index d9d4eb41ad0..0183d9fecbe 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -4542,7 +4542,12 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst, int free_drm_desc_on_err = 1; int sync_fd = -1; - AVDRMFrameDescriptor *drm_desc = av_mallocz(sizeof(*drm_desc)); + AVDRMFrameDescriptor *drm_desc; + + if (f->tiling != VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) + return AVERROR(ENOSYS); + + drm_desc = av_mallocz(sizeof(*drm_desc)); if (!drm_desc) return AVERROR(ENOMEM); -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
