Search code examples
graphicsvulkanfreeimage

Vulkan output RGBA color to BGRA color attachment


I wrote a simple Vulkan demo with BGRA images queried from swapchain. If I output RGBA pixels to it, the R channel and G channel in final result were swapped.

But when I checked the demo in Vulkan SDK dir, I found that it also use a BGRA image view for color output (I checked this in code and RenderDoc), but the final result is correct!

So, when did the conversion happen? Did I miss something?

vulkan demo output

vulkan demo output

Vulkan demo has a BGRA format output

vulkan demo has a BGRA format output

My poor result

my poor result

Edit:

Sorry about the lack of the code. The first answer gave me a hint to find the real problem in loading image from disk by FreeImage. Images it loads are stored as BGRA format with default setting on windows:

enter image description here

Thanks for your help and advice, @opa and @solidpixel.


Solution

  • You're either setting up your texture reads incorrectly, or you're setting up your swapchain writes incorrectly. If I had to guess you're uploading data into the wrong texture format, but without a complete example it's hard to tell.