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

Method CreateBuffer

include/vk_mem_alloc.h:14425–14503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14423}
14424
14425VkResult VmaAllocator_T::CreateBuffer(
14426 const VkBufferCreateInfo* pBufferCreateInfo,
14427 const VmaAllocationCreateInfo* pAllocationCreateInfo,
14428 void* pMemoryAllocateNext,
14429 VkBuffer* pBuffer,
14430 VmaAllocation* pAllocation,
14431 VmaAllocationInfo* pAllocationInfo)
14432{
14433 *pBuffer = VK_NULL_HANDLE;
14434 *pAllocation = VK_NULL_HANDLE;
14435
14436 if (pBufferCreateInfo->size == 0)
14437 {
14438 return VK_ERROR_INITIALIZATION_FAILED;
14439 }
14440 if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_COPY) != 0 &&
14441 !m_UseKhrBufferDeviceAddress)
14442 {
14443 VMA_ASSERT(0 && "Creating a buffer with VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT is not valid if VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT was not used.");
14444 return VK_ERROR_INITIALIZATION_FAILED;
14445 }
14446
14447 // 1. Create VkBuffer.
14448 VkResult res = (*m_VulkanFunctions.vkCreateBuffer)(m_hDevice, pBufferCreateInfo,
14449 GetAllocationCallbacks(), pBuffer);
14450 if (res >= 0)
14451 {
14452 // 2. vkGetBufferMemoryRequirements.
14453 VkMemoryRequirements vkMemReq = {};
14454 bool requiresDedicatedAllocation = false;
14455 bool prefersDedicatedAllocation = false;
14456 GetBufferMemoryRequirements(*pBuffer, vkMemReq,
14457 requiresDedicatedAllocation, prefersDedicatedAllocation);
14458
14459 // 3. Allocate memory using allocator.
14460 res = AllocateMemory(
14461 vkMemReq,
14462 requiresDedicatedAllocation,
14463 prefersDedicatedAllocation,
14464 *pBuffer, // dedicatedBuffer
14465 VK_NULL_HANDLE, // dedicatedImage
14466 VmaBufferImageUsage(*pBufferCreateInfo, m_UseKhrMaintenance5), // dedicatedBufferImageUsage
14467 pMemoryAllocateNext,
14468 *pAllocationCreateInfo,
14469 VMA_SUBALLOCATION_TYPE_BUFFER,
14470 1, // allocationCount
14471 pAllocation);
14472 if (res >= 0)
14473 {
14474 // 3. Bind buffer with memory.
14475 if ((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0)
14476 {
14477 res = BindBufferMemory(*pAllocation, 0, *pBuffer, VMA_NULL);
14478 }
14479 if (res >= 0)
14480 {
14481 // All steps succeeded.
14482#if VMA_STATS_STRING_ENABLED

Callers 3

vmaCreateBufferFunction · 0.45
vmaCreateDedicatedBufferFunction · 0.45

Calls 2

VmaBufferImageUsageClass · 0.85
InitBufferUsageMethod · 0.80

Tested by

no test coverage detected