From patchwork Wed Jul 19 04:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 42824 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:b813:b0:130:ccc6:6c4b with SMTP id fi19csp932519pzb; Tue, 18 Jul 2023 21:20:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHFEg9XnmdigXrS++oi+kB6VY+cCqTgq5gn2wpoZwf8gtD35/SdWPuw78gQ4FY253bj4S8 X-Received: by 2002:a17:907:8a08:b0:993:e752:1a6d with SMTP id sc8-20020a1709078a0800b00993e7521a6dmr1736979ejc.18.1689740406592; Tue, 18 Jul 2023 21:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689740406; cv=none; d=google.com; s=arc-20160816; b=tL7BBRkWUzfTHa0go58pz5ILfhLnPjzUj+YKhA1CcJm0BKVLvQ7dpWp7j7OtzIuAZG UmwOwv00+H8q1StS4DG2GRH5senxBfjJyIS1woaMsA9MChvOheUn/erG+gk+n72k+7fh wmeYm/nQs0r9dnWGo+he1KU+4dW0+RgYgYBnPTBf0JD+xLgBh7itcbs5wndzjU/+RYlK nv/UCi1xELsQOLkeXHwFmicbxiBeFrlGJdyjYy3Uab13+DNK8UsgWMCCPGOPBms17qwv F0NLY5XzUqRlcaJI/u/5hGq+GtVDOmB5DPDzwZUd4bkQMls9MXpFrioOtx5xoPPF40wj VfSg== 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:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=BSE+tFWT7ifRK+JrR44g6FZBAu4nEaJZluaVB3Zcz54=; fh=awftJPkKIDcYG+GZSKK7EGrS2s4rqD3QuLTgwd5DXmc=; b=C1jKdIlnUbQ7mA7X/V3fMvaYCgRN2NUbplvocxfwrN+10AvHa/YbDI6CJOSLCU7IYO r6hGDtv3Bhdg5BIzCm+pVETbO9vYHoV885XsxEzWu4fCS6tFoHnDCfxfEpByP6KGzSQu L/NSCzwoUv2k1SCJZ5Cv0usIVllEBf5YfXfMYM46QYX6gB5HvLtaxqh3ueWmG10J3XAC w0lBDrH4p3onvKoy+D/pLKzX80Vf7Yvz236PU5TdPReO42BmyVjBPk2vX2pYf4miuQ4U yNRVj45cV5nKapX2hd7bYXhQHrzjvgcKw9oeBvFGpDjxXnrKN+YHOaB8hJ80X0yz6H9l MYLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=mBrpbtDs; 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=NONE sp=NONE 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 qx21-20020a170906fcd500b00965a6d6b536si2105734ejb.335.2023.07.18.21.20.06; Tue, 18 Jul 2023 21:20:06 -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=mBrpbtDs; 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=NONE sp=NONE 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 76DA968C5B9; Wed, 19 Jul 2023 07:20:03 +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 A782A68C318 for ; Wed, 19 Jul 2023 07:19:56 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 0CAB81060140 for ; Wed, 19 Jul 2023 04:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1689740396; 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:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=siCQWSKR69usiMG/DuDtj2k9wPiai4bi5DrJX+IpsSg=; b=mBrpbtDsrnJRYdtSsjngb3LOsVMvU3iPTyrjFzh5Cf6ayFFpp4rdaKDhXEFpXXWq U+Yg9OKcUDbTRHhEV/C3funzlfW9YTgZIXKLdXCTnLb9g+dU60Q3JhD2+YaNdV1tet2 xqaQu4/e1GTbFOoF8uOdrZ+rLLR9AdqbOkKLunKsvTrtfaG4cTvfHc8+M5vg5yfRgd1 F+5odoAYRaC+KLw1pn0hzFqA5SnF1CngeQ48ptOaTcK8Maqp30mChiTsZuAiBpb5iia zwKf6imbmdAQVvwiMsvKC3ePgAwZGmdaheyv84X/A+aMekY/d3ciLiYCMw4vrQDha// tb/w93IyTA== Date: Wed, 19 Jul 2023 06:19:56 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] lavu/vulkan: remove threadsafe buffer index load and fix a signed overflow 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: oDSHq3Ivav75 It's not needed anymore, as no pools are used between threads. This also fixes a small potential integer overflow. Patch attached. From 797c62be618fe8e6223b7b01184bce7c6f231a96 Mon Sep 17 00:00:00 2001 From: Lynne Date: Wed, 19 Jul 2023 04:54:37 +0200 Subject: [PATCH 2/3] lavu/vulkan: remove threadsafe buffer index load and fix a signed overflow It's not needed anymore. --- libavutil/vulkan.c | 4 +--- libavutil/vulkan.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index 26b9b6f1fb..48f5f4b5dc 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -282,8 +282,6 @@ int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkCommandPoolCreateInfo cqueue_create; VkCommandBufferAllocateInfo cbuf_create; - atomic_init(&pool->idx, 0); - /* Create command pool */ cqueue_create = (VkCommandPoolCreateInfo) { .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, @@ -472,7 +470,7 @@ VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool) { - int idx = atomic_fetch_add_explicit(&pool->idx, 1, memory_order_relaxed); + uint32_t idx = pool->idx++; idx %= pool->pool_size; return &pool->contexts[idx]; } diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h index bbbc9374ae..7171fb3c42 100644 --- a/libavutil/vulkan.h +++ b/libavutil/vulkan.h @@ -151,7 +151,7 @@ typedef struct FFVulkanPipeline { } FFVulkanPipeline; typedef struct FFVkExecContext { - int idx; + uint32_t idx; const struct FFVkExecPool *parent; pthread_mutex_t lock; -- 2.40.1