An efficient profiling workflow for Unreal Engine project.

- CPU and GPU are not working in parallel
- Not all rendering-related issues are related to the GPU
- Before the GPU actually renders, CPU also needs to deal with rendering tasks
- Some GPU tasks will need to wait for CPU tasks finish
- Some CPU tasks will need to wait for GPU tasks finish
- That's the reason we will see some waiting tasks in profiled result- Game (Game Thread): Gameplay logic + decides what should be rendered > related to CPU bottleneck, game logic too heavy
- Darw (Render Thread): Prepares rendering work(draw calls, material permutations, culling, sorting, batching, pass...), high-level rendering abstraction > related to CPU bottleneck, scene complexity
- RHIT (RHI Thread): translates render commands into actual GPU commands (DirectX, Vulkan, Metal...), manages GPU resources > related to CPU/GPU bottleneck (two side)
- GPU: Actual GPU render > related to GPU bottleneck, rendering/shader overload
- GPU is rendering frame N
- RHI Thread is submitting frame N+1
- Render Thread is building frame N+2
- Game Thread is simulating frame N+3
- Set up target fps first: 30 fps = 33.33 ms/frame, 60 fps = 16.66 ms/frame
- Initial Bottleneck Identification: Is it CPU, GPU or Memory?
- Always tackling the biggest problem first, leading to maximum performance return for the time invested
- Finding spikes in profiled result
Common Profiling Tools
stat fps: Show current fpsstat unit: Overall frame time as well as the game thread, rendering thread, and GPU timesstat unitgraph: See the graph with the stat unit datastat rhi: Displays Render Hardware Interface(RHI) memory and performance statisticsstat memory: Shows statistics on how much memory is being used by various subsystems
Simple Profiling Tools
stat game: Gives feedback on how long the various Gameplay Ticks are takingstat physics: Displays physics performance statisticsstat anim: Shows how long skinned meshes are taking to compute per tickstat navigation: Shows performance and memory information for the navigation system
Unreal Insights
- Filter CPU tracks only

- Find the key funciton (or a set of functions) that cause performance issue. Search from high level to low level

- Diagnose funciton counts and time spent

- Enable Stat Named Events will be slightly heavier but provide more tracing details

- Read function in source code if needed

Simple Profiling Tools
stat gpu: Displays GPU statistics for the frame
ProfileGPU(GPU Visualizer)
Unreal Insights
- For tracking all frames in general and finding performance spikes
- Not for diagnose deeply into a single frame(use Render Doc instead)
- Filter GPU tracks only

- Find the key elements (or a set of elements) that cause performance issue

- GPU bottleneck will block other thread's tasks

RenderDoc
- For detail diagnoise of a single frame (dive deep into Draw call, Overdraw, Shader Complexity, Render target...)
- Not for finding performance spikes (use Unreal Insights instead)
- Texture Viewer: Viewing all textures and render targets used during the capture

- Pipeline State: A complete snapshot of the GPU pipeline configuration for the currently selected draw call

- Mesh Viewer: A tool for inspecting the geometry produced by a draw call

- Event Browser: A timeline/tree of all GPU commands recorded in the captured frame

- We can search for the specific render pass in Event Browser to dive deep into it. Ex: BasePass
- We can search for actor's display name in Event Browser to dive deep into it
Windows PIX (WIP)
Simple Profiling Tools
stat memory: Shows statistics on how much memory is being used by various subsystems in Unreal Engine
stat streaming: Displays basic statistics on streaming assets, like how much memory streaming textures are using, or how many streaming textures there are in the scene
Memory Insights
- Change the path inside "RunMemoryInsight.bat" file to match with your Unreal Engine location
- Execute "RunMemoryInsight.bat" file. This will run both Unreal Engine and Unreal Insight with memory profiling enabled

- Unreal Art Optimization : https://unrealartoptimization.github.io/book/process/measuring-performance/
- How to run Unreal Insight : https://dev.epicgames.com/documentation/en-us/unreal-engine/unreal-insights-in-unreal-engine
- How to run memory insight : https://dev.epicgames.com/documentation/en-us/unreal-engine/memory-insights-in-unreal-engine
- How to enable RenderDoc in Unreal Engine : https://dev.epicgames.com/documentation/en-us/unreal-engine/using-renderdoc-with-unreal-engine
- How to use RenderDoc : https://renderdoc.org/docs/index.html




