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

#include <AllocatorVk.h>

Public Types

enum  ALLOCATION_TYPE { ALLOCATION_TYPE_NONE , ALLOCATION_TYPE_BLOCK , ALLOCATION_TYPE_DEDICATED , ALLOCATION_TYPE_BLOCK_DEDICATED }
 

Public Member Functions

 Allocation_T (uint32_t currentFrameIndex, bool userDataString)
 
 ~Allocation_T ()
 
void InitBlockAllocation (Pool hPool, DeviceMemoryBlock *block, VkDeviceSize offset, VkDeviceSize alignment, VkDeviceSize size, SuballocationType suballocationType, bool mapped, bool canBecomeLost)
 
void InitLost ()
 
void ChangeBlockAllocation (Allocator hAllocator, DeviceMemoryBlock *block, VkDeviceSize offset)
 
void InitDedicatedAllocation (uint32_t memoryTypeIndex, VkDeviceMemory hMemory, SuballocationType suballocationType, void *pMappedData, VkDeviceSize size)
 
ALLOCATION_TYPE GetType () const
 
VkDeviceSize GetAlignment () const
 
VkDeviceSize GetSize () const
 
bool IsUserDataString () const
 
void * GetUserData () const
 
void SetUserData (Allocator hAllocator, void *pUserData)
 
SuballocationType GetSuballocationType () const
 
uint8_t GetMapCount () const
 
uint8_t GetFlags () const
 
DeviceMemoryBlock * GetBlock () const
 
VkDeviceSize GetOffset () const
 
VkDeviceMemory GetMemory () const
 
uint32_t GetMemoryTypeIndex () const
 
bool IsPersistentMap () const
 
void * GetMappedData () const
 
bool CanBecomeLost () const
 
Pool GetPool () const
 
uint32_t GetLastUseFrameIndex () const
 
bool CompareExchangeLastUseFrameIndex (uint32_t &expected, uint32_t desired)
 
bool MakeLost (uint32_t currentFrameIndex, uint32_t frameInUseCount)
 
void DedicatedAllocCalcStatsInfo (StatInfo &outInfo)
 
void BlockAllocMap ()
 
void BlockAllocUnmap ()
 
VkResult DedicatedAllocMap (Allocator hAllocator, void **ppData)
 
void DedicatedAllocUnmap (Allocator hAllocator)
 
char * __rep__ (bool remove=false)
 

Public Attributes

const int ID
 
char name [16]
 
void * m_pUserData
 
BlockAllocation m_BlockAllocation
 
DedicatedAllocation m_DedicatedAllocation
 

Detailed Description

Definition at line 1108 of file AllocatorVk.h.

Member Enumeration Documentation

◆ ALLOCATION_TYPE

Enumerator
ALLOCATION_TYPE_NONE 
ALLOCATION_TYPE_BLOCK 
ALLOCATION_TYPE_DEDICATED 
ALLOCATION_TYPE_BLOCK_DEDICATED 

Definition at line 1124 of file AllocatorVk.h.

Constructor & Destructor Documentation

◆ Allocation_T()

vkmm::Allocation_T::Allocation_T ( uint32_t  currentFrameIndex,
bool  userDataString 
)
inline

Definition at line 1134 of file AllocatorVk.h.

1134 :
1135 ID(counter++),
1136 m_Alignment(1),
1137 m_Size(0),
1138 m_pUserData(nullptr),
1139 m_LastUseFrameIndex(currentFrameIndex),
1140 m_Type((uint8_t)ALLOCATION_TYPE_NONE),
1141 m_SuballocationType((uint8_t)SUBALLOCATION_TYPE_UNKNOWN),
1142 m_MapCount(0),
1143 m_Flags(userDataString ? (uint8_t)FLAG_USER_DATA_STRING : 0)
1144 {
1145#if VMA_STATS_STRING_ENABLED
1146 m_CreationFrameIndex = currentFrameIndex;
1147 m_BufferImageUsage = 0;
1148#endif
1149 }
@ SUBALLOCATION_TYPE_UNKNOWN
Definition: AllocatorVk.h:741

