VulkanRaytracingCycles 0.0.0
Cycles Render Engine With VulkanRaytracingShaderModules. ( Experiment , in progress)
vkmm::Allocator_T Struct Reference

#include <AllocatorVk.h>

Public Types

typedef tbb::concurrent_unordered_map< int, vkmm::Allocation, std::hash< int >, std::equal_to< int >, front::tbbTAllocatorAllocMapTy
 COM VmaBlockVector* m_pBlockVectors[VK_MAX_MEMORY_TYPES];. More...
 
typedef tbb::concurrent_unordered_map< int, AllocMapTy, std::hash< int >, std::equal_to< int >, front::tbbTAllocatorAllocMapMapTy
 

Public Member Functions

 Allocator_T ()
 
 Allocator_T (const AllocatorCreateInfo *pCreateInfo)
 
VkResult Init (const AllocatorCreateInfo *pCreateInfo)
 
 ~Allocator_T ()
 
const VkAllocationCallbacks * GetAllocationCallbacks () const
 
VkDeviceSize GetBufferImageGranularity () const
 
uint32_t GetMemoryHeapCount () const
 
uint32_t GetMemoryTypeCount () const
 
uint32_t MemoryTypeIndexToHeapIndex (uint32_t memTypeIndex) const
 
bool IsMemoryTypeNonCoherent (uint32_t memTypeIndex) const
 
VkDeviceSize GetMemoryTypeMinAlignment (uint32_t memTypeIndex) const
 
bool IsIntegratedGpu () const
 
void GetBufferMemoryRequirements (VkBuffer hBuffer, VkMemoryRequirements &memReq, bool &requiresDedicatedAllocation, bool &prefersDedicatedAllocation) const
 
void GetImageMemoryRequirements (VkImage hImage, VkMemoryRequirements &memReq, bool &requiresDedicatedAllocation, bool &prefersDedicatedAllocation) const
 
VkResult AllocateMemory (const VkMemoryRequirements &vkMemReq, bool requiresDedicatedAllocation, bool prefersDedicatedAllocation, VkBuffer dedicatedBuffer, VkImage dedicatedImage, AllocationCreateInfo &createInfo, SuballocationType suballocType, Allocation *pAllocation)
 
void FreeMemory (const Allocation allocation)
 
void CalculateStats (Stats *pStats)
 
VkResult Defragment (Allocation *pAllocations, size_t allocationCount, VkBool32 *pAllocationsChanged, const DefragmentationInfo *pDefragmentationInfo, DefragmentationStats *pDefragmentationStats)
 
void GetAllocationInfo (Allocation hAllocation, AllocationInfo *pAllocationInfo)
 
bool TouchAllocation (Allocation hAllocation)
 
VkResult CreatePool (const PoolCreateInfo *pCreateInfo, Pool *pPool)
 
void DestroyPool (Pool pool)
 
void GetPoolStats (Pool pool, PoolStats *pPoolStats)
 
void SetCurrentFrameIndex (uint32_t frameIndex)
 
uint32_t GetCurrentFrameIndex () const
 
void MakePoolAllocationsLost (Pool hPool, size_t *pLostAllocationCount)
 
VkResult CheckPoolCorruption (Pool hPool)
 
VkResult CheckCorruption (uint32_t memoryTypeBits)
 
void CreateLostAllocation (Allocation *pAllocation)
 
VkResult AllocateVulkanMemory (VkMemoryAllocateInfo *pAllocateInfo, VkDeviceMemory *pMemory)
 
void FreeVulkanMemory (uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory)
 
VkResult Map (Allocation hAllocation, void **ppData)
 
void Unmap (Allocation hAllocation)
 
VkResult BindBufferMemory (Allocation hAllocation, VkBuffer hBuffer)
 
VkResult BindImageMemory (Allocation hAllocation, VkImage hImage)
 
void FlushOrInvalidateAllocation (Allocation hAllocation, VkDeviceSize offset, VkDeviceSize size, CACHE_OPERATION op)
 
void FillAllocation (const Allocation hAllocation, uint8_t pattern)
 
VkDeviceSize CalcPreferredBlockSize (uint32_t memTypeIndex)
 COM VmaVulkanFunctions m_VulkanFunctions;. More...
 
VkResult AllocateMemoryOfType (VkDeviceSize size, VkDeviceSize alignment, bool dedicatedAllocation, VkBuffer dedicatedBuffer, VkImage dedicatedImage, AllocationCreateInfo &createInfo, uint32_t memTypeIndex, SuballocationType suballocType, Allocation *pAllocation)
 
VkResult AllocateDedicatedMemory (VkDeviceSize size, SuballocationType suballocType, uint32_t memTypeIndex, bool map, bool isUserDataString, AllocationCreateInfo &createInfo, VkBuffer dedicatedBuffer, VkImage dedicatedImage, Allocation *pAllocation)
 
void FreeDedicatedMemory (Allocation allocation)
 

Public Attributes

SRWLOCK slim
 
bool m_UseMutex
 
bool m_UseKhrDedicatedAllocation
 
VkDevice m_hDevice
 
bool m_AllocationCallbacksSpecified
 
VkAllocationCallbacks m_AllocationCallbacks
 
DeviceMemoryCallbacks m_DeviceMemoryCallbacks
 
VkDeviceSize m_HeapSizeLimit [VK_MAX_MEMORY_HEAPS_MIN]
 
VkPhysicalDeviceProperties m_PhysicalDeviceProperties
 COM VMA_MUTEX m_HeapSizeLimitMutex;. More...
 
VkPhysicalDeviceMemoryProperties m_MemProps
 
AllocMapMapTy m_pDedicatedAllocations
 
VkDeviceSize m_PreferredLargeHeapBlockSize
 private: More...
 
VkPhysicalDevice m_PhysicalDevice
 
std::atomic< UINT > m_CurrentFrameIndex
 
VkmmVector< Pool, StlAllocator< Pool > > m_Pools
 COM VMA_MUTEX m_PoolsMutex;. More...
 
uint32_t m_NextPoolId
 

Detailed Description

Definition at line 907 of file AllocatorVk.h.

Member Typedef Documentation

◆ AllocMapMapTy

typedef tbb::concurrent_unordered_map<int, AllocMapTy, std::hash<int>, std::equal_to<int>, front::tbbTAllocator> vkmm::Allocator_T::AllocMapMapTy

Definition at line 934 of file AllocatorVk.h.

◆ AllocMapTy

typedef tbb::concurrent_unordered_map<int, vkmm::Allocation, std::hash<int>, std::equal_to<int>, front::tbbTAllocator> vkmm::Allocator_T::AllocMapTy

COM VmaBlockVector* m_pBlockVectors[VK_MAX_MEMORY_TYPES];.

Definition at line 933 of file AllocatorVk.h.

Constructor & Destructor Documentation

