From patchwork Sun Sep 22 07:22:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 51693 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d154:0:b0:48e:c0f8:d0de with SMTP id bt20csp1851993vqb; Sun, 22 Sep 2024 00:23:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWLkmXOyi6bwA8oEVwJj6lXVOX5EhVvJujpSIKA3WK0948gkaIZRSYQDe85YQA0JHoHtF6CKNqug8MYY5YKZQyS@gmail.com X-Google-Smtp-Source: AGHT+IG1AIGM0uouo6ZWh8jYkj1Ot0dSU247SwyQm5bouf4BIT/HrcCv3/BvthUMQxlfwTcxvUPN X-Received: by 2002:a05:6402:2547:b0:5c5:b6d5:1d86 with SMTP id 4fb4d7f45d1cf-5c5b6d51ed5mr3422967a12.26.1726989810114; Sun, 22 Sep 2024 00:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726989810; cv=none; d=google.com; s=arc-20240605; b=AGPTTvkKOTgGk+wyt5fYBuhZ8pA4BA9bV/+vy3tFXBnBQMvPmg7G2L2sWfyRVb7Gc7 bppH+6LbWgygSfFl6IbC1lcW01C6MsZYUfpEl2CSoOSRe1gzBaA3/Gz6tbrWmXrTY0zg /gZiHeajoE5nYtZdrYGPSeGynctjuf3fxzopJ8//T9/8Mqs7KS1QvSw5cFnFplPWEy91 zuV6LujhorgIjAlpoVez1rpQ9BQeWR0g8cyvo8/qFGm1Rbw1w0lH6Oqd0H/six8uc4Ok wdEMkxnYjce7lzECDgtAb2kEHdydx0u/GrTsCZSxgOtcoJ6mzIidmkLKYMdGskvogGMO X9QQ== 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=1iTC3QZ4ALm++uAsaEWyCngCuzhWYcB7U8A5DylFnGU=; fh=nenT92/WZoU6unXd3J6UhGUdod4piddKfVtctNBOh6k=; b=cXIlAyxhdYcbFworYSIOOqr8ZiS5ufBDjoKTsEuBNQMfN9tcn+E8VthAwr3uuigcdO pj2Z026ms2VQ9pQ4AMay3Rz8Zpd9xQaj/ms9yb9HXwjvdxTllRFO2DKa8GoaDxCsXQA5 zR+1YD4BsbJO2KgDwoqkg843NrMfsIVhzlgxMftBC2BQ1R3IR7IuJMlOphj5cY37fyrJ BOhQtU1XT8cTSBB1Z1H1DvVjHDkpaDonY28GRK01vgDj4a5wsAxU4h+qYkjzm2PfZ13T Zg2ZGFoatRnoiF9ebh3jTjYsikI1GNL5x7RZm+mS6H20AYFhSgqJ0Uisfk5Ga8tOXrEg kRYA==; 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 4fb4d7f45d1cf-5c42bb900e1si11983725a12.276.2024.09.22.00.23.29; Sun, 22 Sep 2024 00:23:30 -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 5ACC568DB97; Sun, 22 Sep 2024 10:22:58 +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 2B19568DB14 for ; Sun, 22 Sep 2024 10:22:48 +0300 (EEST) To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Sep 2024 09:22:34 +0200 Message-ID: <20240922072243.175005-1-dev@lynne.ee> X-Mailer: git-send-email 2.45.2.753.g447d99e1c3b MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] vulkan: separate out descriptor layouts from sets 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: bcFYTB4Vl5to Just avoids a single temporary allocation. --- libavutil/vulkan.c | 35 +++++++++++++++++++---------------- libavutil/vulkan.h | 4 ++-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index da71f241f0..e3fb70da46 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -1524,6 +1524,7 @@ int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, int has_sampler = 0; FFVulkanFunctions *vk = &s->vkfn; FFVulkanDescriptorSet *set; + VkDescriptorSetLayout *layout; VkDescriptorSetLayoutCreateInfo desc_create_layout; if (print_to_shader_only) @@ -1535,7 +1536,15 @@ int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, if (!set) return AVERROR(ENOMEM); pl->desc_set = set; + + layout = av_realloc_array(pl->desc_layout, sizeof(*pl->desc_layout), + pl->nb_descriptor_sets + 1); + if (!layout) + return AVERROR(ENOMEM); + pl->desc_layout = layout; + set = &set[pl->nb_descriptor_sets]; + layout = &layout[pl->nb_descriptor_sets]; memset(set, 0, sizeof(*set)); set->binding = av_calloc(nb, sizeof(*set->binding)); @@ -1573,19 +1582,19 @@ int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, set->usage |= VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT; ret = vk->CreateDescriptorSetLayout(s->hwctx->act_dev, &desc_create_layout, - s->hwctx->alloc, &set->layout); + s->hwctx->alloc, layout); if (ret != VK_SUCCESS) { av_log(s, AV_LOG_ERROR, "Unable to init descriptor set layout: %s", ff_vk_ret2str(ret)); return AVERROR_EXTERNAL; } - vk->GetDescriptorSetLayoutSizeEXT(s->hwctx->act_dev, set->layout, &set->layout_size); + vk->GetDescriptorSetLayoutSizeEXT(s->hwctx->act_dev, *layout, &set->layout_size); set->aligned_size = FFALIGN(set->layout_size, s->desc_buf_props.descriptorBufferOffsetAlignment); for (int i = 0; i < nb; i++) - vk->GetDescriptorSetLayoutBindingOffsetEXT(s->hwctx->act_dev, set->layout, + vk->GetDescriptorSetLayoutBindingOffsetEXT(s->hwctx->act_dev, *layout, i, &set->binding_offset[i]); set->singular = singular; @@ -1808,18 +1817,10 @@ static int init_pipeline_layout(FFVulkanContext *s, FFVulkanPipeline *pl) FFVulkanFunctions *vk = &s->vkfn; VkPipelineLayoutCreateInfo pipeline_layout_info; - VkDescriptorSetLayout *desc_layouts = av_malloc(pl->nb_descriptor_sets* - sizeof(desc_layouts)); - if (!desc_layouts) - return AVERROR(ENOMEM); - - for (int i = 0; i < pl->nb_descriptor_sets; i++) - desc_layouts[i] = pl->desc_set[i].layout; - /* Finally create the pipeline layout */ pipeline_layout_info = (VkPipelineLayoutCreateInfo) { .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, - .pSetLayouts = desc_layouts, + .pSetLayouts = pl->desc_layout, .setLayoutCount = pl->nb_descriptor_sets, .pushConstantRangeCount = pl->push_consts_num, .pPushConstantRanges = pl->push_consts, @@ -1827,7 +1828,6 @@ static int init_pipeline_layout(FFVulkanContext *s, FFVulkanPipeline *pl) ret = vk->CreatePipelineLayout(s->hwctx->act_dev, &pipeline_layout_info, s->hwctx->alloc, &pl->pipeline_layout); - av_free(desc_layouts); if (ret != VK_SUCCESS) { av_log(s, AV_LOG_ERROR, "Unable to init pipeline layout: %s\n", ff_vk_ret2str(ret)); @@ -1911,13 +1911,16 @@ void ff_vk_pipeline_free(FFVulkanContext *s, FFVulkanPipeline *pl) if (set->buf.mem) ff_vk_unmap_buffer(s, &set->buf, 0); ff_vk_free_buf(s, &set->buf); - if (set->layout) - vk->DestroyDescriptorSetLayout(s->hwctx->act_dev, set->layout, - s->hwctx->alloc); av_free(set->binding); av_free(set->binding_offset); } + for (int i = 0; i < pl->nb_descriptor_sets; i++) + if (pl->desc_layout[i]) + vk->DestroyDescriptorSetLayout(s->hwctx->act_dev, pl->desc_layout[i], + s->hwctx->alloc); + + av_freep(&pl->desc_layout); av_freep(&pl->desc_set); av_freep(&pl->desc_bind); av_freep(&pl->bound_buffer_indices); diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h index e2f5a35b98..35e3488690 100644 --- a/libavutil/vulkan.h +++ b/libavutil/vulkan.h @@ -113,7 +113,6 @@ typedef struct FFVkQueueFamilyCtx { } FFVkQueueFamilyCtx; typedef struct FFVulkanDescriptorSet { - VkDescriptorSetLayout layout; FFVkBuffer buf; uint8_t *desc_mem; VkDeviceSize layout_size; @@ -143,7 +142,8 @@ typedef struct FFVulkanPipeline { /* Workgroup */ int wg_size[3]; - /* Descriptors */ + /* Descriptor buffer */ + VkDescriptorSetLayout *desc_layout; FFVulkanDescriptorSet *desc_set; VkDescriptorBufferBindingInfoEXT *desc_bind; uint32_t *bound_buffer_indices;