diff mbox series

[FFmpeg-devel] lavu/vulkan: remove threadsafe buffer index load and fix a signed overflow

Message ID N_gN3Pp--3-9@lynne.ee
State New
Headers show
Series [FFmpeg-devel] lavu/vulkan: remove threadsafe buffer index load and fix a signed overflow | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Lynne July 19, 2023, 4:19 a.m. UTC
It's not needed anymore, as no pools are used between threads.

This also fixes a small potential integer overflow.

Patch attached.
diff mbox series

Patch

From 797c62be618fe8e6223b7b01184bce7c6f231a96 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
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