From 2a75ee68a053386fb43296a31ee4107c541bd37b Mon Sep 17 00:00:00 2001 From: kearwood Date: Tue, 19 Jul 2022 00:12:40 -0700 Subject: [PATCH] Added helper functions, KRTexture::destroyHandles and KRTexture::destroyNewHandles --- kraken/KRTexture.cpp | 51 +++++++++++++++++++++++--------------------- kraken/KRTexture.h | 2 ++ 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/kraken/KRTexture.cpp b/kraken/KRTexture.cpp index 49eb061..bdcdf23 100755 --- a/kraken/KRTexture.cpp +++ b/kraken/KRTexture.cpp @@ -53,27 +53,37 @@ KRTexture::~KRTexture() releaseHandles(); } +void KRTexture::destroyHandles() +{ + KRDeviceManager* deviceManager = getContext().getDeviceManager(); + for (TextureHandle t : m_handles) { + std::unique_ptr& device = deviceManager->getDevice(t.device); + VmaAllocator allocator = device->getAllocator(); + vmaDestroyImage(allocator, t.image, t.allocation); + } + m_handles.clear(); + m_textureMemUsed = 0; +} + +void KRTexture::destroyNewHandles() +{ + KRDeviceManager* deviceManager = getContext().getDeviceManager(); + for (TextureHandle t : m_newHandles) { + std::unique_ptr& device = deviceManager->getDevice(t.device); + VmaAllocator allocator = device->getAllocator(); + vmaDestroyImage(allocator, t.image, t.allocation); + } + m_newHandles.clear(); + m_newTextureMemUsed = 0; +} + void KRTexture::releaseHandles() { long mem_size = getMemSize(); - KRDeviceManager* deviceManager = getContext().getDeviceManager(); while(m_handle_lock.test_and_set()); // Spin lock - for (TextureHandle t : m_newHandles) { - std::unique_ptr& device = deviceManager->getDevice(t.device); - VmaAllocator allocator = device->getAllocator(); - vmaDestroyImage(allocator, t.image, t.allocation); - } - m_newHandles.clear(); - m_newTextureMemUsed = 0; - - for (TextureHandle t : m_handles) { - std::unique_ptr& device = deviceManager->getDevice(t.device); - VmaAllocator allocator = device->getAllocator(); - vmaDestroyImage(allocator, t.image, t.allocation); - } - m_handles.clear(); - m_textureMemUsed = 0; + destroyNewHandles(); + destroyHandles(); m_current_lod_max_dim = 0; m_new_lod_max_dim = 0; @@ -225,17 +235,10 @@ void KRTexture::bind(GLuint texture_unit) { void KRTexture::_swapHandles() { - KRDeviceManager* deviceManager = getContext().getDeviceManager(); - //while(m_handle_lock.test_and_set()); // Spin lock if(!m_handle_lock.test_and_set()) { if(m_haveNewHandles) { - for (TextureHandle t : m_handles) { - std::unique_ptr& device = deviceManager->getDevice(t.device); - VmaAllocator allocator = device->getAllocator(); - vmaDestroyImage(allocator, t.image, t.allocation); - } - m_handles.clear(); + destroyHandles(); m_handles.swap(m_newHandles); m_textureMemUsed = (long)m_newTextureMemUsed; m_newTextureMemUsed = 0; diff --git a/kraken/KRTexture.h b/kraken/KRTexture.h index 5904236..881d13d 100755 --- a/kraken/KRTexture.h +++ b/kraken/KRTexture.h @@ -90,6 +90,8 @@ public: protected: virtual bool createGPUTexture(int lod_max_dim) = 0; GLuint getHandle(); + void destroyHandles(); + void destroyNewHandles(); struct TextureHandle { VkImage image;