Jump to content

View more

Image of the Day

Trying out some of Pickle Jar compositions in @SketchUp and Unity, for a late #screenshotsaturday #gamedev https://t.co/HU0kZAnQtD
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.

Sign up now

How to copy Swap chain Image to VkBuffer in case of multiple subpasses in Vulkan?

2: Adsense
  • You cannot reply to this topic
1 reply to this topic

#1 dilipd   Members   


Posted 27 February 2017 - 12:34 AM

I am looking in this demo for rendering a scene in vulkan using depth peeling Order Independent Transparency

Blog: https://matthewwellings.com/blog/depth-peeling-order-independent-transparency-in-vulkan/ Code: https://github.com/openforeveryone/VulkanDepthPeel

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.

Once the primary command buffer consisting secondary command buffers responsible for drawing operations is submitted to queue for execution & 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 & then mapping the buffer memory to an unsigned char pointer & 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.

My guess is this might be the case due to this particular demo involving multiple subpasses & 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 & hence PNG & render should match.

Rendered Frame:


Saved Frame:


Let me know if I have missed explaining any details, any help is appreciated. Thanks!

#2 dilipd   Members   


Posted 27 February 2017 - 07:25 AM

Found the solution. The image was being saved correctly, its just that compositing was done differently on the rendered surface & while saving the png. I am using VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR in my swapchain. So Vulkan will not do any pre or post multiplication while compositing the image but that task is left to native window platform surface which calculates the final composited image & hence the rendered image was different than the saved png, setting the alpha value to 255 while saving the png does solve this problem.