◆ Allocator_T() [1/2]

vkmm::Allocator_T::Allocator_T ( )
inline

Definition at line 939 of file AllocatorVk.h.

939{};

◆ Allocator_T() [2/2]

vkmm::Allocator_T::Allocator_T ( const AllocatorCreateInfo pCreateInfo)

COM ImportVulkanFunctions(pCreateInfo->pVulkanFunctions);

Definition at line 1189 of file AllocatorVk.cpp.

1189 :
1190 m_UseMutex((pCreateInfo->flags& ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT) == 0),
1192 m_hDevice($device),
1193 m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != nullptr),
1194 m_AllocationCallbacks(pCreateInfo->pAllocationCallbacks ?
1195 *pCreateInfo->pAllocationCallbacks : EmptyAllocationCallbacks),
1197 m_PhysicalDevice($physicaldevice),
1199 m_Pools(StlAllocator<Pool>(GetAllocationCallbacks())),
1200 m_NextPoolId(0)
1201 {
1203 InitializeSRWLock(&slim);
1204
1205#ifdef USE_HIREDIS
1206 rlog.SetUp();
1207 rlog.FlushDB(15);
1208#endif
1209
1211 {
1212 // Needs to be multiply of uint32_t size because we are going to write VMA_CORRUPTION_DETECTION_MAGIC_VALUE to it.
1213 assert(_DEBUG_MARGIN % sizeof(uint32_t) == 0);
1214 }
1215
1216 assert($physicaldevice && $device);
1217
1218#if !(DEDICATED_ALLOCATION)
1219 if ((pCreateInfo->flags & ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0)
1220 {
1221 assert(0 && "VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT set but required extensions are disabled by preprocessor macros.");
1222 }
1223#endif
1224
1227 memset(&m_MemProps, 0, sizeof(m_MemProps));
1228
1229 // memset(&m_pBlockVectors, 0, sizeof(m_pBlockVectors));
1230 // memset(&m_pDedicatedAllocations, 0, sizeof(m_pDedicatedAllocations));
1231
1232 for (uint32_t i = 0; i < VK_MAX_MEMORY_HEAPS_MIN; ++i)
1233 {
1234 m_HeapSizeLimit[i] = VK_WHOLE_SIZE;
1235 }
1236
1237 if (pCreateInfo->pDeviceMemoryCallbacks != nullptr)
1238 {
1239 m_DeviceMemoryCallbacks.pfnAllocate = pCreateInfo->pDeviceMemoryCallbacks->pfnAllocate;
1240 m_DeviceMemoryCallbacks.pfnFree = pCreateInfo->pDeviceMemoryCallbacks->pfnFree;
1241 }
1242
1244 m_PhysicalDeviceProperties = $properties;
1245 m_MemProps = $memoryProperties;
1246
1247 m_PreferredLargeHeapBlockSize = (pCreateInfo->preferredLargeHeapBlockSize != 0) ?
1248 pCreateInfo->preferredLargeHeapBlockSize : static_cast<VkDeviceSize>(_DEFAULT_LARGE_HEAP_BLOCK_SIZE);
1249
1250 if (pCreateInfo->pHeapSizeLimit != nullptr)
1251 {
1252 for (uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex)
1253 {
1254 const VkDeviceSize limit = pCreateInfo->pHeapSizeLimit[heapIndex];
1255 if (limit != VK_WHOLE_SIZE)
1256 {
1257 m_HeapSizeLimit[heapIndex] = limit;
1258 if (limit < m_MemProps.memoryHeaps[heapIndex].size)
1259 {
1260 m_MemProps.memoryHeaps[heapIndex].size = limit;
1261 }
1262 }
1263 }
1264 }
1265
1266
1267
1268 for (uint32_t memTypeIndex = 0; memTypeIndex < VK_MAX_MEMORY_TYPES_MIN; ++memTypeIndex)
1269 {
1270 /*
1271 const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(memTypeIndex);
1272 m_pBlockVectors[memTypeIndex] = vma_new(this, VmaBlockVector)(
1273 this,
1274 memTypeIndex,
1275 preferredBlockSize,
1276 0,
1277 SIZE_MAX,
1278 GetBufferImageGranularity(),
1279 pCreateInfo->frameInUseCount,
1280 false, // isCustomPool
1281 false, // explicitBlockSize
1282 false); // linearAlgorithm
1283 */
1284 // No need to call m_pBlockVectors[memTypeIndex][blockVectorTypeIndex]->CreateMinBlocks here,
1285 // becase minBlockCount is 0.
1286 m_pDedicatedAllocations[memTypeIndex] = AllocMapTy();
1287 }
1288 }
#define VK_MAX_MEMORY_TYPES_MIN
Definition: AllocatorVk.h:410
#define VK_MAX_MEMORY_HEAPS_MIN
Definition: AllocatorVk.h:411
#define _DEFAULT_LARGE_HEAP_BLOCK_SIZE
Definition: AllocatorVk.h:721
#define _DEBUG_DETECT_CORRUPTION
Definition: AllocatorVk.h:717
#define _DEBUG_MARGIN
Definition: AllocatorVk.h:715
@ ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT
Definition: AllocatorVk.h:543
@ ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT
Definition: AllocatorVk.h:545
bool m_AllocationCallbacksSpecified
Definition: AllocatorVk.h:917
VkPhysicalDeviceMemoryProperties m_MemProps
Definition: AllocatorVk.h:926
AllocMapMapTy m_pDedicatedAllocations
Definition: AllocatorVk.h:936
uint32_t m_NextPoolId
Definition: AllocatorVk.h:1069
VkDeviceSize m_HeapSizeLimit[VK_MAX_MEMORY_HEAPS_MIN]
Definition: AllocatorVk.h:922
VkPhysicalDevice m_PhysicalDevice
Definition: AllocatorVk.h:1063
VkmmVector< Pool, StlAllocator< Pool > > m_Pools
COM VMA_MUTEX m_PoolsMutex;.
Definition: AllocatorVk.h:1068
VkDevice m_hDevice
Definition: AllocatorVk.h:916
VkAllocationCallbacks m_AllocationCallbacks
Definition: AllocatorVk.h:918
const VkAllocationCallbacks * GetAllocationCallbacks() const
Definition: AllocatorVk.h:944
std::atomic< UINT > m_CurrentFrameIndex
Definition: AllocatorVk.h:1064
DeviceMemoryCallbacks m_DeviceMemoryCallbacks
Definition: AllocatorVk.h:919
VkDeviceSize m_PreferredLargeHeapBlockSize
private:
Definition: AllocatorVk.h:1061
uint32_t GetMemoryHeapCount() const
Definition: AllocatorVk.h:957
VkPhysicalDeviceProperties m_PhysicalDeviceProperties
COM VMA_MUTEX m_HeapSizeLimitMutex;.
Definition: AllocatorVk.h:925
bool m_UseKhrDedicatedAllocation
Definition: AllocatorVk.h:915
tbb::concurrent_unordered_map< int, vkmm::Allocation, std::hash< int >, std::equal_to< int >, front::tbbTAllocator > AllocMapTy
COM VmaBlockVector* m_pBlockVectors[VK_MAX_MEMORY_TYPES];.
Definition: AllocatorVk.h:933
PFN_FreeDeviceMemoryFunction pfnFree
Optional, can be null.
Definition: AllocatorVk.h:538
PFN_AllocateDeviceMemoryFunction pfnAllocate
Optional, can be null.
Definition: AllocatorVk.h:536

◆ ~Allocator_T()

vkmm::Allocator_T::~Allocator_T ( )

COM assert(m_Pools.empty());

COM Delete(this, m_pBlockVectors[i]);

Definition at line 1297 of file AllocatorVk.cpp.

1298 {
1299
1301#ifdef USE_HIREDIS
1302 rlog.TearDown();
1303#endif
1304 for (size_t i = GetMemoryTypeCount(); i--; )
1305 {
1306 m_pDedicatedAllocations[i].clear();
1308 }
1310 }
uint32_t GetMemoryTypeCount() const
Definition: AllocatorVk.h:958

Member Function Documentation

◆ AllocateDedicatedMemory()

VkResult vkmm::Allocator_T::AllocateDedicatedMemory ( VkDeviceSize  size,
SuballocationType  suballocType,
uint32_t  memTypeIndex,
bool  map,
bool  isUserDataString,
AllocationCreateInfo createInfo,
VkBuffer  dedicatedBuffer,
VkImage  dedicatedImage,
Allocation *  pAllocation 
)

Definition at line 1315 of file AllocatorVk.cpp.

1325 {
1326
1327 assert(pAllocation);
1328 createInfo.info.memoryTypeIndex = memTypeIndex;
1329 bool dedicated = true;
1330 if (memTypeIndex == 2 || memTypeIndex == 3 || memTypeIndex == 0) {
1331 if (HOST_VISIBLE_SINGLE_ALLO_MAX < size) {
1332 log_bad("memory out of range \n");
1333 }
1334 }
1335
1336 if(dedicated) {
1337 createInfo.info.allocationSize = size;
1338#if DEDICATED_ALLOCATION
1339 VkMemoryDedicatedAllocateInfo* dedicatedAllocInfo = nullptr;
1341 {
1342 createInfo.info.append(dedicatedAllocInfo);
1343 if (dedicatedBuffer != VK_NULL_HANDLE)
1344 {
1345 assert(dedicatedImage == VK_NULL_HANDLE);
1346 dedicatedAllocInfo->buffer = dedicatedBuffer;
1347 }
1348 else if (dedicatedImage != VK_NULL_HANDLE)
1349 {
1350 dedicatedAllocInfo->image = dedicatedImage;
1351 }
1352 }
1353#endif // #if VMA_DEDICATED_ALLOCATION
1354 // Allocate VkDeviceMemory.
1355 VkDeviceMemory hMemory = VK_NULL_HANDLE;
1356 VkResult res = AllocateVulkanMemory((VkMemoryAllocateInfo*)&createInfo.info, &hMemory);
1357 if (res < 0)
1358 {
1359 VKMM_DEBUG_LOG(" vkAllocateMemory FAILED");
1360 return res;
1361 }
1362
1363 void* pMappedData = nullptr;
1364 if (map)
1365 {
1366 res = vkMapMemory(
1367 m_hDevice,
1368 hMemory,
1369 0,
1370 VK_WHOLE_SIZE,
1371 0,
1372 &pMappedData);
1373 if (res < 0)
1374 {
1375 VKMM_DEBUG_LOG(" vkMapMemory FAILED");
1376 FreeVulkanMemory(memTypeIndex, size, hMemory);
1377 return res;
1378 }
1379 }
1380
1381 *pAllocation = vkmm_new(this, Allocation_T)(m_CurrentFrameIndex.load(), isUserDataString);
1382 (*pAllocation)->InitDedicatedAllocation(memTypeIndex, hMemory, suballocType, pMappedData, size);
1383 }
1384
1385
1386 strcpy((*pAllocation)->name, createInfo.name);
1387
1389 {
1390 FillAllocation(*pAllocation, ALLOCATION_FILL_PATTERN_CREATED);
1391 }
1392
1393 {
1394
1395 GetCTX($ctx)
1396 $ctx->deb.setObjectName(dedicatedBuffer, createInfo.name);
1397
1398 AllocMapTy pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
1399 pDedicatedAllocations[(*pAllocation)->ID] = (*pAllocation);
1400 }
1401
1402 VKMM_DEBUG_LOG(" Allocated DedicatedMemory MemoryTypeIndex=#%u", memTypeIndex);
1403
1404 return VK_SUCCESS;
1405 }
#define _DEBUG_INITIALIZE_ALLOCATIONS
Definition: AllocatorVk.h:716
#define VKMM_DEBUG_LOG(...)
Definition: AllocatorVk.h:712
#define vkmm_new(allocator, type)
Definition: AllocatorVk.h:813
#define GetCTX(c)
Definition: Context1Vk.h:39
#define HOST_VISIBLE_SINGLE_ALLO_MAX
Definition: MemoryVk.h:10
#define log_bad(...)
Definition: log.hpp:37
VkResult AllocateVulkanMemory(VkMemoryAllocateInfo *pAllocateInfo, VkDeviceMemory *pMemory)
void FillAllocation(const Allocation hAllocation, uint8_t pattern)
void FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory)

