// UE_LOG(PerformanceManagerLog,Display,TEXT("Stat RHI Memory."));
TArray<FStatMessage> Stats;
GetPermanentStats(Stats);
FName NAME_STATGROUP_RHI(FStatGroup_STATGROUP_RHI::GetGroupName());
int64 TotalMemory = 0;
int64 TotalMemoryTest = 0;
for (int32 Index = 0; Index < Stats.Num(); Index++)
{
FStatMessage const& Meta = Stats[Index];
FName LastGroup = Meta.NameAndInfo.GetGroupName();
if (LastGroup == NAME_STATGROUP_RHI && Meta.NameAndInfo.GetFlag(EStatMetaFlags::IsMemory))
{
// RenderTargetMemory2D 内存不在这里计算,通过输入灯光数量进行计算
FString StatName =FStatsUtils::DebugPrint(Meta);
TotalMemoryTest += Meta.GetValue_int64();
if(!StatName.Contains("STAT_RenderTargetMemory2D"))
{
TotalMemory += Meta.GetValue_int64();
}
}
}
int64 RT2DAll = 0;
int64 RT2DNoDenoiser = 0;
int64 RT2DDenoiser = 0;
int64 RTWith = 1420;
int64 RTHeight = 944;
// 计算RenderTargetMemory2D中非Denoiser部分的内存占用
for (int32 i = 0; i < static_cast<int32>(GRenderTargetPool.GetElementCount()); ++i)
{
if (const FPooledRenderTarget* Element = GRenderTargetPool.GetElementById(i))
{
uint32 ElementAllocationInBit = (Element->ComputeMemorySize() + 1023);
RT2DAll += ElementAllocationInBit;
const TCHAR* DebugName = Element->GetDesc().DebugName;
FString DebugNameS = DebugName;
if(DebugNameS.Contains("Shadow.Denoiser"))
{
RT2DDenoiser+= ElementAllocationInBit;
UE_LOG(PerformanceManagerLog,Display,TEXT("RenderTargetPool: %s %d Bit"), DebugName, ElementAllocationInBit);
continue;
}
if(DebugNameS.Contains("GBufferA"))
{
RTWith = Element->GetDesc().Extent.X;
RTHeight = Element->GetDesc().Extent.Y;
}
TotalMemory += ElementAllocationInBit;
RT2DNoDenoiser += ElementAllocationInBit;
}
}
bool bDebug = false;
if(bDebug)
{
UE_LOG(PerformanceManagerLog,Display,TEXT("RenderTarget2D execpt denoiser: %f MB"), RT2DNoDenoiser/1024.0f/1024.0f);
UE_LOG(PerformanceManagerLog,Display,TEXT("RenderTarget2D-all: %f MB"), RT2DAll/1024.0f/1024.0f);
UE_LOG(PerformanceManagerLog,Display,TEXT("RHI execpt RenderTarget2D: %f MB"), TotalMemory/1024.0f/1024.0f);
UE_LOG(PerformanceManagerLog,Display,TEXT("RHI-all: %f MB"), TotalMemoryTest/1024.0f/1024.0f);
UE_LOG(PerformanceManagerLog,Display,TEXT("Denoiser Width: %lld "), RTWith);
UE_LOG(PerformanceManagerLog,Display,TEXT("Denoiser Width: %lld "), RTHeight);
UE_LOG(PerformanceManagerLog,Display,TEXT("RenderTarget2D denoiser: %f MB"), RT2DDenoiser/1024.0f/1024.0f);
UE_LOG(PerformanceManagerLog,Display,TEXT("RenderTarget2D denoiser: %f MB [Custom]"), DenoiserLightNum * RTWith * RTHeight * (8 + 1)/1024.0f/1024.0f * TemporalAccumulation);
}
// 计算Denoiser内存占用,计算系数大约是9.1左右。
TotalMemory += DenoiserLightNum * RTWith * RTHeight * (9 + 1) * TemporalAccumulation;
// UE启动时就占用1.2G,所以这里加上去。1.2G是通过实验估计出,不是精确值。待后续优化。
return TotalMemory / 1024.f / 1024.f + 1300.f;