layers: Fix img layout state in CmdExecuteCommands
Previously the layout state in the primary command buffer was just
overwritten with the state in the secondary command buffer.
This can lead to spurious errors upon submission of the primary CB, if
an image used in the secondary CB is used prior to CmdExecuteCommands
in the primary CB with a different initial layout. This is because the
initialLayout field for the image on the primary CB is overwritten
with that of the secondary CB.
An example case that was incorrectly erroring (these commands refer to
the same image, newly created):
(primary buffer)
vkCmdPipelineBarrier, transition UNDEFINED -> TRANSFER_DST_OPTIMAL
vkCmdExecuteCommands
(secondary buffer)
...
vkCmdCopyBufferToImage, layout TRANSFER_DST_OPTIMAL
Just before the CmdExecuteCommands, the image had initialLayout =
UNDEFINED and layout = TRANSFER_DST_OPTIMAL on the primary CB, and
initialLayout = layout = TRANSFER_DST_OPTIMAL on the secondary.
After CmdExecuteCommands, the primary CB state is overwritten, so
it has initialLayout = layout = TRANSFER_DST_OPTIMAL. At submission,
this then errors because the global image layout is UNDEFINED.
Fix by only setting initialLayout on the primary CB from the secondary
if the image hasn't already been used on the primary.
Change-Id: Iae248ed09b1f87598fd192ba3d6f0bcf7ad38ada