◆ ~Allocation_T()

vkmm::Allocation_T::~Allocation_T ( )
inline

Definition at line 1167 of file AllocatorVk.h.

1168 {
1169 assert((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) == 0 && "Allocation was not unmapped before destruction.");
1170
1171 // Check if owned string was freed.
1172 assert(m_pUserData == nullptr);
1173 }

Member Function Documentation

◆ __rep__()

char * vkmm::Allocation_T::__rep__ ( bool  remove = false)
inline

Definition at line 1290 of file AllocatorVk.h.

1290 {
1291
1292 static char msg[512];
1293 memset(msg, 1, sizeof(msg));
1294
1295 if (remove) {
1296 sprintf_s(msg, "DELETE %s :: addr[%p] \n memoryType %u align:%zu size:%zu \n",
1297 name,
1298 m_DedicatedAllocation.m_hMemory,
1299 m_DedicatedAllocation.m_MemoryTypeIndex,
1300 m_Alignment,
1301 m_Size);
1302 }
1303 else {
1304 sprintf_s(msg, "NEW %s :: addr[%p] \n memoryType %u align:%zu size:%zu \n",
1305 name,
1306 m_DedicatedAllocation.m_hMemory,
1307 m_DedicatedAllocation.m_MemoryTypeIndex,
1308 m_Alignment,
1309 m_Size);
1310 }
1311 return msg;
1312
1313 }
DedicatedAllocation m_DedicatedAllocation
Definition: AllocatorVk.h:1355

◆ BlockAllocMap()

void vkmm::Allocation_T::BlockAllocMap ( )

◆ BlockAllocUnmap()

void vkmm::Allocation_T::BlockAllocUnmap ( )

◆ CanBecomeLost()

bool vkmm::Allocation_T::CanBecomeLost ( ) const

Definition at line 760 of file AllocatorVk.cpp.

761 {
762 switch (m_Type)
763 {
765 return m_BlockAllocation.m_CanBecomeLost;
767 return false;
768 default:
769 assert(0);
770 return false;
771 }
772
773 }
BlockAllocation m_BlockAllocation
Definition: AllocatorVk.h:1353

◆ ChangeBlockAllocation()

void vkmm::Allocation_T::ChangeBlockAllocation ( Allocator  hAllocator,
DeviceMemoryBlock *  block,
VkDeviceSize  offset 
)

◆ CompareExchangeLastUseFrameIndex()

bool vkmm::Allocation_T::CompareExchangeLastUseFrameIndex ( uint32_t &  expected,
uint32_t  desired 
)
inline

Definition at line 1266 of file AllocatorVk.h.

1267 {
1268 return m_LastUseFrameIndex.compare_exchange_weak(expected, desired);
1269 }

◆ DedicatedAllocCalcStatsInfo()

void vkmm::Allocation_T::DedicatedAllocCalcStatsInfo ( StatInfo outInfo)
inline

Definition at line 1272 of file AllocatorVk.h.

1273 {
1274 assert(m_Type == ALLOCATION_TYPE_DEDICATED);
1275 outInfo.blockCount = 1;
1276 outInfo.allocationCount = 1;
1277 outInfo.unusedRangeCount = 0;
1278 outInfo.usedBytes = m_Size;
1279 outInfo.unusedBytes = 0;
1280 outInfo.allocationSizeMin = outInfo.allocationSizeMax = m_Size;
1281 outInfo.unusedRangeSizeMin = UINT64_MAX;
1282 outInfo.unusedRangeSizeMax = 0;
1283 }

◆ DedicatedAllocMap()

VkResult vkmm::Allocation_T::DedicatedAllocMap ( Allocator  hAllocator,
void **  ppData 
)

