Pooling memory for images

Hello,

The articles about advanced memory managment in vulkan, like this: https://developer.nvidia.com/vulkan-memory-management or like this: Using Vulkan® Device Memory - AMD GPUOpen
advice us to avoid over-subscribing GPU-side memory, allocate device memory with big chunks and create big buffers to share em among vertices, indices, uniforms and etc.

In case we need allocate memory for buffer there is no any problems we can create big enough buffer with any required usages flags and the allocate memory for that buffers.

But the question is how to pooling memory for images?

in simple way (with no pooling):

  1. we firstly create image with required format, type, usages flags, mip levels and etc.
  2. then we get memory requirements with vkGetImageMemoryRequirements, to get to know suitable memory types and size that actually needs to allocate
  3. and then we can choose suitable memory type depends on required memory properties flags and then can allocate device memory.

In case we need to create some pooling system for memory for images:

Of couse we can not create some generic big image to use it like resource for any other images - so, we need allocate memory chunk before creating image resource and in this case we can not use vkGetImageMemoryRequirements.

In case we have no memory requirements how we can be sure, that required memory size can be allocated or maybe this size required some aligment or how we can be sure that select memory type is suitable for any type images and etc?

In case we need to create some pooling system for memory

I feel the need to react to this. Indeed this is half the problem. It is a optimization – you potentially pay for it with coding time and making less readable and flexible code. First step should be asking, if you absolutely need to do it, or are doing it just because all the cool kids do it.

Of couse we can not create some generic big image to use it like resource for any other images - so, we need allocate memory chunk before creating image resource and in this case we can not use vkGetImageMemoryRequirements.

We can if we reeeealy wanted to (actually I think that is done; especially in OpenGL).
And we can (actually we always should use vkGetImageMemoryRequirements).

In case we have no memory requirements how we can be sure, that required memory size can be allocated or maybe this size required some aligment or how we can be sure that select memory type is suitable for any type images and etc?

There is a good chance that on traditional GPUs there is this one big heap of memory obviously for general purpose. (Then there is a lot of special types; usually dealing with CPU side).
You should still use vkGetImageMemoryRequirements to check the image can be on that memory type.

And even on some uber-obscure GPU with more device side memory heaps that support different kinds of images each – then it is no tragedy. You would just have one such memory pool per each such memory heap. And allocate the Image in the one the Image requires.

As for size, the Pool should be large enough to fit your needs. And if isn’t you can always allocate another Pool to fit more image(s).
The alignment should be handled by choosing appropriate offset into the Memory Pool.