Same buffer transfer different regions

Hello, In my Vulkan journey I made a home made memory allocator. My question is about performances when we use VK_BUFFER_USAGE_TRANSFER_SRC to buffer. I explain:
I create a buffer with memory let say of size 100 (for test purpose) then I upload 3 vertex buffers A = 40, B = 15, C = 15. then I freed buffer B. At that moment the memory looks like this :

         [0-39 Used] - [40 - 54 Free] - [55 - 69 used] - [70 -99 free].

when I add D = 40 it can’t fill in the first free block [40-55] and neither in the last one [70 - 99] . 40 > 15 && 40 > 30
So I wanted to move the data to get:

                     [0-39 Used] - [40 - 54 used] - [55 - 99 free]. 

The problem is that I created the buffer with usage : VK_BUFFER_USAGE_TRANSFER_DST_BITS | VK_BUFFER_USAGE_VERTEX_BITS | VK_BUFFER_USAGE_INDEX_BIT meaning I cant use vkCopy as it require that the source should be create with VK_BUFFER_USAGE_TRANSFER_SRC_BIT.

I think of 2 solutions:
1 - add VK_BUFFER_USAGE_TRANSFER_SRC_BIT when creating the buffer.
2 - create another buffer with VK_BUFFER_USAGE_TRANSFER_SRC_BIT and bind it to the same memory (I didn’t try yet)
The memory was created in LOCAL_DEVICE in case this is important to know.

Questions: 
 if I use (1) is there any performance penalties if I create all my buffer with transfer_src_bit?  
 is even the (2) possible I may try myself before somebody answers but if it works is that a correct used of buffer/memory ?

Thanks

ps: Sometimes in the forums there are some people who don’t answer the question and tell us USE VMA or this or that don’t recreate the whell. I know VMA exists and the goal here is not to write better but to understand more, what’s best to understand vulkan memory than writing something just to learn?

I think both your solutions will work. I would pick (1).

Regarding (1), performance may differ between platforms, but I expect on most GPUs a buffer is a buffer, just a sequence of bytes, and so adding TRANSFER_SRC usage flag shouldn’t make anything worse.

Regarding (2), according to Vulkan spec, chapter 12.10. Memory Aliasing, aliasing memory of buffers is legal and well defined. Images have special flag VK_IMAGE_CREATE_ALIAS_BIT that needs to be used when aliasing, but buffers don’t require and don’t have an equivalent.

You don’t need to use VMA :grinning: It can help, but implementing any part of the program by yourself can provide many benefits, like getting better understanding of the technology that you mentioned.

Thanks for your input. For (1) I knew it would work my problem was more about performances issue. for (2) has I am using a memory by usage e.g VK_BUFFER_USAGE_UNIFORM will have it’s own memory has IMAGES will have they own you just told me that for images I should add the flag VK_IMAGE_CREATE_ALIAS_BIT thank you again.

And I confirm after test (2) will not produce any validation layer error. I go with the (2) for the moment.

About VMA is feel that I have to add the comment because sometimes specially on StackOverflow people instead of answering point you to a library or lecture you about not doing things yourself without trying to first ask why you do it yourself.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.