RHI 显存计算

// 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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值