Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not create a dummy buffer and destroy when call vmaFindMemoryTypeIndexForBufferInfo #419

Open
papazhang66 opened this issue Jun 6, 2024 · 2 comments
Labels
feature Adding new feature future release To be done some time in the future

Comments

@papazhang66
Copy link

we saw everytime call vmaFindMemoryTypeIndexForBufferInfo, it take quite a few cpu cycles to do the following

"// Must create a dummy buffer to query :(
VkBuffer hBuffer = VK_NULL_HANDLE;
res = funcs->vkCreateBuffer(
hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer);
if(res == VK_SUCCESS)
{
VkMemoryRequirements memReq = {};
funcs->vkGetBufferMemoryRequirements(hDev, hBuffer, &memReq);

        res = allocator->FindMemoryTypeIndex(
            memReq.memoryTypeBits, pAllocationCreateInfo,
            VmaBufferImageUsage(*pBufferCreateInfo, allocator->m_UseKhrMaintenance5), pMemoryTypeIndex);

        funcs->vkDestroyBuffer(
            hDev, hBuffer, allocator->GetAllocationCallbacks());
    }"

according to the spec.
"The memoryTypeBits member is identical for all VkBuffer objects created with the same value for the flags and usage members in the VkBufferCreateInfo structure and the handleTypes member of the VkExternalMemoryBufferCreateInfo structure passed to vkCreateBuffer. Further, if usage1 and usage2 of type VkBufferUsageFlags are such that the bits set in usage2 are a subset of the bits set in usage1, and they have the same flags and VkExternalMemoryBufferCreateInfo::handleTypes, then the bits set in memoryTypeBits returned for usage1 must be a subset of the bits set in memoryTypeBits returned for usage2, for all values of flags."
it looks the returned memoryTypeBit only affected by flags and usage and external buffer type. can we create a cache to avoid everytime create a dummy buffer.

@adam-sawicki-a
Copy link
Contributor

Thank you for this suggestion.

The problem doesn't occur if you use Vulkan 1.3 or VK_KHR_maintenance4 extension (and inform VMA library about it during library initialization), because then function vmaFindMemoryTypeIndexForBufferInfo can use a new Vulkan function vkGetDeviceBufferMemoryRequirements. Can you enable Vulkan 1.3 or this extension in your project?

Implementing a cache for recently used buffer/image creation parameters is a good idea that may be implemented in the future.

@adam-sawicki-a adam-sawicki-a added feature Adding new feature future release To be done some time in the future labels Jun 7, 2024
@papazhang66
Copy link
Author

currently we can not update the version to 1.3. since we have so many device running on vulkan 1.1. it will be perfect, if can fix this issue. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding new feature future release To be done some time in the future
Projects
None yet
Development

No branches or pull requests

2 participants