Fixed GPU memory leak when stopping starting + disabled tracy by default

This commit is contained in:
antopilo
2025-04-17 18:39:24 -04:00
parent a809c5a568
commit a8c38a5a4e
6 changed files with 62 additions and 12 deletions

View File

@@ -21,14 +21,35 @@ TextureAttachment::TextureAttachment(const std::string& name, ImageFormat format
gpuResources.AddTexture(Image);
}
TextureAttachment::~TextureAttachment()
{
if (Image)
{
auto& gpuResources = GPUResources::Get();
gpuResources.RemoveTexture(Image);
}
}
RenderPass::RenderPass(const std::string& name) :
Name(name),
PushConstantSize(0),
IsLinePass(false),
Topology(PolygonTopology::TRIANGLE_LIST)
Topology(PolygonTopology::TRIANGLE_LIST),
IsBuilt(false)
{
}
RenderPass::~RenderPass()
{
if (!IsBuilt)
{
return;
}
vkDestroyPipeline(VkRenderer::Get().GetDevice(), Pipeline, nullptr);
vkDestroyPipelineLayout(VkRenderer::Get().GetDevice(), PipelineLayout, nullptr);
}
void RenderPass::SetIsLinePass(bool enabled)
{
IsLinePass = enabled;
@@ -288,6 +309,8 @@ void RenderPass::Build()
}
Pipeline = pipelineBuilder.BuildPipeline(VkRenderer::Get().GetDevice());
IsBuilt = true;
}
void RenderPass::SetPushConstant(std::any data, size_t size)
@@ -300,10 +323,17 @@ RenderPipeline::RenderPipeline() :
Built(false)
{ }
RenderPipeline::~RenderPipeline()
{
if (Built)
{
}
}
RenderPass& RenderPipeline::AddPass(const std::string& name)
{
auto newPass = RenderPass(name);
return RenderPasses.emplace_back(std::move(newPass));
return RenderPasses.emplace_back(name);
}
RenderPass& RenderPipeline::GetRenderPass(const std::string& name)

View File

@@ -37,7 +37,7 @@ namespace Nuake
public:
TextureAttachment(const std::string& name, ImageFormat format, ImageUsage usage = ImageUsage::Default, bool clearOnLoad = true);
TextureAttachment() = default;
~TextureAttachment() = default;
~TextureAttachment();
};
struct RenderPassSpec
@@ -87,13 +87,16 @@ namespace Nuake
std::function<void(PassRenderContext& ctx)> PreRender;
std::function<void(PassRenderContext& ctx)> RenderCb;
std::function<void(PassRenderContext& ctx)> PostRender;
bool IsBuilt;
public:
VkPipeline Pipeline;
VkPipeline Pipeline;
VkPipelineLayout PipelineLayout;
public:
RenderPass(const std::string& name);
~RenderPass() = default;
~RenderPass();
void Execute(PassRenderContext& ctx, PassAttachments& inputs);
@@ -150,7 +153,7 @@ namespace Nuake
std::vector<RenderPass> RenderPasses;
public:
RenderPipeline();
~RenderPipeline() = default;
~RenderPipeline();
public:
RenderPass& AddPass(const std::string& name);

View File

@@ -228,6 +228,26 @@ SceneRenderPipeline::SceneRenderPipeline()
RecreatePipeline();
}
SceneRenderPipeline::~SceneRenderPipeline()
{
auto& res = GPUResources::Get();
res.RemoveTexture(GBufferAlbedo);
res.RemoveTexture(GBufferNormal);
res.RemoveTexture(GBufferMaterial);
res.RemoveTexture(GBufferDepth);
res.RemoveTexture(TonemappedOutput);
res.RemoveTexture(GBufferEntityID);
res.RemoveTexture(OutlineOutput);
res.RemoveTexture(LineOutput);
res.RemoveTexture(LineCombineOutput);
res.RemoveTexture(SSAOOutput);
res.RemoveTexture(SSAOBlurOutput);
res.RemoveTexture(GizmoOutput);
res.RemoveTexture(GizmoCombineOutput);
res.RemoveTexture(BloomOutput);
res.RemoveTexture(BloomThreshold);
}
void SceneRenderPipeline::SetCamera(UUID camera)
{
CurrentCameraID = camera;

View File

@@ -193,7 +193,7 @@ namespace Nuake
public:
SceneRenderPipeline();
~SceneRenderPipeline() = default;
~SceneRenderPipeline();
void SetCamera(UUID camera);
void Render(PassRenderContext& ctx);

View File

@@ -139,7 +139,7 @@ bool GPUResources::AddTexture(Ref<VulkanImage> image)
Images[id] = image;
return true;
}
Logger::Log("Buffer with ID already exists", "vulkan", CRITICAL);
return false;
}
@@ -151,7 +151,6 @@ void GPUResources::RemoveTexture(Ref<VulkanImage> image)
{
return;
}
Images.erase(id);
}
@@ -576,7 +575,6 @@ void GPUResources::CleanUp(uint32_t frame)
{
deletionQueue.top()();
deletionQueue.pop();
Logger::Log("Deleted GPU resource", "vulkan", VERBOSE);
}
}

View File

@@ -57,7 +57,6 @@ binaryOutputDir = outputdir .. "Binaries/"
intBinaryOutputDir = outputdir .. "Binaries-Intermediate/"
globalDefines = {
"TRACY_ENABLE",
"TRACY_ON_DEMAND",
"NK_VK",
"IMGUI_DEFINE_MATH_OPERATORS",