Add clearing render target pool textures to pink during in Debug builds

This commit is contained in:
Wojtek Figat
2024-08-08 21:25:08 +02:00
parent 1c24f5d3ce
commit 7ca45e1f54

View File

@@ -2,6 +2,9 @@
#include "RenderTargetPool.h"
#include "GPUDevice.h"
#if BUILD_DEBUG
#include "GPUContext.h"
#endif
#include "Engine/Core/Log.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Profiler/ProfilerCPU.h"
@@ -45,6 +48,13 @@ GPUTexture* RenderTargetPool::Get(const GPUTextureDescription& desc)
{
PROFILE_CPU();
// Initialize render targets with pink color in debug builds to prevent incorrect data usage (GPU doesn't clear texture upon creation)
#if BUILD_DEBUG
#define RENDER_TARGET_POOL_CLEAR() if (desc.Dimensions == TextureDimensions::Texture && EnumHasAllFlags(desc.Flags, GPUTextureFlags::RenderTarget) && GPUDevice::Instance->IsRendering() && IsInMainThread()) GPUDevice::Instance->GetMainContext()->Clear(e.RT->View(), Color::Pink);
#else
#define RENDER_TARGET_POOL_CLEAR()
#endif
// Find free render target with the same properties
const uint32 descHash = GetHash(desc);
for (int32 i = 0; i < TemporaryRTs.Count(); i++)
@@ -54,6 +64,7 @@ GPUTexture* RenderTargetPool::Get(const GPUTextureDescription& desc)
{
// Mark as used
e.IsOccupied = true;
RENDER_TARGET_POOL_CLEAR();
return e.RT;
}
}
@@ -82,7 +93,9 @@ GPUTexture* RenderTargetPool::Get(const GPUTextureDescription& desc)
e.RT = rt;
e.DescriptionHash = descHash;
TemporaryRTs.Add(e);
RENDER_TARGET_POOL_CLEAR();
#undef RENDER_TARGET_POOL_CLEAR
return rt;
}