From 3459fd780a67b502e8016855563cc7f0aa74af81 Mon Sep 17 00:00:00 2001 From: Denis Orlov Date: Wed, 4 Jan 2023 17:10:15 +0300 Subject: [PATCH 1/2] Fix atomic type used in AtomicTransactionalIncrement This partially reverts changes from 4dfa169ffc65583cd35bdb7ec13057cde8897c66 --- include/vk_mem_alloc.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 844bbff..c802331 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -4002,12 +4002,10 @@ private: #ifndef _VMA_ATOMIC_TRANSACTIONAL_INCREMENT // An object that increments given atomic but decrements it back in the destructor unless Commit() is called. -template +template struct AtomicTransactionalIncrement { public: - typedef std::atomic AtomicT; - ~AtomicTransactionalIncrement() { if(m_Atomic) @@ -4015,7 +4013,7 @@ public: } void Commit() { m_Atomic = nullptr; } - T Increment(AtomicT* atomic) + typename AtomicT::value_type Increment(AtomicT* atomic) { m_Atomic = atomic; return m_Atomic->fetch_add(1); @@ -15374,7 +15372,7 @@ VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits) VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory) { - AtomicTransactionalIncrement deviceMemoryCountIncrement; + AtomicTransactionalIncrement deviceMemoryCountIncrement; const uint64_t prevDeviceMemoryCount = deviceMemoryCountIncrement.Increment(&m_DeviceMemoryCount); #if VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT if(prevDeviceMemoryCount >= m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount) From 3e3877ac83e14b899b6998c7bfc16746c48662eb Mon Sep 17 00:00:00 2001 From: Denis Orlov Date: Wed, 4 Jan 2023 23:50:30 +0300 Subject: [PATCH 2/2] Fix builds on Linux CI This fixes compilation on older Linux compilers (gcc 7.5.0, clang 7.0.0) that do not seem to implement P0558R1 defect report, thus not allowing the usage of value_type member typedef from std::atomic. --- include/vk_mem_alloc.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index c802331..b787c36 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -4006,6 +4006,8 @@ template struct AtomicTransactionalIncrement { public: + using T = decltype(AtomicT().load()); + ~AtomicTransactionalIncrement() { if(m_Atomic) @@ -4013,7 +4015,7 @@ public: } void Commit() { m_Atomic = nullptr; } - typename AtomicT::value_type Increment(AtomicT* atomic) + T Increment(AtomicT* atomic) { m_Atomic = atomic; return m_Atomic->fetch_add(1);