[PATCH 0/2] MR637: vkd3d: Get rid of vkd3d_atomic_increment() and vkd3d_atomic_decrement().
From: Henri Verbeet <hverbeet(a)codeweavers.com> --- libs/vkd3d/command.c | 2 +- libs/vkd3d/resource.c | 6 +++--- libs/vkd3d/vkd3d_private.h | 14 -------------- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 609300d31..132ab2286 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -1921,7 +1921,7 @@ HRESULT d3d12_command_allocator_create(struct d3d12_device *device, static void d3d12_command_signature_incref(struct d3d12_command_signature *signature) { - vkd3d_atomic_increment(&signature->internal_refcount); + vkd3d_atomic_increment_u32(&signature->internal_refcount); } static void d3d12_command_signature_decref(struct d3d12_command_signature *signature) diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index c04f48702..2368473a2 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2314,7 +2314,7 @@ static void *vkd3d_desc_object_cache_get(struct vkd3d_desc_object_cache *cache) STATIC_ASSERT(!(ARRAY_SIZE(cache->heads) & HEAD_INDEX_MASK)); - i = (vkd3d_atomic_increment(&cache->next_index)) & HEAD_INDEX_MASK; + i = vkd3d_atomic_increment_u32(&cache->next_index) & HEAD_INDEX_MASK; for (;;) { if (vkd3d_atomic_compare_exchange(&cache->heads[i].spinlock, 0, 1)) @@ -2345,7 +2345,7 @@ static void vkd3d_desc_object_cache_push(struct vkd3d_desc_object_cache *cache, /* Using the same index as above may result in a somewhat uneven distribution, * but the main objective is to avoid costly spinlock contention. */ - i = (vkd3d_atomic_increment(&cache->next_index)) & HEAD_INDEX_MASK; + i = vkd3d_atomic_increment_u32(&cache->next_index) & HEAD_INDEX_MASK; for (;;) { if (vkd3d_atomic_compare_exchange(&cache->heads[i].spinlock, 0, 1)) @@ -2357,7 +2357,7 @@ static void vkd3d_desc_object_cache_push(struct vkd3d_desc_object_cache *cache, u.header->next = head; cache->heads[i].head = u.object; vkd3d_atomic_exchange(&cache->heads[i].spinlock, 0); - vkd3d_atomic_increment(&cache->free_count); + vkd3d_atomic_increment_u32(&cache->free_count); } #undef HEAD_INDEX_MASK diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 5955e6168..eb65397a2 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -257,11 +257,6 @@ static inline void vkd3d_cond_destroy(struct vkd3d_cond *cond) { } -static inline unsigned int vkd3d_atomic_increment(unsigned int volatile *x) -{ - return InterlockedIncrement((LONG volatile *)x); -} - static inline unsigned int vkd3d_atomic_decrement(unsigned int volatile *x) { return InterlockedDecrement((LONG volatile *)x); @@ -398,15 +393,6 @@ static inline unsigned int vkd3d_atomic_decrement(unsigned int volatile *x) # error "vkd3d_atomic_decrement() not implemented for this platform" # endif /* HAVE_SYNC_SUB_AND_FETCH */ -# if HAVE_SYNC_ADD_AND_FETCH -static inline unsigned int vkd3d_atomic_increment(unsigned int volatile *x) -{ - return __sync_add_and_fetch(x, 1); -} -# else -# error "vkd3d_atomic_increment() not implemented for this platform" -# endif /* HAVE_SYNC_ADD_AND_FETCH */ - # if HAVE_SYNC_BOOL_COMPARE_AND_SWAP static inline bool vkd3d_atomic_compare_exchange(unsigned int volatile *x, unsigned int cmp, unsigned int xchg) { -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/637
From: Henri Verbeet <hverbeet(a)codeweavers.com> --- configure.ac | 1 - libs/vkd3d/command.c | 2 +- libs/vkd3d/resource.c | 4 ++-- libs/vkd3d/vkd3d_private.h | 14 -------------- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index 0b84b1abb..4cb229d5e 100644 --- a/configure.ac +++ b/configure.ac @@ -154,7 +154,6 @@ VKD3D_CHECK_FUNC([HAVE_BUILTIN_CLZ], [__builtin_clz], [__builtin_clz(0)]) VKD3D_CHECK_FUNC([HAVE_BUILTIN_POPCOUNT], [__builtin_popcount], [__builtin_popcount(0)]) VKD3D_CHECK_FUNC([HAVE_BUILTIN_ADD_OVERFLOW], [__builtin_add_overflow], [__builtin_add_overflow(0, 0, (int *)0)]) VKD3D_CHECK_FUNC([HAVE_SYNC_ADD_AND_FETCH], [__sync_add_and_fetch], [__sync_add_and_fetch((int *)0, 0)]) -VKD3D_CHECK_FUNC([HAVE_SYNC_SUB_AND_FETCH], [__sync_sub_and_fetch], [__sync_sub_and_fetch((int *)0, 0)]) VKD3D_CHECK_FUNC([HAVE_SYNC_BOOL_COMPARE_AND_SWAP], [__sync_bool_compare_and_swap], [__sync_bool_compare_and_swap((int *)0, 0, 0)]) VKD3D_CHECK_FUNC([HAVE_ATOMIC_EXCHANGE_N], [__atomic_exchange_n], [__atomic_exchange_n((int *)0, 0, 0)]) AC_CHECK_FUNCS([gettid]) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 132ab2286..9a3e44c6e 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -1926,7 +1926,7 @@ static void d3d12_command_signature_incref(struct d3d12_command_signature *signa static void d3d12_command_signature_decref(struct d3d12_command_signature *signature) { - unsigned int refcount = vkd3d_atomic_decrement(&signature->internal_refcount); + unsigned int refcount = vkd3d_atomic_decrement_u32(&signature->internal_refcount); if (!refcount) { diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 2368473a2..8f4d18358 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2321,7 +2321,7 @@ static void *vkd3d_desc_object_cache_get(struct vkd3d_desc_object_cache *cache) { if ((u.object = cache->heads[i].head)) { - vkd3d_atomic_decrement(&cache->free_count); + vkd3d_atomic_decrement_u32(&cache->free_count); cache->heads[i].head = u.header->next; vkd3d_atomic_exchange(&cache->heads[i].spinlock, 0); return u.object; @@ -2429,7 +2429,7 @@ void vkd3d_view_decref(void *view, struct d3d12_device *device) { union d3d12_desc_object u = {view}; - if (vkd3d_atomic_decrement(&u.header->refcount)) + if (vkd3d_atomic_decrement_u32(&u.header->refcount)) return; if (u.header->magic != VKD3D_DESCRIPTOR_MAGIC_CBV) diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index eb65397a2..a74c49ead 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -257,11 +257,6 @@ static inline void vkd3d_cond_destroy(struct vkd3d_cond *cond) { } -static inline unsigned int vkd3d_atomic_decrement(unsigned int volatile *x) -{ - return InterlockedDecrement((LONG volatile *)x); -} - static inline bool vkd3d_atomic_compare_exchange(unsigned int volatile *x, unsigned int cmp, unsigned int xchg) { return InterlockedCompareExchange((LONG volatile *)x, xchg, cmp) == cmp; @@ -384,15 +379,6 @@ static inline void vkd3d_cond_destroy(struct vkd3d_cond *cond) ERR("Could not destroy the condition variable, error %d.\n", ret); } -# if HAVE_SYNC_SUB_AND_FETCH -static inline unsigned int vkd3d_atomic_decrement(unsigned int volatile *x) -{ - return __sync_sub_and_fetch(x, 1); -} -# else -# error "vkd3d_atomic_decrement() not implemented for this platform" -# endif /* HAVE_SYNC_SUB_AND_FETCH */ - # if HAVE_SYNC_BOOL_COMPARE_AND_SWAP static inline bool vkd3d_atomic_compare_exchange(unsigned int volatile *x, unsigned int cmp, unsigned int xchg) { -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/637
This merge request was approved by Giovanni Mascellani. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/637
participants (3)
-
Giovanni Mascellani (@giomasce) -
Henri Verbeet -
Henri Verbeet (@hverbeet)