From patchwork Wed Nov 24 04:11:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31615 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp9779784iob; Tue, 23 Nov 2021 20:16:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAax0eqdCMBlbUlZeB8Snw29xqt7rYmVDwa7FHuDC7MJS6yVyHc8MQK9HZUMTD/34kox1A X-Received: by 2002:a17:906:7955:: with SMTP id l21mr16514101ejo.6.1637727375528; Tue, 23 Nov 2021 20:16:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637727375; cv=none; d=google.com; s=arc-20160816; b=MSS4RgFijU8/fPgfQG+jW/bnfsWLn09L53afEHvZ5orHzZXoSqmmgatrIpp5A/z0Zd Vah8Vd6LI50/7hJ4bum4jU54Z3/miJD42o19fsYNboSvhW2Rr/3f+GHywhliqE4hhClm FLYJZxMLUex32o8QtcvUgZfZ9j6XXtVYPofeH0XlKZ5Wg4W1CgRrOtQ0D1Jy9WV1gnAn KzITkGgbyJoQaV30eJJvw8YgBDbEekU5BhfLC22EXYaVWJzn7FTaKjRAK4P4gJo7TxXY f9XXlbcoBoDcx4grsTwxVR30o/ANcvozUE0YcRfUOSnZCOF8EXzUINqdBCaqjlKZbU0y F6/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=xnSpRdfbSaYcZTn4+JW9fR1Eo3toH4x8jH0f/T/QcGRNmt8RxLrdE3ulwfnnioApIb FNda1xBW/8PIk//U75kc9CD3CnJ3tHjrbrIf85c6kuSsnP4KIrdU408h2/j7gTdqvDUi USc4W1/T6gcDm0tw4x6pq7gETIGB3VKg77YTdr28UVkOEgqTlOj3weVUiSivFpM8HFzu pRvuAQoA9evkWfdEHc7vveIHoBSbSvkPYSTWvbvo3BSKRo+VJJI55/NB8ynMHCjUfT3u gGepY/KZWYUcnoVZd9JRlJbXwHp0U3csP3Hfjil4zvWUiZgBAH4cHg8zvE5Kq7CGMWaZ JxsA== 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 e10si6117754edj.222.2021.11.23.20.16.14; Tue, 23 Nov 2021 20:16:15 -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 E1A99688073; Wed, 24 Nov 2021 06:16:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 77452688073 for ; Wed, 24 Nov 2021 06:16:03 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10177"; a="232692339" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="232692339" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 20:16:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="509676681" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga008.jf.intel.com with ESMTP; 23 Nov 2021 20:16:00 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Nov 2021 12:11:51 +0800 Message-Id: <20211124041154.1090109-1-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: 0UJy5G/kUfUZ 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 Wed Nov 24 04:11:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31614 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp9779984iob; Tue, 23 Nov 2021 20:16:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1GmuXekCq6cxGn7h/r1JtYKZfxRTSEZMx4HySI/rMLWfR8sgsbzyTcNAIebIBZln08VcI X-Received: by 2002:a05:6402:100e:: with SMTP id c14mr19582560edu.196.1637727385642; Tue, 23 Nov 2021 20:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637727385; cv=none; d=google.com; s=arc-20160816; b=Ojz8dsK8dUMTkOBiHwyAVGO3wBt88NlddKvbOwBlPZ2S3FP0gP+P18pF1RBAGMQZDz ZvIFYxv/U0VmPbbbnfWJ+BU2Uu5qwjWnglW1AYtzMemvX+B0b8p9T9sxJTBPhmiOon+P hV3cxoezLH4jr9MZu9XOn7gjEqKUw7H9tCz4hhnmM90ukTu2OQSVCdMe5ltMWExtKs5m 4p3McjLU5vRjm3qP+RYMRtXHL7YDImVAnM9vdTRctEV731w3iGakR3kK3wOMbuuYMmeu 8ga8KDBvmJEB5qtEmUdKzlCojBQkzVeg7D3yyUC53f8D7PmXxyw97ugqLS6RG2kcU2/1 aYrA== 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=v1QXWyNTVBOtl1B+/+88uho4NfFl7JtxIMMvlTMQd/9MzL6BnoxE2bkWyunPW7318g ryO2x36KCM0memLuyCQJNKBx+wqnXn6/IdWgDbQ9zwDfi84uhShPvy2LR76OF+wx04ze U+f/5+wf8j1WjyN77Ed5TmBw0XZdliajVP6HIbroHQMIIuYqzW2wVBzWCWaYYKSt78jN zkQnA4xTT1PkSdQmE07z9m1m/i5BF+2OQSWlc2jqmqZ3PnSlPjJqoKVvV+K1JFF5uA+6 j5xutd1YJZfUdanoospjQM2eObvoGz29lP8+qbGLnbX4TXfJkg9ld9y5S0ZTNJ6mmjq4 fp7Q== 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 dm11si37703918ejc.54.2021.11.23.20.16.25; Tue, 23 Nov 2021 20:16:25 -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 1450368AEDE; Wed, 24 Nov 2021 06:16:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2021C688073 for ; Wed, 24 Nov 2021 06:16:04 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10177"; a="232692342" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="232692342" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 20:16:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="509676695" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga008.jf.intel.com with ESMTP; 23 Nov 2021 20:16:01 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Nov 2021 12:11:52 +0800 Message-Id: <20211124041154.1090109-2-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124041154.1090109-1-jianhua.wu@intel.com> References: <20211124041154.1090109-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: dxcCH+b6NiOh 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 Wed Nov 24 04:11:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31613 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp9780181iob; Tue, 23 Nov 2021 20:16:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSgPJIRw0gzglgx8Dc4og9TeQt9uAHrrKMAbbODVmWnINGKNC+SeELU+T9nNlJt+x3uDye X-Received: by 2002:a05:6402:430e:: with SMTP id m14mr19330124edc.93.1637727395476; Tue, 23 Nov 2021 20:16:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637727395; cv=none; d=google.com; s=arc-20160816; b=i/vOmtE44UpQ0UMUFoqs3wO+ZPl2DIjbJ7xqD88ALYyMvQSH8mcqlj9+be3ScamQs/ bzrL0duS0XTH0raXVxrA84zk8GvqoKHivTSoIZgvBs9ZOOllAHxbZ8TCnQk5mrZYZZOb Avpr60XzZ7TozRCdQYqIMgFmoCKbxkhJNXl8XHa3nkOp3RcINZQONfPlocZfihXW2Xds H1ddy6oFf41YaJPbW2ymIEC2g3ESsBsJs6M+Rm+/WcR4ZJX3VQPXUpl+NkdKBfItTr5s QvqxV1nVbxt2aitQlQZdzWaMql/21Gb+OmQ1nvVkVSzf4mUI0dTC9CXx9WVabxhJSTLx lWfg== 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=Sfofvb30miW3XkKs5hZ71Viv1I/U+BnjKF7d+WwRYibCewVnfOwDOORzN5dsuFhkOB NaMSXT3XDNYIYfDgVOcTzunCyvGhdEcx1C8BXMBg1tFAZp+FlMMd6GkCw4NILzA6dQyf XF61eXY3Neyp3zy0FT8LX5oxVPo+WrnxVieIPkQAgA3n2dMBWd4TQtayTNf/7kO+dh3k dHPt1RbQcXc5lAyM1AdqlcfBixjNcBDSwYrZw5n9nTiv3NgzQeCquiRsK5E5aeQ1sDHi jKNieULDBGWaPUM+9C1MWtMqF/Lq8UGykGVeF+mKgtR1SYB63Q3CX8+n7vgHLJ0Ew5bL DPhg== 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 g2si51294031ejt.760.2021.11.23.20.16.35; Tue, 23 Nov 2021 20:16:35 -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 207A468AF0E; Wed, 24 Nov 2021 06:16:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 811CA68AEBF for ; Wed, 24 Nov 2021 06:16:06 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10177"; a="232692347" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="232692347" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 20:16:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="509676705" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga008.jf.intel.com with ESMTP; 23 Nov 2021 20:16:02 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Nov 2021 12:11:53 +0800 Message-Id: <20211124041154.1090109-3-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124041154.1090109-1-jianhua.wu@intel.com> References: <20211124041154.1090109-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: rR/jd5+d0Toa 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 Wed Nov 24 04:11:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31616 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp9780420iob; Tue, 23 Nov 2021 20:16:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/W3XyhviQSCCoUlmU7nIeHBSVeSrxNUknfRbIyQ0h2C/7f2zSydgzhVy4kNefed/8gssX X-Received: by 2002:a05:6402:516c:: with SMTP id d12mr19143678ede.391.1637727406221; Tue, 23 Nov 2021 20:16:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637727406; cv=none; d=google.com; s=arc-20160816; b=ElzNqZGfpGlD5daMLY6DWOIPH5wTqS4lbkJ4eLdtkHuFk/xEdhQOkv6FZ/oFjTTt7f z9Wz9W5WeOrrEddWSJgsnHiohdp+tbd6RYutfGRhWUntysLbDmRafOhKB5XgJlINsLuN 3Sr1LFdK4PVzQUw+Je3SvEaeaL6zxLD7CgmjGy8pXIug3K6d0p7QYyseCig49GOUk+Wx QTY1n9LAgpP/BXSh7e6pACszB4xv4xbftTkC43wCbzrZQV/6IOc6AqtNi7eV+4WC1ji4 1W2C6AJ+hK2UQ9lF6J3LYL3vsDqYoI8En64rLf18l+BgORF293HPA2JACZ7l47mojeZV ZkHA== 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=3ztOGrJtL72P9lFjsq5k72N1G5JP3awOk4npeb+UXa4=; b=lJWF5Oi3IUuCXCuIhEfQy3yKZuS2575eyAIToS86bphoYm9fuvwCqlDbAli1ckrqPG I59By5ZmenSmr0Gv/gegpu0yHif2sTIr969GRnK7G4F2oABJ4S+OlAIuQibHK+xYnmF5 QBU/MKY86Cpbv8OlfTs+RGvcs/9NEpAhb9U1FMPtqUDw29WFFwhvVKsbtP/tRLqjbTb6 0y8OgqMjw0+71nSlIlNj13De1ngkP67jXMI+tqWOAgeydL3+wJ12mHsZl0D7grMh7BPF UW/BcUkT1EIxDhoGIKLD9PbDSpqmqdzVMHnvj/8sKxnIfAyyEMlXkM900KRzy2G7Iyj2 QlSw== 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 k23si32826962edk.555.2021.11.23.20.16.45; Tue, 23 Nov 2021 20:16:46 -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 3383468AE6D; Wed, 24 Nov 2021 06:16:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7020A68AF0C for ; Wed, 24 Nov 2021 06:16:09 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10177"; a="232692353" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="232692353" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 20:16:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="509676715" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga008.jf.intel.com with ESMTP; 23 Nov 2021 20:16:03 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Nov 2021 12:11:54 +0800 Message-Id: <20211124041154.1090109-4-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124041154.1090109-1-jianhua.wu@intel.com> References: <20211124041154.1090109-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: Eti9nZjGhi6V 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_LUNARG_monitor+VK_LAYER_LUNARG_api_dump Signed-off-by: Wu Jianhua --- libavutil/hwcontext_vulkan.c | 136 +++++++++++++++++++++++++++++------ 1 file changed, 113 insertions(+), 23 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 644ed947f8..75f9f90d70 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,101 @@ 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) +{ + static const char default_layer[] = { "VK_LAYER_KHRONOS_validation" }; + + int found = 0, 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); + if (!strcmp(default_layer, sup_layers[i].layerName)) + found = 1; + } + + if (!found) { + av_log(ctx, AV_LOG_ERROR, "Default layer\"%s\" isn't supported. Please " + "check if vulkan-validation-layers installed\n", default_layer); + } else { + av_log(ctx, AV_LOG_VERBOSE, + "Default validation layer %s is enabled\n", default_layer); + ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, default_layer); + } + + token = av_strtok(user_layers_str, "+", &save); + while (token) { + found = 0; + if (!strcmp(default_layer, token)) { + token = av_strtok(NULL, "+", &save); + continue; + } + 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 +651,16 @@ 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; + goto fail; 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); + if (err) + goto fail; } /* Try to create the instance */ @@ -574,16 +670,14 @@ 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; + err = AVERROR_EXTERNAL; + goto fail; } err = ff_vk_load_functions(ctx, vk, p->extensions, 1, 0); if (err < 0) { av_log(ctx, AV_LOG_ERROR, "Unable to load instance functions!\n"); - return err; + goto fail; } if (debug_mode) { @@ -604,10 +698,11 @@ 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; + err = 0; - return 0; +fail: + RELEASE_PROPS(inst_props.ppEnabledLayerNames, inst_props.enabledLayerCount); + return err; } typedef struct VulkanDeviceSelection { @@ -1163,13 +1258,8 @@ 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); } static int vulkan_device_create_internal(AVHWDeviceContext *ctx,