Andrew Williamson
Andrew Williamson

Reputation: 8696

Size in MemoryRequirements not what I'm expecting

I'm creating a texture, querying the memory requirements, and it's not what I was expecting. Here's the ImageCreateInfo structure:

ImageCreateInfo()
    .X2D(1024, 1024)
    .Format(Format::R8G8B8_UNORM)
    .InitialLayout(ImageLayout::PREINITIALIZED)
    .Tiling(ImageTiling::LINEAR)
    .Usage(ImageUsageFlagBits::TRANSFER_SRC);

Now, I was expecting one byte for each of R,G,B, at width and height of 1024 to give memory requirements of 3 * 1024 * 1024 = 3,145,728. But instead, it returns 1,048,576, which is perfectly 1024 * 1024. It seems to not care about the one byte for each channel of RGB. What am I missing here?

Upvotes: 2

Views: 309

Answers (1)

Sascha Willems
Sascha Willems

Reputation: 5798

You're right in that this should return 3,145,728 bytes, but is the R8G8B8_UNORM format actually available on your implementation? If not, you won't get a correct allocation size because you actually are not going to be able to use that image anyway.

If you enable validation layers this should throw an error from the image validation layers btw.

At least on the GPU I'm right now it's not supported for any of the tiling modes or as a buffer format. But e.g. R8G8B8A8 or R8G8 are available and return the correct allocation size.

If R8G8B8 is actually available on your GPU could you post your complete VkImageCreateInfo structure, including number of mips and layers?

So a good idea would be to check if the image format you request (and want to allocate for) is actually supported for your use case (linear, optimal, buffer).

Upvotes: 3

Related Questions