◆ AllocateMemory()

VkResult vkmm::Allocator_T::AllocateMemory ( const VkMemoryRequirements &  vkMemReq,
bool  requiresDedicatedAllocation,
bool  prefersDedicatedAllocation,
VkBuffer  dedicatedBuffer,
VkImage  dedicatedImage,
AllocationCreateInfo createInfo,
SuballocationType  suballocType,
Allocation *  pAllocation 
)

Definition at line 1525 of file AllocatorVk.cpp.

1534 {
1535 if ((createInfo.flags & ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0 &&
1536 (createInfo.flags & ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
1537 {
1538 assert(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT together with VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT makes no sense.");
1539 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1540 }
1541 if ((createInfo.flags & ALLOCATION_CREATE_MAPPED_BIT) != 0 &&
1542 (createInfo.flags & ALLOCATION_CREATE_CAN_BECOME_LOST_BIT) != 0)
1543 {
1544 assert(0 && "Specifying VMA_ALLOCATION_CREATE_MAPPED_BIT together with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT is invalid.");
1545 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1546 }
1547
1548 if (requiresDedicatedAllocation)
1549 {
1550 if ((createInfo.flags & ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
1551 {
1552 assert(0 && "VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT specified while dedicated allocation is required.");
1553 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1554 }
1555 if (createInfo.pool != VK_NULL_HANDLE)
1556 {
1557 assert(0 && "Pool specified while dedicated allocation is required.");
1558 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1559 }
1560 }
1561
1562 if ((createInfo.pool != VK_NULL_HANDLE) &&
1563 ((createInfo.flags & (ALLOCATION_CREATE_DEDICATED_MEMORY_BIT)) != 0))
1564 {
1565 assert(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT when pool != null is invalid.");
1566 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1567 }
1568
1569 if (createInfo.pool != VK_NULL_HANDLE)
1570 {
1571 /*/// COM
1572 const VkDeviceSize alignmentForPool = __max(
1573 vkMemReq.alignment,
1574 GetMemoryTypeMinAlignment(createInfo.pool->m_BlockVector.GetMemoryTypeIndex()));
1575 return createInfo.pool->m_BlockVector.Allocate(
1576 createInfo.pool,
1577 m_CurrentFrameIndex.load(),
1578 vkMemReq.size,
1579 alignmentForPool,
1580 createInfo,
1581 suballocType,
1582 pAllocation);
1583 */
1584 }
1585 else
1586 {
1587 // Bit mask of memory Vulkan types acceptable for this allocation.
1588 uint32_t memoryTypeBits = vkMemReq.memoryTypeBits;
1589 uint32_t memTypeIndex = UINT32_MAX;
1590 VkResult res = FindMemoryTypeIndex(this, memoryTypeBits, &createInfo, &memTypeIndex);
1591
1592 if (res == VK_SUCCESS)
1593 {
1594 VkDeviceSize alignmentForMemType = __max(
1595 vkMemReq.alignment,
1596 GetMemoryTypeMinAlignment(memTypeIndex));
1597
1599 vkMemReq.size,
1600 alignmentForMemType,
1601 requiresDedicatedAllocation || prefersDedicatedAllocation,
1602 dedicatedBuffer,
1603 dedicatedImage,
1604 createInfo,
1605 memTypeIndex,
1606 suballocType,
1607 pAllocation);
1608 // Succeeded on first try.
1609 if (res == VK_SUCCESS)
1610 {
1611 return res;
1612 }
1613 // Allocation from this memory type failed. Try other compatible memory types.
1614 else
1615 {
1616 for (;;)
1617 {
1618 // Remove old memTypeIndex from list of possibilities.
1619 memoryTypeBits &= ~(1u << memTypeIndex);
1620 // Find alternative memTypeIndex.
1621 res = FindMemoryTypeIndex(this, memoryTypeBits, &createInfo, &memTypeIndex);
1622 if (res == VK_SUCCESS)
1623 {
1624 alignmentForMemType = __max(
1625 vkMemReq.alignment,
1626 GetMemoryTypeMinAlignment(memTypeIndex));
1627
1629 vkMemReq.size,
1630 alignmentForMemType,
1631 requiresDedicatedAllocation || prefersDedicatedAllocation,
1632 dedicatedBuffer,
1633 dedicatedImage,
1634 createInfo,
1635 memTypeIndex,
1636 suballocType,
1637 pAllocation);
1638 // Allocation from this alternative memory type succeeded.
1639 if (res == VK_SUCCESS)
1640 {
1641 return res;
1642 }
1643 // else: Allocation from this memory type failed. Try next one - next loop iteration.
1644 }
1645 // No other matching memory type index could be found.
1646 else
1647 {
1648 // Not returning res, which is VK_ERROR_FEATURE_NOT_PRESENT, because we already failed to allocate once.
1649 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1650 }
1651 }
1652 }
1653 }
1654 // Can't find any single memory type maching requirements. res is VK_ERROR_FEATURE_NOT_PRESENT.
1655 else
1656 return res;
1657 }
1658 assert(0);
1659 return (VkResult)0;
1660 }
@ ALLOCATION_CREATE_MAPPED_BIT
Definition: AllocatorVk.h:613
@ ALLOCATION_CREATE_CAN_BECOME_LOST_BIT
Definition: AllocatorVk.h:615
@ ALLOCATION_CREATE_NEVER_ALLOCATE_BIT
Definition: AllocatorVk.h:611
@ ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
Definition: AllocatorVk.h:609
VkResult FindMemoryTypeIndex(Allocator allocator, uint32_t memoryTypeBits, AllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
VkResult AllocateMemoryOfType(VkDeviceSize size, VkDeviceSize alignment, bool dedicatedAllocation, VkBuffer dedicatedBuffer, VkImage dedicatedImage, AllocationCreateInfo &createInfo, uint32_t memTypeIndex, SuballocationType suballocType, Allocation *pAllocation)
VkDeviceSize GetMemoryTypeMinAlignment(uint32_t memTypeIndex) const
Definition: AllocatorVk.h:972

◆ AllocateMemoryOfType()

VkResult vkmm::Allocator_T::AllocateMemoryOfType ( VkDeviceSize  size,
VkDeviceSize  alignment,
bool  dedicatedAllocation,
VkBuffer  dedicatedBuffer,
VkImage  dedicatedImage,
AllocationCreateInfo createInfo,
uint32_t  memTypeIndex,
SuballocationType  suballocType,
Allocation *  pAllocation 
)

Definition at line 1407 of file AllocatorVk.cpp.

1417 {
1418 assert(pAllocation != nullptr);
1419
1420 AllocationCreateInfo& finalCreateInfo = createInfo;
1421
1422 // If memory type is not HOST_VISIBLE, disable MAPPED.
1423 if ((finalCreateInfo.flags & ALLOCATION_CREATE_MAPPED_BIT) != 0 &&
1424 (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
1425 {
1426 finalCreateInfo.flags &= ~ALLOCATION_CREATE_MAPPED_BIT;
1427 }
1428
1429 /*COM
1430 VmaBlockVector* const blockVector = m_pBlockVectors[memTypeIndex];
1431 assert(blockVector);
1432 const VkDeviceSize preferredBlockSize = blockVector->GetPreferredBlockSize();
1433 */
1434
1435 const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(memTypeIndex);
1436
1437 bool preferDedicatedMemory =
1439 dedicatedAllocation ||
1440 // Heuristics: Allocate dedicated memory if requested size if greater than half of preferred block size.
1441 size > preferredBlockSize / 2;
1442
1443 if (preferDedicatedMemory &&
1444 (finalCreateInfo.flags & ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0 &&
1445 finalCreateInfo.pool == VK_NULL_HANDLE)
1446 {
1447 finalCreateInfo.flags |= ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
1448 }
1449
1450 if ((finalCreateInfo.flags & ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0)
1451 {
1452 if ((finalCreateInfo.flags & ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
1453 {
1454 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1455 }
1456 else
1457 {
1459 size,
1460 suballocType,
1461 memTypeIndex,
1462 (finalCreateInfo.flags & ALLOCATION_CREATE_MAPPED_BIT) != 0,
1463 (finalCreateInfo.flags & ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
1464 finalCreateInfo,
1465 dedicatedBuffer,
1466 dedicatedImage,
1467 pAllocation);
1468 }
1469 }
1470 else
1471 {
1472 /*COM
1473 VkResult res = blockVector->Allocate(
1474 VK_NULL_HANDLE, // hCurrentPool
1475 m_CurrentFrameIndex.load(),
1476 size,
1477 alignment,
1478 finalCreateInfo,
1479 suballocType,
1480 pAllocation);
1481 if (res == VK_SUCCESS)
1482 {
1483 return res;
1484 }
1485
1486 // 5. Try dedicated memory.
1487 if ((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
1488 {
1489 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
1490 }
1491 else
1492 {
1493 res = AllocateDedicatedMemory(
1494 size,
1495 suballocType,
1496 memTypeIndex,
1497 (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0,
1498 (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
1499 finalCreateInfo.pUserData,
1500 dedicatedBuffer,
1501 dedicatedImage,
1502 pAllocation);
1503 if (res == VK_SUCCESS)
1504 {
1505 // Succeeded: AllocateDedicatedMemory function already filld pMemory, nothing more to do here.
1506 VMA_DEBUG_LOG(" Allocated as DedicatedMemory");
1507 return VK_SUCCESS;
1508 }
1509 else
1510 {
1511 // Everything failed: Return error code.
1512 VMA_DEBUG_LOG(" vkAllocateMemory FAILED");
1513 return res;
1514 }
1515 }
1516 */
1517 }
1518
1519 assert(0);
1520 return (VkResult)0;
1521
1522 }
#define _DEBUG_ALWAYS_DEDICATED_MEMORY
Definition: AllocatorVk.h:713
@ ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT
Definition: AllocatorVk.h:619
struct vkmm::AllocationCreateInfo AllocationCreateInfo
AllocationCreateFlags flags
Use #VmaAllocationCreateFlagBits enum.
Definition: AllocatorVk.h:629
VkDeviceSize CalcPreferredBlockSize(uint32_t memTypeIndex)
COM VmaVulkanFunctions m_VulkanFunctions;.
VkResult AllocateDedicatedMemory(VkDeviceSize size, SuballocationType suballocType, uint32_t memTypeIndex, bool map, bool isUserDataString, AllocationCreateInfo &createInfo, VkBuffer dedicatedBuffer, VkImage dedicatedImage, Allocation *pAllocation)

◆ AllocateVulkanMemory()

VkResult vkmm::Allocator_T::AllocateVulkanMemory ( VkMemoryAllocateInfo *  pAllocateInfo,
VkDeviceMemory *  pMemory 
)

VmaMutexLock lock(m_HeapSizeLimitMutex, m_UseMutex);

Definition at line 1074 of file AllocatorVk.cpp.

1075 {
1076 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
1077
1078 VkResult res;
1079 if (m_HeapSizeLimit[heapIndex] != VK_WHOLE_SIZE)
1080 {
1083 if (m_HeapSizeLimit[heapIndex] >= pAllocateInfo->allocationSize)
1084 {
1085 res = vkAllocateMemory(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory);
1086 if (res == VK_SUCCESS)
1087 {
1088 m_HeapSizeLimit[heapIndex] -= pAllocateInfo->allocationSize;
1089
1090 }
1091 }
1092 else
1093 {
1094 res = VK_ERROR_OUT_OF_DEVICE_MEMORY;
1095 }
1096 }
1097 else
1098 {
1099 res = vkAllocateMemory(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory);
1100 }
1101
1102 if (res == VK_SUCCESS && m_DeviceMemoryCallbacks.pfnAllocate != nullptr)
1103 {
1104 (*m_DeviceMemoryCallbacks.pfnAllocate)(this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize);
1105 }
1106
1107 return res;
1108 }
uint32_t MemoryTypeIndexToHeapIndex(uint32_t memTypeIndex) const
Definition: AllocatorVk.h:960

◆ BindBufferMemory()

VkResult vkmm::Allocator_T::BindBufferMemory ( Allocation  hAllocation,
VkBuffer  hBuffer 
)

Definition at line 854 of file AllocatorVk.cpp.

855 {
856 VkResult res = VK_SUCCESS;
857 switch (hAllocation->GetType())
858 {
860 res = vkBindBufferMemory(
861 m_hDevice,
862 hBuffer,
863 hAllocation->GetMemory(),
864 0); //memoryOffset
865 break;
866
868 {
869 /*
870 VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock();
871 VMA_ASSERT(pBlock && "Binding buffer to allocation that doesn't belong to any block. Is the allocation lost?");
872 res = pBlock->BindBufferMemory(this, hAllocation, hBuffer);
873 */
874 break;
875 }
876 default:
877 assert(0);
878 }
879 return res;
880 }

◆ BindImageMemory()

VkResult vkmm::Allocator_T::BindImageMemory ( Allocation  hAllocation,
VkImage  hImage 
)

◆ CalcPreferredBlockSize()

VkDeviceSize vkmm::Allocator_T::CalcPreferredBlockSize ( uint32_t  memTypeIndex)

COM VmaVulkanFunctions m_VulkanFunctions;.

COM void ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunctions);

Definition at line 1774 of file AllocatorVk.cpp.

1775 {
1776 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
1777 const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size;
1778 const bool isSmallHeap = heapSize <= _SMALL_HEAP_MAX_SIZE; //1GB
1779 return isSmallHeap ? (heapSize / 8) : m_PreferredLargeHeapBlockSize;
1780 }
#define _SMALL_HEAP_MAX_SIZE
Definition: AllocatorVk.h:720

◆ CalculateStats()

void vkmm::Allocator_T::CalculateStats ( Stats pStats)

◆ CheckCorruption()

VkResult vkmm::Allocator_T::CheckCorruption ( uint32_t  memoryTypeBits)

◆ CheckPoolCorruption()

VkResult vkmm::Allocator_T::CheckPoolCorruption ( Pool  hPool)

◆ CreateLostAllocation()

void vkmm::Allocator_T::CreateLostAllocation ( Allocation *  pAllocation)

◆ CreatePool()

VkResult vkmm::Allocator_T::CreatePool ( const PoolCreateInfo pCreateInfo,
Pool *  pPool 
)

◆ Defragment()

VkResult vkmm::Allocator_T::Defragment ( Allocation *  pAllocations,
size_t  allocationCount,
VkBool32 *  pAllocationsChanged,
const DefragmentationInfo pDefragmentationInfo,
DefragmentationStats pDefragmentationStats 
)

◆ DestroyPool()

void vkmm::Allocator_T::DestroyPool ( Pool  pool)

◆ FillAllocation()

void vkmm::Allocator_T::FillAllocation ( const Allocation  hAllocation,
uint8_t  pattern 
)

Definition at line 628 of file AllocatorVk.cpp.

629 {
631 !hAllocation->CanBecomeLost() &&
632 (m_MemProps.memoryTypes[hAllocation->GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
633 {
634 void* pData = nullptr;
635 VkResult res = Map(hAllocation, &pData);
636 if (res == VK_SUCCESS)
637 {
638 memset(pData, (int)pattern, (size_t)hAllocation->GetSize());
639 FlushOrInvalidateAllocation(hAllocation, 0, VK_WHOLE_SIZE, CACHE_FLUSH);
640 Unmap(hAllocation);
641 }
642 else
643 {
644 assert(0 && "VMA_DEBUG_INITIALIZE_ALLOCATIONS is enabled, but couldn't map memory to fill allocation.");
645 }
646 }
647 }
@ CACHE_FLUSH
Definition: AllocatorVk.h:903
VkResult Map(Allocation hAllocation, void **ppData)
void Unmap(Allocation hAllocation)
void FlushOrInvalidateAllocation(Allocation hAllocation, VkDeviceSize offset, VkDeviceSize size, CACHE_OPERATION op)

◆ FlushOrInvalidateAllocation()

void vkmm::Allocator_T::FlushOrInvalidateAllocation ( Allocation  hAllocation,
VkDeviceSize  offset,
VkDeviceSize  size,
CACHE_OPERATION  op 
)

Definition at line 682 of file AllocatorVk.cpp.

686 {
687 const uint32_t memTypeIndex = hAllocation->GetMemoryTypeIndex();
688 if (size > 0 && IsMemoryTypeNonCoherent(memTypeIndex))
689 {
690 const VkDeviceSize allocationSize = hAllocation->GetSize();
691 assert(offset <= allocationSize);
692
693 const VkDeviceSize nonCoherentAtomSize = m_PhysicalDeviceProperties.limits.nonCoherentAtomSize;
694
695 VkMappedMemoryRange memRange = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
696 memRange.memory = hAllocation->GetMemory();
697
698 switch (hAllocation->GetType())
699 {
701 memRange.offset = AlignDown(offset, nonCoherentAtomSize);
702 if (size == VK_WHOLE_SIZE)
703 {
704 memRange.size = allocationSize - memRange.offset;
705 }
706 else
707 {
708 assert(offset + size <= allocationSize);
709 memRange.size = __min(
710 AlignUp(size + (offset - memRange.offset), nonCoherentAtomSize),
711 allocationSize - memRange.offset);
712 }
713 break;
714
716 {
717 /* COM
718 // 1. Still within this allocation.
719 memRange.offset = AlignDown(offset, nonCoherentAtomSize);
720 if (size == VK_WHOLE_SIZE)
721 {
722 size = allocationSize - offset;
723 }
724 else
725 {
726 assert(offset + size <= allocationSize);
727 }
728 memRange.size = AlignUp(size + (offset - memRange.offset), nonCoherentAtomSize);
729
730 // 2. Adjust to whole block.
731 const VkDeviceSize allocationOffset = hAllocation->GetOffset();
732 assert(allocationOffset % nonCoherentAtomSize == 0);
733 const VkDeviceSize blockSize = hAllocation->GetBlock()->m_pMetadata->GetSize();
734 memRange.offset += allocationOffset;
735 memRange.size = __min(memRange.size, blockSize - memRange.offset);
736
737 break;
738 */
739 }
740
741 default:
742 assert(0);
743 }
744
745 switch (op)
746 {
747 case CACHE_FLUSH:
748 vkFlushMappedMemoryRanges(m_hDevice, 1, &memRange);
749 break;
750 case CACHE_INVALIDATE:
751 vkInvalidateMappedMemoryRanges(m_hDevice, 1, &memRange);
752 break;
753 default:
754 assert(0);
755 }
756 }
757 // else: Just ignore this call.
758 }
@ CACHE_INVALIDATE
Definition: AllocatorVk.h:903
bool IsMemoryTypeNonCoherent(uint32_t memTypeIndex) const
Definition: AllocatorVk.h:966

◆ FreeDedicatedMemory()

void vkmm::Allocator_T::FreeDedicatedMemory ( Allocation  allocation)

Definition at line 1144 of file AllocatorVk.cpp.

1145 {
1146
1147 assert(allocation && allocation->GetType() == Allocation_T::ALLOCATION_TYPE_DEDICATED);
1148
1149 const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
1150 {
1151 AllocMapTy pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
1152 const int id = allocation->ID;
1153 AcquireSRWLockExclusive(&slim);
1154 pDedicatedAllocations.unsafe_erase(id);
1155 ReleaseSRWLockExclusive(&slim);
1156 }
1157
1158 VkDeviceMemory hMemory = allocation->GetMemory();
1159
1160 if (allocation->GetMappedData() != nullptr)
1161 {
1162 vkUnmapMemory(m_hDevice, hMemory);
1163 }
1164
1165 FreeVulkanMemory(memTypeIndex, allocation->GetSize(), hMemory);
1166
1167 VKMM_DEBUG_LOG(" Freed DedicatedMemory MemoryTypeIndex=%u", memTypeIndex);
1168 }

◆ FreeMemory()

void vkmm::Allocator_T::FreeMemory ( const Allocation  allocation)

Definition at line 1663 of file AllocatorVk.cpp.

1664 {
1665 assert(allocation);
1666
1667 if (TouchAllocation(allocation))
1668 {
1670 {
1671 FillAllocation(allocation, ALLOCATION_FILL_PATTERN_DESTROYED);
1672 }
1673
1674 switch (allocation->GetType())
1675 {
1677 {
1678 /*COM
1679 BlockVector* pBlockVector = VMA_NULL;
1680 Pool hPool = allocation->GetPool();
1681 if (hPool != VK_NULL_HANDLE)
1682 {
1683 pBlockVector = &hPool->m_BlockVector;
1684 }
1685 else
1686 {
1687 const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
1688 pBlockVector = m_pBlockVectors[memTypeIndex];
1689 }
1690 pBlockVector->Free(allocation);
1691 */
1692 }
1693 break;
1695 FreeDedicatedMemory(allocation);
1696 break;
1697 default:
1698 assert(0);
1699 }
1700 }
1701
1702 vkmm::Delete(this, allocation);
1703
1704
1705 }
void FreeDedicatedMemory(Allocation allocation)
bool TouchAllocation(Allocation hAllocation)

◆ FreeVulkanMemory()

void vkmm::Allocator_T::FreeVulkanMemory ( uint32_t  memoryType,
VkDeviceSize  size,
VkDeviceMemory  hMemory 
)

Definition at line 1057 of file AllocatorVk.cpp.

1058 {
1059 if (m_DeviceMemoryCallbacks.pfnFree != nullptr)
1060 {
1061 (*m_DeviceMemoryCallbacks.pfnFree)(this, memoryType, hMemory, size);
1062 }
1063
1064 vkFreeMemory(m_hDevice, hMemory, GetAllocationCallbacks());
1065
1066 const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memoryType);
1067 if (m_HeapSizeLimit[heapIndex] != VK_WHOLE_SIZE)
1068 {
1069 //VmaMutexLock lock(m_HeapSizeLimitMutex, m_UseMutex);
1070 m_HeapSizeLimit[heapIndex] += size;
1071 }
1072 }

◆ GetAllocationCallbacks()

const VkAllocationCallbacks * vkmm::Allocator_T::GetAllocationCallbacks ( ) const
inline

Definition at line 944 of file AllocatorVk.h.

945 {
947 }

◆ GetAllocationInfo()

void vkmm::Allocator_T::GetAllocationInfo ( Allocation  hAllocation,
AllocationInfo pAllocationInfo 
)

Definition at line 575 of file AllocatorVk.cpp.

576 {
577 if (hAllocation->CanBecomeLost())
578 {
579 /*
580 Warning: This is a carefully designed algorithm.
581 Do not modify unless you really know what you're doing :)
582 */
583 const uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
584 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
585 for (;;)
586 {
587 if (localLastUseFrameIndex == FRAME_INDEX_LOST)
588 {
589 pAllocationInfo->memoryType = UINT32_MAX;
590 pAllocationInfo->deviceMemory = VK_NULL_HANDLE;
591 pAllocationInfo->offset = 0;
592 pAllocationInfo->size = hAllocation->GetSize();
593 pAllocationInfo->pMappedData = nullptr;
594 pAllocationInfo->pUserData = hAllocation->GetUserData();
595 return;
596 }
597 else if (localLastUseFrameIndex == localCurrFrameIndex)
598 {
599 pAllocationInfo->memoryType = hAllocation->GetMemoryTypeIndex();
600 pAllocationInfo->deviceMemory = hAllocation->GetMemory();
601 pAllocationInfo->offset = hAllocation->GetOffset();
602 pAllocationInfo->size = hAllocation->GetSize();
603 pAllocationInfo->pMappedData = nullptr;
604 pAllocationInfo->pUserData = hAllocation->GetUserData();
605 return;
606 }
607 else // Last use time earlier than current time.
608 {
609 if (hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
610 {
611 localLastUseFrameIndex = localCurrFrameIndex;
612 }
613 }
614 }
615 }
616 else
617 {
618
619
620 pAllocationInfo->memoryType = hAllocation->GetMemoryTypeIndex();
621 pAllocationInfo->deviceMemory = hAllocation->GetMemory();
622 pAllocationInfo->offset = hAllocation->GetOffset();
623 pAllocationInfo->size = hAllocation->GetSize();
624 pAllocationInfo->pMappedData = hAllocation->GetMappedData();
625 pAllocationInfo->pUserData = hAllocation->GetUserData();
626 }
627 }

◆ GetBufferImageGranularity()

VkDeviceSize vkmm::Allocator_T::GetBufferImageGranularity ( ) const
inline

Definition at line 950 of file AllocatorVk.h.

951 {
952 return __max(
953 static_cast<VkDeviceSize>(_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY),
954 m_PhysicalDeviceProperties.limits.bufferImageGranularity);
955 }
#define _DEBUG_MIN_BUFFER_IMAGE_GRANULARITY
Definition: AllocatorVk.h:719

◆ GetBufferMemoryRequirements()

void vkmm::Allocator_T::GetBufferMemoryRequirements ( VkBuffer  hBuffer,
VkMemoryRequirements &  memReq,
bool &  requiresDedicatedAllocation,
bool &  prefersDedicatedAllocation 
) const

Definition at line 1110 of file AllocatorVk.cpp.

1115 {
1116
1117#if DEDICATED_ALLOCATION
1119 {
1120 VkBufferMemoryRequirementsInfo2 memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2 };
1121 memReqInfo.buffer = hBuffer;
1122
1123 VkMemoryDedicatedRequirements memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS };
1124
1125 VkMemoryRequirements2 memReq2 = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2 };
1126 memReq2.pNext = &memDedicatedReq;
1127
1128 vkGetBufferMemoryRequirements2(m_hDevice, &memReqInfo, &memReq2);
1129
1130 memReq = memReq2.memoryRequirements;
1131 requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE);
1132 prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
1133
1134 }
1135 else
1136#endif // #if VMA_DEDICATED_ALLOCATION
1137 {
1138 vkGetBufferMemoryRequirements(m_hDevice, hBuffer, &memReq);
1139 requiresDedicatedAllocation = false;
1140 prefersDedicatedAllocation = false;
1141 }
1142 }

◆ GetCurrentFrameIndex()

uint32_t vkmm::Allocator_T::GetCurrentFrameIndex ( ) const
inline

Definition at line 1034 of file AllocatorVk.h.

1034{ return m_CurrentFrameIndex.load(); }

◆ GetImageMemoryRequirements()

void vkmm::Allocator_T::GetImageMemoryRequirements ( VkImage  hImage,
VkMemoryRequirements &  memReq,
bool &  requiresDedicatedAllocation,
bool &  prefersDedicatedAllocation 
) const

◆ GetMemoryHeapCount()

uint32_t vkmm::Allocator_T::GetMemoryHeapCount ( ) const
inline

Definition at line 957 of file AllocatorVk.h.

957{ return m_MemProps.memoryHeapCount; }

◆ GetMemoryTypeCount()

uint32_t vkmm::Allocator_T::GetMemoryTypeCount ( ) const
inline

Definition at line 958 of file AllocatorVk.h.

958{ return m_MemProps.memoryTypeCount; }

◆ GetMemoryTypeMinAlignment()

VkDeviceSize vkmm::Allocator_T::GetMemoryTypeMinAlignment ( uint32_t  memTypeIndex) const
inline

Definition at line 972 of file AllocatorVk.h.

973 {
974 return IsMemoryTypeNonCoherent(memTypeIndex) ?
975 __max((VkDeviceSize)_DEBUG_ALIGNMENT, m_PhysicalDeviceProperties.limits.nonCoherentAtomSize) :
976 (VkDeviceSize)_DEBUG_ALIGNMENT;
977 }
#define _DEBUG_ALIGNMENT
Definition: AllocatorVk.h:714

◆ GetPoolStats()

void vkmm::Allocator_T::GetPoolStats ( Pool  pool,
PoolStats pPoolStats 
)

◆ Init()

VkResult vkmm::Allocator_T::Init ( const AllocatorCreateInfo pCreateInfo)

Definition at line 1290 of file AllocatorVk.cpp.

1291 {
1292 VkResult res = VK_SUCCESS;
1293
1294 return res;
1295 }

◆ IsIntegratedGpu()

bool vkmm::Allocator_T::IsIntegratedGpu ( ) const
inline

Definition at line 979 of file AllocatorVk.h.

980 {
981 return m_PhysicalDeviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
982 }

◆ IsMemoryTypeNonCoherent()

bool vkmm::Allocator_T::IsMemoryTypeNonCoherent ( uint32_t  memTypeIndex) const
inline

Definition at line 966 of file AllocatorVk.h.

967 {
968 return (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) ==
969 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
970 }

◆ MakePoolAllocationsLost()

void vkmm::Allocator_T::MakePoolAllocationsLost ( Pool  hPool,
size_t *  pLostAllocationCount 
)

◆ Map()

VkResult vkmm::Allocator_T::Map ( Allocation  hAllocation,
void **  ppData 
)

Definition at line 882 of file AllocatorVk.cpp.

883 {
884 if (hAllocation->CanBecomeLost())
885 {
886 return VK_ERROR_MEMORY_MAP_FAILED;
887 }
888
889 switch (hAllocation->GetType())
890 {
892 {
893 /*COM
894 DeviceMemoryBlock* const pBlock = hAllocation->GetBlock();
895 char* pBytes = VMA_NULL;
896 VkResult res = pBlock->Map(this, 1, (void**)&pBytes);
897 if (res == VK_SUCCESS)
898 {
899 *ppData = pBytes + (ptrdiff_t)hAllocation->GetOffset();
900 hAllocation->BlockAllocMap();
901 }
902 return res;
903 */
904 }
906 return hAllocation->DedicatedAllocMap(this, ppData);
907 default:
908 assert(0);
909 return VK_ERROR_MEMORY_MAP_FAILED;
910 }
911 }

◆ MemoryTypeIndexToHeapIndex()

uint32_t vkmm::Allocator_T::MemoryTypeIndexToHeapIndex ( uint32_t  memTypeIndex) const
inline

Definition at line 960 of file AllocatorVk.h.

961 {
962 assert(memTypeIndex < m_MemProps.memoryTypeCount);
963 return m_MemProps.memoryTypes[memTypeIndex].heapIndex;
964 }

◆ SetCurrentFrameIndex()

void vkmm::Allocator_T::SetCurrentFrameIndex ( uint32_t  frameIndex)

◆ TouchAllocation()

bool vkmm::Allocator_T::TouchAllocation ( Allocation  hAllocation)

Definition at line 648 of file AllocatorVk.cpp.

649 {
650 // This is a stripped-down version of VmaAllocator_T::GetAllocationInfo.
651 if (hAllocation->CanBecomeLost())
652 {
653 uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
654 uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
655 for (;;)
656 {
657 if (localLastUseFrameIndex == FRAME_INDEX_LOST)
658 {
659 return false;
660 }
661 else if (localLastUseFrameIndex == localCurrFrameIndex)
662 {
663 return true;
664 }
665 else // Last use time earlier than current time.
666 {
667 if (hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
668 {
669 localLastUseFrameIndex = localCurrFrameIndex;
670 }
671 }
672 }
673 }
674 else
675 {
676
677
678 return true;
679 }
680 }

◆ Unmap()

void vkmm::Allocator_T::Unmap ( Allocation  hAllocation)

Definition at line 913 of file AllocatorVk.cpp.

914 {
915 switch (hAllocation->GetType())
916 {
918 {
919 /*
920 VmaDeviceMemoryBlock* const pBlock = hAllocation->GetBlock();
921 hAllocation->BlockAllocUnmap();
922 pBlock->Unmap(this, 1);
923 */
924 }
925 break;
927 hAllocation->DedicatedAllocUnmap(this);
928 break;
929 default:
930 assert(0);
931 }
932 }

Member Data Documentation

◆ m_AllocationCallbacks

VkAllocationCallbacks vkmm::Allocator_T::m_AllocationCallbacks

Definition at line 918 of file AllocatorVk.h.

◆ m_AllocationCallbacksSpecified

bool vkmm::Allocator_T::m_AllocationCallbacksSpecified

Definition at line 917 of file AllocatorVk.h.

◆ m_CurrentFrameIndex

std::atomic<UINT> vkmm::Allocator_T::m_CurrentFrameIndex

Definition at line 1064 of file AllocatorVk.h.

◆ m_DeviceMemoryCallbacks

DeviceMemoryCallbacks vkmm::Allocator_T::m_DeviceMemoryCallbacks

Definition at line 919 of file AllocatorVk.h.

◆ m_hDevice

VkDevice vkmm::Allocator_T::m_hDevice

Definition at line 916 of file AllocatorVk.h.

◆ m_HeapSizeLimit

VkDeviceSize vkmm::Allocator_T::m_HeapSizeLimit[VK_MAX_MEMORY_HEAPS_MIN]

Definition at line 922 of file AllocatorVk.h.

◆ m_MemProps

VkPhysicalDeviceMemoryProperties vkmm::Allocator_T::m_MemProps

Definition at line 926 of file AllocatorVk.h.

◆ m_NextPoolId

uint32_t vkmm::Allocator_T::m_NextPoolId

Definition at line 1069 of file AllocatorVk.h.

◆ m_pDedicatedAllocations

AllocMapMapTy vkmm::Allocator_T::m_pDedicatedAllocations

Definition at line 936 of file AllocatorVk.h.

◆ m_PhysicalDevice

VkPhysicalDevice vkmm::Allocator_T::m_PhysicalDevice

Definition at line 1063 of file AllocatorVk.h.

◆ m_PhysicalDeviceProperties

VkPhysicalDeviceProperties vkmm::Allocator_T::m_PhysicalDeviceProperties

COM VMA_MUTEX m_HeapSizeLimitMutex;.

Definition at line 925 of file AllocatorVk.h.

◆ m_Pools

VkmmVector<Pool, StlAllocator<Pool> > vkmm::Allocator_T::m_Pools

COM VMA_MUTEX m_PoolsMutex;.

Definition at line 1068 of file AllocatorVk.h.

◆ m_PreferredLargeHeapBlockSize

VkDeviceSize vkmm::Allocator_T::m_PreferredLargeHeapBlockSize

private:

Definition at line 1061 of file AllocatorVk.h.

◆ m_UseKhrDedicatedAllocation

bool vkmm::Allocator_T::m_UseKhrDedicatedAllocation

Definition at line 915 of file AllocatorVk.h.

◆ m_UseMutex

bool vkmm::Allocator_T::m_UseMutex

Definition at line 914 of file AllocatorVk.h.

◆ slim

SRWLOCK vkmm::Allocator_T::slim

Definition at line 912 of file AllocatorVk.h.


The documentation for this struct was generated from the following files: