Skip to content
Snippets Groups Projects
Commit adb05281 authored by Sascha Willems's avatar Sascha Willems
Browse files

Proper mip tail memory cleanup

Refs #882
parent a5c2a8e7
No related branches found
No related tags found
No related merge requests found
......@@ -137,6 +137,10 @@ void VirtualTexture::destroy()
{
vkFreeMemory(device, bind.memory, nullptr);
}
// Clean up mip tail
if (mipTailimageMemoryBind.memory != VK_NULL_HANDLE) {
vkFreeMemory(device, mipTailimageMemoryBind.memory, nullptr);
}
}
/*
......@@ -791,18 +795,21 @@ void VulkanExample::fillRandomPages()
void VulkanExample::fillMipTail()
{
// Clean up previous mip tail memory allocation
if (texture.mipTailimageMemoryBind.memory != VK_NULL_HANDLE) {
vkFreeMemory(device, texture.mipTailimageMemoryBind.memory, nullptr);
}
//@todo: WIP
VkDeviceSize imageMipTailSize = texture.sparseImageMemoryRequirements.imageMipTailSize;
VkDeviceSize imageMipTailOffset = texture.sparseImageMemoryRequirements.imageMipTailOffset;
// Stride between memory bindings for each mip level if not single mip tail (VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT not set)
VkDeviceSize imageMipTailStride = texture.sparseImageMemoryRequirements.imageMipTailStride;
VkSparseImageMemoryBind mipTailimageMemoryBind{};
VkMemoryAllocateInfo allocInfo = vks::initializers::memoryAllocateInfo();
allocInfo.allocationSize = imageMipTailSize;
allocInfo.memoryTypeIndex = texture.memoryTypeIndex;
VK_CHECK_RESULT(vkAllocateMemory(device, &allocInfo, nullptr, &mipTailimageMemoryBind.memory));
VK_CHECK_RESULT(vkAllocateMemory(device, &allocInfo, nullptr, &texture.mipTailimageMemoryBind.memory));
uint32_t mipLevel = texture.sparseImageMemoryRequirements.imageMipTailFirstLod;
uint32_t width = std::max(texture.width >> texture.sparseImageMemoryRequirements.imageMipTailFirstLod, 1u);
......
......@@ -42,13 +42,15 @@ struct VirtualTexture
VkBindSparseInfo bindSparseInfo; // Sparse queue binding information
std::vector<VirtualTexturePage> pages; // Contains all virtual pages of the texture
std::vector<VkSparseImageMemoryBind> sparseImageMemoryBinds; // Sparse image memory bindings of all memory-backed virtual tables
std::vector<VkSparseMemoryBind> opaqueMemoryBinds; // Sparse ópaque memory bindings for the mip tail (if present)
std::vector<VkSparseMemoryBind> opaqueMemoryBinds; // Sparse opaque memory bindings for the mip tail (if present)
VkSparseImageMemoryBindInfo imageMemoryBindInfo; // Sparse image memory bind info
VkSparseImageOpaqueMemoryBindInfo opaqueMemoryBindInfo; // Sparse image opaque memory bind info (mip tail)
uint32_t mipTailStart; // First mip level in mip tail
VkSparseImageMemoryRequirements sparseImageMemoryRequirements; // @todo: Comment
uint32_t memoryTypeIndex; // @todo: Comment
VkSparseImageMemoryBind mipTailimageMemoryBind{};
// @todo: comment
struct MipTailInfo {
bool singleMipTail;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment