Hi,
I’m getting a synchronization validation error that I’d like to understand better and fix properly. I have 2 (vertex) buffers created with VMA, and checking the VmaAllocationInfo, they end up to be adjacent to each other into the same deviceMemory:
A) deviceMemory: 0x0000060000000006
offset: 1767168
size: 3072
B) deviceMemory: 0x0000060000000006
offset: 1770240
size: 3072
I fill buffer A (using a staging buffer and vkCmdCopyBuffer) and then use it for drawing without any issues. Then I’m trying to do exactly the same with buffer B, but when recording its vkCmdCopyBuffer, I get the following error:
vkCmdCopyBuffer(): WRITE_AFTER_READ hazard detected. vkCmdCopyBuffer writes to VkBuffer 0x19750000001975, which was previously read by vkCmdDraw.
No sufficient synchronization is present to ensure that a write (VK_ACCESS_2_TRANSFER_WRITE_BIT) at VK_PIPELINE_STAGE_2_COPY_BIT does not conflict with a prior read (VK_ACCESS_2_VERTEX_ATTRIBUTE_READ_BIT) at VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT.
Vulkan insight: an execution dependency is sufficient to prevent this hazard.
However, it’s the first time I’m touching buffer B and only buffer A was used for drawing. I have a basic tracking system for accesses and stages, so I do put a barrier before copying data to B (with dstStage = VK_PIPELINE_STAGE_2_COPY_BIT_KHR and dstAccess = VK_ACCESS_2_TRANSFER_WRITE_BIT_KHR), but since this is its first usage, the srcStage & srcAccess are both 0.
The offsets and sizes in the VkBufferMemoryBarrier seem to be correct for each buffer (offset = 0, size = 3072 or VK_WHOLE_SIZE).
I understand the validation error, but is this to be expected? I don’t understand why I should put an execution dependency to a buffer I’ve never used before, even though I kinda get that buffer A’s memory “state” is affecting B somehow, but I don’t get why. Is there some fact that I ignore or I have probably messed something somewhere else?
Please also note that if I use the VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT in the VmaAllocationCreateFlags, then no validation error occurs. I guess because with this the 2 buffers use a different deviceMemory, but I wouldn’t like to use this as my solution because it’s probably not optimal.
Thanks in advance for any help & insights!