154 lines
5.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: RDG Debug笔记
date: 2025-06-14 15:44:47
excerpt:
tags:
rating: ⭐
---
# 前言
- [UE5 Render Dependency Graph-实用指南](https://zhuanlan.zhihu.com/p/637889120)
# Command
- r.rdg
- AsyncCompute
- BreakPoint
## Reference
```c++
FAutoConsoleVariableRef CVarRDGDebug(
TEXT("r.RDG.Debug"),
GRDGDebug,
TEXT("Allow to output warnings for inefficiencies found during wiring and execution of the passes.\n")
TEXT(" 0: disabled;\n")
TEXT(" 1: emit warning once (default);\n")
TEXT(" 2: emit warning everytime issue is detected."),
ECVF_RenderThreadSafe);
FAutoConsoleVariableRef CVarRDGClobberResources(
TEXT("r.RDG.ClobberResources"),
GRDGClobberResources,
TEXT("Clears all render targets and texture / buffer UAVs with the requested clear color at allocation time. Useful for debugging.\n")
TEXT(" 0:off (default);\n")
TEXT(" 1: 1000 on RGBA channels;\n")
TEXT(" 2: NaN on RGBA channels;\n")
TEXT(" 3: +INFINITY on RGBA channels.\n"),
ECVF_Cheat | ECVF_RenderThreadSafe);
FAutoConsoleVariableRef CVarRDGOverlapUAVs(
TEXT("r.RDG.OverlapUAVs"), GRDGOverlapUAVs,
TEXT("RDG will overlap UAV work when requested; if disabled, UAV barriers are always inserted."),
ECVF_RenderThreadSafe);
FAutoConsoleVariableRef CVarRDGTransitionLog(
TEXT("r.RDG.TransitionLog"), GRDGTransitionLog,
TEXT("Logs resource transitions to the console.\n")
TEXT(" 0: disabled(default);\n")
TEXT(">0: enabled for N frames;\n")
TEXT("<0: enabled;\n"),
ECVF_RenderThreadSafe);
TAutoConsoleVariable<FString> CVarRDGDebugPassFilter(
TEXT("r.RDG.Debug.PassFilter"), TEXT(""),
TEXT("Filters certain debug events to specific passes. Set to 'None' to reset.\n"),
ECVF_Default);
TAutoConsoleVariable<FString> CVarRDGDebugResourceFilter(
TEXT("r.RDG.Debug.ResourceFilter"), TEXT(""),
TEXT("Filters certain debug events to a specific resource. Set to 'None' to reset.\n"),
ECVF_Default);
FAutoConsoleVariableRef CVarRDGParallelSetup(
TEXT("r.RDG.ParallelSetup"), GRDGParallelSetup,
TEXT("RDG will setup passes in parallel when prompted by calls to FRDGBuilder::FlushSetupQueue.")
TEXT(" 0: pass setup is done synchronously in AddPass;")
TEXT(" 1: pass setup is done asynchronously (default);"),
ECVF_RenderThreadSafe);
```
# Visualize Texture Integration
**vis**
使用vis指令可以打印vis指令帮助信息以及当前帧使用到的所有的资源信息
![[RDG_Vis.jpg|1200]]
**vis [RT Name]**
使用vis [RT Name]可以实时预览当前RT的内容在调试渲染特性的时候可以很方便的Debug
![[RDG_Vis_RTName.jpg|800]]
**vis [RT Name] bump**
打印当前RT到Saved/Screenshots
**vis off**
关闭当前帧的debug模式
# r.RDG.ImmediateMode
将RDG设置成理解执行模式方便进行资源绑定Debug以及断点。
- RDG立即执行模式:
- 立刻执行Pass在其被添加的时候
- 产生和延后执行时一样的功能
- 如果打断点,会非常容易检查其创建的代码
- 由于这个原因所以不能在AddPass后再去更改Pass参数
- 可以利用r.RDG.ImmediateMode在运行时切换
- 会消耗更多的内存可以考虑使用r.Test.SecondaryUpscaleOverride运行在低分辨率下。r.Test.SecondaryUpscaleOverride 设置的参数越大越模糊)
![[RDG_Immediate.png|800]]
- **r.RDG.ImmediateMode 1** / -rdgimmediate : 去除RDG的影响
- **r.RHICmdBypass 1** 去除RHI和并行渲染的影响
- r.RDG.ParallelExecute=0
- r.RDG.ParallelSetup=0
## RDG Async Compute
1.直接设置ComputePassFlags为ERDGPassFlags::AsyncCompute剩下的工作交给RDG自动判断和设置
```c++
ERDGPassFlags ComputePassFlags = (GSupportsEfficientAsyncCompute && CVarTSRAsyncCompute.GetValueOnRenderThread() != 0) ? ERDGPassFlags::AsyncCompute : ERDGPassFlags::Compute;
TShaderMapRef<FTSRClearPrevTexturesCS> ComputeShader(View.ShaderMap);
FComputeShaderUtils::AddPass(
GraphBuilder,
RDG_EVENT_NAME("TSR ClearPrevTextures %dx%d", InputRect.Width(), InputRect.Height()),
ComputePassFlags,
ComputeShader,
PassParameters,
FComputeShaderUtils::GetGroupCount(InputRect.Size(), 8 * 2));
```
2.在Render层调整Pass顺序为RDG提供更多Async Compute Overlap的可能性
# ValidateShaderParameters
ValidateShaderParameters()可以检测RDG绑定的资源是否都存在。
# -rdgdebug
`r.RDG.Debug = 1`来开启。
# RDG Insight
开启RDG Insight Plugin之后即可在UnrealInsight看到额外添加RDG Channel。
命令行启动游戏:
`Game.exe -trace=rdg,defaults`
# DumpGPU
使用DumpGPU指令可以将当前帧的所有Pass和资源信息打印可以很方便的进行查看。
在Console中输入DumpGPU指令会弹出生成好的html文件
![](https://pica.zhimg.com/v2-675aa8a985ccd280ef78e7578d509f16_1440w.jpg)
执行OpenGPUDumpViewer.bat打开网页默认只支持chrome浏览器可以通过修改脚本调用别的浏览器
![](https://pic1.zhimg.com/v2-2fb3021428caca29b8c41b2cb01a0f26_1440w.jpg)
可以看到各个Pass的信息
![](https://pic1.zhimg.com/v2-3732fc0379732e15eaf15d341b08586c_1440w.jpg)
显示当前帧所有CVar的值
![](https://pica.zhimg.com/v2-79ba2f962e6167dfec0f88f08ac3c2aa_1440w.jpg)
比较像素的值:
![](https://picx.zhimg.com/v2-16e264f19d4c0d98b3942fb485115ecf_1440w.jpg)