MCPcopy Create free account
hub / github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator / AllocateMemory

Method AllocateMemory

include/vk_mem_alloc.h:14586–14683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14584}
14585
14586VkResult VmaAllocator_T::AllocateMemory(
14587 VkMemoryRequirements vkMemReq,
14588 bool requiresDedicatedAllocation,
14589 bool prefersDedicatedAllocation,
14590 VkBuffer dedicatedBuffer,
14591 VkImage dedicatedImage,
14592 VmaBufferImageUsage dedicatedBufferImageUsage,
14593 // pNext chain for VkMemoryAllocateInfo. When used, must specify requiresDedicatedAllocation = true.
14594 void* pMemoryAllocateNext,
14595 const VmaAllocationCreateInfo& createInfo,
14596 VmaSuballocationType suballocType,
14597 size_t allocationCount,
14598 VmaAllocation* pAllocations)
14599{
14600 memset(pAllocations, 0, sizeof(VmaAllocation) * allocationCount);
14601
14602 vkMemReq.alignment = VMA_MAX(vkMemReq.alignment, createInfo.minAlignment);
14603 VMA_ASSERT(VmaIsPow2(vkMemReq.alignment));
14604
14605 // If using custom pNext chain for VkMemoryAllocateInfo, must require dedicated allocations.
14606 if(pMemoryAllocateNext != VMA_NULL)
14607 {
14608 requiresDedicatedAllocation = true;
14609 }
14610
14611 if(vkMemReq.size == 0)
14612 {
14613 return VK_ERROR_INITIALIZATION_FAILED;
14614 }
14615
14616 VmaAllocationCreateInfo createInfoFinal = createInfo;
14617 VkResult res = CalcAllocationParams(createInfoFinal, requiresDedicatedAllocation);
14618 if(res != VK_SUCCESS)
14619 return res;
14620
14621 if(createInfoFinal.pool != VK_NULL_HANDLE)
14622 {
14623 VmaBlockVector& blockVector = createInfoFinal.pool->m_BlockVector;
14624 return AllocateMemoryOfType(
14625 createInfoFinal.pool,
14626 vkMemReq.size,
14627 vkMemReq.alignment,
14628 prefersDedicatedAllocation,
14629 dedicatedBuffer,
14630 dedicatedImage,
14631 dedicatedBufferImageUsage,
14632 pMemoryAllocateNext,
14633 createInfoFinal,
14634 blockVector.GetMemoryTypeIndex(),
14635 suballocType,
14636 createInfoFinal.pool->m_DedicatedAllocations,
14637 blockVector,
14638 allocationCount,
14639 pAllocations);
14640 }
14641
14642 // Bit mask of memory Vulkan types acceptable for this allocation.
14643 uint32_t memoryTypeBits = vkMemReq.memoryTypeBits;

Callers 5

vmaAllocateMemoryFunction · 0.80
vmaAllocateMemoryPagesFunction · 0.80

Calls 2

VmaIsPow2Function · 0.85
GetMemoryTypeIndexMethod · 0.45

Tested by

no test coverage detected