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

interface More...

Classes

struct  Allocation_T
 
struct  AllocationCreateInfo
 
struct  AllocationInfo
 
struct  Allocator_T
 
struct  AllocatorCreateInfo
 
struct  BufferAllocation
 
struct  DefragmentationInfo
 
struct  DefragmentationStats
 
struct  DeviceMemoryCallbacks
 
struct  MemoryVk
 
struct  PointerLess
 
struct  PoolCreateInfo
 
struct  PoolStats
 
struct  StatInfo
 
struct  Stats
 General statistics from current state of Allocator. More...
 
class  StlAllocator
 
struct  VkMAInfo
 

Typedefs

typedef void(VKAPI_PTR * PFN_AllocateDeviceMemoryFunction) (Allocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size)
 VK_DEFINE_HANDLE(Allocator) More...
 
typedef void(VKAPI_PTR * PFN_FreeDeviceMemoryFunction) (Allocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size)
 Callback function called before vkFreeMemory. More...
 
typedef struct vkmm::DeviceMemoryCallbacks DeviceMemoryCallbacks
 
typedef enum vkmm::AllocatorCreateFlagBits AllocatorCreateFlagBits
 
typedef VkFlags AllocatorCreateFlags
 
typedef struct vkmm::AllocatorCreateInfo AllocatorCreateInfo
 
typedef struct vkmm::StatInfo StatInfo
 
typedef struct vkmm::Stats Stats
 General statistics from current state of Allocator. More...
 
typedef enum vkmm::MemoryUsage MemoryUsage
 
typedef enum vkmm::AllocationCreateFlagBits AllocationCreateFlagBits
 
typedef VkFlags AllocationCreateFlags
 
typedef struct vkmm::AllocationCreateInfo AllocationCreateInfo
 
typedef enum vkmm::PoolCreateFlagBits PoolCreateFlagBits
 
typedef VkFlags PoolCreateFlags
 
typedef struct vkmm::PoolCreateInfo PoolCreateInfo
 
typedef struct vkmm::PoolStats PoolStats
 
typedef struct vkmm::AllocationInfo AllocationInfo
 
typedef struct vkmm::DefragmentationInfo DefragmentationInfo
 
typedef struct vkmm::DefragmentationStats DefragmentationStats
 
typedef struct Allocator_TAllocator
 

Enumerations

enum  AllocatorCreateFlagBits { ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT = 0x00000001 , ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT = 0x00000002 , ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF }
 
enum  MemoryUsage {
  MEMORY_USAGE_UNKNOWN = 0 , MEMORY_USAGE_GPU =1 , MEMORY_USAGE_GPU_ONLY = 2 , MEMORY_USAGE_CPU_ONLY = 3 ,
  MEMORY_USAGE_CPU_TO_GPU = 4 , MEMORY_USAGE_GPU_TO_CPU = 5 , MEMORY_USAGE_MAX_ENUM = 0x7FFFFFFF
}
 
enum  AllocationCreateFlagBits {
  ALLOCATION_CREATE_DEDICATED_MEMORY_BIT = 0x00000001 , ALLOCATION_CREATE_NEVER_ALLOCATE_BIT = 0x00000002 , ALLOCATION_CREATE_MAPPED_BIT = 0x00000004 , ALLOCATION_CREATE_CAN_BECOME_LOST_BIT = 0x00000008 ,
  ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT = 0x00000010 , ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT = 0x00000020 , ALLOCATION_CREATE_UPPER_ADDRESS_BIT = 0x00000040 , ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
}
 
enum  PoolCreateFlagBits { POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT = 0x00000002 , POOL_CREATE_LINEAR_ALGORITHM_BIT = 0x00000004 , POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF }
 
enum  SuballocationType {
  SUBALLOCATION_TYPE_FREE = 0 , SUBALLOCATION_TYPE_UNKNOWN = 1 , SUBALLOCATION_TYPE_BUFFER = 2 , SUBALLOCATION_TYPE_IMAGE_UNKNOWN = 3 ,
  SUBALLOCATION_TYPE_IMAGE_LINEAR = 4 , SUBALLOCATION_TYPE_IMAGE_OPTIMAL = 5 , SUBALLOCATION_TYPE_MAX_ENUM = 0x7FFFFFFF
}
 
enum  CACHE_OPERATION { CACHE_FLUSH , CACHE_INVALIDATE }
 

Functions

VkResult CreateAllocator (const AllocatorCreateInfo *pCreateInfo, Allocator *pAllocator)
 
VkResult MapMemory (Allocator allocator, Allocation allocation, void **ppData)
 
void UnmapMemory (Allocator allocator, Allocation allocation)
 
template<typename CmpLess , typename VectorT >
bool VectorRemoveSorted (VectorT &v, typename VectorT::value_type &value)
 
template<typename CmpLess , typename VectorT >
size_t VectorInsertSorted (VectorT &vector, const typename VectorT::value_type &value)
 
template<typename P , typename T >
void append_pNext (P &parent, T &child)
 
template<typename T >
void _printbits (T number, unsigned int num_bits_to_print)
 
template<typename T >
void printbits (T number)
 
