From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id DF3754B9C9 for ; Sat, 29 Nov 2025 06:10:36 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'lenRJ1eUfKk4+6bRXGthRQpsPNIHeKk+hjASOmGzs/M=', expected b'sA0sTK7DVZWnZdbjR8bIlxl9//RKgVGraKmIXW8L+1Q=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1764396494; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=lenRJ1eUfKk4+6bRXGthRQpsPNIHeKk+hjASOmGzs/M=; b=GB+W9Yoomo773UH0S5/lucVhLItb/2E86KKXGLolyjPyu7EXZYKpvYrjwJDFBN41EN5Dr To9+//AioXUBeFDeKgfryyeQ0jyYtZ/fKtSJE9LcCpCB7TBp5R06MRD/Mw4RLjrA9+C9GXw 7rObIsHS418Uhs5WHJD9HK0bXZRZ57y62RdOdPEQcYEuJZgzxDuRO5zJ4fVUPrhUfY7AK7B hKvh0gv+r4+uXvqZwfcKQEwrm8fkojnlj+hf9QyznYo9XCcjWpYxietlvB6qZzzCHwLjc5S php0ZOxz32J4zM2DLvjKuTi20/BGDk30pWOJX0du3Imh09Nt8kWvZqWDKYxw== Received: from [172.19.0.3] (unknown [172.19.0.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id EC0746902C2; Sat, 29 Nov 2025 08:08:14 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1764396452; b=LzVAA1TbWcZ4ehaUCxkGEOXnd2qUHTNjWlmfaLphTxO7CL0u4rICdfunVVPIGkEasGNga hLipohtg/MzhhzpVAFx3ODuWLLqGTYSEnehOrJDRhDMx+sKiazBQvRJFICc9H3Euc+OkGlg ez7X3XOmwYjETSc14/ROVyGvbLfgX3vnfZdvet6Mx74X8pr+frZVxFMmISEJYObzoXhwojC JrUuFJRxBajuqG1T9xdGpLvJTbuguUcw3Ee3Yz3adYggY1x2fp1IbagexLzuRiFYScTQalY 0t6LkGKCITDEyrS84whZer0w/9nGDYnNs3L7xoh3tRlfPloIuZMNPY3AI4Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1764396452; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=ZeTE0JMRdUTvqPoSlaXhxvMQECwvUTmPYcJxgUPa8yI=; b=UtUoYFEr7DqGtpQYE1Zp2WLfK9ohSELRDM4nw4sehZzPPEWYZzvcxOvNHtD8fz67LhOor vMsodvR4rFIbDtda5SHpw/Wo+PlzXKZ0VicdPVT/gHVMQioggEiIJ5kFObc2IBBGeFJrkbq VVPqUu0PQfWmiJbeN5OyP+Pv4H03BTY1+TkOZdJIQjCUl+nOkURfGu4KKbtN/7+ncVbKpYH vhZV64wNpgwVWehwB9DFqY6KyVyUA7fSGX/+LWlBFiG1V8tcqooxXdHwadGD93H5Dd/PwVL QhhYZbx0DISViq8bQM8ksLpk9LdQ069M67OKydmOkjFd8Pa8u/7KPgO/dVEA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1764396438; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=sA0sTK7DVZWnZdbjR8bIlxl9//RKgVGraKmIXW8L+1Q=; b=ZvQIfGfLCRGbhbrNff9LeOubbMCrv73Mgczs666oXUKhjns/VrTL2xIXfWaZx462HtkIn +Ts72XzhbQeDILdyxCN8QnfmXbFC6jN++4p8sIT+nsZDXtOTlcNeNFInKtkS7SFOTIgxW4Z Zhk08g85UCbnmRoMjYn2u69GNJQTK6Q6w+mJgK3fH7mz/EAuzqzbWb2AquHTiWSChwf7N9N S6mzjE1l0Ndemz4pAjO8CPQXhCKsyHQZasD+WWdEtx0ZdLUfuu7poIzSLgOsxd4VOkVuXAa SHoIb4vJkeezi/gylZgxInAFo3jCIqHM7fhOr7/TjoniweruSKB8Djw70Nyw== Received: from 55ca25703178 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id AC21069023C for ; Sat, 29 Nov 2025 08:07:18 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Sat, 29 Nov 2025 06:07:18 -0000 Message-ID: <176439643886.39.17832507834584934524@2cb04c0e5124> Message-ID-Hash: ZW3BO6DLTKLOGXLZPN2LLHUBTRHE3T52 X-Message-ID-Hash: ZW3BO6DLTKLOGXLZPN2LLHUBTRHE3T52 X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] hwcontext_vulkan: add support for implict DRM sync for export (PR #21042) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: russelltg via ffmpeg-devel Cc: russelltg Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21042 opened by russelltg URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21042 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21042.patch When a frame is exported to DRM, it may be written to to read to in an asyncronous fashion. Make sure, on unmap of a Vulkan frame that was mapped to DRM, to import any fences that were put on the dmabuf. The context for myself here is I'm working on a vulkan-video based screen recorder, which allocates vulkan frames using ffmpeg, then exports them as DRM dmabuf to send to the compositor, which then writes to it. Without this change, I see all sorts of frame corruption because the read from ffmpeg's vulkan filter happens before/during the compositor writing to it. >>From 52c81b688fcc77f6274c64911c67ace14cb7f4ec Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Fri, 28 Nov 2025 23:04:57 -0700 Subject: [PATCH] hwcontext_vulkan: add support for implict DRM sync for export When a frame is exported to DRM, it may be written to to read to in an asyncronous fashion. Make sure, on unmap of a Vulkan frame that was mapped to DRM, to import any fences that were put on the dmabuf --- libavutil/hwcontext_vulkan.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index a2caaa0959..5b0607089c 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -3488,7 +3488,7 @@ fail: } static int vulkan_map_from_drm_frame_sync(AVHWFramesContext *hwfc, AVFrame *dst, - const AVFrame *src, int flags) + const AVDRMFrameDescriptor *desc, int flags) { int err; VkResult ret; @@ -3498,8 +3498,6 @@ static int vulkan_map_from_drm_frame_sync(AVHWFramesContext *hwfc, AVFrame *dst, AVVulkanDeviceContext *hwctx = &p->p; FFVulkanFunctions *vk = &p->vkctx.vkfn; - const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)src->data[0]; - #ifdef DMA_BUF_IOCTL_EXPORT_SYNC_FILE if (p->vkctx.extensions & FF_VK_EXT_EXTERNAL_FD_SEM) { VkCommandBuffer cmd_buf; @@ -3619,6 +3617,7 @@ static int vulkan_map_from_drm(AVHWFramesContext *hwfc, AVFrame *dst, { int err = 0; AVVkFrame *f; + const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)src->data[0]; if ((err = vulkan_map_from_drm_frame_desc(hwfc, &f, src, flags))) return err; @@ -3633,7 +3632,7 @@ static int vulkan_map_from_drm(AVHWFramesContext *hwfc, AVFrame *dst, if (err < 0) goto fail; - err = vulkan_map_from_drm_frame_sync(hwfc, dst, src, flags); + err = vulkan_map_from_drm_frame_sync(hwfc, dst, desc, flags); if (err < 0) return err; @@ -4037,6 +4036,10 @@ static void vulkan_unmap_to_drm(AVHWFramesContext *hwfc, HWMapDescriptor *hwmap) { AVDRMFrameDescriptor *drm_desc = hwmap->priv; + /* on unmap from DRM, make sure to import sync objects so that we are sync'd with any work that was + * done on the buffer while exported. We don't know if who used the dmabuf did reads or writes, so protect against both */ + vulkan_map_from_drm_frame_sync(hwfc, hwmap->source, drm_desc, AV_HWFRAME_MAP_READ | AV_HWFRAME_MAP_WRITE); + for (int i = 0; i < drm_desc->nb_objects; i++) close(drm_desc->objects[i].fd); -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org