Skip to content

Commit 65afd9e

Browse files
committed
documentation
1 parent 9402a6b commit 65afd9e

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

Doxyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,7 @@ PREDEFINED = VMA_CALL_PRE= \
24662466
VMA_MEMORY_PRIORITY=1 \
24672467
VMA_KHR_MAINTENANCE4=1 \
24682468
VMA_KHR_MAINTENANCE5=1 \
2469+
VMA_EXTERNAL_MEMORY_WIN32=1 \
24692470
VMA_EXTERNAL_MEMORY=1 \
24702471
VMA_EXTENDS_VK_STRUCT= \
24712472
VMA_STATS_STRING_ENABLED=1

include/vk_mem_alloc.h

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ extern "C" {
242242
#endif
243243
#endif
244244

245-
// Defined to 1 when VK_KHR_external_memory device extension is defined in Vulkan headers.
245+
// Defined to 1 when VK_KHR_external_memory_win32 device extension is defined in Vulkan headers.
246246
#if !defined(VMA_EXTERNAL_MEMORY_WIN32)
247247
#if VK_KHR_external_memory_win32
248248
#define VMA_EXTERNAL_MEMORY_WIN32 1
@@ -1052,7 +1052,7 @@ typedef struct VmaVulkanFunctions
10521052
/// Fetch from "vkGetDeviceImageMemoryRequirements" on Vulkan >= 1.3, but you can also fetch it from "vkGetDeviceImageMemoryRequirementsKHR" if you enabled extension VK_KHR_maintenance4.
10531053
PFN_vkGetDeviceImageMemoryRequirementsKHR VMA_NULLABLE vkGetDeviceImageMemoryRequirements;
10541054
#endif
1055-
#ifdef VK_USE_PLATFORM_WIN32_KHR
1055+
#ifdef VMA_EXTERNAL_MEMORY_WIN32
10561056
PFN_vkGetMemoryWin32HandleKHR VMA_NULLABLE vkGetMemoryWin32HandleKHR;
10571057
#else
10581058
void* VMA_NULLABLE vkGetMemoryWin32HandleKHR;
@@ -6096,7 +6096,7 @@ class VmaWin32Handle
60966096
{
60976097
public:
60986098
VmaWin32Handle() noexcept : m_hHandle(VMA_NULL) { }
6099-
VmaWin32Handle(HANDLE hHandle) noexcept : m_hHandle(hHandle) { }
6099+
explicit VmaWin32Handle(HANDLE hHandle) noexcept : m_hHandle(hHandle) { }
61006100
~VmaWin32Handle() noexcept { if (m_hHandle != VMA_NULL) { ::CloseHandle(m_hHandle); } }
61016101
VMA_CLASS_NO_COPY_NO_MOVE(VmaWin32Handle)
61026102

@@ -6105,32 +6105,26 @@ class VmaWin32Handle
61056105
VkResult GetHandle(VkDevice device, VkDeviceMemory memory, decltype(&vkGetMemoryWin32HandleKHR) pvkGetMemoryWin32HandleKHR, HANDLE hTargetProcess, bool useMutex, HANDLE* pHandle) noexcept
61066106
{
61076107
*pHandle = VMA_NULL;
6108-
// We only care about atomicity of handle retrieval, not about memory order.
6109-
HANDLE handle = m_hHandle.load(std::memory_order_relaxed);
6110-
61116108
// Try to get handle first.
6112-
if (handle != VMA_NULL)
6109+
if (m_hHandle != VMA_NULL)
61136110
{
61146111
*pHandle = Duplicate(hTargetProcess);
61156112
return VK_SUCCESS;
61166113
}
61176114

6118-
HANDLE hCreatedHandle = VMA_NULL;
6119-
61206115
VkResult res = VK_SUCCESS;
61216116
// If failed, try to create it.
61226117
{
61236118
VmaMutexLockWrite lock(m_Mutex, useMutex);
6124-
if (m_hHandle.load(std::memory_order_relaxed) == VMA_NULL)
6119+
if (m_hHandle == VMA_NULL)
61256120
{
6126-
VkResult res = Create(device, memory, pvkGetMemoryWin32HandleKHR, &hCreatedHandle);
6127-
m_hHandle.store(hCreatedHandle, std::memory_order_relaxed);
6121+
res = Create(device, memory, pvkGetMemoryWin32HandleKHR, &m_hHandle);
61286122
}
61296123
}
61306124

61316125
*pHandle = Duplicate(hTargetProcess);
61326126
return res;
6133-
}
6127+
}
61346128

61356129
operator bool() const noexcept { return m_hHandle != VMA_NULL; }
61366130
private:
@@ -6150,20 +6144,19 @@ class VmaWin32Handle
61506144
}
61516145
HANDLE Duplicate(HANDLE hTargetProcess = VMA_NULL) const noexcept
61526146
{
6153-
HANDLE handle = m_hHandle.load(std::memory_order_relaxed);
6154-
if (!handle)
6155-
return handle;
6147+
if (!m_hHandle)
6148+
return m_hHandle;
61566149

61576150
HANDLE hCurrentProcess = ::GetCurrentProcess();
61586151
HANDLE hDupHandle = VMA_NULL;
6159-
if (!::DuplicateHandle(hCurrentProcess, handle, hTargetProcess ? hTargetProcess : hCurrentProcess, &hDupHandle, 0, FALSE, DUPLICATE_SAME_ACCESS))
6152+
if (!::DuplicateHandle(hCurrentProcess, m_hHandle, hTargetProcess ? hTargetProcess : hCurrentProcess, &hDupHandle, 0, FALSE, DUPLICATE_SAME_ACCESS))
61606153
{
61616154
VMA_ASSERT(0 && "Failed to duplicate handle.");
61626155
}
61636156
return hDupHandle;
61646157
}
61656158
private:
6166-
std::atomic<HANDLE> m_hHandle;
6159+
HANDLE m_hHandle;
61676160
VMA_RW_MUTEX m_Mutex; // Protects access m_Handle
61686161
};
61696162
#else
@@ -10804,7 +10797,7 @@ VkResult VmaDeviceMemoryBlock::BindImageMemory(
1080410797
VkResult VmaDeviceMemoryBlock::CreateWin32Handle(const VmaAllocator hAllocator, decltype(&vkGetMemoryWin32HandleKHR) pvkGetMemoryWin32HandleKHR, HANDLE hTargetProcess, HANDLE* pHandle) noexcept
1080510798
{
1080610799
VMA_ASSERT(pHandle);
10807-
return m_Handle.GetHandle(hAllocator->m_hDevice, m_hMemory, &vkGetMemoryWin32HandleKHR, hTargetProcess, hAllocator->m_UseMutex, pHandle);
10800+
return m_Handle.GetHandle(hAllocator->m_hDevice, m_hMemory, pvkGetMemoryWin32HandleKHR, hTargetProcess, hAllocator->m_UseMutex, pHandle);
1080810801
}
1080910802
#endif // VMA_EXTERNAL_MEMORY_WIN32
1081010803
#endif // _VMA_DEVICE_MEMORY_BLOCK_FUNCTIONS

0 commit comments

Comments
 (0)