| 14503 | } |
| 14504 | |
| 14505 | VkResult VmaAllocator_T::CreateImage( |
| 14506 | const VkImageCreateInfo* pImageCreateInfo, |
| 14507 | const VmaAllocationCreateInfo* pAllocationCreateInfo, |
| 14508 | void* pMemoryAllocateNext, |
| 14509 | VkImage* pImage, |
| 14510 | VmaAllocation* pAllocation, |
| 14511 | VmaAllocationInfo* pAllocationInfo) |
| 14512 | { |
| 14513 | *pImage = VK_NULL_HANDLE; |
| 14514 | *pAllocation = VK_NULL_HANDLE; |
| 14515 | |
| 14516 | if (pImageCreateInfo->extent.width == 0 || |
| 14517 | pImageCreateInfo->extent.height == 0 || |
| 14518 | pImageCreateInfo->extent.depth == 0 || |
| 14519 | pImageCreateInfo->mipLevels == 0 || |
| 14520 | pImageCreateInfo->arrayLayers == 0) |
| 14521 | { |
| 14522 | return VK_ERROR_INITIALIZATION_FAILED; |
| 14523 | } |
| 14524 | |
| 14525 | // 1. Create VkImage. |
| 14526 | VkResult res = (*m_VulkanFunctions.vkCreateImage)(m_hDevice, pImageCreateInfo, |
| 14527 | GetAllocationCallbacks(), pImage); |
| 14528 | if (res == VK_SUCCESS) |
| 14529 | { |
| 14530 | VmaSuballocationType suballocType = pImageCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL ? |
| 14531 | VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL : |
| 14532 | VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR; |
| 14533 | |
| 14534 | // 2. Allocate memory using allocator. |
| 14535 | VkMemoryRequirements vkMemReq = {}; |
| 14536 | bool requiresDedicatedAllocation = false; |
| 14537 | bool prefersDedicatedAllocation = false; |
| 14538 | GetImageMemoryRequirements(*pImage, vkMemReq, |
| 14539 | requiresDedicatedAllocation, prefersDedicatedAllocation); |
| 14540 | |
| 14541 | res = AllocateMemory( |
| 14542 | vkMemReq, |
| 14543 | requiresDedicatedAllocation, |
| 14544 | prefersDedicatedAllocation, |
| 14545 | VK_NULL_HANDLE, // dedicatedBuffer |
| 14546 | *pImage, // dedicatedImage |
| 14547 | VmaBufferImageUsage(*pImageCreateInfo), // dedicatedBufferImageUsage |
| 14548 | pMemoryAllocateNext, |
| 14549 | *pAllocationCreateInfo, |
| 14550 | suballocType, |
| 14551 | 1, // allocationCount |
| 14552 | pAllocation); |
| 14553 | if (res == VK_SUCCESS) |
| 14554 | { |
| 14555 | // 3. Bind image with memory. |
| 14556 | if ((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0) |
| 14557 | { |
| 14558 | res = BindImageMemory(*pAllocation, 0, *pImage, VMA_NULL); |
| 14559 | } |
| 14560 | if (res == VK_SUCCESS) |
| 14561 | { |
| 14562 | // All steps succeeded. |
no test coverage detected