From 308c884d0267dd4218e8723cf349e39b4d768586 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 1 Mar 2019 18:31:33 +0100 Subject: [PATCH] - use a linked list to keep track of all allocated VkHardwareTexture objects --- src/rendering/vulkan/system/vk_framebuffer.cpp | 10 +++++----- src/rendering/vulkan/system/vk_framebuffer.h | 2 -- src/rendering/vulkan/textures/vk_hwtexture.cpp | 7 +++++++ src/rendering/vulkan/textures/vk_hwtexture.h | 4 ++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 0230fa1ef..e3608c1fd 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -66,6 +66,10 @@ VulkanFrameBuffer::VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevi VulkanFrameBuffer::~VulkanFrameBuffer() { + // All descriptors must be destroyed before the descriptor pool in renderpass manager is destroyed + for (VkHardwareTexture *cur = VkHardwareTexture::First; cur; cur = cur->Next) + cur->Reset(); + delete MatricesUBO; delete ColorsUBO; delete GlowingWallsUBO; @@ -73,8 +77,6 @@ VulkanFrameBuffer::~VulkanFrameBuffer() delete mSkyData; delete mViewpoints; delete mLights; - for (auto tex : AllTextures) - tex->Reset(); } void VulkanFrameBuffer::InitializeState() @@ -277,9 +279,7 @@ void VulkanFrameBuffer::CleanForRestart() IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture() { - auto texture = new VkHardwareTexture(); - AllTextures.Push(texture); - return texture; + return new VkHardwareTexture(); } FModelRenderer *VulkanFrameBuffer::CreateModelRenderer(int mli) diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index b2d83235a..6d7350843 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -86,8 +86,6 @@ private: int lastSwapWidth = 0; int lastSwapHeight = 0; - - TArray AllTextures; }; inline VulkanFrameBuffer *GetVulkanFrameBuffer() { return static_cast(screen); } diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index e4127aebd..8ac88b1c0 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -37,12 +37,19 @@ #include "vulkan/renderer/vk_renderpass.h" #include "vk_hwtexture.h" +VkHardwareTexture *VkHardwareTexture::First = nullptr; + VkHardwareTexture::VkHardwareTexture() { + Next = First; + First = this; + if (Next) Next->Prev = this; } VkHardwareTexture::~VkHardwareTexture() { + if (Next) Next->Prev = Prev; + if (!Prev) First = Next; } void VkHardwareTexture::Reset() diff --git a/src/rendering/vulkan/textures/vk_hwtexture.h b/src/rendering/vulkan/textures/vk_hwtexture.h index 105bb2a0b..018dd8647 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.h +++ b/src/rendering/vulkan/textures/vk_hwtexture.h @@ -32,6 +32,10 @@ public: uint8_t *MapBuffer() override; unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const char *name) override; + static VkHardwareTexture *First; + VkHardwareTexture *Prev = nullptr; + VkHardwareTexture *Next = nullptr; + private: VulkanImageView *GetImageView(FTexture *tex, int clampmode, int translation, int flags);