VKMemAlloc.cpp: use shared_mutex in vk_mem_alloc.h

Because it allows to use custom implementation.
Also fix compilation.
This commit is contained in:
Nekotekina 2020-12-11 17:52:29 +03:00
parent aa3aef4beb
commit 7a015b6fc0
2 changed files with 28 additions and 8 deletions

View File

@ -22,16 +22,8 @@
#include "../display.h" #include "../display.h"
#include "../rsx_utils.h" #include "../rsx_utils.h"
#define VMA_ATOMIC_UINT32 atomic_t<u32>
#define VMA_ATOMIC_UINT64 atomic_t<u64>
#define compare_exchange_strong compare_exchange
#define compare_exchange_weak compare_exchange
#include "3rdparty/GPUOpen/include/vk_mem_alloc.h" #include "3rdparty/GPUOpen/include/vk_mem_alloc.h"
#undef compare_exchange_strong
#undef compare_exchange_weak
#ifdef __APPLE__ #ifdef __APPLE__
#define VK_DISABLE_COMPONENT_SWIZZLE 1 #define VK_DISABLE_COMPONENT_SWIZZLE 1
#else #else

View File

@ -1,12 +1,40 @@
#define VMA_IMPLEMENTATION #define VMA_IMPLEMENTATION
#include "util/atomic.hpp" #include "util/atomic.hpp"
#include "Utilities/mutex.h"
// Protect some STL headers from macro (add more if it fails to compile)
#include <atomic>
#include <thread>
#include <memory>
#include <mutex>
// Replace VMA atomics with atomic_t
#define VMA_ATOMIC_UINT32 atomic_t<u32> #define VMA_ATOMIC_UINT32 atomic_t<u32>
#define VMA_ATOMIC_UINT64 atomic_t<u64> #define VMA_ATOMIC_UINT64 atomic_t<u64>
#define compare_exchange_strong compare_exchange #define compare_exchange_strong compare_exchange
#define compare_exchange_weak compare_exchange #define compare_exchange_weak compare_exchange
// Replace VMA mutex with shared_mutex
class VmaRWMutex
{
public:
void LockRead() { m_mutex.lock_shared(); }
void UnlockRead() { m_mutex.unlock_shared(); }
bool TryLockRead() { return m_mutex.try_lock_shared(); }
void LockWrite() { m_mutex.lock(); }
void UnlockWrite() { m_mutex.unlock(); }
bool TryLockWrite() { return m_mutex.try_lock(); }
void Lock() { m_mutex.lock(); }
void Unlock() { m_mutex.unlock(); }
bool TryLock() { return m_mutex.try_lock(); }
private:
shared_mutex m_mutex;
};
#define VMA_RW_MUTEX VmaRWMutex
#define VMA_MUTEX VmaRWMutex
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push, 0) #pragma warning(push, 0)
#else #else