Issue with BGR images in Vulkan

Hello!

I’m trying to read an image using OpenCV and then show it using Vulkan, but I’m having issues with VK_FORMAT_B8G8R8_UNORM.

If I read the image with OpenCV using:

cv::Mat img = cv::imread("image.png");

or

cv::Mat img = cv::imread("image.png", cv::IMREAD_COLOR);

I get a runtime error “0x00007FFA6701E651 (igvk64.dll)… read access violation” at the following function:

err = vkBindImageMemory(device, m_Image, m_Memory, 0);

But the thing is that if I read the image with the following call, it works fine:

cv::Mat img = cv::imread("image.png", cv::IMREAD_UNCHANGED);

The only difference between these calls is that I used VK_FORMAT_B8G8R8_UNORM for the first two cases and VK_FORMAT_B8G8R8A8_UNORM for the last one.

The size calculation is done via this call:

size_t sizeOfBuffer = img.cols * img.rows * img.elemSize();

I’m really new to Vulkan and I am using Walnut framework for the application that I’m running (which uses Vulkan as the rendering API).

I would appreciate if anyone could give me a hand to figure this one out. Thank you in advance!