From f9d08888c7ef34c243e492447843c6d138793cc5 Mon Sep 17 00:00:00 2001 From: DrChat Date: Thu, 7 Sep 2017 14:22:04 -0500 Subject: [PATCH] Vulkan: ClearCache for texture cache, properly free all textures and allocator on exit. --- src/xenia/gpu/vulkan/texture_cache.cc | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/xenia/gpu/vulkan/texture_cache.cc b/src/xenia/gpu/vulkan/texture_cache.cc index 57b32c965..f8d380f49 100644 --- a/src/xenia/gpu/vulkan/texture_cache.cc +++ b/src/xenia/gpu/vulkan/texture_cache.cc @@ -207,12 +207,11 @@ TextureCache::~TextureCache() { device_->ReleaseQueue(device_queue_); } - for (auto it = samplers_.begin(); it != samplers_.end(); ++it) { - vkDestroySampler(*device_, it->second->sampler, nullptr); - delete it->second; - } - samplers_.clear(); + // Free all textures allocated. + ClearCache(); + Scavenge(); + vmaDestroyAllocator(mem_allocator_); vkDestroyDescriptorSetLayout(*device_, texture_descriptor_set_layout_, nullptr); } @@ -1453,7 +1452,20 @@ void TextureCache::RemoveInvalidatedTextures() { } void TextureCache::ClearCache() { - // TODO(DrChat): Nuke everything. + RemoveInvalidatedTextures(); + for (auto it = textures_.begin(); it != textures_.end(); ++it) { + while (!FreeTexture(it->second)) { + // Texture still in use. Busy loop. + xe::threading::MaybeYield(); + } + } + textures_.clear(); + + for (auto it = samplers_.begin(); it != samplers_.end(); ++it) { + vkDestroySampler(*device_, it->second->sampler, nullptr); + delete it->second; + } + samplers_.clear(); } void TextureCache::Scavenge() {