I have implemented a custom allocator to track the memory that is allocated by vkAllocateMemory
.
I have also studied the official Khronos documentation regarding this topic but I could not found an answer to a following questions:
- What is acutally the
size
parameterPFN_vkAllocationFunction
? I have found out that apparently it is not the size of the actual buffer we want to allocate the memory for. I am suspecting that this is size of a Vulkan structures or any other Vulkan internal buffers. No matter how big memory chunk I want to allocate, it the size is always set to200
(it is machine/GPU/driver dependent value but it is a constant value). For the testing purposes I used triangle from: https://github.com/SaschaWillems/Vulkan and an allocator from a similar question: Vulkan's VkAllocationCallbacks implemented with malloc/free()
triangle before vkAllocateMemory: memAlloc.allocationSize: 7864320 sizeof(memAlloc): 32
triangle after vkAllocateMemory: memAlloc.allocationSize: 7864320
pAllocator's allocationFunction: <Memory>, size: 200, alignment: 8, allocationScope: 1, return ptr* : 0x0x5564ac917b20
I have also found out that for other calls, this size
is different for different vulkan calls, like vkCreateRenderPass
or vkCreateImageView
.
pAllocator's allocationFunction: <ImageView>, size: 160, alignment: 8, allocationScope: 1, return ptr* : 0x0x5564acdf8390
pAllocator's allocationFunction: <ImageView>, size: 824, alignment: 8, allocationScope: 1, return ptr* : 0x0x5564acdf8440
pAllocator's allocationFunction: <RenderPass>, size: 200, alignment: 8, allocationScope: 1, return ptr* : 0x0x5564ac950ee0
pAllocator's allocationFunction: <RenderPass>, size: 88, alignment: 8, allocationScope: 1, return ptr* : 0x0x5564acdf8780
pAllocator's allocationFunction: <RenderPass>, size: 56, alignment: 8, allocationScope: 1, return ptr* : 0x0x5564acdf7a00
pAllocator's allocationFunction: <RenderPass>, size: 344, alignment: 8, allocationScope: 1, return ptr* : 0x0x5564ac6a07c0
pAllocator's allocationFunction: <RenderPass>, size: 8, alignment: 8, allocationScope: 1, return ptr* : 0x0x5564acdf87e0
- Is it possible to allocate the host-visible memory using those callbacks? I would like to emulate the behaviour of
VK_EXT_external_memory_host
,VK_KHR_external_memory_fd
orVK_EXT_external_memory_dma_buf
but I don't know if this approach (that is implementing own allocator) can be useful for it.