Definition at line 1707 of file AllocatorVk.cpp.

1708 {
1710
1711 if (m_MapCount != 0)
1712 {
1713 if ((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) < 0x7F)
1714 {
1715 assert(m_DedicatedAllocation.m_pMappedData != nullptr);
1716 *ppData = m_DedicatedAllocation.m_pMappedData;
1717 //++m_MapCount;
1718 m_MapCount = 1;
1719 return VK_SUCCESS;
1720 }
1721 else
1722 {
1723 assert(0 && "Dedicated allocation mapped too many times simultaneously.");
1724 return VK_ERROR_MEMORY_MAP_FAILED;
1725 }
1726 }
1727 else
1728 {
1729 VkResult result = vkMapMemory(
1730 hAllocator->m_hDevice,
1731 m_DedicatedAllocation.m_hMemory,
1732 0, // offset
1733 VK_WHOLE_SIZE,
1734 0, // flags
1735 ppData);
1736 if (result == VK_SUCCESS)
1737 {
1738 m_DedicatedAllocation.m_pMappedData = *ppData;
1739 m_MapCount = 1;
1740 }
1741 return result;
1742 }
1743 }
ALLOCATION_TYPE GetType() const
Definition: AllocatorVk.h:1236

◆ DedicatedAllocUnmap()

void vkmm::Allocation_T::DedicatedAllocUnmap ( Allocator  hAllocator)

Definition at line 1744 of file AllocatorVk.cpp.

1745 {
1747
1748 if ((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) != 0)
1749 {
1750 --m_MapCount;
1751 if (m_MapCount == 0)
1752 {
1753 m_DedicatedAllocation.m_pMappedData = nullptr;
1754 vkUnmapMemory(
1755 hAllocator->m_hDevice,
1756 m_DedicatedAllocation.m_hMemory);
1757 }
1758 }
1759 else
1760 {
1761 log_allo( "Unmapping dedicated allocation not previously mapped.");
1762 }
1763 }
#define log_allo(...)
Definition: AllocatorVk.h:12

◆ GetAlignment()

VkDeviceSize vkmm::Allocation_T::GetAlignment ( ) const
inline

Definition at line 1237 of file AllocatorVk.h.

1237{ return m_Alignment; }

◆ GetBlock()

DeviceMemoryBlock * vkmm::Allocation_T::GetBlock ( ) const
inline

Definition at line 1249 of file AllocatorVk.h.

1250 {
1251 assert(m_Type == ALLOCATION_TYPE_BLOCK);
1252 return m_BlockAllocation.m_Block;
1253 }

◆ GetFlags()

uint8_t vkmm::Allocation_T::GetFlags ( ) const
inline

Definition at line 1246 of file AllocatorVk.h.

1246 {
1247 return m_Flags;
1248 };

◆ GetLastUseFrameIndex()

uint32_t vkmm::Allocation_T::GetLastUseFrameIndex ( ) const
inline

Definition at line 1262 of file AllocatorVk.h.

1263 {
1264 return m_LastUseFrameIndex.load();
1265 }

◆ GetMapCount()

uint8_t vkmm::Allocation_T::GetMapCount ( ) const
inline

Definition at line 1243 of file AllocatorVk.h.

1243 {
1244 return m_MapCount;
1245 };

◆ GetMappedData()

void * vkmm::Allocation_T::GetMappedData ( ) const

Definition at line 817 of file AllocatorVk.cpp.

818 {
819 switch (m_Type)
820 {
822 /*COM
823 if (m_MapCount != 0)
824 {
825 void* pBlockData = m_BlockAllocation.m_Block->GetMappedData();
826 VMA_ASSERT(pBlockData != VMA_NULL);
827 return (char*)pBlockData + m_BlockAllocation.m_Offset;
828 }
829 else
830 {
831 return VMA_NULL;
832 }
833 */
834 break;
836 assert((m_DedicatedAllocation.m_pMappedData != nullptr) == (m_MapCount != 0));
837 return m_DedicatedAllocation.m_pMappedData;
838 default:
839 assert(0);
840 return nullptr;
841 }
842 return nullptr;
843 }

