title: How to copy Swap chain Image to VkBuffer in case of multiple subpasses in Vulkan
body: <p>I am looking in this demo for rendering a scene in vulkan using depth peeling Order Independent Transparency</p>
  
  <p>Blog: <a href="https://matthewwellings.com/blog/depth-peeling-order-independent-transparency-in-vulkan/" rel="nofollow noreferrer">https://matthewwellings.com/blog/depth-peeling-order-independent-transparency-in-vulkan/</a>
  Code: <a href="https://github.com/openforeveryone/VulkanDepthPeel" rel="nofollow noreferrer">https://github.com/openforeveryone/VulkanDepthPeel</a></p>
  
  <p>I have modified the code so that I am able to save the final render in an output image(png) before presenting for rendering to the surface.</p>
  
  <p>Once the primary command buffer consisting secondary command buffers responsible for drawing operations is submitted to queue for execution &amp; rendering is finished, I am using vkCmdCopyImageToBuffer for copying the data from the current swap chain image(The copy operation is done after introducing the image barrier to make sure rendering is completed first) to a VkBuffer &amp; then mapping the buffer memory to an unsigned char pointer &amp; writing this information to the PNG file. But the output which I see in the PNG is different from the one rendered on window as the boxes are almost entirely transparent with some RGB information as you can see in the image below.</p>
  
  <p>My guess is this might be the case due to this particular demo involving multiple subpasses &amp; I am not copying the data properly but only thing bothering me is that since I am directly copying from swapchain image just before finally presenting to the surface, I should be having the final color data in the image &amp; hence PNG &amp; render should match.</p>
  
  <p>Rendered Frame:
  <a href="https://i.stack.imgur.com/Q2L6q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q2L6q.png" alt="enter image description here"></a>
  Saved Frame:</p>
  
  <p><a href="https://i.stack.imgur.com/gJNZR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gJNZR.png" alt="enter image description here"></a></p>
  
  <p>Let me know if I have missed explaining any details, any help is appreciated. Thanks!</p>