Skip to content

Commit

Permalink
Manage postprocess texture lifetimes in the same way as for hw textures
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas authored and coelckers committed Jun 22, 2022
1 parent b3316fb commit ef802b8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/common/rendering/vulkan/textures/vk_pptexture.cpp
Expand Up @@ -21,6 +21,7 @@
*/

#include "vk_pptexture.h"
#include "vk_texture.h"
#include "vulkan/system/vk_framebuffer.h"
#include "vulkan/system/vk_commandbuffer.h"

Expand Down Expand Up @@ -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));
}
}
4 changes: 4 additions & 0 deletions src/common/rendering/vulkan/textures/vk_pptexture.h
Expand Up @@ -4,6 +4,7 @@
#include "hwrenderer/postprocessing/hw_postprocess.h"
#include "vulkan/system/vk_objects.h"
#include "vulkan/textures/vk_imagetransition.h"
#include <list>

class VulkanFrameBuffer;

Expand All @@ -13,7 +14,10 @@ class VkPPTexture : public PPTextureBackend
VkPPTexture(VulkanFrameBuffer* fb, PPTexture *texture);
~VkPPTexture();

void Reset();

VulkanFrameBuffer* fb = nullptr;
std::list<VkPPTexture*>::iterator it;

VkTextureImage TexImage;
std::unique_ptr<VulkanBuffer> Staging;
Expand Down
15 changes: 15 additions & 0 deletions src/common/rendering/vulkan/textures/vk_texture.cpp
Expand Up @@ -22,6 +22,7 @@

#include "vk_texture.h"
#include "vk_hwtexture.h"
#include "vk_pptexture.h"

VkTextureManager::VkTextureManager(VulkanFrameBuffer* fb) : fb(fb)
{
Expand All @@ -31,6 +32,8 @@ VkTextureManager::~VkTextureManager()
{
while (!Textures.empty())
RemoveTexture(Textures.back());
while (!PPTextures.empty())
RemovePPTexture(PPTextures.back());
}

void VkTextureManager::AddTexture(VkHardwareTexture* texture)
Expand All @@ -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);
}
5 changes: 5 additions & 0 deletions src/common/rendering/vulkan/textures/vk_texture.h
Expand Up @@ -7,6 +7,7 @@
class VulkanFrameBuffer;
class VkHardwareTexture;
class VkMaterial;
class VkPPTexture;

class VkTextureManager
{
Expand All @@ -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<VkHardwareTexture*> Textures;
std::list<VkPPTexture*> PPTextures;
};

0 comments on commit ef802b8

Please sign in to comment.