I have a similar issue and i am at the point of blaming the AMD drivers and or the spec :razz:
I have 2 command buffers which each display an object. The app will show either object 1 or 2 or both. The render thread will actually just execute command buffer 1 and/or 2. Now of course the RenderPass must state the layout, so i tried to make it _GENERAL and it worked/works perfectly (after a lot of trial and error). Then i wanted to get synch done right and now try to use the _OPTIMAL layout and thats when problems started.
Just 2 examples:
The images are in layout UNDEFINED for the first run (only). So i need to transition the layout to _OPTIMAL. Thats what a 3. command buffer shall do. Sounds like a trivial task… when it is not. What does the spec say:
“A pipeline barrier inserts an execution dependency and a set of memory dependencies between a set of commands earlier
in the command buffer and a set of commands later in the command buffer.”
“VK_ACCESS_MEMORY_READ_BIT indicates that the access is a read via a non-specific unit attached to the memory.
This unit may be external to the Vulkan device or otherwise not part of the core Vulkan pipeline. When included in
dstAccessMask, all writes using access types in srcAccessMask performed by pipeline stages in srcStageMask
must be visible in memory.”
“The VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT is useful for accomplishing memory barriers and layout transitions when the next accesses will be
done in a different queue or by a presentation engine”
Yes, thats confusing, not to say contradicting. But it should… or may work… Lets see what happens:
t{0} vkBeginCommandBuffer(commandBuffer = 00000000052C20F0, pBeginInfo = 000000000020ECA8) = VK_SUCCESS
pBeginInfo (000000000020ECA8)
sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO
pNext = 0000000000000000
flags = 1
pInheritanceInfo = 0000000000000000
t{0} vkCmdPipelineBarrier(commandBuffer = 00000000052C20F0, srcStageMask = 8192, dstStageMask = 8192, dependencyFlags = 0, memoryBarrierCount = 0, pMemoryBarriers = 0000000000000000, bufferMemoryBarrierCount = 1, pBufferMemoryBarriers = 000000000020EF38, imageMemoryBarrierCount = 1, pImageMemoryBarriers = 000000000020EED0)
pImageMemoryBarriers[0] (000000000020EED0)
sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER
pNext = 0000000000000000
srcAccessMask = 0
dstAccessMask = 34304
oldLayout = VK_IMAGE_LAYOUT_UNDEFINED
newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
srcQueueFamilyIndex = 4294967295
dstQueueFamilyIndex = 4294967295
image = 00000000054A3350
subresourceRange = 000000000020EF00
subresourceRange (000000000020EF00)
aspectMask = 1
baseMipLevel = 0
levelCount = 1
baseArrayLayer = 0
layerCount = 1
[…]
t{0} vkEndCommandBuffer(commandBuffer = 00000000052C20F0) = VK_SUCCESS
t{0} vkQueueSubmit(queue = 00000000051313F8, submitCount = 1, pSubmits = 000000000020EF90, fence = 00000000054A3550) = VK_SUCCESS
pSubmits[0] (000000000020EF90)
sType = VK_STRUCTURE_TYPE_SUBMIT_INFO
pNext = 0000000000000000
waitSemaphoreCount = 0
pWaitSemaphores = 0000000000000000
pWaitDstStageMask = 0000000000000000
commandBufferCount = 1
pCommandBuffers = 00000000054B31C0
signalSemaphoreCount = 0
pSignalSemaphores = 0000000000000000
pCommandBuffers[0].handle = 00000000052C20F0
t{0} vkDeviceWaitIdle(device = 0000000005130A10) = VK_SUCCESS
t{0} vkWaitForFences(device = 0000000005130A10, fenceCount = 1, pFences = 00000000054B3200, waitAll = 0, timeout = 18446744073709551615) = VK_SUCCESS
pFences[0] (00000000054B3200)
00000000054A3550
t{0} vkResetFences(device = 0000000005130A10, fenceCount = 1, pFences = 00000000054B3200) = VK_SUCCESS
pFences[0] (00000000054B3200)
00000000054A3550
AND NOW…
[…] draw etc. pp
ERROR: Cannot submit cmd buffer using image with layout VK_IMAGE_LAYOUT_UNDEFINED when first use is VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL.
ERROR: Cannot submit cmd buffer using image with layout VK_IMAGE_LAYOUT_UNDEFINED when first use is VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL.
t{1} vkQueueSubmit(queue = 00000000051313F8, submitCount = 1, pSubmits = 000000000708E730, fence = 00000000054A3550) = VK_SUCCESS
Voila…Nothing happens. So much for changing layout. Its undefined for the 1. object only btw. So the layout is transitioned somewhere somehow, i dont know. Is this correct behaviour, is it not? I do not know. Reading the spec, it could be…
Just doesnt produce the result i would like to see.
Even more confusing to me was this:
t{1} vkCmdEndRenderPass(commandBuffer = 00000000052C20F0)
t{1} vkCmdPipelineBarrier(commandBuffer = 00000000052C20F0, srcStageMask = 65536, dstStageMask = 65536, dependencyFlags = 0, memoryBarrierCount = 0, pMemoryBarriers = 0000000000000000, bufferMemoryBarrierCount = 0, pBufferMemoryBarriers = 0000000000000000, imageMemoryBarrierCount = 2, pImageMemoryBarriers = 000000000708E180)
pImageMemoryBarriers[0] (000000000708E180)
sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER
pNext = 0000000000000000
srcAccessMask = 256
dstAccessMask = 32768
oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
srcQueueFamilyIndex = 4294967295
dstQueueFamilyIndex = 4294967295
image = 00000000054A3310
subresourceRange = 000000000708E1B0
subresourceRange (000000000708E1B0)
aspectMask = 1
baseMipLevel = 0
levelCount = 1
baseArrayLayer = 0
layerCount = 1
pImageMemoryBarriers[1] (000000000708E1C8 )
sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER
pNext = 0000000000000000
srcAccessMask = 1536
dstAccessMask = 2048
oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
srcQueueFamilyIndex = 4294967295
dstQueueFamilyIndex = 4294967295
image = 00000000054A3350
subresourceRange = 000000000708E1F8
subresourceRange (000000000708E1F8)
aspectMask = 1
baseMipLevel = 0
levelCount = 1
baseArrayLayer = 0
layerCount = 1
(its actually: )
{
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT|VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, //VkAccessFlags srcAccessMask;
VK_ACCESS_TRANSFER_READ_BIT, //VkAccessFlags dstAccessMask;
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, //VkImageLayout oldLayout;
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, //VkImageLayout newLayout;
VK_QUEUE_FAMILY_IGNORED, //uint32_t srcQueueFamilyIndex;
VK_QUEUE_FAMILY_IGNORED, //uint32_t dstQueueFamilyIndex;
}
with VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
ERROR: Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL and doesn’t match the current layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL.
t{1} vkCmdCopyImageToBuffer(commandBuffer = 00000000052C20F0, srcImage = 00000000054A3350, srcImageLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dstBuffer = 00000000054A3380, regionCount = 1, pRegions = 000000000708E6D8 )
pRegions[0] (000000000708E6D8 )
bufferOffset = 0
bufferRowLength = 800
bufferImageHeight = 600
imageSubresource = 000000000708E6E8
imageOffset = 000000000708E6F8
imageExtent = 000000000708E704
imageExtent (000000000708E704)
width = 800
height = 600
depth = 1
imageOffset (000000000708E6F8)
x = 0
y = 0
z = 0
imageSubresource (000000000708E6E8)
aspectMask = 2
mipLevel = 0
baseArrayLayer = 0
layerCount = 1
t{1} vkEndCommandBuffer(commandBuffer = 00000000052C20F0) = VK_SUCCESS
Less error checking emphasizes the need for correct source code. Reading the spec I just can’t see whats wrong with the source. The result is wrong though 
Switching the source layout to VK_IMAGE_LAYOUT_GENERAL works, while VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL does not. I’m not too happy with the solution, but for now it works. Maybe that can help with your issue as well.