• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Debugging Tips
2
3There are many ways to debug ANGLE using generic or platform-dependent tools. Here is a list of tips
4on how to use them.
5
6## Running ANGLE under apitrace on Linux
7
8[Apitrace](http://apitrace.github.io/) captures traces of OpenGL commands for later analysis,
9allowing us to see how ANGLE translates OpenGL ES commands. In order to capture the trace, it
10inserts a driver shim using `LD_PRELOAD` that records the command and then forwards it to the OpenGL
11driver.
12
13The problem with ANGLE is that it exposes the same symbols as the OpenGL driver so apitrace captures
14the entry point calls intended for ANGLE and reroutes them to the OpenGL driver. In order to avoid
15this problem, use the following:
16
171. Link your application against the static ANGLE libraries (libGLESv2_static and libEGL_static) so
18   they don't get shadowed by apitrace's shim.
192. Ask apitrace to explicitly load the driver instead of using a dlsym on the current module.
20   Otherwise apitrace will use ANGLE's symbols as the OpenGL driver entrypoint (causing infinite
21   recursion). To do this you must point an environment variable to your GL driver.  For example:
22   `export TRACE_LIBGL=/usr/lib/libGL.so.1`. You can find your libGL with
23   `ldconfig -p | grep libGL`.
243. Link ANGLE against libGL instead of dlsyming the symbols at runtime; otherwise ANGLE won't use
25   the replaced driver entry points. This is done with the gn arg `angle_link_glx = true`.
26
27If you follow these steps, apitrace will work correctly aside from a few minor bugs like not being
28able to figure out what the default framebuffer size is if there is no glViewport command.
29
30For example, to trace a run of `hello_triangle`, assuming the apitrace executables are in `$PATH`:
31
32```
33gn args out/Debug # add "angle_link_glx = true"
34# edit samples/BUILD.gn and append "_static" to "angle_util", "libEGL", "libGLESv2"
35ninja -C out/Debug
36export TRACE_LIBGL="/usr/lib/libGL.so.1" # may require a different path
37apitrace trace -o mytrace ./out/Debug/hello_triangle
38qapitrace mytrace
39```
40
41## Enabling General Logging
42
43Normally, ANGLE only logs errors and warnings (e.g. to Android logcat).  General logging, or
44additional levels of "trace" messages will be logged when the following GN arg is set:
45```
46angle_enable_trace = true
47```
48
49To log all GLES and EGL commands submitted by an application, including the following flag:
50```
51angle_enable_trace_events = true
52```
53
54If you want to enable `INFO`-level logs (and up) without incuring the log spam
55of `angle_enable_trace`, you can instead use the following flag:
56```
57angle_always_log_info = true
58```
59
60## Debug Angle on Android
61
62Android is built as an Android APK, which makes it more difficult to debug an APK that is using ANGLE.  The following information can allow you to debug ANGLE with LLDB.
63* You need to build ANGLE with debug symbols enabled. Assume your build variant is called Debug. Make sure you have these lines in out/Debug/args.gn
64```
65is_component_build = false
66is_debug = true
67is_official_build = false
68symbol_level = 2
69strip_debug_info = false
70ignore_elf32_limitations = true
71angle_extract_native_libs = true
72```
73The following local patch may also be necessary:
74```
75diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni
76index 96a18d91a3f6..ca7971fdfd48 100644
77--- a/build/config/compiler/compiler.gni
78+++ b/build/config/compiler/compiler.gni
79@@ -86,7 +86,8 @@ declare_args() {
80   # Whether an error should be raised on attempts to make debug builds with
81   # is_component_build=false. Very large debug symbols can have unwanted side
82   # effects so this is enforced by default for chromium.
83-  forbid_non_component_debug_builds = build_with_chromium
84+  forbid_non_component_debug_builds = false
85```
86
87Build/install/enable ANGLE apk for your application following other instructions.
88* Modify gdbclient.py script to let it find the ANGLE symbols.
89```
90diff --git a/scripts/gdbclient.py b/scripts/gdbclient.py
91index 61fac4000..1f43f4f64 100755
92--- a/scripts/gdbclient.py
93+++ b/scripts/gdbclient.py
94@@ -395,6 +395,8 @@ def generate_setup_script(debugger_path, sysroot, linker_search_dir, binary_file
95     vendor_paths = ["", "hw", "egl"]
96     solib_search_path += [os.path.join(symbols_dir, x) for x in symbols_paths]
97     solib_search_path += [os.path.join(vendor_dir, x) for x in vendor_paths]
98+    solib_search_path += ["/your_path_to_chromium_src/out/Debug/lib.unstripped/"]
99     if linker_search_dir is not None:
100         solib_search_path += [linker_search_dir]
101```
102* Start your lldbclient.py from `/your_path_to_chromium_src/out/Debug` folder. This adds the ANGLE source-file paths to what is visible to LLDB, which allows LLDB to show ANGLE's source files. Refer to https://source.android.com/devices/tech/debug/gdb for how to attach the app for debugging.
103* If you are debugging angle_perftests, you can use `--shard-timeout 100000000` to disable the timeout so that the test won't get killed while you are debugging. If the test runs too fast that you don't have time to attach, use `--delay-test-start=60` to give you extra time to attach.
104
105## Enabling Debug-Utils Markers
106
107ANGLE can emit debug-utils markers for every GLES API command that are visible to both Android GPU
108Inspector (AGI) and RenderDoc.  This support requires
109[enabling general logging](#enabling-general-logging) as well as setting the following additional
110GN arg:
111```
112angle_enable_annotator_run_time_checks = true
113```
114In addition, if the following GN arg is set, the API calls will output to Android's logcat:
115```
116angle_enable_trace_android_logcat = true
117```
118Once compiled, the markers need to be turned on.
119
120### Turning on Debug Markers on Android
121
122On Android, debug markers are turned on and off with an Android debug property that is
123automatically deleted at the next reboot:
124
125```
126adb shell setprop debug.angle.markers 1
127```
128
129* 0: Turned off/disabled (default)
130* 1: Turned on/enabled
131
132### Turning on Debug Markers on Desktop
133
134On desktop, debug markers are turned on and off with the ANGLE_ENABLE_DEBUG_MARKERS environment
135variable (set in OS-specific manner):
136
137* 0: Turned off/disabled (default)
138* 1: Turned on/enabled
139
140
141## Running ANGLE under GAPID on Linux
142
143[GAPID](https://github.com/google/gapid) can be used to capture trace of Vulkan commands on Linux.
144When capturing traces of gtest based tests built inside Chromium checkout, make sure to run the
145tests with `--single-process-tests` argument.
146
147## Running ANGLE under GAPID on Android
148
149[GAPID](https://github.com/google/gapid) can be used to capture a trace of the Vulkan or OpenGL ES
150command stream on Android.  For it to work, ANGLE's libraries must have different names from the
151system OpenGL libraries.  This is done with the gn arg:
152
153```
154angle_libs_suffix = "_ANGLE_DEV"
155```
156
157All
158[AngleNativeTest](https://chromium.googlesource.com/chromium/src/+/main/third_party/angle/src/tests/test_utils/runner/android/java/src/com/android/angle/test/AngleNativeTest.java)
159based tests share the same activity name, `com.android.angle.test.AngleUnitTestActivity`.
160Thus, prior to capturing your test trace, the specific test APK must be installed on the device.
161When you build the test, a test launcher is generated, for example,
162`./out/Release/bin/run_angle_end2end_tests`. The best way to install the APK is to run this test
163launcher once.
164
165In GAPID's "Capture Trace" dialog, "Package / Action:" should be:
166
167```
168android.intent.action.MAIN:com.android.angle.test/com.android.angle.test.AngleUnitTestActivity
169```
170
171The mandatory [extra intent
172argument](https://developer.android.com/studio/command-line/adb.html#IntentSpec) for starting the
173activity is `org.chromium.native_test.NativeTest.StdoutFile`. Without it the test APK crashes. Test
174filters can be specified via either the `org.chromium.native_test.NativeTest.CommandLineFlags` or
175the `org.chromium.native_test.NativeTest.GtestFilter` argument.  Example "Intent Arguments:" values in
176GAPID's "Capture Trace" dialog:
177
178```
179-e org.chromium.native_test.NativeTest.StdoutFile /sdcard/chromium_tests_root/out.txt -e org.chromium.native_test.NativeTest.CommandLineFlags "--gtest_filter=*ES2_VULKAN"
180```
181
182or
183
184```
185-e org.chromium.native_test.NativeTest.StdoutFile /sdcard/chromium_tests_root/out.txt --e org.chromium.native_test.NativeTest.GtestFilter RendererTest.SimpleOperation/ES2_VULKAN:SimpleOperationTest.DrawWithTexture/ES2_VULKAN
186```
187
188## Running ANGLE under RenderDoc
189
190An application running through ANGLE can confuse [RenderDoc](https://github.com/baldurk/renderdoc),
191as RenderDoc [hooks to EGL](https://github.com/baldurk/renderdoc/issues/1045) and ends up tracing
192the calls the application makes, instead of the calls ANGLE makes to its backend.  As ANGLE is a
193special case, there's little support for it by RenderDoc, though there are workarounds.
194
195### Windows
196
197On Windows, RenderDoc supports setting the environment variable `RENDERDOC_HOOK_EGL` to 0 to avoid
198this issue.
199
200### Linux
201
202On Linux, there is no supported workaround by RenderDoc.  See [this
203issue](https://github.com/baldurk/renderdoc/issues/1045#issuecomment-463999869).  To capture Vulkan
204traces, the workaround is to build RenderDoc without GL(ES) support.
205
206Building RenderDoc is straightforward.  However, here are a few instructions to keep in mind.
207
208```
209# Install dependencies based on RenderDoc document.  Here are some packages that are unlikely to be already installed:
210$ sudo apt install libxcb-keysyms1-dev python3-dev qt5-qmake libqt5svg5-dev libqt5x11extras5-dev
211
212# Inside the RenderDoc directory:
213$ cmake -DCMAKE_BUILD_TYPE=Release -Bbuild -H. -DENABLE_GLES=OFF -DENABLE_GL=OFF
214
215# QT_SELECT=5 is necessary if your distribution doesn't default to Qt5
216$ QT_SELECT=5 make -j -C build
217
218# Run RenderDoc from the build directory:
219$ ./build/bin/qrenderdoc
220```
221
222If your distribution does not provide a recent Vulkan SDK package, you would need to manually
223install that.  This script tries to perform this installation as safely as possible.  It would
224overwrite the system package's files, so follow at your own risk.  Place this script just above the
225extracted SDK directory.
226
227```
228#! /bin/bash
229
230if [ $# -lt 1 ]; then
231  echo "Usage: $0 <version>"
232  exit 1
233fi
234
235ver=$1
236
237if [ ! -d "$ver" ]; then
238  echo "$ver is not a directory"
239fi
240
241# Verify everything first
242echo "Verifying files..."
243echo "$ver"/x86_64/bin/vulkaninfo
244test -f "$ver"/x86_64/bin/vulkaninfo || exit 1
245echo "$ver"/x86_64/etc/explicit_layer.d/
246test -d "$ver"/x86_64/etc/explicit_layer.d || exit 1
247echo "$ver"/x86_64/lib/
248test -d "$ver"/x86_64/lib || exit 1
249
250echo "Verified. Performing copy..."
251
252echo sudo cp "$ver"/x86_64/bin/vulkaninfo /usr/bin/vulkaninfo
253sudo cp "$ver"/x86_64/bin/vulkaninfo /usr/bin/vulkaninfo
254echo sudo cp "$ver"/x86_64/etc/explicit_layer.d/* /etc/explicit_layer.d/
255sudo cp "$ver"/x86_64/etc/explicit_layer.d/* /etc/explicit_layer.d/
256echo sudo rm /usr/lib/x86_64-linux-gnu/libvulkan.so*
257sudo rm /usr/lib/x86_64-linux-gnu/libvulkan.so*
258echo sudo cp -P "$ver"/x86_64/lib/lib* /usr/lib/x86_64-linux-gnu/
259sudo cp -P "$ver"/x86_64/lib/lib* /usr/lib/x86_64-linux-gnu/
260
261echo "Done."
262```
263
264### Android
265#### Using Linux as a Local Machine
266
267If you are on Linux, make sure not to use the build done in the previous section.  The GL renderer
268disabled in the previous section is actually needed in this section.
269
270```
271# Inside the RenderDoc directory:
272# First delete the Cmake Cache in build/ directory
273rm build/CMakeCache.txt
274
275# Then build RenderDoc with cmake:
276cmake -DCMAKE_BUILD_TYPE=Release -Bbuild -H.
277QT_SELECT=5 make -j -C build
278```
279
280Follow
281[Android Dependencies on Linux](https://github.com/baldurk/renderdoc/blob/v1.x/docs/CONTRIBUTING/Dependencies.md#android-dependencies-on-linux)
282to download dependency files.
283
284Define the following environment variables, for example in `.bashrc` (values are examples):
285
286```
287export JAVA_HOME=<path_to_jdk_root>
288export ANDROID_SDK=<path_to_sdk_root>
289export ANDROID_NDK=<path_to_ndk_root>
290export ANDROID_NDK_HOME=<path_to_ndk_root>
291```
292
293In the renderdoc directory, create Android builds of RenderDoc:
294
295```
296mkdir build-android-arm32
297cd build-android-arm32/
298cmake -DBUILD_ANDROID=On -DANDROID_ABI=armeabi-v7a ..
299make -j
300cd ../
301
302mkdir build-android-arm64
303cd build-android-arm64/
304cmake -DBUILD_ANDROID=On -DANDROID_ABI=arm64-v8a ..
305make -j
306cd ../
307```
308
309Note that you need both arm32 and arm64 builds even if working with an arm64 device.  See
310[RenderDoc's documentation](https://github.com/baldurk/renderdoc/blob/v1.x/docs/CONTRIBUTING/Compiling.md#android)
311for more information.
312
313When you run RenderDoc, choose the "Replay Context" from the bottom-left part of the UI (defaults to
314Local).  When selecting the device, you should see the RenderDoc application running.
315
316In ANGLE itself, make sure you add a suffix for its names to be different from the system's.  Add
317this to gn args:
318
319```
320angle_libs_suffix = "_ANGLE_DEV"
321```
322
323Next, you need to install an ANGLE test APK.  When you build the test, a test launcher is generated,
324for example, `./out/Release/bin/run_angle_end2end_tests`. The best way to install the APK is to run
325this test launcher once.
326
327In RenderDoc, use `com.android.angle.test/com.android.angle.test.AngleUnitTestActivity` as the
328Executable Path, and provide the following arguments:
329
330```
331-e org.chromium.native_test.NativeTest.StdoutFile /sdcard/chromium_tests_root/out.txt -e org.chromium.native_test.NativeTest.CommandLineFlags "--gtest_filter=*ES2_VULKAN"
332```
333
334Note that in the above, only a single command line argument is supported with RenderDoc.  If testing
335dEQP on a non-default platform, the easiest way would be to modify `GetDefaultAPIName()` in
336`src/tests/deqp_support/angle_deqp_gtest.cpp` (and avoid `--use-angle=X`).
337
338
339#### Using Windows as a Local Machine
340You should be able to download the latest [RenderDoc on Windows](https://renderdoc.org/builds) and follow the
341[RenderDoc Official Documentation](https://renderdoc.org/docs/how/how_android_capture.html) for instructions on how to
342use RenderDoc on Android. If you would like to build RenderDoc for Android on Windows yourself, you can follow the
343[RenderDoc Officual Documentation](https://github.com/baldurk/renderdoc/blob/v1.x/docs/CONTRIBUTING/Compiling.md#android).
344We listed more detailed instructions below on how to set up the build on Windows.
345
346##### Install Android Dependencies
347
348On windows, we need to install dependencies to build android, as described in
349[RenderDoc Official Documentation](https://github.com/baldurk/renderdoc/blob/v1.x/docs/CONTRIBUTING/Dependencies.md#android)
3501. Install [Android SDK](https://developer.android.com/about/versions/12/setup-sdk#install-sdk).
351
352   Add a new system variable:
353
354   Variable: ANDROID_SDK
355
356   Value: path_to_sdk_directory (e.g. C:\Users\test\Appdata\Local\Android\Sdk)
3572. Install [Android NDK](https://developer.android.com/studio/projects/install-ndk).
358
359   Add a new system variable:
360
361   Variable: ANDROID_NDK
362
363   Value: path_to_ndk_directory (e.g. C:\Users\test\Appdata\Local\Android\Sdk\ndk\23.1.7779620)
364
3653. Install [Java 8](https://www.oracle.com/java/technologies/downloads/#java8).
366
367   Add a new system variable:
368
369   Variable: JAVA_HOME
370
371   Value: path_to_jdk1.8_directory (e.g. C:\Program Files\Java\jdk1.8.0_311)
372
3735. Install [Android Debug Bridge](https://developer.android.com/studio/releases/platform-tools).
374
375   Append android_sdk_platform-tools_directory to the Path system variable.
376
377   e.g. C:\Users\Test\AppData\Local\Android\Sdk\platform-tools
378
379
380##### Install Build Tools
381
3821. Install a bash shell. Git Bash comes with Git installation on Windows should work.
3832. Install [make](http://gnuwin32.sourceforge.net/packages/make.htm).
384   Add the path to bin folder of GnuWin32 to the Path system variable.
385
386
387##### Build RenderDoc Android APK on Windows
388
389If you are using the Git Bash that comes with MinGW generator, you can run below commands to build Android APK
390```
391mkdir build-android-arm32
392cd build-android-arm32/
393cmake -DBUILD_ANDROID=On -DANDROID_ABI=armeabi-v7a -G "MinGW Makefiles" ..
394make -j
395cd ../
396
397mkdir build-android-arm64
398cd build-android-arm64/
399cmake -DBUILD_ANDROID=On -DANDROID_ABI=arm64-v8a -G "MinGW Makefiles" ..
400make -j
401cd ../
402```
403If the generator type of the bash shell you are using is different from MinGW, replace the "MinGW" in the above cmake
404command with the generator
405type you are using, as described in
406[RenderDoc Official Documentation](https://github.com/baldurk/renderdoc/blob/v1.x/docs/CONTRIBUTING/Compiling.md#android).
407
408
409##### Build Errors And Resolutions
410
411* **cmake command errors**
412
413```
414Error: Failed to run MSBuild command:
415C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/MSBuild/Current/Bin/MSBuild.exe to get the value of
416VCTargetsPath:
417error : The BaseOutputPath/OutputPath property is not set for project 'VCTargetsPath.vcxproj'.
418Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.
419Configuration='Debug'  Platform='x64'.
420```
421
422This is due to the cmake command is using Visual Studio as the generator type. Run the cmake command with the
423generator type "MinGW Makefiles" or "MSYS Makefiles".
424
425```Error: Does not match the generator used previously```
426
427
428
429Delete the CMakeCache file in build directories build-android-arm64/ or build-android-arm32/.
430
431
432* **make command errors**
433
434```
435-Djava.ext.dirs is not supported.
436Error: Could not create the Java Virtual Machine.
437Error: A fatal exception has occurred. Program will exit.
438
439```
440
441Downgrade Java JDK version to [Java 8](https://www.oracle.com/java/technologies/downloads/#java8).
442
443
444##### Steps to use the RenderDoc you just built
4451. Build arm32 and arm64 android packages. See [instructions](#build-renderdoc-android-apk-on-windows) in the above
446section.
447
4482. Uninstall the renderdoc package.
449
450This step is required if you have installed / used RenderDoc on the same Android device before. RenderDoc only pushes
451the renderdoccmd APK to the Android device if it finds the version of the existing APK on the device is different from
452the version of the APK we are going to install, and the version is dictated by the git hash it was built from. Therefore
453any local modifications in the RenderDoc codebase would not get picked up if we don't uninstall the old APK first.
454
455```
456adb uninstall org.renderdoc.renderdoccmd.arm64
457adb uninstall org.renderdoc.renderdoccmd.arm32
458```
4593. Build renderdoc on windows desktop by clicking "build solution" in visual studio.
4604. Launch renderdoc from visual studio, and push the android packages to android device by selecting the connected
461device at the bottom left corner.
462
463### Add SPIRV-to-GLSL Shader View Option
464RenderDoc allows us to add and configure customized shader processing tools:
465https://renderdoc.org/docs/window/settings_window.html#shader-processing-tools-config.
466
467To configure RenderDoc to display shader source code in GLSL, instead of spirv,
468follow the below steps:
469
470
4711. Get the SPIRV-Cross tool:
472
473Clone the SPIRV-Cross git repo: https://github.com/KhronosGroup/SPIRV-Cross:
474```
475git clone https://github.com/KhronosGroup/SPIRV-Cross.git
476```
477Compile the SPIRV-Cross:
478```
479# inside SPIRV-Cross directory
480make
481```
4822. Open Shader Viewer Settings window: RenderDoc -> Tools -> Settings, and select
483   Shader Viewer on the left.
4843. Click Add on the bottom to add a new tool, and fill the new tool details:
485
486| Item       | Value                               |
487|------------|-------------------------------------|
488| Name       | SPIRV-CROSS                         |
489| Tool Type  | SPIRV-Cross                         |
490| Executable | <spirv-cross-repo-root>/spirv-cross |
491
4925. Restart RenderDoc.
493
494## Testing with Chrome Canary
495
496Many of ANGLE's OpenGL ES entry points are exposed in Chromium as WebGL 1.0 and WebGL 2.0 APIs that
497are available via JavaScript. For testing purposes, custom ANGLE builds may be injected in Chrome
498Canary.
499
500### Setup
501
502#### Windows
503
5041. Download and install [Google Chrome Canary](https://www.google.com/chrome/canary/).
5052. Build ANGLE x64, Release.
5063. Run `python scripts\update_chrome_angle.py` to replace Canary's ANGLE with your custom ANGLE
507   (note: Canary must be closed).
508
509#### Linux
510
5111. Install Google Chrome Dev (via apt, or otherwise).  Expected installation directory is
512   `/opt/google/chrome-unstable`.
5132. Build ANGLE for the running platform.  `is_component_build = false` is suggested in the GN args.
5143. Run `python scripts/update_chrome_angle.py` to replace Dev's ANGLE with your custom ANGLE
5154. Add ANGLE's build path to the `LD_LIBRARY_PATH` environment variable.
516
517#### macOS
518
5191. Download and install [Google Chrome Canary](https://www.google.com/chrome/canary/).
5202. Build ANGLE for the running platform; GN args should contain `is_debug = false`.
5213. Run `./scripts/update_chrome_angle.py` to replace Canary's ANGLE with your custom ANGLE.
522
523### Usage
524
525Run Chrome:
526
527- On Windows: `%LOCALAPPDATA%\Google\Chrome SxS\chrome.exe`
528- On Linux: `/opt/google/chrome-unstable/google-chrome-unstable`
529- On macOS: `./Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary`
530
531With the following command-line options:
532
533* `--use-cmd-decoder=passthrough --use-gl=angle` and one of
534  * `--use-angle=d3d9` (Direct3D 9 renderer, Windows only)
535  * `--use-angle=d3d11` (Direct3D 11 renderer, Windows only)
536  * `--use-angle=d3d11on12` (Direct3D 11on12 renderer, Windows only)
537  * `--use-angle=gl` (OpenGL renderer)
538  * `--use-angle=gles` (OpenGL ES renderer)
539  * `--use-angle=vulkan` (Vulkan renderer)
540  * `--use-angle=swiftshader` (SwiftShader renderer)
541  * `--use-angle=metal` (Metal renderer, macOS only)
542
543Additional useful options:
544
545* `--enable-logging`: To see logs
546* `--disable-gpu-watchdog`: To disable Chromium's watchdog, killing the GPU process when slow (due
547  to a debug build for example)
548* `--disable-gpu-sandbox`: To disable Chromium's sandboxing features, if it's getting in the way of
549  testing.
550* `--disable-gpu-compositing`: To make sure only the WebGL test being debugged is run through ANGLE,
551  not the entirety of Chromium.
552