◆ GetMemory()

VkDeviceMemory vkmm::Allocation_T::GetMemory ( ) const

COM return m_BlockAllocation.m_Block->GetDeviceMemory();

Definition at line 789 of file AllocatorVk.cpp.

790 {
791 switch (m_Type)
792 {
796 return m_DedicatedAllocation.m_hMemory;
797 default:
798 assert(0);
799 return VK_NULL_HANDLE;
800 }
801 }

◆ GetMemoryTypeIndex()

uint32_t vkmm::Allocation_T::GetMemoryTypeIndex ( ) const

COM return m_BlockAllocation.m_Block->GetMemoryTypeIndex();

Definition at line 803 of file AllocatorVk.cpp.

804 {
805 switch (m_Type)
806 {
810 return m_DedicatedAllocation.m_MemoryTypeIndex;
811 default:
812 assert(0);
813 return UINT32_MAX;
814 }
815 }

◆ GetOffset()

VkDeviceSize vkmm::Allocation_T::GetOffset ( ) const

COM return m_BlockAllocation.m_Offset;

Definition at line 775 of file AllocatorVk.cpp.

776 {
777 switch (m_Type)
778 {
782 return 0;
783 default:
784 assert(0);
785 return 0;
786 }
787 }

◆ GetPool()

Pool vkmm::Allocation_T::GetPool ( ) const

◆ GetSize()

VkDeviceSize vkmm::Allocation_T::GetSize ( ) const
inline

Definition at line 1238 of file AllocatorVk.h.

1238{ return m_Size; }

◆ GetSuballocationType()

SuballocationType vkmm::Allocation_T::GetSuballocationType ( ) const
inline

Definition at line 1242 of file AllocatorVk.h.

1242{ return (SuballocationType)m_SuballocationType; }
SuballocationType
Definition: AllocatorVk.h:739

◆ GetType()

ALLOCATION_TYPE vkmm::Allocation_T::GetType ( ) const
inline

Definition at line 1236 of file AllocatorVk.h.

1236{ return (ALLOCATION_TYPE)m_Type; }

◆ GetUserData()

void * vkmm::Allocation_T::GetUserData ( ) const
inline

Definition at line 1240 of file AllocatorVk.h.

1240{ return m_pUserData; }

◆ InitBlockAllocation()

void vkmm::Allocation_T::InitBlockAllocation ( Pool  hPool,
DeviceMemoryBlock *  block,
VkDeviceSize  offset,
VkDeviceSize  alignment,
VkDeviceSize  size,
SuballocationType  suballocationType,
bool  mapped,
bool  canBecomeLost 
)
inline

Definition at line 1175 of file AllocatorVk.h.

1184 {
1185 assert(m_Type == ALLOCATION_TYPE_NONE);
1186 assert(block != nullptr);
1187 m_Type = (uint8_t)ALLOCATION_TYPE_BLOCK;
1188 m_Alignment = alignment;
1189 m_Size = size;
1190 m_MapCount = mapped ? MAP_COUNT_FLAG_PERSISTENT_MAP : 0;
1191 m_SuballocationType = (uint8_t)suballocationType;
1192 m_BlockAllocation.m_hPool = hPool;
1193 m_BlockAllocation.m_Block = block;
1194 m_BlockAllocation.m_Offset = offset;
1195 m_BlockAllocation.m_CanBecomeLost = canBecomeLost;
1196 }

◆ InitDedicatedAllocation()

void vkmm::Allocation_T::InitDedicatedAllocation ( uint32_t  memoryTypeIndex,
VkDeviceMemory  hMemory,
SuballocationType  suballocationType,
void *  pMappedData,
VkDeviceSize  size 
)
inline

Definition at line 1215 of file AllocatorVk.h.

