KTX-Software icon indicating copy to clipboard operation
KTX-Software copied to clipboard

How to combine with VulkanMemoryAllocator

Open rHermes opened this issue 2 years ago • 5 comments

Hey!

I just wanted to ask how this might be combined with something like: https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator

As far as I can see, there is no option in ktxTexture_VkUploadEx() to specify how the image is allocated. I would like to use the VMA functions for this. How is this inteded to be achieved?

Best regards, Teodor Spæren

rHermes avatar May 01 '22 18:05 rHermes

When you create the VulkanDeviceInfo struct (withktxVulkanDeviceInfo_{Create,Construct}), that is used to pass device info to ktxVkUploadEx, you can pass a pointer to a VkAllocationCallbacks struct. This will be used by any allocation done by ktxVkUploadEx.

I'm not familiar with VulkanMemoryAllocator, which long postdates ktxVkUploadEx, but as VkAllocationCallbacks is the Vulkan API interface for providing external allocators, I expect the library must have such a structure that you can obtain and pass to ktxVulkanDeviceInfo_{Create,Construct}.

MarkCallow avatar May 02 '22 07:05 MarkCallow

Thanks for the quick reply!

I did indeed look at the VkAllocationCallbacks struct, but as far as I understand, this is only for host only memory, things like data structs and so forth, and not for allocating VkDeviceMemory which is what VMA deals with. What I'm currently looking at is to just reimplement the entire logic of the current ktxTexture_VkUploadEx(), but replace the allocation calls with the VMA equivalent, but I was wondering if there was a way to avoid doing this.

rHermes avatar May 02 '22 07:05 rHermes

Indeed VkAllocationCallbacks appears to be for host memory.

I don't think there is any alternative than reimplementing ktxTexture_VkUploadEx(). Currently it calls vkAllocateMemory to obtain device memory. Perhaps you can add device memory allocation pointers to ktxVulkanDeviceInfo which default to vkAllocateMemory and vkFreeMemory and use those pointers for device memory allocation in ktxTexture_VkUploadEx().

I would accept a PR to add VMA support to the libktx provided ktxTexture_VkUploadEx() can still be used as today without VMA and there is no significant performance loss.

MarkCallow avatar May 02 '22 08:05 MarkCallow

Hey! The mentioned PR doesn't really resolve this situation. VulkanMemoryAllocator has additional structures that is needed. We will need to provide a more generic solution for this, or even implement a specific version for VMA.

I have yet to really think about how this should be done. I'm thinking I'll first fork the project and attempt to adapt it specifically for VMA. When I have a better idea of what should be done, I'll think of how to make it generic.

rHermes avatar May 23 '22 10:05 rHermes

Reopening. Feel free to submit another PR when you're ready.

MarkCallow avatar May 24 '22 02:05 MarkCallow

Have you had any more thoughts on a PR for this?

MarkCallow avatar Jun 14 '23 08:06 MarkCallow

Fixed by #748.

MarkCallow avatar Sep 16 '23 13:09 MarkCallow