From patchwork Fri Sep 20 06:23:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 51673 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d154:0:b0:48e:c0f8:d0de with SMTP id bt20csp764249vqb; Thu, 19 Sep 2024 23:23:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWdudR1T9erKBL1JT7STD9ztpX9xuuq98i4SDu5m6vvHMPycYjjSxUnxz8la+rullyE4920D3qhE7eiXcqQ3nah@gmail.com X-Google-Smtp-Source: AGHT+IGXvm4ktka+38kkS5NxOP7eV8Ouub/jHMHAHCwm494FkPGJ21PAGtQGpeoq57ruAJ50yUAY X-Received: by 2002:a2e:be08:0:b0:2ec:1810:e50a with SMTP id 38308e7fff4ca-2f7cb335e07mr10721291fa.32.1726813431735; Thu, 19 Sep 2024 23:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726813431; cv=none; d=google.com; s=arc-20240605; b=LA+HtQ1w5wf6qcXq+wLrr58FSb6ZW14dcX7proUAM3Hmj+DHHDpbeAguAbGnaNmwNa nJ9vx6XyA9wrR0hI7VgcxtoXGiRE4Ww5v/HJ/Rx/vw6ZRpU4BuJzDcwkP1MjnASbtgPe CZNSw/bebDqXk1/g89kbchhkWvrHmDzplYY49caFudxKZr03j/zj3xlrRKUGJh9lmjSY vcO4LE9OhttA6QNIN1Z0HHPymp5fkgKDriAe9dCnNG6BfNuodeDKFZvPaNBc096u69rt 7jXV3fLnxnuo1kd4u49T6nbnbpNy2DFjmP/bH+FvORsuafcNXR9KEdRJ1G0mbFZmuX8A ea1w== 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=UEzbo0OOUg/s2Kt6LQ+A/bQyVMCtiGAM9zOLJN3eZY8=; fh=nenT92/WZoU6unXd3J6UhGUdod4piddKfVtctNBOh6k=; b=bB/qpE/po7k5oWv6nFmarmxKY0mu7uLjSFVbQ/XSOR+lJtID/nWwbQmRZ3RFE8FZTI vF4qhe/R/ML5kD9AMWAJaYZtATWUavwC/awK/Rupia88nrVBM8x5+ZaDhV0YLgLkmK+D ui42AKUCvFp8tpl+4AW/kmiPLyZD6hhDLEBybsb2YQwx92ylMmTwOlMUwutVl2m+Evp+ NJ8kig1qi5MV9tx/oooAA+Em5oEgtmgNhTLRPR0x5fuU2pJ+xmdhpoAA0tbYl4P2/VFN Z+czDa/ymIMXa9WG8i5umgvR8gQ8S0R7RLbO9vNSSNF4yGgcXI3BUSZlTMqRvLKwoCmn 9/MQ==; 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 38308e7fff4ca-2f79d48a1c9si40820851fa.649.2024.09.19.23.23.51; Thu, 19 Sep 2024 23:23:51 -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 9CC7768DCAE; Fri, 20 Sep 2024 09:23:46 +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 1FBD268D9E8 for ; Fri, 20 Sep 2024 09:23:39 +0300 (EEST) To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Sep 2024 08:23:31 +0200 Message-ID: <20240920062337.933413-2-dev@lynne.ee> X-Mailer: git-send-email 2.45.2.753.g447d99e1c3b In-Reply-To: <20240920062337.933413-1-dev@lynne.ee> References: <20240920062337.933413-1-dev@lynne.ee> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] vulkan: add ff_vk_exec_add_dep_bool_sem 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: XILU1jI+c7mj This function simply takes in a binary semaphore as a dependency to an execution. --- libavutil/vulkan.c | 108 ++++++++++++++++++++++++++++++++++++++++----- libavutil/vulkan.h | 4 ++ 2 files changed, 102 insertions(+), 10 deletions(-) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index e9f094261d..6bc978a8c3 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -562,6 +562,104 @@ int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, return 0; } +#define ARR_REALLOC(str, arr, alloc_s, cnt) \ + do { \ + arr = av_fast_realloc(str->arr, alloc_s, (cnt + 1)*sizeof(*arr)); \ + if (!arr) { \ + ff_vk_exec_discard_deps(s, e); \ + return AVERROR(ENOMEM); \ + } \ + str->arr = arr; \ + } while (0) + +typedef struct TempSyncCtx { + int nb_sem; + VkSemaphore sem[]; +} TempSyncCtx; + +static void destroy_tmp_semaphores(void *opaque, uint8_t *data) +{ + FFVulkanContext *s = opaque; + FFVulkanFunctions *vk = &s->vkfn; + TempSyncCtx *ts = (TempSyncCtx *)data; + + for (int i = 0; i < ts->nb_sem; i++) + vk->DestroySemaphore(s->hwctx->act_dev, ts->sem[i], s->hwctx->alloc); + + av_free(ts); +} + +int ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, FFVkExecContext *e, + VkSemaphore *sem, int nb, + VkPipelineStageFlagBits2 stage, + int wait) +{ + int err; + size_t buf_size; + AVBufferRef *buf; + TempSyncCtx *ts; + FFVulkanFunctions *vk = &s->vkfn; + + /* Do not transfer ownership if we're signalling a binary semaphore, + * since we're probably exporting it. */ + if (!wait) { + for (int i = 0; i < nb; i++) { + VkSemaphoreSubmitInfo *sem_sig; + ARR_REALLOC(e, sem_sig, &e->sem_sig_alloc, e->sem_sig_cnt); + + e->sem_sig[e->sem_sig_cnt++] = (VkSemaphoreSubmitInfo) { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, + .semaphore = sem[i], + .stageMask = stage, + }; + } + + return 0; + } + + buf_size = sizeof(int) + sizeof(VkSemaphore)*nb; + ts = av_mallocz(buf_size); + if (!ts) { + err = AVERROR(ENOMEM); + goto fail; + } + + memcpy(ts->sem, sem, nb*sizeof(*sem)); + ts->nb_sem = nb; + + buf = av_buffer_create((uint8_t *)ts, buf_size, destroy_tmp_semaphores, s, 0); + if (!buf) { + av_free(ts); + err = AVERROR(ENOMEM); + goto fail; + } + + err = ff_vk_exec_add_dep_buf(s, e, &buf, 1, 0); + if (err < 0) { + av_buffer_unref(&buf); + return err; + } + + for (int i = 0; i < nb; i++) { + VkSemaphoreSubmitInfo *sem_wait; + ARR_REALLOC(e, sem_wait, &e->sem_wait_alloc, e->sem_wait_cnt); + + e->sem_wait[e->sem_wait_cnt++] = (VkSemaphoreSubmitInfo) { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, + .semaphore = sem[i], + .stageMask = stage, + }; + } + + return 0; + +fail: + for (int i = 0; i < nb; i++) + vk->DestroySemaphore(s->hwctx->act_dev, sem[i], s->hwctx->alloc); + + return err; +} + int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage) @@ -583,16 +681,6 @@ int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, if (e->frame_deps[i]->data[0] == f->data[0]) return 1; -#define ARR_REALLOC(str, arr, alloc_s, cnt) \ - do { \ - arr = av_fast_realloc(str->arr, alloc_s, (cnt + 1)*sizeof(*arr)); \ - if (!arr) { \ - ff_vk_exec_discard_deps(s, e); \ - return AVERROR(ENOMEM); \ - } \ - str->arr = arr; \ - } while (0) - ARR_REALLOC(e, layout_dst, &e->layout_dst_alloc, e->nb_frame_deps); ARR_REALLOC(e, queue_family_dst, &e->queue_family_dst_alloc, e->nb_frame_deps); ARR_REALLOC(e, access_dst, &e->access_dst_alloc, e->nb_frame_deps); diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h index df5507d19f..e2f5a35b98 100644 --- a/libavutil/vulkan.h +++ b/libavutil/vulkan.h @@ -383,6 +383,10 @@ void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e); */ int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, AVBufferRef **deps, int nb_deps, int ref); +int ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, FFVkExecContext *e, + VkSemaphore *sem, int nb, + VkPipelineStageFlagBits2 stage, + int wait); /* Ownership transferred if !wait */ int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage);