From ef802b85e7e58884503465a442940787414f3cfc Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 10 Jun 2022 02:26:53 +0200 Subject: [PATCH] Manage postprocess texture lifetimes in the same way as for hw textures --- .../vulkan/textures/vk_pptexture.cpp | 20 ++++++++++++++----- .../rendering/vulkan/textures/vk_pptexture.h | 4 ++++ .../rendering/vulkan/textures/vk_texture.cpp | 15 ++++++++++++++ .../rendering/vulkan/textures/vk_texture.h | 5 +++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/common/rendering/vulkan/textures/vk_pptexture.cpp b/src/common/rendering/vulkan/textures/vk_pptexture.cpp index 14bc84bf86a..f6de4fa6edd 100644 --- a/src/common/rendering/vulkan/textures/vk_pptexture.cpp +++ b/src/common/rendering/vulkan/textures/vk_pptexture.cpp @@ -21,6 +21,7 @@ */ #include "vk_pptexture.h" +#include "vk_texture.h" #include "vulkan/system/vk_framebuffer.h" #include "vulkan/system/vk_commandbuffer.h" @@ -91,13 +92,22 @@ VkPPTexture::VkPPTexture(VulkanFrameBuffer* fb, PPTexture *texture) barrier.addImage(&TexImage, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, true); barrier.execute(fb->GetCommands()->GetTransferCommands()); } + + fb->GetTextureManager()->AddPPTexture(this); } VkPPTexture::~VkPPTexture() { - if (TexImage.Image) fb->GetCommands()->FrameDeleteList.Images.push_back(std::move(TexImage.Image)); - if (TexImage.View) fb->GetCommands()->FrameDeleteList.ImageViews.push_back(std::move(TexImage.View)); - if (TexImage.DepthOnlyView) fb->GetCommands()->FrameDeleteList.ImageViews.push_back(std::move(TexImage.DepthOnlyView)); - if (TexImage.PPFramebuffer) fb->GetCommands()->FrameDeleteList.Framebuffers.push_back(std::move(TexImage.PPFramebuffer)); - if (Staging) fb->GetCommands()->FrameDeleteList.Buffers.push_back(std::move(Staging)); + if (fb) + fb->GetTextureManager()->RemovePPTexture(this); +} + +void VkPPTexture::Reset() +{ + if (fb) + { + TexImage.Reset(fb); + if (Staging) + fb->GetCommands()->FrameDeleteList.Buffers.push_back(std::move(Staging)); + } } diff --git a/src/common/rendering/vulkan/textures/vk_pptexture.h b/src/common/rendering/vulkan/textures/vk_pptexture.h index 7efd7a9cb52..e6590be5723 100644 --- a/src/common/rendering/vulkan/textures/vk_pptexture.h +++ b/src/common/rendering/vulkan/textures/vk_pptexture.h @@ -4,6 +4,7 @@ #include "hwrenderer/postprocessing/hw_postprocess.h" #include "vulkan/system/vk_objects.h" #include "vulkan/textures/vk_imagetransition.h" +#include class VulkanFrameBuffer; @@ -13,7 +14,10 @@ class VkPPTexture : public PPTextureBackend VkPPTexture(VulkanFrameBuffer* fb, PPTexture *texture); ~VkPPTexture(); + void Reset(); + VulkanFrameBuffer* fb = nullptr; + std::list::iterator it; VkTextureImage TexImage; std::unique_ptr Staging; diff --git a/src/common/rendering/vulkan/textures/vk_texture.cpp b/src/common/rendering/vulkan/textures/vk_texture.cpp index 9ce47960529..021774369b8 100644 --- a/src/common/rendering/vulkan/textures/vk_texture.cpp +++ b/src/common/rendering/vulkan/textures/vk_texture.cpp @@ -22,6 +22,7 @@ #include "vk_texture.h" #include "vk_hwtexture.h" +#include "vk_pptexture.h" VkTextureManager::VkTextureManager(VulkanFrameBuffer* fb) : fb(fb) { @@ -31,6 +32,8 @@ VkTextureManager::~VkTextureManager() { while (!Textures.empty()) RemoveTexture(Textures.back()); + while (!PPTextures.empty()) + RemovePPTexture(PPTextures.back()); } void VkTextureManager::AddTexture(VkHardwareTexture* texture) @@ -44,3 +47,15 @@ void VkTextureManager::RemoveTexture(VkHardwareTexture* texture) texture->fb = nullptr; Textures.erase(texture->it); } + +void VkTextureManager::AddPPTexture(VkPPTexture* texture) +{ + texture->it = PPTextures.insert(PPTextures.end(), texture); +} + +void VkTextureManager::RemovePPTexture(VkPPTexture* texture) +{ + texture->Reset(); + texture->fb = nullptr; + PPTextures.erase(texture->it); +} diff --git a/src/common/rendering/vulkan/textures/vk_texture.h b/src/common/rendering/vulkan/textures/vk_texture.h index 7d478ade866..e4abe3c94d6 100644 --- a/src/common/rendering/vulkan/textures/vk_texture.h +++ b/src/common/rendering/vulkan/textures/vk_texture.h @@ -7,6 +7,7 @@ class VulkanFrameBuffer; class VkHardwareTexture; class VkMaterial; +class VkPPTexture; class VkTextureManager { @@ -17,8 +18,12 @@ class VkTextureManager void AddTexture(VkHardwareTexture* texture); void RemoveTexture(VkHardwareTexture* texture); + void AddPPTexture(VkPPTexture* texture); + void RemovePPTexture(VkPPTexture* texture); + private: VulkanFrameBuffer* fb = nullptr; std::list Textures; + std::list PPTextures; };