VkResult FindMemoryTypeIndex (Allocator allocator, uint32_t memoryTypeBits, AllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
 
VkResult CreateBuffer (Allocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, AllocationCreateInfo &pAllocationCreateInfo, VkBuffer *pBuffer, Allocation *pAllocation, AllocationInfo *pAllocationInfo)
 
void DestroyBuffer (Allocator allocator, VkBuffer buffer, Allocation allocation)
 
void * Malloc (Allocator hAllocator, size_t size, size_t alignment)
 
void Free (Allocator hAllocator, void *ptr)
 
template<typename T >
RoundDiv (T x, T y)
 

Detailed Description

interface

block

allocate

vulkan

utils

vector

Typedef Documentation

◆ AllocationCreateFlagBits

◆ AllocationCreateFlags

typedef VkFlags vkmm::AllocationCreateFlags

Definition at line 625 of file AllocatorVk.h.

◆ AllocationCreateInfo

◆ AllocationInfo

◆ Allocator

typedef struct Allocator_T* vkmm::Allocator

Definition at line 68 of file vthreepy_types.h.

◆ AllocatorCreateFlagBits

Description of a Allocator to be created. /// Flags for created #VmaAllocator.

◆ AllocatorCreateFlags

typedef VkFlags vkmm::AllocatorCreateFlags

Definition at line 550 of file AllocatorVk.h.

◆ AllocatorCreateInfo

◆ DefragmentationInfo

◆ DefragmentationStats

◆ DeviceMemoryCallbacks

◆ MemoryUsage

◆ PFN_AllocateDeviceMemoryFunction

typedef void(VKAPI_PTR * vkmm::PFN_AllocateDeviceMemoryFunction) (Allocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size)

VK_DEFINE_HANDLE(Allocator)

Definition at line 522 of file AllocatorVk.h.

◆ PFN_FreeDeviceMemoryFunction

typedef void(VKAPI_PTR * vkmm::PFN_FreeDeviceMemoryFunction) (Allocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size)

Callback function called before vkFreeMemory.

Definition at line 528 of file AllocatorVk.h.

◆ PoolCreateFlagBits

◆ PoolCreateFlags

typedef VkFlags vkmm::PoolCreateFlags

Definition at line 654 of file AllocatorVk.h.

◆ PoolCreateInfo

◆ PoolStats

◆ StatInfo

◆ Stats

typedef struct vkmm::Stats vkmm::Stats

General statistics from current state of Allocator.

Enumeration Type Documentation

◆ AllocationCreateFlagBits

Enumerator
ALLOCATION_CREATE_DEDICATED_MEMORY_BIT 
ALLOCATION_CREATE_NEVER_ALLOCATE_BIT 
ALLOCATION_CREATE_MAPPED_BIT 
ALLOCATION_CREATE_CAN_BECOME_LOST_BIT 
ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT 
ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT 
ALLOCATION_CREATE_UPPER_ADDRESS_BIT 
ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM 

Definition at line 607 of file AllocatorVk.h.

607 {
608
610
612
613 ALLOCATION_CREATE_MAPPED_BIT = 0x00000004,
614
616
618
620
622
@ ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM
Definition: AllocatorVk.h:623
@ ALLOCATION_CREATE_MAPPED_BIT
Definition: AllocatorVk.h:613
@ ALLOCATION_CREATE_UPPER_ADDRESS_BIT
Definition: AllocatorVk.h:621
@ ALLOCATION_CREATE_CAN_BECOME_LOST_BIT
Definition: AllocatorVk.h:615
@ ALLOCATION_CREATE_NEVER_ALLOCATE_BIT
Definition: AllocatorVk.h:611
@ ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT
Definition: AllocatorVk.h:619
@ ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT
Definition: AllocatorVk.h:617
@ ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
Definition: AllocatorVk.h:609
enum vkmm::AllocationCreateFlagBits AllocationCreateFlagBits

◆ AllocatorCreateFlagBits

Description of a Allocator to be created. /// Flags for created #VmaAllocator.

Enumerator
ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT 
ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT 
ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM 

Definition at line 542 of file AllocatorVk.h.

542 {
544
546
enum vkmm::AllocatorCreateFlagBits AllocatorCreateFlagBits
@ ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM
Definition: AllocatorVk.h:547
@ ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT
Definition: AllocatorVk.h:543
@ ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT
Definition: AllocatorVk.h:545

◆ CACHE_OPERATION

Enumerator
CACHE_FLUSH 
CACHE_INVALIDATE 

Definition at line 903 of file AllocatorVk.h.

@ CACHE_INVALIDATE
Definition: AllocatorVk.h:903
@ CACHE_FLUSH
Definition: AllocatorVk.h:903

◆ MemoryUsage

Enumerator
MEMORY_USAGE_UNKNOWN 
MEMORY_USAGE_GPU 
MEMORY_USAGE_GPU_ONLY 
MEMORY_USAGE_CPU_ONLY 
MEMORY_USAGE_CPU_TO_GPU 
MEMORY_USAGE_GPU_TO_CPU 
MEMORY_USAGE_MAX_ENUM 

Definition at line 596 of file AllocatorVk.h.

597 {
598
605 MEMORY_USAGE_MAX_ENUM = 0x7FFFFFFF
606 } MemoryUsage;
@ MEMORY_USAGE_GPU_ONLY
Definition: AllocatorVk.h:601
@ MEMORY_USAGE_CPU_TO_GPU
Definition: AllocatorVk.h:603
@ MEMORY_USAGE_UNKNOWN
Definition: AllocatorVk.h:599
@ MEMORY_USAGE_GPU
Definition: AllocatorVk.h:600
@ MEMORY_USAGE_GPU_TO_CPU
Definition: AllocatorVk.h:604
@ MEMORY_USAGE_CPU_ONLY
Definition: AllocatorVk.h:602
@ MEMORY_USAGE_MAX_ENUM
Definition: AllocatorVk.h:605
enum vkmm::MemoryUsage MemoryUsage

◆ PoolCreateFlagBits

Enumerator
POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT 
POOL_CREATE_LINEAR_ALGORITHM_BIT 
POOL_CREATE_FLAG_BITS_MAX_ENUM 

Definition at line 646 of file AllocatorVk.h.

646 {
647
649
651
enum vkmm::PoolCreateFlagBits PoolCreateFlagBits
@ POOL_CREATE_FLAG_BITS_MAX_ENUM
Definition: AllocatorVk.h:652
@ POOL_CREATE_LINEAR_ALGORITHM_BIT
Definition: AllocatorVk.h:650
@ POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT
Definition: AllocatorVk.h:648

◆ SuballocationType

Enumerator
SUBALLOCATION_TYPE_FREE 
SUBALLOCATION_TYPE_UNKNOWN 
SUBALLOCATION_TYPE_BUFFER 
SUBALLOCATION_TYPE_IMAGE_UNKNOWN 
SUBALLOCATION_TYPE_IMAGE_LINEAR 
SUBALLOCATION_TYPE_IMAGE_OPTIMAL 
SUBALLOCATION_TYPE_MAX_ENUM 

Definition at line 738 of file AllocatorVk.h.

739 {
746 SUBALLOCATION_TYPE_MAX_ENUM = 0x7FFFFFFF
747 };
@ SUBALLOCATION_TYPE_FREE
Definition: AllocatorVk.h:740
@ SUBALLOCATION_TYPE_BUFFER
Definition: AllocatorVk.h:742
@ SUBALLOCATION_TYPE_UNKNOWN
Definition: AllocatorVk.h:741
@ SUBALLOCATION_TYPE_IMAGE_LINEAR
Definition: AllocatorVk.h:744
@ SUBALLOCATION_TYPE_IMAGE_UNKNOWN
Definition: AllocatorVk.h:743
@ SUBALLOCATION_TYPE_IMAGE_OPTIMAL
Definition: AllocatorVk.h:745
@ SUBALLOCATION_TYPE_MAX_ENUM
Definition: AllocatorVk.h:746

Function Documentation

◆ _printbits()

template<typename T >
void vkmm::_printbits ( number,
unsigned int  num_bits_to_print 
)

Definition at line 391 of file AllocatorVk.cpp.

392 {
393 if (number || num_bits_to_print > 0) {
394 _printbits(number >> (T)1, num_bits_to_print - 1);
395 printf("%d", ((int)number) & 1);
396 }
397 }
void _printbits(T number, unsigned int num_bits_to_print)

◆ append_pNext()

template<typename P , typename T >
void vkmm::append_pNext ( P &  parent,
T &  child 
)

Definition at line 375 of file AllocatorVk.cpp.

376 {
377
378 struct ExtensionHeader
379 {
380 VkStructureType sType;
381 void* pNext;
382 };
383
384 auto last = (ExtensionHeader*)&parent;
385 while (last->pNext != nullptr)last = (ExtensionHeader*)last->pNext;
386 last->pNext = &child;
387
388 }

◆ CreateAllocator()

VkResult vkmm::CreateAllocator ( const AllocatorCreateInfo pCreateInfo,
Allocator pAllocator 
)

Definition at line 228 of file AllocatorVk.cpp.

231 {
232 assert(pCreateInfo && pAllocator);
233 *pAllocator = vkmm_new(pCreateInfo->pAllocationCallbacks, Allocator_T)(pCreateInfo);
234 return (*pAllocator)->Init(pCreateInfo);
235 }
#define vkmm_new(allocator, type)
Definition: AllocatorVk.h:813
const VkAllocationCallbacks * pAllocationCallbacks
Custom CPU memory allocation callbacks. Optional.
Definition: AllocatorVk.h:560

◆ CreateBuffer()

VkResult vkmm::CreateBuffer ( Allocator  allocator,
const VkBufferCreateInfo *  pBufferCreateInfo,
AllocationCreateInfo pAllocationCreateInfo,
VkBuffer *  pBuffer,
Allocation *  pAllocation,
AllocationInfo pAllocationInfo 
)

VMA_DEBUG_GLOBAL_MUTEX_LOCK

Definition at line 934 of file AllocatorVk.cpp.

941 {
942 assert(allocator && pBufferCreateInfo && &pAllocationCreateInfo && pBuffer && pAllocation);
944
945 *pBuffer = VK_NULL_HANDLE;
946 *pAllocation = VK_NULL_HANDLE;
947 VkResult res = vkCreateBuffer(
948 allocator->m_hDevice,
949 pBufferCreateInfo,
950 allocator->GetAllocationCallbacks(),
951 pBuffer);
952 if (res >= 0)
953 {
954
955 VkMemoryRequirements vkMemReq = {};
956 bool requiresDedicatedAllocation = false;
957 bool prefersDedicatedAllocation = false;
958 allocator->GetBufferMemoryRequirements(*pBuffer, vkMemReq,
959 requiresDedicatedAllocation, prefersDedicatedAllocation);
960
961 if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) != 0)
962 {
963 assert(vkMemReq.alignment %
964 allocator->m_PhysicalDeviceProperties.limits.minTexelBufferOffsetAlignment == 0);
965 }
966 if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 0)
967 {
968 assert(vkMemReq.alignment %
969 allocator->m_PhysicalDeviceProperties.limits.minUniformBufferOffsetAlignment == 0);
970 }
971 if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) != 0)
972 {
973 assert(vkMemReq.alignment %
974 allocator->m_PhysicalDeviceProperties.limits.minStorageBufferOffsetAlignment == 0);
975 }
976
977
978 if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) != 0) {
979 VkMemoryAllocateFlagsInfo* info = nullptr;
980 pAllocationCreateInfo.info.append(info);
981 info->deviceMask = 0;
982 info->flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT | VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT;
983 }
984
985
986
987
988 res = allocator->AllocateMemory(
989 vkMemReq,
990 requiresDedicatedAllocation,
991 prefersDedicatedAllocation,
992 *pBuffer,
993 VK_NULL_HANDLE,
994 pAllocationCreateInfo,
996 pAllocation);
997
998 if (res >= 0)
999 {
1000
1001 res = allocator->BindBufferMemory(*pAllocation, *pBuffer);
1002 if (res >= 0)
1003 {
1004
1005#if VMA_STATS_STRING_ENABLED
1006 (*pAllocation)->InitBufferImageUsage(pBufferCreateInfo->usage);
1007#endif
1008 if (pAllocationInfo != nullptr)
1009 {
1010 allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
1011 }
1012
1013 return VK_SUCCESS;
1014 }
1015
1016 allocator->FreeMemory(*pAllocation);
1017 *pAllocation = VK_NULL_HANDLE;
1018 vkDestroyBuffer(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks());
1019 *pBuffer = VK_NULL_HANDLE;
1020 return res;
1021 }
1022
1023 vkDestroyBuffer(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks());
1024 *pBuffer = VK_NULL_HANDLE;
1025 return res;
1026 }
1027 return res;
1028 }
void append(T *&info)
Definition: AllocatorVk.h:481
#define allocator

