From patchwork Sun Sep 1 02:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 51283 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:4027:b0:48e:c0f8:d0de with SMTP id ky39csp1168507vqb; Sat, 31 Aug 2024 19:50:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUVi26yyQRqlYhc/FfjpfQzclyxngCHCOmad3DXmo8LF/AMOraFjvdJUvYRNDS8+QIq8dg9TnqM5G81+6pYGft2@gmail.com X-Google-Smtp-Source: AGHT+IG1op1pm8Aq5M1pphFGIGxe0BAz2Snq2JE2veTQqmS5RVvEzfil+cJ2OZaU77ACKn38X6S3 X-Received: by 2002:a17:907:c21:b0:a7a:9d1e:3b28 with SMTP id a640c23a62f3a-a89a377d761mr288946866b.5.1725159011686; Sat, 31 Aug 2024 19:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725159011; cv=none; d=google.com; s=arc-20240605; b=Hgc5r3nFdJZkSniugy0OGnasBjWNjedsPQeAOgRycsT2oiAefNF1T/zRk0f9EwAMfg ALiCWXyjMPTMfuKHjwtKoVHQphx7/WXSfH6DHaDVzh6zO2qxFYfyqR+fhaONk3pAr0Q6 n2Cy/0i12EVx1ugzwCGxmlpd/mx1RBBt0tJvaZhv9M+VCfExbMQZmPPdfcJt+sMH99GV vxwHNeBx1HOZkf9MMq7aLP4X+LHrEbpukQ8/0oKEdvhmp5Art/5h5Np99alrhSE2DjX6 whi49N03DvVgJXgSDeDd9+mq/5LghCORWZyxoAJIdoVls5qojCVF1KvbLF3wIZVCHO3i M58w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to :delivered-to; bh=op9X6aUOVFj3Xss5PsfqLo+90YxiViGRUDz0uXvDU1Y=; fh=nenT92/WZoU6unXd3J6UhGUdod4piddKfVtctNBOh6k=; b=cs4cNZBis/9KnrFh1W1R9Y0P5+iPMFWjFYiWeY+dlOlsK5D8vjHxpr6dhdRnNrx7Kf MVpqBJqspKFDF2Zrrpli5zj3Bj8bIGr1d4GbuFG7SzJaS48Virz5j4Xyt836tLpT8nKi YsE6EqDXyCS3QrB5s+LbsApvHaPP/gMGuew/goOB5IJun3uAn/GAem5Xw74/lUl5/CZ0 veBkVHo1du4VDp8XHuvKytRXFgPWWBmDoyvVjjOihhbv9+4fcgTqGu7/Js9SaSpA9DGW EiboeXOCXPfKpWv81CgWZbDoivXyH0A8E7hFoY2kY53O8ZKU/GJqqDKCsMJYTjqdpzJ+ T8hg==; dara=google.com 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a8988f40e7bsi552353466b.203.2024.08.31.19.50.11; Sat, 31 Aug 2024 19:50:11 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1130C68DD1F; Sun, 1 Sep 2024 05:41:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vidala.lynne.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 02F6868DD1F for ; Sun, 1 Sep 2024 05:41:48 +0300 (EEST) To: ffmpeg-devel@ffmpeg.org Date: Sun, 1 Sep 2024 04:41:38 +0200 Message-ID: <20240901024143.438584-1-dev@lynne.ee> X-Mailer: git-send-email 2.45.2.753.g447d99e1c3b MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] vulkan: add a ff_vk_init function 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: , X-Patchwork-Original-From: Lynne via ffmpeg-devel From: Lynne Reply-To: FFmpeg development discussions and patches Cc: Lynne Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: sOYjAs9Tn0Tw This function sets the class correctly, and calls functions that all users have to call anyway. --- libavutil/vulkan.c | 62 +++++++++++++++++++++++++++++++++++++++++++--- libavutil/vulkan.h | 12 ++++++++- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index c2a3b5cfa3..3e3c087aff 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -22,6 +22,7 @@ #include "mem.h" #include "vulkan.h" +#include "libavutil/vulkan_loader.h" const VkComponentMapping ff_comp_identity_map = { .r = VK_COMPONENT_SWIZZLE_IDENTITY, @@ -443,14 +444,13 @@ VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, int64_t res = 0; VkQueryResultFlags qf = 0; - if (!e->had_submission) - return VK_INCOMPLETE; - if (!e->query_data) { av_log(s, AV_LOG_ERROR, "Requested a query with a NULL query_data pointer!\n"); return VK_INCOMPLETE; } + qf |= e->had_submission ? + VK_QUERY_RESULT_WAIT_BIT : 0x0; qf |= pool->query_64bit ? VK_QUERY_RESULT_64_BIT : 0x0; qf |= pool->query_statuses ? @@ -816,7 +816,7 @@ int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req, } if (index < 0) { - av_log(s->device, AV_LOG_ERROR, "No memory type found for flags 0x%x\n", + av_log(s, AV_LOG_ERROR, "No memory type found for flags 0x%x\n", req_flags); return AVERROR(EINVAL); } @@ -1868,5 +1868,59 @@ void ff_vk_uninit(FFVulkanContext *s) av_freep(&s->video_props); av_freep(&s->coop_mat_props); + av_buffer_unref(&s->device_ref); av_buffer_unref(&s->frames_ref); } + +int ff_vk_init(FFVulkanContext *s, void *log_parent, + AVBufferRef *device_ref, AVBufferRef *frames_ref) +{ + int err; + + static const AVClass vulkan_context_class = { + .class_name = "vk", + .version = LIBAVUTIL_VERSION_INT, + .parent_log_context_offset = offsetof(FFVulkanContext, log_parent), + }; + + memset(s, 0, sizeof(*s)); + s->log_parent = log_parent; + s->class = &vulkan_context_class; + + if (frames_ref) { + s->frames_ref = av_buffer_ref(frames_ref); + if (!s->frames_ref) + return AVERROR(ENOMEM); + + s->frames = (AVHWFramesContext *)s->frames_ref->data; + s->hwfc = s->frames->hwctx; + + device_ref = s->frames->device_ref; + } + + s->device_ref = av_buffer_ref(device_ref); + if (!s->device_ref) { + ff_vk_uninit(s); + return AVERROR(ENOMEM); + } + + s->device = (AVHWDeviceContext *)s->device_ref->data; + s->hwctx = s->device->hwctx; + + s->extensions = ff_vk_extensions_to_mask(s->hwctx->enabled_dev_extensions, + s->hwctx->nb_enabled_dev_extensions); + + err = ff_vk_load_functions(s->device, &s->vkfn, s->extensions, 1, 1); + if (err < 0) { + ff_vk_uninit(s); + return err; + } + + err = ff_vk_load_props(s); + if (err < 0) { + ff_vk_uninit(s); + return err; + } + + return 0; +} diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h index 05bd71ae45..371de8ab51 100644 --- a/libavutil/vulkan.h +++ b/libavutil/vulkan.h @@ -227,7 +227,8 @@ typedef struct FFVkExecPool { } FFVkExecPool; typedef struct FFVulkanContext { - const AVClass *class; /* Filters and encoders use this */ + const AVClass *class; + void *log_parent; FFVulkanFunctions vkfn; FFVulkanExtensions extensions; @@ -251,6 +252,7 @@ typedef struct FFVulkanContext { VkPhysicalDeviceVulkan12Features feats_12; VkPhysicalDeviceFeatures2 feats; + AVBufferRef *device_ref; AVHWDeviceContext *device; AVVulkanDeviceContext *hwctx; @@ -303,6 +305,14 @@ static inline void ff_vk_link_struct(void *chain, const void *in) /* Identity mapping - r = r, b = b, g = g, a = a */ extern const VkComponentMapping ff_comp_identity_map; +/** + * Initializes the AVClass, in case this context is not used + * as the main user's context. + * May use either a frames context reference, or a device context reference. + */ +int ff_vk_init(FFVulkanContext *s, void *log_parent, + AVBufferRef *device_ref, AVBufferRef *frames_ref); + /** * Converts Vulkan return values to strings */ From patchwork Sun Sep 1 02:41:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 51282 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:4027:b0:48e:c0f8:d0de with SMTP id ky39csp1167230vqb; Sat, 31 Aug 2024 19:42:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWX9sBay9vne5Ol6qNof+0xwYiwzKVs31viipuAC1Cp4wpgaS17DJdjW5v/oH+SX6Bqf0SnRdrCfnjdxoRFFRJW@gmail.com X-Google-Smtp-Source: AGHT+IGUjbdPupmjvcLYXUhuBDxONoIjl1UuDmSjAG9JVI2NBxyxR7brW5IuNsaDT09n3DQuYYpH X-Received: by 2002:a17:907:7e91:b0:a80:f63e:159b with SMTP id a640c23a62f3a-a89a30b5b14mr292468966b.0.1725158530117; Sat, 31 Aug 2024 19:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725158530; cv=none; d=google.com; s=arc-20240605; b=AJX9bZ2Xvz2IqNZwnVbGoGPAQjb/OlV4Y7xpoMBGHLTVxoYNFGzBGlHfS5piFkpXPY R+MnV+PaJYUHtCqPDFJaAD9xchJZVv2RYTtCqqCcJ3sV9FDo8pgSKazsJIRhGEqzc5+d RyHQ04WGC1f6iThGDPfHXFzlry9sCKsuBP2EKGDbkNaOPEUZa+AQZHvF0xExvp+ILr70 w8m91HrIP/uQDlVhRJJh9NS2c2gJcwotL9Xu+yuEeEmTGWQ8/P9OrwtjMk2j1/shK2Cp 9WgVCIJByE7RHm1WmYa0BJB65wT2eui8/5NDP30P8nxSmtbe7J3BOTmY1mJAfQXVaqBG fbqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:delivered-to; bh=pDd1a3/szdhSrmn3oapIo4NIBlPeMNvFSF71CtHHoL0=; fh=nenT92/WZoU6unXd3J6UhGUdod4piddKfVtctNBOh6k=; b=RHc3SUsLUcoBzwWYGu4ZHXISohMJlTNI2bmaxnqVSY+ZvfvwLGmYt2dEXjQuGNUxut bnwU/6NIA58nNJXUO1k6H6uR8buBL4s6gmIR9d70x7+oNgCin8eagTYgS+pt77i/s6W8 DrLEowNs0FBdEP4gAGOmVEbCK9+QnBBH6+GZo0yYMDPLZQl85oKNCgVWF1o5opXxuKtv 7LSJgE1pbhznxozbno27kVcZYo1+FecCLVSWIv7n51OTktYdhGTXSyBz+9CkfMvspudV TSO6otQ9puomVMczMCl56m3+dYPK7wtTavvMgV6PQfoUhP9WqF81HktPwDKE2bK79ET9 RIXw==; dara=google.com 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a8988f45b80si534117766b.113.2024.08.31.19.42.09; Sat, 31 Aug 2024 19:42:10 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5576A68DF3A; Sun, 1 Sep 2024 05:41:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vidala.lynne.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 33E6768DF3A for ; Sun, 1 Sep 2024 05:41:52 +0300 (EEST) To: ffmpeg-devel@ffmpeg.org Date: Sun, 1 Sep 2024 04:41:39 +0200 Message-ID: <20240901024143.438584-2-dev@lynne.ee> X-Mailer: git-send-email 2.45.2.753.g447d99e1c3b In-Reply-To: <20240901024143.438584-1-dev@lynne.ee> References: <20240901024143.438584-1-dev@lynne.ee> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] vulkan_decode: use ff_vk_init 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: , X-Patchwork-Original-From: Lynne via ffmpeg-devel From: Lynne Reply-To: FFmpeg development discussions and patches Cc: Lynne Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qQA8geAMvy3I This solves the issue of an av_log function being called with a context with invalid class. Most of the patch was written by Anton Khirnov. --- libavcodec/vulkan_decode.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 35966cd60d..f6b8866ff5 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -1114,12 +1114,9 @@ int ff_vk_decode_init(AVCodecContext *avctx) s = &ctx->s; vk = &ctx->s.vkfn; - s->frames_ref = av_buffer_ref(avctx->hw_frames_ctx); - s->frames = (AVHWFramesContext *)s->frames_ref->data; - s->hwfc = s->frames->hwctx; - - s->device = (AVHWDeviceContext *)s->frames->device_ref->data; - s->hwctx = s->device->hwctx; + err = ff_vk_init(s, avctx, NULL, avctx->hw_frames_ctx); + if (err < 0) + return err; profile = get_video_profile(ctx, avctx->codec_id); if (!profile) { @@ -1127,10 +1124,6 @@ int ff_vk_decode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - err = ff_vk_load_props(s); - if (err < 0) - goto fail; - /* Create queue context */ vk_desc = get_codecdesc(avctx->codec_id); err = ff_vk_video_qf_init(s, &ctx->qf,