From patchwork Sun May 10 10:54:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 19605 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bac9:0:0:0:0:0 with SMTP id a9csp1069802ybk; Sun, 10 May 2020 03:54:44 -0700 (PDT) X-Google-Smtp-Source: APiQypJpeKBmiMLekWg6H0R5d6pWwhgtfOG4bHp/KYnJc7OiHAU85z8LvWROREGRmO6UpQO5lJR9 X-Received: by 2002:a5d:6ac1:: with SMTP id u1mr12864781wrw.319.1589108083997; Sun, 10 May 2020 03:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589108083; cv=none; d=google.com; s=arc-20160816; b=qdt2xku1ZSx0XPnGlPemXFiV14Dy1IBFtr+ItNm7f8dkbEWu5BMuEg8KIx0gk0ErF/ 0ut3NTxelWlZmHtGAt6ZF1l4JgoZE4VeR4xWfZ9QlZzfXInNTsnYt/69b6AznySwNeuK T5+GjAiFpHOL4vNjQpurrvfwGFBwnsLjqFgdyXPrGzb6ShyjJP+SbrVigO3Rk40OhnU/ kZlrWqeBH2xf6I8cckk8KQEH8xwN/wptdyEhUVXflk/SRgEHPQnm135cI/KvP+GUw9wV U0lxsyyeiGHyQVqVmHu7M9007Hy1HBorKQ0itjqFdD+43+lR1E+f+Uncvru+H56rlvJ7 PXNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=kvbcHN7hzQom6DtRJ0o1oAYNvpXXIXQvYF1cLgTep1A=; b=kTIuzAo1xQalN13CjBgoieP/Qg4ra86aBYmyDBIE1zRSPLMXCSxAapBkaqBNkdY6F5 TnLUwebAmOmJsvqJPBEKePRExxeeh6ibwhImfUwr5iA2HfSbEJ9FXvTCptB7lewn/JNx oE4lEOToqQEhTeeAQVyXhsVpsBOjWErsAXL1u34nF9ADi4Bq5zwoEFfORe3AjQ/cTSi6 h6N8iqBc6uZvXw7h0CqMslod9aZ3G9SIwGmZX+Euae528a1m/lWpXCWi6dxMMx4wgih2 JKV/qtZQ2aJ9A3nPHeie2OmBoZH99I1PDUEFyBblXWw9K/T3tHISvNU1J7g/DAtKCxA2 lKOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=McACPkuT; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y17si6718158wrr.464.2020.05.10.03.54.43; Sun, 10 May 2020 03:54:43 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=McACPkuT; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 77E056882EB; Sun, 10 May 2020 13:54:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3CF9A68816F for ; Sun, 10 May 2020 13:54:34 +0300 (EEST) Received: from w3.tutanota.de (unknown [192.168.1.164]) by w4.tutanota.de (Postfix) with ESMTP id DEA0D106029E for ; Sun, 10 May 2020 10:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1589108073; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=ldTVBQoDRFyyl9stfiiTZpNIetS9dSWo434gbh4cgog=; b=McACPkuTyX0GXpNJdODSUk/Qm+EXihsDQa9+VKvW3GvicINh09jDf5IfM7fmfBXz 65/MaPYrywQT+PBFBs4Lyjl8ve8xx3bVCcl4AUNdMRhAcZHX4AeliL3FhO69kD00h2p Ky7c3/4wJ2DzGQVv7ndggqIlBjMwqtTk2t4aePbbgETdCfeTYFiWSp3fA01z/kbi8Ct QLB3SrfgvvYwxC3WUGUxA88y3QHGlzlLUZeYN5mW5dW4IhECKjQ4OgyVJfkgoHdjV6M y+jg9b175eSz9C6c/xkmECf9oNfnFXCXt8O4Bpqpl8uNz/sANWyyWUNGMO3wV4f1Sok 2b6MBzxMCA== Date: Sun, 10 May 2020 12:54:33 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] hwcontext_vulkan: expose enabled device and instance extensions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HWj7c2FIVovd Content-Length: 6079 This solves a huge oversight - it lets users reliably use their own AVVulkanDeviceContext. Otherwise, the extensions supplied and enabled are not discoverable by anything outside of hwcontext_vulkan. Patch attached. This, and the previous patch to enable extensions through the options are really needed to make the hwcontext useful and interoperable with other Vulkan API users, so I'm planning to push them later tonight. Subject: [PATCH 2/2] hwcontext_vulkan: expose enabled device and instance extensions This solves a huge oversight - it lets users reliably use their own AVVulkanDeviceContext. Otherwise, the extensions supplied and enabled are not discoverable by anything outside of hwcontext_vulkan. --- libavutil/hwcontext_vulkan.c | 27 ++++++++++++++++++++++----- libavutil/hwcontext_vulkan.h | 12 ++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index a35c1d3a4f..4135cc5209 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -415,13 +415,11 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) /* Try to create the instance */ ret = vkCreateInstance(&inst_props, hwctx->alloc, &hwctx->inst); - /* Free used memory */ - av_free((void *)inst_props.ppEnabledExtensionNames); - /* Check for errors */ if (ret != VK_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Instance creation failure: %s\n", vk_ret2str(ret)); + av_free((void *)inst_props.ppEnabledExtensionNames); return AVERROR_EXTERNAL; } @@ -444,6 +442,9 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) hwctx->alloc, &p->debug_ctx); } + hwctx->enabled_inst_extensions = inst_props.ppEnabledExtensionNames; + hwctx->num_enabled_inst_extensions = inst_props.enabledExtensionCount; + return 0; } @@ -749,6 +750,9 @@ static void vulkan_device_free(AVHWDeviceContext *ctx) } vkDestroyInstance(hwctx->inst, hwctx->alloc); + + av_free((void *)hwctx->enabled_inst_extensions); + av_free((void *)hwctx->enabled_dev_extensions); } static int vulkan_device_create_internal(AVHWDeviceContext *ctx, @@ -809,11 +813,10 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, ret = vkCreateDevice(hwctx->phys_dev, &dev_info, hwctx->alloc, &hwctx->act_dev); - av_free((void *)dev_info.ppEnabledExtensionNames); - if (ret != VK_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Device creation failure: %s\n", vk_ret2str(ret)); + av_free((void *)dev_info.ppEnabledExtensionNames); err = AVERROR_EXTERNAL; goto end; } @@ -823,6 +826,9 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, if (opt_d) p->use_linear_images = strtol(opt_d->value, NULL, 10); + hwctx->enabled_dev_extensions = dev_info.ppEnabledExtensionNames; + hwctx->num_enabled_dev_extensions = dev_info.enabledExtensionCount; + end: return err; } @@ -834,6 +840,17 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) AVVulkanDeviceContext *hwctx = ctx->hwctx; VulkanDevicePriv *p = ctx->internal->priv; + /* Set device extension flags */ + for (int i = 0; i < hwctx->num_enabled_dev_extensions; i++) { + for (int j = 0; j < FF_ARRAY_ELEMS(optional_device_exts); j++) { + if (!strcmp(hwctx->enabled_dev_extensions[i], + optional_device_exts[j].name)) { + p->extensions |= optional_device_exts[j].flag; + break; + } + } + } + vkGetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &queue_num, NULL); if (!queue_num) { av_log(ctx, AV_LOG_ERROR, "Failed to get queues!\n"); diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h index ebc28916f3..2f9f92a3a2 100644 --- a/libavutil/hwcontext_vulkan.h +++ b/libavutil/hwcontext_vulkan.h @@ -42,6 +42,11 @@ typedef struct AVVulkanDeviceContext { * Instance */ VkInstance inst; + /** + * Enabled instance extensions. By default, VK_KHR_surface is enabled if found. + */ + const char * const *enabled_inst_extensions; + int num_enabled_inst_extensions; /** * Physical device */ @@ -50,6 +55,13 @@ typedef struct AVVulkanDeviceContext { * Active device */ VkDevice act_dev; + /** + * Enabled device extensions. By default, VK_KHR_external_memory_fd, + * VK_EXT_external_memory_dma_buf, VK_EXT_image_drm_format_modifier and + * VK_KHR_external_semaphore_fd are enabled if found. + */ + const char * const *enabled_dev_extensions; + int num_enabled_dev_extensions; /** * Queue family index for graphics * @note av_hwdevice_create() will set all 3 queue indices if unset