◆ DestroyBuffer()

void vkmm::DestroyBuffer ( Allocator  allocator,
VkBuffer  buffer,
Allocation  allocation 
)

VKMM_DEBUG_GLOBAL_MUTEX_LOCK

Definition at line 1030 of file AllocatorVk.cpp.

1034 {
1035
1036 assert(allocator);
1037 if (buffer == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE)
1038 {
1039 return;
1040 }
1041
1042 VKMM_DEBUG_LOG("DestroyBuffer");
1043
1045
1046 if (buffer != VK_NULL_HANDLE)
1047 {
1048 vkDestroyBuffer(allocator->m_hDevice, buffer, allocator->GetAllocationCallbacks());
1049 }
1050
1051 if (allocation != VK_NULL_HANDLE)
1052 {
1053 allocator->FreeMemory(allocation);
1054 }
1055 }
#define VKMM_DEBUG_LOG(...)
Definition: AllocatorVk.h:712

◆ FindMemoryTypeIndex()

VkResult vkmm::FindMemoryTypeIndex ( Allocator  allocator,
uint32_t  memoryTypeBits,
AllocationCreateInfo pAllocationCreateInfo,
uint32_t *  pMemoryTypeIndex 
)

Definition at line 425 of file AllocatorVk.cpp.

430 {
431 assert(allocator != VK_NULL_HANDLE);
432 assert(pAllocationCreateInfo != nullptr);
433 assert(pMemoryTypeIndex != nullptr);
434
435 if (pAllocationCreateInfo->memoryTypeBits != 0)
436 {
437 memoryTypeBits &= pAllocationCreateInfo->memoryTypeBits;
438 }
439
440 uint32_t requiredFlags = pAllocationCreateInfo->requiredFlags;
441 uint32_t preferredFlags = pAllocationCreateInfo->preferredFlags;
442
443 const bool mapped = (pAllocationCreateInfo->flags & ALLOCATION_CREATE_MAPPED_BIT) != 0;
444 if (mapped)
445 {
446 preferredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
447 }
448
449 // Convert usage to requiredFlags and preferredFlags.
450 switch (pAllocationCreateInfo->usage)
451 {
453 break;
455 if (!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
456 {
457 requiredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
458 }
459 break;
460
461 case MEMORY_USAGE_GPU:
462 if (!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
463 {
464 preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
465 }
466 break;
468 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
469 break;
471 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
472 if ( (pAllocationCreateInfo->flags & ALLOCATION_CREATE_MAPPED_BIT) == 0) {
473 pAllocationCreateInfo->flags |= ALLOCATION_CREATE_MAPPED_BIT;
474 }
475 if (!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
476 {
477 preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
478 }
479 break;
481 requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
482 preferredFlags |= VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
483 break;
484 default:
485 break;
486 }
487
488 /*
489 printf("memTypeBit Request ");
490 printbits(memoryTypeBits);
491
492 printf("memTypeBit Require ");
493 printbits(requiredFlags);
494
495 printf("memTypeBit Prefered ");
496 printbits(preferredFlags);
497
498 for (uint32_t memTypeIndex = 0, memTypeBit = 1;
499 memTypeIndex < allocator->GetMemoryTypeCount();
500 ++memTypeIndex, memTypeBit <<= 1)
501 {
502 // This memory type is acceptable according to memoryTypeBits bitmask.
503 printf("memTypeBit[%d] ", memTypeIndex);
504 printbits(memTypeBit);
505 printf(" propFlags .ex{Cache | Coherent | Visible| DeviceLocal ,None} [%d] ", memTypeIndex);
506 printbits(allocator->m_MemProps.memoryTypes[memTypeIndex].propertyFlags);
507
508 }
509 */
510 *pMemoryTypeIndex = UINT32_MAX;
511 uint32_t minCost = UINT32_MAX;
512 for (uint32_t memTypeIndex = 0, memTypeBit = 1;
513 memTypeIndex < allocator->GetMemoryTypeCount();
514 ++memTypeIndex, memTypeBit <<= 1)
515 {
516
517 if ((memTypeBit & memoryTypeBits) != 0)
518 {
519 const VkMemoryPropertyFlags currFlags =
520 allocator->m_MemProps.memoryTypes[memTypeIndex].propertyFlags;
521 // This memory type contains requiredFlags.
522 if ((requiredFlags & ~currFlags) == 0)
523 {
524 // Calculate cost as number of bits from preferredFlags not present in this memory type.
525 uint32_t currCost = CountBitsSet(preferredFlags & ~currFlags);
526 // Remember memory type with lowest cost.
527 if (currCost < minCost)
528 {
529 *pMemoryTypeIndex = memTypeIndex;
530 if (currCost == 0)
531 {
532 return VK_SUCCESS;
533 }
534 minCost = currCost;
535 }
536 }
537 }
538 }
539 return (*pMemoryTypeIndex != UINT32_MAX) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT;
540 }
VkMemoryPropertyFlags requiredFlags
Definition: AllocatorVk.h:633
VkMemoryPropertyFlags preferredFlags
Definition: AllocatorVk.h:635
AllocationCreateFlags flags
Use #VmaAllocationCreateFlagBits enum.
Definition: AllocatorVk.h:629

◆ Free()

void vkmm::Free ( Allocator  hAllocator,
void *  ptr 
)

Definition at line 1184 of file AllocatorVk.cpp.

1185 {
1186 Free(&hAllocator->m_AllocationCallbacks, ptr);
1187 }
void Free(Allocator hAllocator, void *ptr)
VkAllocationCallbacks m_AllocationCallbacks
Definition: AllocatorVk.h:918

◆ Malloc()

void * vkmm::Malloc ( Allocator  hAllocator,
size_t  size,
size_t  alignment 
)

Definition at line 1179 of file AllocatorVk.cpp.

1180 {
1181 return Malloc(&hAllocator->m_AllocationCallbacks, size, alignment);
1182 }
void * Malloc(Allocator hAllocator, size_t size, size_t alignment)

◆ MapMemory()

VkResult vkmm::MapMemory ( Allocator  allocator,
Allocation  allocation,
void **  ppData 
)

Definition at line 238 of file AllocatorVk.cpp.

242 {
243 assert(allocator && allocation && ppData);
244
245 //VMA_DEBUG_GLOBAL_MUTEX_LOCK
246
247 VkResult res = allocator->Map(allocation, ppData);
248
249 return res;
250 }

◆ printbits()

template<typename T >
void vkmm::printbits ( number)

Definition at line 399 of file AllocatorVk.cpp.

400 {
401 if (number < 0) {
402 printf(" Negative Binary : You should use unsigned type.\n");
403 return;
404 };
405
406 printf("0B");
407 _printbits(number, 8 * sizeof(T));
408 printf("\n");
409
410 }

◆ RoundDiv()

template<typename T >
T vkmm::RoundDiv ( x,
y 
)
inline

Definition at line 1403 of file AllocatorVk.h.

1404 {
1405 return (x + (y / (T)2)) / y;
1406 }

◆ UnmapMemory()

void vkmm::UnmapMemory ( Allocator  allocator,
Allocation  allocation 
)

Definition at line 252 of file AllocatorVk.cpp.

255 {
256 assert(allocator && allocation);
257 //VMA_DEBUG_GLOBAL_MUTEX_LOCK
258 allocator->Unmap(allocation);
259
260 }

◆ VectorInsertSorted()

template<typename CmpLess , typename VectorT >
size_t vkmm::VectorInsertSorted ( VectorT &  vector,
const typename VectorT::value_type &  value 
)

Definition at line 341 of file AllocatorVk.cpp.

342 {
343
344 const size_t indexToInsert = BinaryFindFirstNotLess(
345 vector.data(),
346 vector.data() + vector.size(),
347 value,
348 CmpLess()) - vector.data();
349
350 VectorInsert(vector, indexToInsert, value);
351 return indexToInsert;
352 }

◆ VectorRemoveSorted()

template<typename CmpLess , typename VectorT >
bool vkmm::VectorRemoveSorted ( VectorT &  v,
typename VectorT::value_type &  value 
)

Definition at line 278 of file AllocatorVk.cpp.

279 {
280 CmpLess comparator;
281 auto it = find(v.begin(), v.end(), value);
282 if (it != v.end())
283 {
284#ifdef USE_HIREDIS
285 rlog.hpush(__FILE__, __LINE__, LOG_TRACE, value.__rep__(true));
286#endif
287 // v.erase(it);
288 return true;
289 }
290
291 /*
292 typename VectorT::iterator it = BinaryFindFirstNotLess(
293 vector.begin(),
294 vector.end(),
295 value,
296 comparator);
297
298 if ((it != vector.end()) && !comparator(*it, value) && !comparator(value, *it))
299 {
300#ifdef USE_HIREDIS
301 rlog.hpush(__FILE__, __LINE__, LOG_TRACE,value->__rep__(true));
302#endif
303 size_t indexToRemove = it - vector.begin();
304 VectorRemove(vector, indexToRemove);
305 return true;
306 }
307 */
308 return false;
309 }
@ LOG_TRACE
Definition: log.hpp:54