diff --git a/Source/Engine/Graphics/RenderTargetPool.cpp b/Source/Engine/Graphics/RenderTargetPool.cpp index 0d31f4077..c55b37e95 100644 --- a/Source/Engine/Graphics/RenderTargetPool.cpp +++ b/Source/Engine/Graphics/RenderTargetPool.cpp @@ -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; }