Optimize render targets freeing on the start of the game

This commit is contained in:
Wojtek Figat
2024-01-28 23:11:24 +01:00
parent 10bed94357
commit 1b33a2aa0d
3 changed files with 16 additions and 22 deletions

View File

@@ -4,6 +4,7 @@
#include "GPUDevice.h"
#include "Engine/Core/Log.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Profiler/ProfilerCPU.h"
struct Entry
{
@@ -20,9 +21,11 @@ namespace
void RenderTargetPool::Flush(bool force, int32 framesOffset)
{
PROFILE_CPU();
if (framesOffset < 0)
framesOffset = 3 * 60; // For how many frames RTs should be cached (by default)
const uint64 maxReleaseFrame = Engine::FrameCount - framesOffset;
const uint64 frameCount = Engine::FrameCount;
const uint64 maxReleaseFrame = frameCount - Math::Min<uint64>(frameCount, framesOffset);
force |= Engine::ShouldExit();
for (int32 i = 0; i < TemporaryRTs.Count(); i++)
@@ -40,6 +43,8 @@ void RenderTargetPool::Flush(bool force, int32 framesOffset)
GPUTexture* RenderTargetPool::Get(const GPUTextureDescription& desc)
{
PROFILE_CPU();
// Find free render target with the same properties
const uint32 descHash = GetHash(desc);
for (int32 i = 0; i < TemporaryRTs.Count(); i++)
@@ -85,7 +90,6 @@ void RenderTargetPool::Release(GPUTexture* rt)
{
if (!rt)
return;
for (int32 i = 0; i < TemporaryRTs.Count(); i++)
{
auto& e = TemporaryRTs[i];
@@ -98,6 +102,5 @@ void RenderTargetPool::Release(GPUTexture* rt)
return;
}
}
LOG(Error, "Trying to release temporary render target which has not been registered in service!");
}