blob: 9da5ebba0f9c2db1e48ae41518806a3e3ce43b79 [file] [log] [blame] [view]
David Ghandeharib1536522017-05-24 00:01:15 -07001# Debugging Tips
2
Kaido Kert612c0202020-01-22 10:28:42 -08003There are many ways to debug ANGLE using generic or platform-dependent tools. Here is a list of tips
4on how to use them.
David Ghandeharib1536522017-05-24 00:01:15 -07005
6## Running ANGLE under apitrace on Linux
7
Kaido Kert612c0202020-01-22 10:28:42 -08008[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.
David Ghandeharib1536522017-05-24 00:01:15 -070012
Kaido Kert612c0202020-01-22 10:28:42 -080013The 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:
David Ghandeharib1536522017-05-24 00:01:15 -070016
Kaido Kert612c0202020-01-22 10:28:42 -0800171. 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`.
David Ghandeharib1536522017-05-24 00:01:15 -070026
Kaido Kert612c0202020-01-22 10:28:42 -080027If 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.
David Ghandeharib1536522017-05-24 00:01:15 -070029
Kaido Kert612c0202020-01-22 10:28:42 -080030For example, to trace a run of `hello_triangle`, assuming the apitrace executables are in `$PATH`:
David Ghandeharib1536522017-05-24 00:01:15 -070031
32```
Kaido Kert612c0202020-01-22 10:28:42 -080033gn args out/Debug # add "angle_link_glx = true"
34# edit samples/BUILD.gn and append "_static" to "angle_util", "libEGL", "libGLESv2"
David Ghandeharib1536522017-05-24 00:01:15 -070035ninja -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```
Kaido Kert612c0202020-01-22 10:28:42 -080040
41## Running ANGLE under GAPID on Linux
42
43[GAPID](https://github.com/google/gapid) can be used to capture trace of Vulkan commands on Linux.
44For it to work, libvulkan has to be a shared library, instead of being statically linked into ANGLE,
45which is the default behavior. This is done with the gn arg:
46
47```
48angle_shared_libvulkan = true
49```
50
51When capturing traces of gtest based tests built inside Chromium checkout, make sure to run the
52tests with `--single-process-tests` argument.
53
54## Running ANGLE under GAPID on Android
55
56[GAPID](https://github.com/google/gapid) can be used to capture a trace of the Vulkan or OpenGL ES
57command stream on Android. For it to work, ANGLE's libraries must have different names from the
58system OpenGL libraries. This is done with the gn arg:
59
60```
61angle_libs_suffix = "_ANGLE_DEV"
62```
63
64All
65[NativeTest](https://chromium.googlesource.com/chromium/src/+/master/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java)
66based tests share the same activity name, `org.chromium.native_test.NativeUnitTestNativeActivity`.
67Thus, prior to capturing your test trace, the specific test APK must be installed on the device.
68When you build the test, a test launcher is generated, for example,
69`./out/Release/bin/run_angle_end2end_tests`. The best way to install the APK is to run this test
70launcher once.
71
72In GAPID's "Capture Trace" dialog, "Package / Action:" should be:
73
74```
75android.intent.action.MAIN:org.chromium.native_test/org.chromium.native_test.NativeUnitTestNativeActivity
76```
77
78The mandatory [extra intent
79argument](https://developer.android.com/studio/command-line/adb.html#IntentSpec) for starting the
80activity is `org.chromium.native_test.NativeTest.StdoutFile`. Without it the test APK crashes. Test
81filters can be specified via either the `org.chromium.native_test.NativeTest.CommandLineFlags` or
82the `org.chromium.native_test.NativeTest.Shard` argument. Example "Intent Arguments:" values in
83GAPID's "Capture Trace" dialog:
84
85```
86-e org.chromium.native_test.NativeTest.StdoutFile /sdcard/chromium_tests_root/out.txt -e org.chromium.native_test.NativeTest.CommandLineFlags "--gtest_filter=*ES2_VULKAN"
87```
88
89or
90
91```
92-e org.chromium.native_test.NativeTest.StdoutFile /sdcard/chromium_tests_root/out.txt --esal org.chromium.native_test.NativeTest.Shard RendererTest.SimpleOperation/ES2_VULKAN,SimpleOperationTest.DrawWithTexture/ES2_VULKAN
93```
94
95## Running ANGLE under RenderDoc
96
97An application running through ANGLE can confuse [RenderDoc](https://github.com/baldurk/renderdoc),
98as RenderDoc [hooks to EGL](https://github.com/baldurk/renderdoc/issues/1045) and ends up tracing
99the calls the application makes, instead of the calls ANGLE makes to its backend. As ANGLE is a
100special case, there's little support for it by RenderDoc, though there are workarounds.
101
102### Windows
103
104On Windows, RenderDoc supports setting the environment variable `RENDERDOC_HOOK_EGL` to 0 to avoid
105this issue.
106
107### Linux
108
109On Linux, there is no supported workaround by RenderDoc. See [this
110issue](https://github.com/baldurk/renderdoc/issues/1045#issuecomment-463999869). To capture Vulkan
111traces, the workaround is to build RenderDoc without GL(ES) support.
112
113Building RenderDoc is straightforward. However, here are a few instructions to keep in mind.
114
115```
116# Install dependencies based on RenderDoc document. Here are some packages that are unlikely to be already installed:
117$ sudo apt install libxcb-keysyms1-dev python3-dev qt5-qmake libqt5svg5-dev libqt5x11extras5-dev
118
119# Inside the RenderDoc directory:
120$ cmake -DCMAKE_BUILD_TYPE=Release -Bbuild -H. -DENABLE_GLES=OFF -DENABLE_GL=OFF
121
122# QT_SELECT=5 is necessary if your distribution doesn't default to Qt5
123$ QT_SELECT=5 make -j -C build
124
125# Run RenderDoc from the build directory:
126$ ./build/bin/qrenderdoc
127```
128
129Additionally, libvulkan has to be a shared library, instead of being statically linked into ANGLE,
130which is the default behavior. This is done with the gn arg:
131
132```
133angle_shared_libvulkan = true
134```
135
136If your distribution does not provide a recent Vulkan SDK package, you would need to manually
137install that. This script tries to perform this installation as safely as possible. It would
138overwrite the system package's files, so follow at your own risk. Place this script just above the
139extracted SDK directory.
140
141```
142#! /bin/bash
143
144if [ $# -lt 1 ]; then
145 echo "Usage: $0 <version>"
146 exit 1
147fi
148
149ver=$1
150
151if [ ! -d "$ver" ]; then
152 echo "$ver is not a directory"
153fi
154
155# Verify everything first
156echo "Verifying files..."
157echo "$ver"/x86_64/bin/vulkaninfo
158test -f "$ver"/x86_64/bin/vulkaninfo || exit 1
159echo "$ver"/x86_64/etc/explicit_layer.d/
160test -d "$ver"/x86_64/etc/explicit_layer.d || exit 1
161echo "$ver"/x86_64/lib/
162test -d "$ver"/x86_64/lib || exit 1
163
164echo "Verified. Performing copy..."
165
166echo sudo cp "$ver"/x86_64/bin/vulkaninfo /usr/bin/vulkaninfo
167sudo cp "$ver"/x86_64/bin/vulkaninfo /usr/bin/vulkaninfo
168echo sudo cp "$ver"/x86_64/etc/explicit_layer.d/* /etc/explicit_layer.d/
169sudo cp "$ver"/x86_64/etc/explicit_layer.d/* /etc/explicit_layer.d/
170echo sudo rm /usr/lib/x86_64-linux-gnu/libvulkan.so*
171sudo rm /usr/lib/x86_64-linux-gnu/libvulkan.so*
172echo sudo cp -P "$ver"/x86_64/lib/lib* /usr/lib/x86_64-linux-gnu/
173sudo cp -P "$ver"/x86_64/lib/lib* /usr/lib/x86_64-linux-gnu/
174
175echo "Done."
176```
177
178### Android
179
180If you are on Linux, make sure not to use the build done in the previous section. The GL renderer
181disabled in the previous section is actually needed in this section.
182
183Define the following environment variables, for example in `.bashrc` (values are examples):
184
185```
186export JAVA_HOME=/usr/local/buildtools/java/jdk
187export ANDROID_SDK=$HOME/chromium/src/third_party/android_sdk/public
188export ANDROID_NDK=$HOME/chromium/src/third_party/android_ndk
189export ANDROID_NDK_HOME=$HOME/chromium/src/third_party/android_ndk
190```
191
192In the renderdoc directory, create Android builds of RenderDoc:
193
194```
195mkdir build-android-arm32
196cd build-android-arm32/
197cmake -DBUILD_ANDROID=On -DANDROID_ABI=armeabi-v7a ..
198make -j
199cd ../
200
201mkdir build-android-arm64
202cd build-android-arm64/
203cmake -DBUILD_ANDROID=On -DANDROID_ABI=arm64-v8a ..
204make -j
205cd ../
206```
207
208Note that you need both arm32 and arm64 builds even if working with an arm64 device. See
209[RenderDoc's documentation](https://github.com/baldurk/renderdoc/blob/v1.x/docs/CONTRIBUTING/Compiling.md#android)
210for more information.
211
212When you run RenderDoc, choose the "Replay Context" from the bottom-left part of the UI (defaults to
213Local). When selecting the device, you should see the RenderDoc application running.
214
215In ANGLE itself, make sure you add a suffix for its names to be different from the system's. Add
216this to gn args:
217
218```
219angle_libs_suffix = "_ANGLE_DEV"
220```
221
222Next, you need to install an ANGLE test apk. When you build the test, a test launcher is generated,
223for example, `./out/Release/bin/run_angle_end2end_tests`. The best way to install the APK is to run
224this test launcher once.
225
226In RenderDoc, use `org.chromium.native_test` as the Executable Path, and provide the following
227arguments:
228
229```
230-e org.chromium.native_test.NativeTest.StdoutFile /sdcard/chromium_tests_root/out.txt -e org.chromium.native_test.NativeTest.CommandLineFlags "--gtest_filter=*ES2_VULKAN"
231```
232
233Note that in the above, only a single command line argument is supported with RenderDoc. If testing
234dEQP on a non-default platform, the easiest way would be to modify `GetDefaultAPIName()` in
235`src/tests/deqp_support/angle_deqp_gtest.cpp` (and avoid `--use-angle=X`).