1221 {
1222 assert(m_Type == ALLOCATION_TYPE_NONE);
1223 assert(hMemory != VK_NULL_HANDLE);
1224 m_Type = (uint8_t)ALLOCATION_TYPE_DEDICATED;
1225 m_Alignment = 0;
1226 m_Size = size;
1227 m_SuballocationType = (uint8_t)suballocationType;
1228 m_MapCount = (pMappedData != nullptr) ? MAP_COUNT_FLAG_PERSISTENT_MAP : 0;
1229 m_DedicatedAllocation.m_MemoryTypeIndex = memoryTypeIndex;
1230 m_DedicatedAllocation.m_hMemory = hMemory;
1231 m_DedicatedAllocation.m_pMappedData = pMappedData;
1232 }

◆ InitLost()

void vkmm::Allocation_T::InitLost ( )
inline

Definition at line 1198 of file AllocatorVk.h.

1199 {
1200 assert(m_Type == ALLOCATION_TYPE_NONE);
1201 assert(m_LastUseFrameIndex.load() == FRAME_INDEX_LOST);
1202 m_Type = (uint8_t)ALLOCATION_TYPE_BLOCK;
1203 m_BlockAllocation.m_hPool = VK_NULL_HANDLE;
1204 m_BlockAllocation.m_Block = nullptr;
1205 m_BlockAllocation.m_Offset = 0;
1206 m_BlockAllocation.m_CanBecomeLost = true;
1207 }

◆ IsPersistentMap()

bool vkmm::Allocation_T::IsPersistentMap ( ) const
inline

Definition at line 1257 of file AllocatorVk.h.

1257{ return (m_MapCount & MAP_COUNT_FLAG_PERSISTENT_MAP) != 0; }

◆ IsUserDataString()

bool vkmm::Allocation_T::IsUserDataString ( ) const
inline

Definition at line 1239 of file AllocatorVk.h.

1239{ return (m_Flags & FLAG_USER_DATA_STRING) != 0; }

◆ MakeLost()

bool vkmm::Allocation_T::MakeLost ( uint32_t  currentFrameIndex,
uint32_t  frameInUseCount 
)

◆ SetUserData()

void vkmm::Allocation_T::SetUserData ( Allocator  hAllocator,
void *  pUserData 
)

Definition at line 553 of file AllocatorVk.cpp.

554 {
555 if (IsUserDataString())
556 {
557 assert(pUserData == nullptr || pUserData != m_pUserData);
558
559 FreeUserDataString(hAllocator);
560
561 if (pUserData != nullptr)
562 {
563 const char* const newStrSrc = (char*)pUserData;
564 const size_t newStrLen = strlen(newStrSrc);
565 char* const newStrDst = vkmm_new_array(hAllocator, char, newStrLen + 1);
566 memcpy(newStrDst, newStrSrc, newStrLen + 1);
567 m_pUserData = newStrDst;
568 }
569 }
570 else
571 {
572 m_pUserData = pUserData;
573 }
574 }
#define vkmm_new_array(allocator, type, count)
Definition: AllocatorVk.h:815
bool IsUserDataString() const
Definition: AllocatorVk.h:1239

Member Data Documentation

◆ ID

const int vkmm::Allocation_T::ID

Definition at line 1121 of file AllocatorVk.h.

◆ m_BlockAllocation

BlockAllocation vkmm::Allocation_T::m_BlockAllocation

Definition at line 1353 of file AllocatorVk.h.

◆ m_DedicatedAllocation

DedicatedAllocation vkmm::Allocation_T::m_DedicatedAllocation

Definition at line 1355 of file AllocatorVk.h.

◆ m_pUserData

void* vkmm::Allocation_T::m_pUserData

Definition at line 1315 of file AllocatorVk.h.

◆ name

char vkmm::Allocation_T::name[16]

Definition at line 1122 of file AllocatorVk.h.


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