From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 00B3646287 for ; Thu, 11 May 2023 16:03:48 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4507C68A084; Thu, 11 May 2023 19:03:46 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EED5A68A084 for ; Thu, 11 May 2023 19:03:39 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A39C02404EC for ; Thu, 11 May 2023 18:03:39 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Z7kBTo1RO9pe for ; Thu, 11 May 2023 18:03:38 +0200 (CEST) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id BDE1E240177 for ; Thu, 11 May 2023 18:03:38 +0200 (CEST) Received: by lain.khirnov.net (Postfix, from userid 1000) id A06001601B2; Thu, 11 May 2023 18:03:38 +0200 (CEST) From: Anton Khirnov To: Ffmpeg Devel In-Reply-To: References: Mail-Followup-To: Ffmpeg Devel Date: Thu, 11 May 2023 18:03:38 +0200 Message-ID: <168382101862.3843.5076464633158031795@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 55/97] Vulkan patchset part 2 - hwcontext rewrite and filtering 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Quoting Lynne (2023-04-24 17:56:38) > From b0c429d0d77d1789b6349bc6b296449ae1f8e9da Mon Sep 17 00:00:00 2001 > From: Lynne > Date: Tue, 15 Mar 2022 23:00:32 +0100 > Subject: [PATCH 26/97] hwcontext_vulkan: support threadsafe queue and frame > operations > > --- > libavutil/hwcontext_vulkan.c | 176 +++++++++++++++++++++++++---------- > libavutil/hwcontext_vulkan.h | 40 +++++++- > 2 files changed, 167 insertions(+), 49 deletions(-) > > diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c > index 894b4b83f3..b0db59b2d8 100644 > --- a/libavutil/hwcontext_vulkan.c > +++ b/libavutil/hwcontext_vulkan.c > @@ -27,6 +27,7 @@ > #include > #endif > > +#include > #include > > #include "config.h" > @@ -92,8 +93,10 @@ typedef struct VulkanDevicePriv { > VkPhysicalDeviceVulkan13Features device_features_1_3; > > /* Queues */ > - uint32_t qfs[5]; > - int num_qfs; > + pthread_mutex_t **qf_mutex; > + int nb_tot_qfs; > + uint32_t img_qfs[5]; > + int nb_img_qfs; This patch would be so much more readable without random renamings. > /* Debug callback */ > VkDebugUtilsMessengerEXT debug_ctx; > @@ -127,6 +130,8 @@ typedef struct VulkanFramesPriv { > } VulkanFramesPriv; > > typedef struct AVVkFrameInternal { > + pthread_mutex_t update_mutex; As far as I can see, none of the mutices you're adding here are ever destroyed. > + > #if CONFIG_CUDA > /* Importing external memory into cuda is really expensive so we keep the > * memory imported all the time */ > @@ -1304,6 +1309,10 @@ static void vulkan_device_free(AVHWDeviceContext *ctx) > if (p->libvulkan) > dlclose(p->libvulkan); > > + for (int i = 0; i < p->nb_tot_qfs; i++) > + av_freep(&p->qf_mutex[i]); > + av_freep(&p->qf_mutex); > + > RELEASE_PROPS(hwctx->enabled_inst_extensions, hwctx->nb_enabled_inst_extensions); > RELEASE_PROPS(hwctx->enabled_dev_extensions, hwctx->nb_enabled_dev_extensions); > } > @@ -1436,13 +1445,26 @@ end: > return err; > } > > +static void lock_queue(AVHWDeviceContext *ctx, int queue_family, int index) It'd be nice to be consistent with types. These are uint32 in vulkan, no? > +{ > + VulkanDevicePriv *p = ctx->internal->priv; > + pthread_mutex_lock(&p->qf_mutex[queue_family][index]); > +} > + > +static void unlock_queue(AVHWDeviceContext *ctx, int queue_family, int index) > +{ > + VulkanDevicePriv *p = ctx->internal->priv; > + pthread_mutex_unlock(&p->qf_mutex[queue_family][index]); > +} > + > static int vulkan_device_init(AVHWDeviceContext *ctx) > { > int err; > - uint32_t queue_num; > + uint32_t qf_num; > AVVulkanDeviceContext *hwctx = ctx->hwctx; > VulkanDevicePriv *p = ctx->internal->priv; > FFVulkanFunctions *vk = &p->vkfn; > + VkQueueFamilyProperties *qf; > int graph_index, comp_index, tx_index, enc_index, dec_index; > > /* Set device extension flags */ > @@ -1481,12 +1503,31 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) > p->dev_is_nvidia = (p->props.properties.vendorID == 0x10de); > p->dev_is_intel = (p->props.properties.vendorID == 0x8086); > > - vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &queue_num, NULL); > - if (!queue_num) { > + vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &qf_num, NULL); > + if (!qf_num) { > av_log(ctx, AV_LOG_ERROR, "Failed to get queues!\n"); > return AVERROR_EXTERNAL; > } > > + qf = av_malloc_array(qf_num, sizeof(VkQueueFamilyProperties)); > + if (!qf) > + return AVERROR(ENOMEM); > + > + vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &qf_num, qf); > + > + p->qf_mutex = av_mallocz(qf_num*sizeof(*p->qf_mutex)); av_calloc() > + if (!p->qf_mutex) > + return AVERROR(ENOMEM); > + p->nb_tot_qfs = qf_num; > + > + for (int i = 0; i < qf_num; i++) { > + p->qf_mutex[i] = av_mallocz(qf[i].queueCount*sizeof(**p->qf_mutex)); av_calloc() > + if (!p->qf_mutex[i]) > + return AVERROR(ENOMEM); > + for (int j = 0; j < qf[i].queueCount; j++) > + pthread_mutex_init(&p->qf_mutex[i][j], NULL); Should be checked. > + } > + > graph_index = hwctx->queue_family_index; > comp_index = hwctx->queue_family_comp_index; > tx_index = hwctx->queue_family_tx_index; > @@ -1501,9 +1542,9 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) > return AVERROR(EINVAL); \ > } else if (fidx < 0 || ctx_qf < 0) { \ > break; \ > - } else if (ctx_qf >= queue_num) { \ > + } else if (ctx_qf >= qf_num) { \ > av_log(ctx, AV_LOG_ERROR, "Invalid %s family index %i (device has %i families)!\n", \ > - type, ctx_qf, queue_num); \ > + type, ctx_qf, qf_num); \ > return AVERROR(EINVAL); \ > } \ > \ > @@ -1520,7 +1561,7 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) > tx_index = (ctx_qf == tx_index) ? -1 : tx_index; \ > enc_index = (ctx_qf == enc_index) ? -1 : enc_index; \ > dec_index = (ctx_qf == dec_index) ? -1 : dec_index; \ > - p->qfs[p->num_qfs++] = ctx_qf; \ > + p->img_qfs[p->nb_img_qfs++] = ctx_qf; \ > } while (0) > > CHECK_QUEUE("graphics", 0, graph_index, hwctx->queue_family_index, hwctx->nb_graphics_queues); > @@ -1531,6 +1572,11 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) > > #undef CHECK_QUEUE > > + if (!hwctx->lock_queue) > + hwctx->lock_queue = lock_queue; > + if (!hwctx->unlock_queue) > + hwctx->unlock_queue = unlock_queue; > + > /* Get device capabilities */ > vk->GetPhysicalDeviceMemoryProperties(hwctx->phys_dev, &p->mprops); > > @@ -1732,9 +1778,6 @@ static void vulkan_free_internal(AVVkFrame *f) > { > AVVkFrameInternal *internal = f->internal; > > - if (!internal) > - return; > - > #if CONFIG_CUDA > if (internal->cuda_fc_ref) { > AVHWFramesContext *cuda_fc = (AVHWFramesContext *)internal->cuda_fc_ref->data; > @@ -1923,9 +1966,11 @@ static int prepare_frame(AVHWFramesContext *hwfc, VulkanExecCtx *ectx, > uint32_t src_qf, dst_qf; > VkImageLayout new_layout; > VkAccessFlags new_access; > + AVVulkanFramesContext *vkfc = hwfc->hwctx; > const int planes = av_pix_fmt_count_planes(hwfc->sw_format); > VulkanDevicePriv *p = hwfc->device_ctx->internal->priv; > FFVulkanFunctions *vk = &p->vkfn; > + AVFrame tmp = { .data[0] = (uint8_t *)frame }; ??? -- Anton Khirnov _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".