Sign in to follow this  
Followers 0
dilipd

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

1 post in this topic

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:

Q2L6q.png

Saved Frame:

gJNZR.png

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

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By L. Spiro
      Home: https://www.khronos.org/vulkan/
      SDK: http://lunarg.com/vulkan-sdk/
       
      AMD drivers: http://gpuopen.com/gaming-product/vulkan/ (Note that Vulkan support is now part of AMD’s official drivers, so simply getting the latest drivers for your card should give you Vulkan support.)
      NVIDIA drivers: https://developer.nvidia.com/vulkan-driver (Note that Vulkan support is now part of NVIDIA’s official drivers, so simply getting the latest drivers for your card should give you Vulkan support.)
      Intel drivers: http://blogs.intel.com/evangelists/2016/02/16/intel-open-source-graphics-drivers-now-support-vulkan/
       
      Quick reference: https://www.khronos.org/registry/vulkan/specs/1.0/refguide/Vulkan-1.0-web.pdf
      Reference: https://www.khronos.org/registry/vulkan/specs/1.0/apispec.html
       
      GLSL-to-SPIR-V: https://github.com/KhronosGroup/glslang

      Sample code: https://github.com/LunarG/VulkanSamples
      https://github.com/SaschaWillems/Vulkan
      https://github.com/nvpro-samples
      https://github.com/nvpro-samples/gl_vk_chopper
      https://github.com/nvpro-samples/gl_vk_threaded_cadscene
      https://github.com/nvpro-samples/gl_vk_bk3dthreaded
      https://github.com/nvpro-samples/gl_vk_supersampled
      https://github.com/McNopper/Vulkan
      https://github.com/GPUOpen-LibrariesAndSDKs/HelloVulkan
       
      C++: https://github.com/nvpro-pipeline/vkcpp
      https://developer.nvidia.com/open-source-vulkan-c-api

      Getting started: https://vulkan-tutorial.com/
      https://renderdoc.org/vulkan-in-30-minutes.html
      https://www.khronos.org/news/events/vulkan-webinar
      https://developer.nvidia.com/engaging-voyage-vulkan
      https://developer.nvidia.com/vulkan-shader-resource-binding
      https://developer.nvidia.com/vulkan-memory-management
      https://developer.nvidia.com/opengl-vulkan
      https://github.com/vinjn/awesome-vulkan

      Videos: https://www.youtube.com/playlist?list=PLYO7XTAX41FPg08uM_bgPE9HLgDAyzDaZ
       
       
      L. Spiro
  • Popular Now