Skip to content

Commit c08b7af

Browse files
committed
Improvements in vmaFindMemoryTypeIndexForBufferInfo, vmaFindMemoryTypeIndexForImageInfo
Based on #506 - thanks @jmccarthy634
1 parent ad70fcb commit c08b7af

1 file changed

Lines changed: 32 additions & 34 deletions

File tree

include/vk_mem_alloc.h

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15902,7 +15902,8 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForBufferInfo(
1590215902
VkResult res = VK_SUCCESS;
1590315903

1590415904
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000
15905-
if(funcs->vkGetDeviceBufferMemoryRequirements)
15905+
if (funcs->vkGetDeviceBufferMemoryRequirements &&
15906+
(allocator->m_UseKhrMaintenance4 || allocator->m_VulkanApiVersion >= VK_MAKE_VERSION(1, 3, 0)))
1590615907
{
1590715908
// Can query straight from VkBufferCreateInfo :)
1590815909
VkDeviceBufferMemoryRequirementsKHR devBufMemReq = {VK_STRUCTURE_TYPE_DEVICE_BUFFER_MEMORY_REQUIREMENTS_KHR};
@@ -15911,29 +15912,27 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForBufferInfo(
1591115912
VkMemoryRequirements2 memReq = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2};
1591215913
(*funcs->vkGetDeviceBufferMemoryRequirements)(hDev, &devBufMemReq, &memReq);
1591315914

15914-
res = allocator->FindMemoryTypeIndex(
15915+
return allocator->FindMemoryTypeIndex(
1591515916
memReq.memoryRequirements.memoryTypeBits, pAllocationCreateInfo,
1591615917
VmaBufferImageUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5), pMemoryTypeIndex);
1591715918
}
15918-
else
1591915919
#endif // VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000
15920+
15921+
// Must create a dummy buffer to query :(
15922+
VkBuffer hBuffer = VK_NULL_HANDLE;
15923+
res = funcs->vkCreateBuffer(
15924+
hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer);
15925+
if(res == VK_SUCCESS)
1592015926
{
15921-
// Must create a dummy buffer to query :(
15922-
VkBuffer hBuffer = VK_NULL_HANDLE;
15923-
res = funcs->vkCreateBuffer(
15924-
hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer);
15925-
if(res == VK_SUCCESS)
15926-
{
15927-
VkMemoryRequirements memReq = {};
15928-
funcs->vkGetBufferMemoryRequirements(hDev, hBuffer, &memReq);
15927+
VkMemoryRequirements memReq = {};
15928+
funcs->vkGetBufferMemoryRequirements(hDev, hBuffer, &memReq);
1592915929

15930-
res = allocator->FindMemoryTypeIndex(
15931-
memReq.memoryTypeBits, pAllocationCreateInfo,
15932-
VmaBufferImageUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5), pMemoryTypeIndex);
15930+
res = allocator->FindMemoryTypeIndex(
15931+
memReq.memoryTypeBits, pAllocationCreateInfo,
15932+
VmaBufferImageUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5), pMemoryTypeIndex);
1593315933

15934-
funcs->vkDestroyBuffer(
15935-
hDev, hBuffer, allocator->GetAllocationCallbacks());
15936-
}
15934+
funcs->vkDestroyBuffer(
15935+
hDev, hBuffer, allocator->GetAllocationCallbacks());
1593715936
}
1593815937
return res;
1593915938
}
@@ -15954,7 +15953,8 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForImageInfo(
1595415953
VkResult res = VK_SUCCESS;
1595515954

1595615955
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000
15957-
if(funcs->vkGetDeviceImageMemoryRequirements)
15956+
if(funcs->vkGetDeviceImageMemoryRequirements &&
15957+
(allocator->m_UseKhrMaintenance4 || allocator->m_VulkanApiVersion >= VK_MAKE_VERSION(1, 3, 0)))
1595815958
{
1595915959
// Can query straight from VkImageCreateInfo :)
1596015960
VkDeviceImageMemoryRequirementsKHR devImgMemReq = {VK_STRUCTURE_TYPE_DEVICE_IMAGE_MEMORY_REQUIREMENTS_KHR};
@@ -15965,29 +15965,27 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForImageInfo(
1596515965
VkMemoryRequirements2 memReq = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2};
1596615966
(*funcs->vkGetDeviceImageMemoryRequirements)(hDev, &devImgMemReq, &memReq);
1596715967

15968-
res = allocator->FindMemoryTypeIndex(
15968+
return allocator->FindMemoryTypeIndex(
1596915969
memReq.memoryRequirements.memoryTypeBits, pAllocationCreateInfo,
1597015970
VmaBufferImageUsage(*pImageCreateInfo), pMemoryTypeIndex);
1597115971
}
15972-
else
1597315972
#endif // VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000
15973+
15974+
// Must create a dummy image to query :(
15975+
VkImage hImage = VK_NULL_HANDLE;
15976+
res = funcs->vkCreateImage(
15977+
hDev, pImageCreateInfo, allocator->GetAllocationCallbacks(), &hImage);
15978+
if(res == VK_SUCCESS)
1597415979
{
15975-
// Must create a dummy image to query :(
15976-
VkImage hImage = VK_NULL_HANDLE;
15977-
res = funcs->vkCreateImage(
15978-
hDev, pImageCreateInfo, allocator->GetAllocationCallbacks(), &hImage);
15979-
if(res == VK_SUCCESS)
15980-
{
15981-
VkMemoryRequirements memReq = {};
15982-
funcs->vkGetImageMemoryRequirements(hDev, hImage, &memReq);
15980+
VkMemoryRequirements memReq = {};
15981+
funcs->vkGetImageMemoryRequirements(hDev, hImage, &memReq);
1598315982

15984-
res = allocator->FindMemoryTypeIndex(
15985-
memReq.memoryTypeBits, pAllocationCreateInfo,
15986-
VmaBufferImageUsage(*pImageCreateInfo), pMemoryTypeIndex);
15983+
res = allocator->FindMemoryTypeIndex(
15984+
memReq.memoryTypeBits, pAllocationCreateInfo,
15985+
VmaBufferImageUsage(*pImageCreateInfo), pMemoryTypeIndex);
1598715986

15988-
funcs->vkDestroyImage(
15989-
hDev, hImage, allocator->GetAllocationCallbacks());
15990-
}
15987+
funcs->vkDestroyImage(
15988+
hDev, hImage, allocator->GetAllocationCallbacks());
1599115989
}
1599215990
return res;
1599315991
}

0 commit comments

Comments
 (0)