From patchwork Tue Nov 23 09:01:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31556 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp8353911iob; Tue, 23 Nov 2021 01:06:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyutMlghk/ge/pUo+9/53DMsVwgADebexl1rKCfXUnLrzgHgCdhw1aeqFT4x7pDnPeh2nfE X-Received: by 2002:a17:906:c111:: with SMTP id do17mr5589820ejc.284.1637658368196; Tue, 23 Nov 2021 01:06:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637658368; cv=none; d=google.com; s=arc-20160816; b=jFwp9+aYWvnLZ0rWAer69GgQ8RW6hX1eRalfXBP6c1N8xYtw+c+UThMIDncpyFRhlr aNS/mJzeLIE48qnm6wUdpYDh4tXOkHY/SZXPXxQZikZsZwCvCB0yKYjCushjs+jUyqAv A7zbFmAfsLG0lJ9FTN26w9y1X/hY+B1x+O0uG2V1I7bxiU4bWX83+VHG98D1SJdgX9KR uyfxNQCaenvaIiLpldfmoM7P2DMbmlWIQhsneCIHM7ddr6v3dPvyBipGsi2Mx2n9XwH1 MTdDn4Qlt4qgguD28UJKDUxTEhYqGLEv4TP5o1jz6TAVPSkxg4XW+9WOML+PsTqME+MB vd+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=W3dR5E4C2K7T1lqGoAoA1a7G3vOsI/a1Nw0Wi7QMtr0=; b=gktTRceZrl3e7vIdtgkcoeCdgpMF+U1yhClK9X9Bj0/Rv9HaZHzrpGBWf0S4HloA7C sy2+TKx3wRJeBvG1dWcY/X6q245XvTd/rDCbSbhCwQz8zhMzEwz59fJDv1PvDugk/zag Npiqzk/SB327nV3KmsEcUeualBlWcK/Ou0FdZEfZUYdMLBDpArxWx5H/ioDw2uzAYqKi RehCeqcu301wOrLgLKIXh/WFUwzXQssyHjC70sS3fYZn+Y+iHds6R9gjR7kP3SJ3+bLf Kw8i1iueRzw+8D3eeY6epeG1275IRhjfgNhZoKIcDFJDeEi2bDC95SovJKPAo2RUuIuW 1plw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id sh11si36273293ejc.687.2021.11.23.01.06.07; Tue, 23 Nov 2021 01:06:08 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1BF2568A441; Tue, 23 Nov 2021 11:06:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B4C486802C3 for ; Tue, 23 Nov 2021 11:05:54 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10176"; a="221866466" X-IronPort-AV: E=Sophos;i="5.87,257,1631602800"; d="scan'208";a="221866466" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 01:05:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,257,1631602800"; d="scan'208";a="509337649" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga008.jf.intel.com with ESMTP; 23 Nov 2021 01:05:45 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 Nov 2021 17:01:16 +0800 Message-Id: <20211123090119.868788-1-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avutil/vulkan_functions: add EnumerateInstanceLayerProperties X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QVHd7SmhCQpi Signed-off-by: Wu Jianhua --- libavutil/vulkan_functions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h index 85a9f943c8..96922d7286 100644 --- a/libavutil/vulkan_functions.h +++ b/libavutil/vulkan_functions.h @@ -45,6 +45,7 @@ typedef enum FFVulkanExtensions { #define FN_LIST(MACRO) \ /* Instance */ \ MACRO(0, 0, FF_VK_EXT_NO_FLAG, EnumerateInstanceExtensionProperties) \ + MACRO(0, 0, FF_VK_EXT_NO_FLAG, EnumerateInstanceLayerProperties) \ MACRO(0, 0, FF_VK_EXT_NO_FLAG, CreateInstance) \ MACRO(1, 0, FF_VK_EXT_NO_FLAG, DestroyInstance) \ \ From patchwork Tue Nov 23 09:01:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31553 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp8354210iob; Tue, 23 Nov 2021 01:06:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxskDJHKiTvhxf6lsjs6MC2rz3QwwL48KqNa92qsEiuCaJf5SCPoV/D+SypFpj6TCtp8MBy X-Received: by 2002:a05:6402:4404:: with SMTP id y4mr6647017eda.321.1637658381539; Tue, 23 Nov 2021 01:06:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637658381; cv=none; d=google.com; s=arc-20160816; b=UABl0OGXULco63VlzsqScbCgf8NC+uC+gQBKqtHrr0iG8ZV+NQTi2KS476wfIIjPBy Vege+MSz04eCVNMJYHFeEGKOxtmWeTh8ra2Z8HPB60pbOhX1k92a6JKpbsTtLsVnDalT wDOeVtbzN3F7/nbjy71o4sCzPdZQ3EFi8dY+ouvELSteqsYVxQIPMqOAWdGz7E8z7ru2 n4/Fam9NoNlRhb37UDMyAN2UCnHUZ1AMKGoHMGVGisOFwJWvgzeV/4bhrHp/hz+Qh5HH tSQtrPKcNp01+S0qK003JeXr50NrFRhy1tfMGD9Yw7wbyiKnjD/uZEb7Tt18zheaCP89 NyFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=ePkngWxoPWp9VVSaBCGCvdp9GlpovrjD0fLD88TjdLs=; b=gxFns+tEXg0jtrB0oxyYojJTwwcEpCcgzfZ/RTCYzL9ZQr86S3gKqMoz8PZOKqJU0S C5ge0hOJEnoUV+7cz3Sovr3hL+R0Wy8HwENOOxn9Fkg/GGPFTXK/NXQE6LClaNXpSajQ caGI183SzT9SLTX78C9o2ypZZYDnF820VH13yXEe1ju4qMSI7jGN+heLSqqbcYqe0hxU VSP/n6qgdsGNMhZghhOGRta3m+tVORWc7BGeNg5725iWLEGfQMaSHDrHqS6M6pQomo69 UGVkD+6WymoA5hsrSGi+wQK3uprdw0ahKIOx72GSk2DJXWD4gayLPoOZGjZ/qLR2iv/D yRBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qw32si41665257ejc.13.2021.11.23.01.06.20; Tue, 23 Nov 2021 01:06:21 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3040468AE99; Tue, 23 Nov 2021 11:06:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9FB1E687F25 for ; Tue, 23 Nov 2021 11:06:00 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10176"; a="221866471" X-IronPort-AV: E=Sophos;i="5.87,257,1631602800"; d="scan'208";a="221866471" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 01:05:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,257,1631602800"; d="scan'208";a="509337676" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga008.jf.intel.com with ESMTP; 23 Nov 2021 01:05:46 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 Nov 2021 17:01:17 +0800 Message-Id: <20211123090119.868788-2-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211123090119.868788-1-jianhua.wu@intel.com> References: <20211123090119.868788-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] avutil/hwcontext_vulkan: check if created before destroying the device X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Tm0cgkRvsjbM Signed-off-by: Wu Jianhua --- libavutil/hwcontext_vulkan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index f1e750cd3e..4ac1058181 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -1150,7 +1150,8 @@ static void vulkan_device_free(AVHWDeviceContext *ctx) FFVulkanFunctions *vk = &p->vkfn; AVVulkanDeviceContext *hwctx = ctx->hwctx; - vk->DestroyDevice(hwctx->act_dev, hwctx->alloc); + if (hwctx->act_dev) + vk->DestroyDevice(hwctx->act_dev, hwctx->alloc); if (p->debug_ctx) vk->DestroyDebugUtilsMessengerEXT(hwctx->inst, p->debug_ctx, From patchwork Tue Nov 23 09:01:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31555 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp8354415iob; Tue, 23 Nov 2021 01:06:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3xjLMZpI3vrw0bLbV2hE/so8abSB6MZsZzgo9GAiaTmOW6Dew74G7MSnbDYAiQ4ZVBPK/ X-Received: by 2002:a17:907:7f9e:: with SMTP id qk30mr5547986ejc.238.1637658392432; Tue, 23 Nov 2021 01:06:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637658392; cv=none; d=google.com; s=arc-20160816; b=W27uwBndCgTr6xePZnxffSChzzYzupb9clXa5zv3CscRq1JROpUnUyvsV5QEIImehI 98/NXzgeEOEKskDRuULKVBHLSm2Il7ZjZxMTofpBYpfZ7mrjupuAo4HGGCrg9t8KXhS4 McBLmkgD3GlvglKHD/X4NmwTLk5KVOk6iSQWq2m+np6GFRfX5Cvjc4+iS7Ql1vgR0wNE kt3Bwy+kMU2ahTU/KMhnE3F0MWt7ZQZbdnuV7hVtq3vRQ3fvD3NfuRJ8v9Cq0681UcYK xXMQbzR/ukI8NvfOyC/CRsrcwRnqHPcQdqREbWBX8zcI2ZNQChq+5Zd1FgkQ1Z+T1fee N2lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=5ijkrQn0AO5jHIcsPCDYnSRdfPgiP/5oo3b+/VPDNiE=; b=RRWA8/VppTu0iD6JY+xJ/IMsSotUB52i0CdfcLInQAxqF1P0YAfgIqo1jbQ1hWzj0m re8KAF1AgPqcW2E4lR9yI7bnQH/s+2yTPDGzbjn+57E13jtTVQrrivDL4TrTA9XOZVnG XmJfgqgTj1U1dYPRXYyK4sU8fnEW7X7udjmRTysb34aF7Qf+X680G596qS6ubOLYl02t uVhOwIvGI70Pb0WxpDX6UaXeth9en3qo+XW9FG39ZIAahFxKQUiLXr00a2ZQqAd8i+Z1 NHoKqMYdq8Wzpl+QuhhyKAaYi8Szu2Qi5XEO1dOtBkVJneAwNRTqjsdQg4BVATtFSng4 yRLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u9si32916659edp.507.2021.11.23.01.06.31; Tue, 23 Nov 2021 01:06:32 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3227D68AEA2; Tue, 23 Nov 2021 11:06:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EB5C568AE8C for ; Tue, 23 Nov 2021 11:06:01 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10176"; a="221866476" X-IronPort-AV: E=Sophos;i="5.87,257,1631602800"; d="scan'208";a="221866476" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 01:05:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,257,1631602800"; d="scan'208";a="509337709" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga008.jf.intel.com with ESMTP; 23 Nov 2021 01:05:47 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 Nov 2021 17:01:18 +0800 Message-Id: <20211123090119.868788-3-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211123090119.868788-1-jianhua.wu@intel.com> References: <20211123090119.868788-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avutil/hwcontext_vulkan: check if created before destroying the instance X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GkHu1m/tiX17 Signed-off-by: Wu Jianhua --- libavutil/hwcontext_vulkan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 4ac1058181..644ed947f8 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -1157,7 +1157,8 @@ static void vulkan_device_free(AVHWDeviceContext *ctx) vk->DestroyDebugUtilsMessengerEXT(hwctx->inst, p->debug_ctx, hwctx->alloc); - vk->DestroyInstance(hwctx->inst, hwctx->alloc); + if (hwctx->inst) + vk->DestroyInstance(hwctx->inst, hwctx->alloc); if (p->libvulkan) dlclose(p->libvulkan); From patchwork Tue Nov 23 09:01:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31554 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp8354666iob; Tue, 23 Nov 2021 01:06:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2iXil5UEFf+9kfMhkiDuft31cIaP/uf0EHkSfS0SGdOzqUpcP+n1zW/K1Mk8lJtvPWq38 X-Received: by 2002:a17:906:1558:: with SMTP id c24mr5584159ejd.553.1637658405141; Tue, 23 Nov 2021 01:06:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637658405; cv=none; d=google.com; s=arc-20160816; b=wYeOAkLZ+xeg3rNK4S5rmu2EK5QXzpTJh/QVEOJ9K6nraVJeoNmKZtde14QlOfvlpK GfFW8t3XANf7sdrFO+mQQkMwb4wOAA2i0UOTZJcZ3fsQzi9STbv8GHZjIHodAGmLdsXz y+ag2JZKiapEjdgOvEbp6rkjUJKwYRa5S9fR8DYd4OcSaekV76XO1iWPLVVlj3XX1iE7 i0Bh7Hw/DO/qSnIKNBarE6lb9eJpeOlSeHhlnsuuKhQDfHJKgJZwEVKQdFJJzlWclcUA bNE9uV9J9HTZysCo1hkUC975RKUggzS7w7fpAgJvy0TK3X7ZNBxZDvLbpqwrxZUEGvtq kU5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=4HeFQVcTKvl1f6j4VvmQgJVRx4aZxjYfrHN60LO0rmI=; b=AS3z2bnzKUD+Spmvl4VFXpbhlDRRfScVXeTJov4wo6hriFgZCfMuXeZphjMz6AC8vB pO2n53Vn4cVrHMVRtIa8ygywRiHNP0CR6xzLOX9NWBXIHQXKgnDC4F1M5ltE4WkJFBFa HwnScjLOWcx8wqD9Gltk1jLEgq3iW3fvQ/U2ecB7q6BVrtZksBpwOL/yXy5DlxWgq8+O Eykmzg9+KD+WsteDw4M5/9aJO+SpfkkmpnoJtY7gqjxUCX/p1eJkU6QTlG2BoozGIhT6 izkH+wDqfd9dagFWpF7cz9Uybw/E4YCDWa0JWYTtChcUfPtHh5U+mbKQZCAMsFSecCGa 0PXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id jg4si37978421ejc.55.2021.11.23.01.06.44; Tue, 23 Nov 2021 01:06:45 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4E56468AEBA; Tue, 23 Nov 2021 11:06:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C150687F25 for ; Tue, 23 Nov 2021 11:06:06 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10176"; a="221866478" X-IronPort-AV: E=Sophos;i="5.87,257,1631602800"; d="scan'208";a="221866478" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 01:05:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,257,1631602800"; d="scan'208";a="509337737" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga008.jf.intel.com with ESMTP; 23 Nov 2021 01:05:48 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 Nov 2021 17:01:19 +0800 Message-Id: <20211123090119.868788-4-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211123090119.868788-1-jianhua.wu@intel.com> References: <20211123090119.868788-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: NrxEnslTPHBd Validation layer is an indispensable part of developing on Vulkan. The following commands is on how to enable validation layers: ffmpeg -init_hw_device vulkan=0,debug=1,validation_layers=VK_LAYER_KHRONOS_validation+VK_LAYER_LUNARG_api_dump Signed-off-by: Wu Jianhua --- libavutil/hwcontext_vulkan.c | 110 ++++++++++++++++++++++++++++------- libavutil/hwcontext_vulkan.h | 7 +++ 2 files changed, 97 insertions(+), 20 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 644ed947f8..b808f8f76c 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -146,6 +146,13 @@ typedef struct AVVkFrameInternal { } \ } while(0) +#define RELEASE_PROPS(props, count) \ + if (props) { \ + for (int i = 0; i < count; i++) \ + av_free((void *)((props)[i])); \ + av_free((void *)props); \ + } + static const struct { enum AVPixelFormat pixfmt; const VkFormat vkfmts[4]; @@ -511,15 +518,83 @@ static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts, return 0; fail: - if (extension_names) - for (int i = 0; i < extensions_found; i++) - av_free((void *)extension_names[i]); - av_free(extension_names); + RELEASE_PROPS(extension_names, extensions_found); av_free(user_exts_str); av_free(sup_ext); return err; } +static int check_validation_layers(AVHWDeviceContext *ctx, AVDictionary *opts, + const char * const **dst, uint32_t *num) +{ + int found, err = 0; + VulkanDevicePriv *priv = ctx->internal->priv; + FFVulkanFunctions *vk = &priv->vkfn; + + uint32_t sup_layer_count; + VkLayerProperties *sup_layers; + + AVDictionaryEntry *user_layers; + char *user_layers_str, *save, *token; + + const char **enabled_layers = NULL; + uint32_t enabled_layers_count = 0; + + user_layers = av_dict_get(opts, "validation_layers", NULL, 0); + if (!user_layers) + return 0; + + user_layers_str = av_strdup(user_layers->value); + if (!user_layers_str) { + err = AVERROR(EINVAL); + goto fail; + } + + vk->EnumerateInstanceLayerProperties(&sup_layer_count, NULL); + sup_layers = av_malloc_array(sup_layer_count, sizeof(VkLayerProperties)); + if (!sup_layers) + return AVERROR(ENOMEM); + vk->EnumerateInstanceLayerProperties(&sup_layer_count, sup_layers); + + av_log(ctx, AV_LOG_VERBOSE, "Supported Validation layers:\n"); + for (int i = 0; i < sup_layer_count; i++) + av_log(ctx, AV_LOG_VERBOSE, "\t%s\n", sup_layers[i].layerName); + + token = av_strtok(user_layers_str, "+", &save); + while (token) { + found = 0; + for (int j = 0; j < sup_layer_count; j++) { + if (!strcmp(token, sup_layers[j].layerName)) { + found = 1; + break; + } + } + if (found) { + av_log(ctx, AV_LOG_VERBOSE, "Requested Validation Layer: %s\n", token); + ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, token); + } else { + av_log(ctx, AV_LOG_ERROR, + "Validation Layer \"%s\" not support.\n", token); + err = AVERROR(EINVAL); + goto fail; + } + token = av_strtok(NULL, "+", &save); + } + + *dst = enabled_layers; + *num = enabled_layers_count; + + av_free(sup_layers); + av_free(user_layers_str); + return 0; + +fail: + RELEASE_PROPS(enabled_layers, enabled_layers_count); + av_free(sup_layers); + av_free(user_layers_str); + return err; +} + /* Creates a VkInstance */ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) { @@ -558,13 +633,18 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) /* Check for present/missing extensions */ err = check_extensions(ctx, 0, opts, &inst_props.ppEnabledExtensionNames, &inst_props.enabledExtensionCount, debug_mode); + hwctx->enabled_inst_extensions = inst_props.ppEnabledExtensionNames; + hwctx->nb_enabled_inst_extensions = inst_props.enabledExtensionCount; if (err < 0) return err; if (debug_mode) { - static const char *layers[] = { "VK_LAYER_KHRONOS_validation" }; - inst_props.ppEnabledLayerNames = layers; - inst_props.enabledLayerCount = FF_ARRAY_ELEMS(layers); + err = check_validation_layers(ctx, opts, &inst_props.ppEnabledLayerNames, + &inst_props.enabledLayerCount); + hwctx->enabled_validation_layers = inst_props.ppEnabledLayerNames; + hwctx->nb_enabled_validation_layers = inst_props.enabledLayerCount; + if (err) + return err; } /* Try to create the instance */ @@ -574,9 +654,6 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) if (ret != VK_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Instance creation failure: %s\n", vk_ret2str(ret)); - for (int i = 0; i < inst_props.enabledExtensionCount; i++) - av_free((void *)inst_props.ppEnabledExtensionNames[i]); - av_free((void *)inst_props.ppEnabledExtensionNames); return AVERROR_EXTERNAL; } @@ -604,9 +681,6 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) hwctx->alloc, &p->debug_ctx); } - hwctx->enabled_inst_extensions = inst_props.ppEnabledExtensionNames; - hwctx->nb_enabled_inst_extensions = inst_props.enabledExtensionCount; - return 0; } @@ -1163,13 +1237,9 @@ static void vulkan_device_free(AVHWDeviceContext *ctx) if (p->libvulkan) dlclose(p->libvulkan); - for (int i = 0; i < hwctx->nb_enabled_inst_extensions; i++) - av_free((void *)hwctx->enabled_inst_extensions[i]); - av_free((void *)hwctx->enabled_inst_extensions); - - for (int i = 0; i < hwctx->nb_enabled_dev_extensions; i++) - av_free((void *)hwctx->enabled_dev_extensions[i]); - av_free((void *)hwctx->enabled_dev_extensions); + RELEASE_PROPS(hwctx->enabled_inst_extensions, hwctx->nb_enabled_inst_extensions); + RELEASE_PROPS(hwctx->enabled_dev_extensions, hwctx->nb_enabled_dev_extensions); + RELEASE_PROPS(hwctx->enabled_validation_layers, hwctx->nb_enabled_validation_layers); } static int vulkan_device_create_internal(AVHWDeviceContext *ctx, diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h index fdf2a60156..80c36d6f26 100644 --- a/libavutil/hwcontext_vulkan.h +++ b/libavutil/hwcontext_vulkan.h @@ -85,6 +85,13 @@ typedef struct AVVulkanDeviceContext { const char * const *enabled_inst_extensions; int nb_enabled_inst_extensions; + /** + * Enabled validation layers. + * If no layers are enabled, set these fields to NULL, and 0 respectively. + */ + const char * const *enabled_validation_layers; + int nb_enabled_validation_layers; + /** * Enabled device extensions. By default, VK_KHR_external_memory_fd, * VK_EXT_external_memory_dma_buf, VK_EXT_image_drm_format_modifier,