Fixed support for VK_KHR_dedicated_allocation: Added missing usage of VkMemoryDedicatedAllocateInfoKHR structure.

This commit is contained in:
Adam Sawicki 2017-10-03 11:26:58 +02:00
parent 5db51b1264
commit 358bc78544

View File

@ -3531,6 +3531,8 @@ struct VmaAllocator_T
VkResult AllocateMemory( VkResult AllocateMemory(
const VkMemoryRequirements& vkMemReq, const VkMemoryRequirements& vkMemReq,
bool dedicatedAllocation, bool dedicatedAllocation,
VkBuffer dedicatedBuffer,
VkImage dedicatedImage,
const VmaAllocationCreateInfo& createInfo, const VmaAllocationCreateInfo& createInfo,
VmaSuballocationType suballocType, VmaSuballocationType suballocType,
VmaAllocation* pAllocation); VmaAllocation* pAllocation);
@ -3591,6 +3593,8 @@ private:
VkResult AllocateMemoryOfType( VkResult AllocateMemoryOfType(
const VkMemoryRequirements& vkMemReq, const VkMemoryRequirements& vkMemReq,
bool dedicatedAllocation, bool dedicatedAllocation,
VkBuffer dedicatedBuffer,
VkImage dedicatedImage,
const VmaAllocationCreateInfo& createInfo, const VmaAllocationCreateInfo& createInfo,
uint32_t memTypeIndex, uint32_t memTypeIndex,
VmaSuballocationType suballocType, VmaSuballocationType suballocType,
@ -3603,6 +3607,8 @@ private:
uint32_t memTypeIndex, uint32_t memTypeIndex,
bool map, bool map,
void* pUserData, void* pUserData,
VkBuffer dedicatedBuffer,
VkImage dedicatedImage,
VmaAllocation* pAllocation); VmaAllocation* pAllocation);
// Tries to free pMemory as Dedicated Memory. Returns true if found and freed. // Tries to free pMemory as Dedicated Memory. Returns true if found and freed.
@ -6390,6 +6396,8 @@ VkDeviceSize VmaAllocator_T::CalcPreferredBlockSize(uint32_t memTypeIndex)
VkResult VmaAllocator_T::AllocateMemoryOfType( VkResult VmaAllocator_T::AllocateMemoryOfType(
const VkMemoryRequirements& vkMemReq, const VkMemoryRequirements& vkMemReq,
bool dedicatedAllocation, bool dedicatedAllocation,
VkBuffer dedicatedBuffer,
VkImage dedicatedImage,
const VmaAllocationCreateInfo& createInfo, const VmaAllocationCreateInfo& createInfo,
uint32_t memTypeIndex, uint32_t memTypeIndex,
VmaSuballocationType suballocType, VmaSuballocationType suballocType,
@ -6439,6 +6447,8 @@ VkResult VmaAllocator_T::AllocateMemoryOfType(
memTypeIndex, memTypeIndex,
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_PERSISTENT_MAP_BIT) != 0, (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_PERSISTENT_MAP_BIT) != 0,
finalCreateInfo.pUserData, finalCreateInfo.pUserData,
dedicatedBuffer,
dedicatedImage,
pAllocation); pAllocation);
} }
} }
@ -6469,6 +6479,8 @@ VkResult VmaAllocator_T::AllocateMemoryOfType(
memTypeIndex, memTypeIndex,
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_PERSISTENT_MAP_BIT) != 0, (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_PERSISTENT_MAP_BIT) != 0,
finalCreateInfo.pUserData, finalCreateInfo.pUserData,
dedicatedBuffer,
dedicatedImage,
pAllocation); pAllocation);
if(res == VK_SUCCESS) if(res == VK_SUCCESS)
{ {
@ -6492,6 +6504,8 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
uint32_t memTypeIndex, uint32_t memTypeIndex,
bool map, bool map,
void* pUserData, void* pUserData,
VkBuffer dedicatedBuffer,
VkImage dedicatedImage,
VmaAllocation* pAllocation) VmaAllocation* pAllocation)
{ {
VMA_ASSERT(pAllocation); VMA_ASSERT(pAllocation);
@ -6500,6 +6514,19 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
allocInfo.memoryTypeIndex = memTypeIndex; allocInfo.memoryTypeIndex = memTypeIndex;
allocInfo.allocationSize = size; allocInfo.allocationSize = size;
VkMemoryDedicatedAllocateInfoKHR dedicatedAllocInfo = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR };
if(dedicatedBuffer != VK_NULL_HANDLE)
{
VMA_ASSERT(dedicatedImage == VK_NULL_HANDLE);
dedicatedAllocInfo.buffer = dedicatedBuffer;
allocInfo.pNext = &dedicatedAllocInfo;
}
else if(dedicatedImage != VK_NULL_HANDLE)
{
dedicatedAllocInfo.image = dedicatedImage;
allocInfo.pNext = &dedicatedAllocInfo;
}
// Allocate VkDeviceMemory. // Allocate VkDeviceMemory.
VkDeviceMemory hMemory = VK_NULL_HANDLE; VkDeviceMemory hMemory = VK_NULL_HANDLE;
VkResult res = AllocateVulkanMemory(&allocInfo, &hMemory); VkResult res = AllocateVulkanMemory(&allocInfo, &hMemory);
@ -6607,6 +6634,8 @@ void VmaAllocator_T::GetImageMemoryRequirements(
VkResult VmaAllocator_T::AllocateMemory( VkResult VmaAllocator_T::AllocateMemory(
const VkMemoryRequirements& vkMemReq, const VkMemoryRequirements& vkMemReq,
bool dedicatedAllocation, bool dedicatedAllocation,
VkBuffer dedicatedBuffer,
VkImage dedicatedImage,
const VmaAllocationCreateInfo& createInfo, const VmaAllocationCreateInfo& createInfo,
VmaSuballocationType suballocType, VmaSuballocationType suballocType,
VmaAllocation* pAllocation) VmaAllocation* pAllocation)
@ -6642,7 +6671,15 @@ VkResult VmaAllocator_T::AllocateMemory(
VkResult res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &createInfo, &memTypeIndex); VkResult res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &createInfo, &memTypeIndex);
if(res == VK_SUCCESS) if(res == VK_SUCCESS)
{ {
res = AllocateMemoryOfType(vkMemReq, dedicatedAllocation, createInfo, memTypeIndex, suballocType, pAllocation); res = AllocateMemoryOfType(
vkMemReq,
dedicatedAllocation,
dedicatedBuffer,
dedicatedImage,
createInfo,
memTypeIndex,
suballocType,
pAllocation);
// Succeeded on first try. // Succeeded on first try.
if(res == VK_SUCCESS) if(res == VK_SUCCESS)
{ {
@ -6659,7 +6696,15 @@ VkResult VmaAllocator_T::AllocateMemory(
res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &createInfo, &memTypeIndex); res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &createInfo, &memTypeIndex);
if(res == VK_SUCCESS) if(res == VK_SUCCESS)
{ {
res = AllocateMemoryOfType(vkMemReq, dedicatedAllocation, createInfo, memTypeIndex, suballocType, pAllocation); res = AllocateMemoryOfType(
vkMemReq,
dedicatedAllocation,
dedicatedBuffer,
dedicatedImage,
createInfo,
memTypeIndex,
suballocType,
pAllocation);
// Allocation from this alternative memory type succeeded. // Allocation from this alternative memory type succeeded.
if(res == VK_SUCCESS) if(res == VK_SUCCESS)
{ {
@ -7322,6 +7367,8 @@ static VkResult AllocateMemoryForImage(
return allocator->AllocateMemory( return allocator->AllocateMemory(
vkMemReq, vkMemReq,
dedicatedAllocation, dedicatedAllocation,
VK_NULL_HANDLE, // dedicatedBuffer
image, // dedicatedImage
*pAllocationCreateInfo, *pAllocationCreateInfo,
suballocType, suballocType,
pAllocation); pAllocation);
@ -7665,6 +7712,8 @@ VkResult vmaAllocateMemory(
VkResult result = allocator->AllocateMemory( VkResult result = allocator->AllocateMemory(
*pVkMemoryRequirements, *pVkMemoryRequirements,
false, // dedicatedAllocation false, // dedicatedAllocation
VK_NULL_HANDLE, // dedicatedBuffer
VK_NULL_HANDLE, // dedicatedImage
*pCreateInfo, *pCreateInfo,
VMA_SUBALLOCATION_TYPE_UNKNOWN, VMA_SUBALLOCATION_TYPE_UNKNOWN,
pAllocation); pAllocation);
@ -7697,6 +7746,8 @@ VkResult vmaAllocateMemoryForBuffer(
VkResult result = allocator->AllocateMemory( VkResult result = allocator->AllocateMemory(
vkMemReq, vkMemReq,
dedicatedAllocation, dedicatedAllocation,
buffer, // dedicatedBuffer
VK_NULL_HANDLE, // dedicatedImage
*pCreateInfo, *pCreateInfo,
VMA_SUBALLOCATION_TYPE_BUFFER, VMA_SUBALLOCATION_TYPE_BUFFER,
pAllocation); pAllocation);
@ -7883,6 +7934,8 @@ VkResult vmaCreateBuffer(
res = allocator->AllocateMemory( res = allocator->AllocateMemory(
vkMemReq, vkMemReq,
dedicatedAllocation, dedicatedAllocation,
*pBuffer, // dedicatedBuffer
VK_NULL_HANDLE, // dedicatedImage
*pAllocationCreateInfo, *pAllocationCreateInfo,
VMA_SUBALLOCATION_TYPE_BUFFER, VMA_SUBALLOCATION_TYPE_BUFFER,
pAllocation); pAllocation);