Debugging Tips
There are many ways to debug ANGLE using generic or platform-dependent tools. Here is a list of tips on how to use them.
Running ANGLE under apitrace on Linux
Apitrace captures traces of OpenGL commands for later analysis, allowing us to see how ANGLE translates OpenGL ES commands. In order to capture the trace, it inserts a driver shim using LD_PRELOAD
that records the command and then forwards it to the OpenGL driver.
The problem with ANGLE is that it exposes the same symbols as the OpenGL driver so apitrace captures the entry point calls intended for ANGLE and reroutes them to the OpenGL driver. In order to avoid this problem, use the following:
Link your application against the static ANGLE libraries (libGLESv2_static and libEGL_static) so they don't get shadowed by apitrace's shim.
Ask apitrace to explicitly load the driver instead of using a dlsym on the current module. Otherwise apitrace will use ANGLE's symbols as the OpenGL driver entrypoint (causing infinite recursion). To do this you must point an environment variable to your GL driver. For example:
export TRACE_LIBGL=/usr/lib/libGL.so.1
. You can find your libGL withldconfig -p | grep libGL
.Link ANGLE against libGL instead of dlsyming the symbols at runtime; otherwise ANGLE won't use the replaced driver entry points. This is done with the gn arg
angle_link_glx = true
.
If you follow these steps, apitrace will work correctly aside from a few minor bugs like not being able to figure out what the default framebuffer size is if there is no glViewport command.
For example, to trace a run of hello_triangle
, assuming the apitrace executables are in $PATH
:
Enabling General Logging
Normally, ANGLE only logs errors and warnings (e.g. to Android logcat). General logging, or additional levels of "trace" messages will be logged when the following GN arg is set:
Debug Angle on Android
Android 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.
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
The following local patch may also be necessary:
Build/install/enable ANGLE apk for your application following other instructions.
Modify gdbclient.py script to let it find the ANGLE symbols.
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.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.
Enabling Debug-Utils Markers
ANGLE can emit debug-utils markers for every GLES API command that are visible to both Android GPU Inspector (AGI) and RenderDoc. This support requires enabling general logging as well as setting the following additional GN arg:
In addition, if the following GN arg is set, the API calls will output to Android's logcat:
Once compiled, the markers need to be turned on.
Turning on Debug Markers on Android
On Android, debug markers are turned on and off with an Android debug property that is automatically deleted at the next reboot:
0: Turned off/disabled (default)
1: Turned on/enabled
Turning on Debug Markers on Desktop
On desktop, debug markers are turned on and off with the ANGLE_ENABLE_DEBUG_MARKERS environment variable (set in OS-specific manner):
0: Turned off/disabled (default)
1: Turned on/enabled
Running ANGLE under GAPID on Linux
GAPID can be used to capture trace of Vulkan commands on Linux. When capturing traces of gtest based tests built inside Chromium checkout, make sure to run the tests with --single-process-tests
argument.
Running ANGLE under GAPID on Android
GAPID can be used to capture a trace of the Vulkan or OpenGL ES command stream on Android. For it to work, ANGLE's libraries must have different names from the system OpenGL libraries. This is done with the gn arg:
All AngleNativeTest based tests share the same activity name, com.android.angle.test.AngleUnitTestActivity
. Thus, prior to capturing your test trace, the specific test APK must be installed on the device. When you build the test, a test launcher is generated, for example, ./out/Release/bin/run_angle_end2end_tests
. The best way to install the APK is to run this test launcher once.
In GAPID's "Capture Trace" dialog, "Package / Action:" should be:
The mandatory extra intent argument for starting the activity is org.chromium.native_test.NativeTest.StdoutFile
. Without it the test APK crashes. Test filters can be specified via either the org.chromium.native_test.NativeTest.CommandLineFlags
or the org.chromium.native_test.NativeTest.GtestFilter
argument. Example "Intent Arguments:" values in GAPID's "Capture Trace" dialog:
or
Running ANGLE under RenderDoc
An application running through ANGLE can confuse RenderDoc, as RenderDoc hooks to EGL and ends up tracing the calls the application makes, instead of the calls ANGLE makes to its backend. As ANGLE is a special case, there's little support for it by RenderDoc, though there are workarounds.
Windows
On Windows, RenderDoc supports setting the environment variable RENDERDOC_HOOK_EGL
to 0 to avoid this issue.
Linux
On Linux, there is no supported workaround by RenderDoc. See this issue. To capture Vulkan traces, the workaround is to build RenderDoc without GL(ES) support.
Building RenderDoc is straightforward. However, here are a few instructions to keep in mind.
If your distribution does not provide a recent Vulkan SDK package, you would need to manually install that. This script tries to perform this installation as safely as possible. It would overwrite the system package's files, so follow at your own risk. Place this script just above the extracted SDK directory.
Android
If you are on Linux, make sure not to use the build done in the previous section. The GL renderer disabled in the previous section is actually needed in this section.
Define the following environment variables, for example in .bashrc
(values are examples):
In the renderdoc directory, create Android builds of RenderDoc:
Note that you need both arm32 and arm64 builds even if working with an arm64 device. See RenderDoc's documentation for more information.
When you run RenderDoc, choose the "Replay Context" from the bottom-left part of the UI (defaults to Local). When selecting the device, you should see the RenderDoc application running.
In ANGLE itself, make sure you add a suffix for its names to be different from the system's. Add this to gn args:
Next, you need to install an ANGLE test apk. When you build the test, a test launcher is generated, for example, ./out/Release/bin/run_angle_end2end_tests
. The best way to install the APK is to run this test launcher once.
In RenderDoc, use com.android.angle.test/com.android.angle.test.AngleUnitTestActivity
as the Executable Path, and provide the following arguments:
Note that in the above, only a single command line argument is supported with RenderDoc. If testing dEQP on a non-default platform, the easiest way would be to modify GetDefaultAPIName()
in src/tests/deqp_support/angle_deqp_gtest.cpp
(and avoid --use-angle=X
).
Testing with Chrome Canary
Many of ANGLE's OpenGL ES entry points are exposed in Chromium as WebGL 1.0 and WebGL 2.0 APIs that are available via JavaScript. For testing purposes, custom ANGLE builds may be injected in Chrome Canary.
Setup
Windows
Download and install Google Chrome Canary.
Build ANGLE x64, Release.
Run
python scripts\update_canary_angle.py
to replace Canary's ANGLE with your custom ANGLE (note: Canary must be closed).
macOS
Download and install Google Chrome Canary.
Clear all attributes.
Build ANGLE x64 or arm64, Release.
Replace ANGLE libraries, adjusting paths if needed.
Re-sign the application bundle.
Usage
Run %LOCALAPPDATA%\Google\Chrome SxS\chrome.exe
(Windows) or ./Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary
(macOS) with the following command-line options:
--use-cmd-decoder=passthrough --use-gl=angle
and one of--use-angle=d3d9
(Direct3D 9 renderer, Windows only)--use-angle=d3d11
(Direct3D 11 renderer, Windows only)--use-angle=d3d11on12
(Direct3D 11on12 renderer, Windows only)--use-angle=gl
(OpenGL renderer)--use-angle=gles
(OpenGL ES renderer)--use-angle=vulkan
(Vulkan renderer)--use-angle=swiftshader
(SwiftShader renderer)--use-angle=metal
(Metal renderer, macOS only)