diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h index cc9e4326..f01c7125 100644 --- a/include/private/vkd3d_common.h +++ b/include/private/vkd3d_common.h @@ -267,16 +267,28 @@ static inline int ascii_strcasecmp(const char *a, const char *b) return c_a - c_b; } +static inline uint64_t vkd3d_atomic_add_fetch_u64(uint64_t volatile *x, uint64_t val) +{ +#if HAVE_SYNC_ADD_AND_FETCH + return __sync_add_and_fetch(x, val); +#elif defined(_WIN32) + return InterlockedAdd64((LONG64 *)x, val); +#else +# error "vkd3d_atomic_add_fetch_u64() not implemented for this platform" +#endif +} + +static inline uint64_t vkd3d_atomic_increment_u64(uint64_t volatile *x) +{ + return vkd3d_atomic_add_fetch_u64(x, 1); +} + #ifndef _WIN32 # if HAVE_SYNC_ADD_AND_FETCH static inline LONG InterlockedIncrement(LONG volatile *x) { return __sync_add_and_fetch(x, 1); } -static inline LONG64 InterlockedIncrement64(LONG64 volatile *x) -{ - return __sync_add_and_fetch(x, 1); -} # else # error "InterlockedIncrement() not implemented for this platform" # endif /* HAVE_SYNC_ADD_AND_FETCH */ diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 163dd6ce..f9e50335 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -22,7 +22,7 @@ #define VKD3D_NULL_BUFFER_SIZE 16 #define VKD3D_NULL_VIEW_FORMAT DXGI_FORMAT_R8G8B8A8_UNORM -LONG64 object_global_serial_id; +uint64_t object_global_serial_id; static inline bool is_cpu_accessible_heap(const D3D12_HEAP_PROPERTIES *properties) { @@ -4314,7 +4314,7 @@ static HRESULT d3d12_descriptor_heap_init(struct d3d12_descriptor_heap *descript descriptor_heap->ID3D12DescriptorHeap_iface.lpVtbl = &d3d12_descriptor_heap_vtbl; descriptor_heap->refcount = 1; - descriptor_heap->serial_id = InterlockedIncrement64(&object_global_serial_id); + descriptor_heap->serial_id = vkd3d_atomic_increment_u64(&object_global_serial_id); descriptor_heap->desc = *desc; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 71945ea1..7d159a17 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -67,7 +67,7 @@ * this number to prevent excessive pool memory use. */ #define VKD3D_MAX_VIRTUAL_HEAP_DESCRIPTORS_PER_TYPE (16 * 1024u) -extern LONG64 object_global_serial_id; +extern uint64_t object_global_serial_id; struct d3d12_command_list; struct d3d12_device;