xref: /aosp_15_r20/external/angle/doc/DebugOverlayInVulkanBackend.md (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# Debug Overlay in ANGLE's Vulkan Backend
2*8975f5c5SAndroid Build Coastguard Worker
3*8975f5c5SAndroid Build Coastguard Worker## Motivation
4*8975f5c5SAndroid Build Coastguard Worker
5*8975f5c5SAndroid Build Coastguard WorkerA complex application has frequently changing performance characteristics due to
6*8975f5c5SAndroid Build Coastguard Workerboth a varying number of objects to draw and different effects that need to be
7*8975f5c5SAndroid Build Coastguard Workerapplied to them. When characterizing the performance of an application, it can
8*8975f5c5SAndroid Build Coastguard Workerbe easy to miss scenes which need optimization, especially if they are
9*8975f5c5SAndroid Build Coastguard Workerephemeral.
10*8975f5c5SAndroid Build Coastguard Worker
11*8975f5c5SAndroid Build Coastguard WorkerA debug overlay that shows on-the-fly statistics from the running application
12*8975f5c5SAndroid Build Coastguard Workercan greatly aid the developer in finding where the bottlenecks are and which
13*8975f5c5SAndroid Build Coastguard Workerscenes need further investigation and profiling.
14*8975f5c5SAndroid Build Coastguard Worker
15*8975f5c5SAndroid Build Coastguard WorkerANGLE's Vulkan debug overlay implements this. The initial implementation
16*8975f5c5SAndroid Build Coastguard Workerincludes a few pieces of information for demonstration purposes. Here's the
17*8975f5c5SAndroid Build Coastguard Workerglmark2 *terrain* scene with these overlay items enabled:
18*8975f5c5SAndroid Build Coastguard Worker
19*8975f5c5SAndroid Build Coastguard Worker![glmark2 terrain scene](img/VangleDebugOverlay.png)
20*8975f5c5SAndroid Build Coastguard Worker
21*8975f5c5SAndroid Build Coastguard WorkerThis is a screenshot of a debug build, hence the low FPS. The command graph size
22*8975f5c5SAndroid Build Coastguard Workerwidget no longer applies to current ANGLE code.
23*8975f5c5SAndroid Build Coastguard Worker
24*8975f5c5SAndroid Build Coastguard Worker## Implementation
25*8975f5c5SAndroid Build Coastguard Worker
26*8975f5c5SAndroid Build Coastguard WorkerOverlay items are of two fundamental types:
27*8975f5c5SAndroid Build Coastguard Worker
28*8975f5c5SAndroid Build Coastguard Worker* Text items: A single line of text with small or large font.
29*8975f5c5SAndroid Build Coastguard Worker* Graph items: A bar graph of data. These each have a Text item attached
30*8975f5c5SAndroid Build Coastguard Worker  that is automatically rendered with the graph item.
31*8975f5c5SAndroid Build Coastguard Worker
32*8975f5c5SAndroid Build Coastguard WorkerBuilt on these, various overlay item types are defined that gather statistics.
33*8975f5c5SAndroid Build Coastguard WorkerFive such types are defined with one item per type as example:
34*8975f5c5SAndroid Build Coastguard Worker
35*8975f5c5SAndroid Build Coastguard Worker* **Count**: An item that counts something. **VulkanValidationMessageCount**
36*8975f5c5SAndroid Build Coastguard Worker  is an overlay item of this type that shows the number of validation messages
37*8975f5c5SAndroid Build Coastguard Worker  received from the validation layers.
38*8975f5c5SAndroid Build Coastguard Worker* **Text**: A generic text widget. **VulkanLastValidationMessage** is an overlay
39*8975f5c5SAndroid Build Coastguard Worker  item of this type that shows the last validation message.
40*8975f5c5SAndroid Build Coastguard Worker* **PerSecond**: A value that gets reset every second automatically. **FPS** is
41*8975f5c5SAndroid Build Coastguard Worker  an overlay item of this type that simply gets incremented on every `swap()`.
42*8975f5c5SAndroid Build Coastguard Worker* **RunningGraph**: A graph of the last N values. **VulkanRenderPassCount** is an
43*8975f5c5SAndroid Build Coastguard Worker  overlay of this type. This counter reports the number of RenderPasses rendered
44*8975f5c5SAndroid Build Coastguard Worker  in each vkQueueSubmit call.
45*8975f5c5SAndroid Build Coastguard Worker* **RunningHistogram**: A histogram of last N values. Input values are in the
46*8975f5c5SAndroid Build Coastguard Worker  [0, 1] range and they are ranked to N buckets for histogram calculation.
47*8975f5c5SAndroid Build Coastguard Worker  **VulkanSecondaryCommandBufferPoolWaste** is an overlay item of this type.
48*8975f5c5SAndroid Build Coastguard Worker  On `vkQueueSubmit()`, the memory waste from command buffer pool allocations
49*8975f5c5SAndroid Build Coastguard Worker  is recorded in the histogram.
50*8975f5c5SAndroid Build Coastguard Worker
51*8975f5c5SAndroid Build Coastguard WorkerOverlay font is placed in [libANGLE/overlay/](../src/libANGLE/overlay/) which
52*8975f5c5SAndroid Build Coastguard Worker[gen_overlay_fonts.py](../src/libANGLE/gen_overlay_fonts.py) processes to create
53*8975f5c5SAndroid Build Coastguard Workeran array of rasterized font data, which is used at runtime to create the font
54*8975f5c5SAndroid Build Coastguard Workerimage (an image with one layer per character, and one mip level per font size).
55*8975f5c5SAndroid Build Coastguard Worker
56*8975f5c5SAndroid Build Coastguard WorkerThe overlay widget layout is defined in
57*8975f5c5SAndroid Build Coastguard Worker[overlay_widgets.json](../src/libANGLE/overlay_widgets.json)
58*8975f5c5SAndroid Build Coastguard Workerwhich [gen_overlay_widgets.py](../src/libANGLE/gen_overlay_widgets.py)
59*8975f5c5SAndroid Build Coastguard Workerprocesses to generate an array of widgets, each of its respective type,
60*8975f5c5SAndroid Build Coastguard Workerand sets their properties, such as color and bounding box.
61*8975f5c5SAndroid Build Coastguard WorkerThe json file allows widgets to align against other widgets as well as against
62*8975f5c5SAndroid Build Coastguard Workerthe framebuffer edges. The following is a part of this file:
63*8975f5c5SAndroid Build Coastguard Worker
64*8975f5c5SAndroid Build Coastguard Worker```json
65*8975f5c5SAndroid Build Coastguard Worker{
66*8975f5c5SAndroid Build Coastguard Worker    "name": "VulkanValidationMessageCount",
67*8975f5c5SAndroid Build Coastguard Worker    "type": "Count",
68*8975f5c5SAndroid Build Coastguard Worker    "color": [255, 0, 0, 255],
69*8975f5c5SAndroid Build Coastguard Worker    "coords": [10, "VulkanLastValidationMessage.top.adjacent"],
70*8975f5c5SAndroid Build Coastguard Worker    "font": "small",
71*8975f5c5SAndroid Build Coastguard Worker    "length": 25
72*8975f5c5SAndroid Build Coastguard Worker},
73*8975f5c5SAndroid Build Coastguard Worker{
74*8975f5c5SAndroid Build Coastguard Worker    "name": "VulkanSecondaryCommandBufferPoolWaste",
75*8975f5c5SAndroid Build Coastguard Worker    "type": "RunningHistogram(50)",
76*8975f5c5SAndroid Build Coastguard Worker    "color": [255, 200, 75, 200],
77*8975f5c5SAndroid Build Coastguard Worker    "coords": [-50, 100],
78*8975f5c5SAndroid Build Coastguard Worker    "bar_width": 6,
79*8975f5c5SAndroid Build Coastguard Worker    "height": 100,
80*8975f5c5SAndroid Build Coastguard Worker    "description": {
81*8975f5c5SAndroid Build Coastguard Worker        "color": [255, 200, 75, 255],
82*8975f5c5SAndroid Build Coastguard Worker        "coords": ["VulkanSecondaryCommandBufferPoolWaste.left.align",
83*8975f5c5SAndroid Build Coastguard Worker                   "VulkanSecondaryCommandBufferPoolWaste.top.adjacent"],
84*8975f5c5SAndroid Build Coastguard Worker        "font": "small",
85*8975f5c5SAndroid Build Coastguard Worker        "length": 40
86*8975f5c5SAndroid Build Coastguard Worker    }
87*8975f5c5SAndroid Build Coastguard Worker}
88*8975f5c5SAndroid Build Coastguard Worker```
89*8975f5c5SAndroid Build Coastguard Worker
90*8975f5c5SAndroid Build Coastguard WorkerNegative coordinates in this file indicate alignment to the right/bottom of the
91*8975f5c5SAndroid Build Coastguard Workerframebuffer. `OtherItem.edge.mode` lets an item be aligned with another.
92*8975f5c5SAndroid Build Coastguard WorkerIf `mode` is `align`, the item has the same origin as `OtherItem` and expands
93*8975f5c5SAndroid Build Coastguard Workerin the same direction. If `adjacent`, the item expands in the opposite
94*8975f5c5SAndroid Build Coastguard Workerdirection.
95*8975f5c5SAndroid Build Coastguard Worker
96*8975f5c5SAndroid Build Coastguard WorkerThe UI is rendered in two passes, one draw call for all graph widgets and
97*8975f5c5SAndroid Build Coastguard Workeranother draw call for all text widgets. The vertex shader in these draw calls
98*8975f5c5SAndroid Build Coastguard Workergenerates 4 vertices for each instance (one instance per widget) based on the
99*8975f5c5SAndroid Build Coastguard Workerwidget bounding box. The fragment shader renders font or a graph based on widget
100*8975f5c5SAndroid Build Coastguard Workerdata. This is done once per frame on `present()`, and the result is blended into
101*8975f5c5SAndroid Build Coastguard Workerthe swapchain image.
102*8975f5c5SAndroid Build Coastguard Worker
103*8975f5c5SAndroid Build Coastguard WorkerTo build ANGLE with overlay capability, `angle_enable_overlay = true` must be
104*8975f5c5SAndroid Build Coastguard Workerplaced in `args.gn`.
105*8975f5c5SAndroid Build Coastguard Worker
106*8975f5c5SAndroid Build Coastguard WorkerCurrently, to enable overlay items an environment variable is used. For example:
107*8975f5c5SAndroid Build Coastguard Worker
108*8975f5c5SAndroid Build Coastguard WorkerOn Desktop:
109*8975f5c5SAndroid Build Coastguard Worker
110*8975f5c5SAndroid Build Coastguard Worker```commandline
111*8975f5c5SAndroid Build Coastguard Worker$ export ANGLE_OVERLAY=FPS:Vulkan*PipelineCache*
112*8975f5c5SAndroid Build Coastguard Worker$ ./hello_triangle --use-angle=vulkan
113*8975f5c5SAndroid Build Coastguard Worker```
114*8975f5c5SAndroid Build Coastguard Worker
115*8975f5c5SAndroid Build Coastguard WorkerOn Android:
116*8975f5c5SAndroid Build Coastguard Worker
117*8975f5c5SAndroid Build Coastguard Worker```
118*8975f5c5SAndroid Build Coastguard Worker$ adb shell setprop debug.angle.overlay FPS:Vulkan*PipelineCache*
119*8975f5c5SAndroid Build Coastguard Worker$ ./hello_triangle --use-angle=vulkan
120*8975f5c5SAndroid Build Coastguard Worker```
121*8975f5c5SAndroid Build Coastguard Worker
122*8975f5c5SAndroid Build Coastguard Worker## Future Work
123*8975f5c5SAndroid Build Coastguard Worker
124*8975f5c5SAndroid Build Coastguard WorkerPossible future work:
125*8975f5c5SAndroid Build Coastguard Worker
126*8975f5c5SAndroid Build Coastguard Worker* On Android, add settings in developer options and enable items based on those.
127*8975f5c5SAndroid Build Coastguard Worker* Spawn a small server in ANGLE and write an application that sends
128*8975f5c5SAndroid Build Coastguard Worker  enable/disable commands remotely.
129*8975f5c5SAndroid Build Coastguard Worker* Move the Overlay rendering functionality to the front-end to benefit all
130*8975f5c5SAndroid Build Coastguard Worker  backends.
131*8975f5c5SAndroid Build Coastguard Worker* Add more overlay widgets.
132*8975f5c5SAndroid Build Coastguard Worker* Implement automatic widget layout to remove the need to specify positions in
133*8975f5c5SAndroid Build Coastguard Worker  the overlay widgets JSON.
134