vk: Fix image view search and destroy

This commit is contained in:
kd-11 2022-06-08 22:02:41 +03:00 committed by kd-11
commit 7530b3c971
2 changed files with 12 additions and 4 deletions

View file

@ -4,6 +4,7 @@
#include "image.h" #include "image.h"
#include "image_helpers.h" #include "image_helpers.h"
#include "../VKResourceManager.h"
#include <memory> #include <memory>
namespace vk namespace vk
@ -391,11 +392,11 @@ namespace vk
} }
} }
const auto storage_key = remap_encoding | (mask << 16); const u64 storage_key = remap_encoding | (static_cast<u64>(mask) << 32);
auto found = views.find(storage_key); auto found = views.find(storage_key);
if (found != views.end() && if (found != views.end())
found->second->info.subresourceRange.aspectMask & mask)
{ {
ensure(found->second->info.subresourceRange.aspectMask & mask);
return found->second.get(); return found->second.get();
} }
@ -434,6 +435,13 @@ namespace vk
new_layout.a != native_component_map.a) new_layout.a != native_component_map.a)
{ {
native_component_map = new_layout; native_component_map = new_layout;
// Safely discard existing views
auto gc = vk::get_resource_manager();
for (auto& p : views)
{
gc->dispose(p.second);
}
views.clear(); views.clear();
} }
} }

View file

@ -124,7 +124,7 @@ namespace vk
class viewable_image : public image class viewable_image : public image
{ {
protected: protected:
std::unordered_map<u32, std::unique_ptr<vk::image_view>> views; std::unordered_map<u64, std::unique_ptr<vk::image_view>> views;
viewable_image* clone(); viewable_image* clone();
public: public: