Jump to content
  • Advertisement
Sign in to follow this  
GuyWithBeard

Vulkan What is the proper way to create a mipmapped texture in Vulkan?

This topic is 418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

I am wondering what is the most efficient way to create a mipmapped texture for use with a texture sampler in Vulkan. Basically I have a bunch of mip levels that I want to tuck into an image with the tiling set to VK_IMAGE_TILING_OPTIMAL, the layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL and the memory properties VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT.

To be able to map to host memory and memcpy the pixel data into the image I have to create a staging image with VK_IMAGE_TILING_LINEAR right? However, VK_IMAGE_TILING_LINEAR only supports one mip level. So what I do is create a staging image for every mip level, memcpy into those and then copy the mip level 0 of each staging image into the correct mip level of the final texture, with vkCmdCopyImage.

This seems like an awful lot of temporary images and copying just to get the texture put together. Is this the best way to do it? How do you do it? Do you have a pool of staging images or do you create temporaries every time?

Cheers!

Share this post


Link to post
Share on other sites
Advertisement

There are a couple of different ways to load mipmapped textures in Vulkan. I use this way:

  • create a buffer that is big enough to contain all mipmap levels
  • bind it to pre-allocated scratch memory that is VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
  • copy the mipmaps into the buffer using vkMapMemory, memcpy, vkUnmapMemory
  • create an image with VK_IMAGE_TILING_OPTIMAL and bind it to VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT memory
  • use vkCmdCopyBufferToImage with VkBufferImageCopy entries for each mipmap that contain the offset into the buffer to point to the mip data.

Also make sure to use vkGetBufferMemoryRequirements and vkGetImageMemoryRequirements. The scratch host visible memory size is 6mb, which is enough for most textures and all the device local textures go into one huge memory.

 

This works well for mipmapped textures and also mipmapped cube maps.

Edited by Mete

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!