Unreal Including IndirectDraw Primitives In Stats(DirectX12 Only) | Blurred code

Unreal Including IndirectDraw Primitives In Stats(DirectX12 Only)

2024/06/17

LastMod:2024/07/07

Categories: UE

Stat Unit / Stat RHI

IndirectDraw is widely used in Unreal (especially on Desktop Deferred Renderer). It's a common practice to use IndirectDraw to draw a large number of objects with a single draw call, with GPU Culling on GPUScene. With GPUScene enabled, HISM and ISM and landscape will be drawn with IndirectDraw.

However, the instances drawn with IndirectDraw are decided by Compute Shader, the result is stored in a GPU Buffer and then used in the IndirectDraw call. There is no simple way to detect how much primitives are drawn.

So, Stat Unit and Stat RHI simply ignore those primitives. In large open world with full of Foliages and Grass, there may be a huge gap between them and the actual primitives are processed on GPU.

For example:

I made a simple scene with about 10 trees with FoliageActor(actually HISM ), and the stat rhi reported drawing about 4000 triangles.

Unreal_Including_IndirectDraw_In_Statistics-2024-06-17-23-23-49

Actually there are about 400'000 vertices drawn, reported by Renderdoc.

Unreal_Including_IndirectDraw_In_Statistics-2024-06-17-23-28-32

Pipeline Statistics Query

How to get the actual number of primitives drawn with IndirectDraw?

The first thing comes to mind is reading back the GPU Buffer and counting the number of instances drawn. However this is not a good idea as it can be extremely slow and may cause a stall.

Another approach is to use GPU Profiling/Debugging Tools such as RenderDoc / XCode and Snapdragon Profiler. These tools collect information from the Hardware Counter or the Hooked Graphics API ,providing accurate numbers. One of the advantages of this approach is that it is graphics API independent and transparent, eliminating the need to modify the code.

The third way is to use Pipeline Statistics Query in the Graphics API.

In Unreal5, only the D3d12 backend has some basic support for Pipeline Statistics Query.

The command stat d3d12rhipipeline provides pipeline statistics.

Unreal_Including_IndirectDraw_In_Statistics-2024-06-17-23-37-23