Loading

UE4 Dynamic Instance 自动合批分析过程记录

分析流程

新建关卡,为了验证动态合批的代码主要执行的位置,在场景中只添加五个使用相同材质的球,和一个默认的天空球。

然后开始调试,需要在MeshPass提交的时候进行断点,在void FParallelMeshDrawCommandPass::DispatchPassSetup()的函数开头设置一个断点。这里第一次断点会断到Depth Pass,点击F5进入到Base Pass处理。

然后逐步进行调试,这里我们需要对上下文环境中的一个变量进行观察,以确定MeshDrawCommand的数量。

void FParallelMeshDrawCommandPass::DispatchPassSetup();

通过调用堆栈我们可以发现:

上图即可确定MeshDrawCommand中的数量为6个,在场景中一共5个小球和一个天空球,共6个图元。但是小球应该被合批优化掉,所以最后的MeshDrawCommand应该为2个。

在下图中,我们看到MeshDrawCommand的数量发生变化

球被Instance了

这里我们主要确定的是通过MeshDrawCommand进行合批优化的实现位置,通过TGraphTask并行执行 FMeshDrawCommandPassSetupTask::DoTask()->FMeshDrawCommandPassSetupTask::AnyThreadTask()->BuildMeshDrawCommandPrimitiveIdBuffer() 实现对MeshDrawCommand的合批处理。


FParallelMeshDrawCommandPass::DispatchPassSetup()中的核心变量TaskContext其位置在 FSceneRenderer::Views::ParallelMeshDrawCommandPasses,其中按照顺序来,第二个是Base Pass

这里我们也可以查看MeshRenderCommand相关的信息

相关参考

Refactoring the Mesh Drawing Pipeline | Unreal Fest Europe 2019 | Unreal Engine - YouTube

UE4 Mesh Piple Line & Auto Instacing | 码农家园 (codenong.com)

Mesh Auto-Instancing on Mobile | Unreal Engine Documentation

4. UE4 的auto instancing 下 - 知乎 (zhihu.com)

3. UE4 的auto instancing 中 - 知乎 (zhihu.com)

2. UE4 的auto instancing 上 - 知乎 (zhihu.com)

Using SV_InstanceID to retrieve the instanceID - UE4 AnswerHub (unrealengine.com)

GPU-Driven Rendering Pipelines (realtimerendering.com)

Unreal 4.22渲染数据管线重构和动态Instancing - 每日头条 (kknews.cc)

网格体绘制管道 | 虚幻引擎文档 (unrealengine.com)

Mesh Drawing Pipeline | Unreal Engine Documentation

posted @ 2022-02-13 14:25  straywriter  阅读(1323)  评论(0编辑  收藏  举报