Is it possible to accidentally overwrite "meta-data" in VkDeviceMemory?

Viewed 43

From the answer from this reddit post.

...drivers may need some additional meta-data to manage given resource. That's why we need to call vkGet...MemoryRequirements() functions and allocate enough memory.

However, vkMapMemory maps the allocated memory, inside which the meta-data required by driver may be contained, according to the above answer.

When I write to that mapped memory, how am I supposed to know whether I am overwriting the meta-data?

1 Answers

You should ignore that part of the post. It's nonsense.

Implementations may in fact need metadata for VkBuffer and VkImage objects. But that metadata is not stored within the VkDeviceMemory you provide when you bind those objects to the memory. They are associated with the VkBuffer and VkImage objects. They are allocated when those objects are constructed (which is why creating them takes a VkAllocationCallbacks) and deallocated when they are destroyed.

The purpose in querying the memory requirements for buffers and images is not for metadata associated with the buffer/image per-se. It's for layout purposes. Some buffer usages have to have specific alignments and the sizes may need to be rounded up to that alignment. Optimally-tiled images have a layout that is completely opaque; you're not allowed to directly write to the bytes of a tiled image. You can only copy into/outof them with image copy commands.

Related