Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I flush device memory after unmap in Vulkan?

Tags:

vulkan

Can I flush a memory range after unmap?

At first seems wrong, because the function is called vkFlushMappedMemoryRanges(), but the documentation seems to imply the memory is ready to be flushed, even after being unmapped:

Unmapping non-coherent memory does not implicitly flush the mapped memory, and host writes that have not been flushed may not ever be visible to the device. However, implementations must ensure that writes that have not been flushed do not become visible to any other memory.

like image 302
lvella Avatar asked Jul 09 '18 22:07

lvella


1 Answers

One of the valid usage rules of vkFlushMappedMemoryRanges() is that all of the VkMappedMemoryRange structures must be valid. And the validity rules for that structure say:

memory must be currently mapped

So if you have unmapped the memory, you can't flush it.

However, flushing does say:

bytes in that range is flushed if any byte in that set has been written by the host since it was first mapped, or the last time it was flushed.

So apparently, if you unmap it and then map it again, you can flush it and still see the data. Personally, I wouldn't count on it.

like image 108
Nicol Bolas Avatar answered Nov 16 '22 00:11

Nicol Bolas