Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 1 | # VA-API |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 2 | |
| 3 | This page documents tracing and debugging the Video Acceleration API (VaAPI or |
Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 4 | VA-API) on ChromeOS. VA-API is an open-source library and API specification, |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 5 | providing access to graphics hardware acceleration capabilities for video and |
Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 6 | image processing. VA-API is used on ChromeOS on both Intel and AMD platforms. |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 7 | |
| 8 | [TOC] |
| 9 | |
Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 10 | VA-API is implemented by a generic `libva` library, developed upstream on |
| 11 | the [VaAPI GitHub repository], from which ChromeOS is a downstream client via |
| 12 | the [libva] package. Several backends are available for it, notably the legacy |
| 13 | [Intel i965], the modern [Intel iHD] and the [AMD]. |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 14 | |
Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 15 |  |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 16 | |
| 17 | [VaAPI GitHub repository]: https://github.com/intel/libva |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 18 | [libva]: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/main/x11-libs/libva/ |
Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 19 | [Intel i965]: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/main/x11-libs/libva-intel-driver/ |
| 20 | [Intel iHD]: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/main/x11-libs/libva-intel-media-driver/ |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 21 | [AMD]: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/main/media-libs/libva-amdgpu-driver/ |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 22 | |
Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 23 | ## `libva` tracing |
| 24 | |
| 25 | The environment variable `LIBVA_TRACE=/path/to/file` can be exposed to libva to |
| 26 | store tracing information (see [va_trace.c]). `libva` will create a number of |
| 27 | e.g. `libva.log.033807.thd-0x00000b25 ` files (one per thread) with a list of |
| 28 | the actions taken and semi-disassembled parameters. |
| 29 | |
| 30 | [va_trace.c]: https://github.com/intel/libva/blob/64520e9ec90ed30e016d7c633d746b3bf538c702/va/va_trace.c#L59 |
| 31 | |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 32 | ## `libva` logging |
Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 33 | |
| 34 | The environment variable `LIBVA_MESSAGING_LEVEL=0` (or `1` or `2`) can be used |
| 35 | to configure increasing logging verbosity to stdout (see [va.c]). Chromium uses |
| 36 | a level `0` by default in `vaapi_wrapper.cc`. |
| 37 | |
| 38 | [va.c]: https://github.com/intel/libva/blob/2ece7099061ba4ea821545c8b6712b5c421c4dea/va/va.c#L194 |
| 39 | |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 40 | ## Tracing power consumption |
Miguel Casas | 32c29a43 | 2021-10-05 17:41:43 | [diff] [blame] | 41 | |
| 42 | Power consumption is available on ChromeOS test/dev images via the command line |
| 43 | binary [`dump_intel_rapl_consumption`]; this tool averages the power |
| 44 | consumption of the four SoC domains over a configurable period of time, usually |
| 45 | a few seconds. These domains are, in the order presented by the tool: |
| 46 | |
| 47 | * `pkg`: estimated power consumption of the whole SoC; in particular, this is a |
| 48 | superset of pp0 and pp1, including all accessory silicon, e.g. video |
| 49 | processing. |
| 50 | * `pp0`: CPU set. |
| 51 | * `pp1`/`gfx`: Integrated GPU or GPUs. |
| 52 | * `dram`: estimated power consumption of the DRAM, from the bus activity. |
| 53 | |
| 54 | |
| 55 | `dump_intel_rapl_consumption` results should be a subset and of the same |
| 56 | numerical value as those produced with e.g. `turbostat`. Note that despite the |
| 57 | name, the tool works on AMD platforms as well, since they provide the same type |
| 58 | of measurement registers, albeit a subset of Intel's. Googlers can read more |
| 59 | about this topic under [go/power-consumption-meas-in-intel]. |
| 60 | |
| 61 | `dump_intel_rapl_consumption` is usually run while a given workload is active |
| 62 | (e.g. a video playback) with an interval larger than a second to smooth out all |
| 63 | kinds of system services that would show up in smaller periods, e.g. WiFi. |
| 64 | |
| 65 | ```shell |
| 66 | dump_intel_rapl_consumption --interval_ms=2000 --repeat --verbose |
| 67 | ``` |
| 68 | |
| 69 | E.g. on a nocturne main1, the average power consumption while playing back the |
| 70 | first minute of a 1080p VP9 [video], the average consumptions in watts are: |
| 71 | |
| 72 | |`pkg` |`pp0` |`pp1`/`gfx` |`dram`| |
| 73 | | ---: | ---: | ---: | ---: | |
| 74 | | 2.63 | 1.44 | 0.29 | 0.87 | |
| 75 | |
| 76 | As can be seen, `pkg` ~= `pp0` + `pp1` + 1W, this extra watt is the cost of all |
| 77 | the associated silicon, e.g. bridges, bus controllers, caches, and the media |
| 78 | processing engine. |
| 79 | |
| 80 | |
| 81 | [`dump_intel_rapl_consumption`]: https://chromium.googlesource.com/chromiumos/platform2/+/main/power_manager/tools/dump_intel_rapl_consumption.cc |
| 82 | [video]: https://commons.wikimedia.org/wiki/File:Big_Buck_Bunny_4K.webm |
| 83 | [go/power-consumption-meas-in-intel]: http://go/power-consumption-meas-in-intel |
| 84 | |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 85 | ## Verifying VaAPI installation and usage |
| 86 | |
| 87 | ### <a name="verify-driver"></a> Verify the VaAPI is correctly installed and can be loaded |
| 88 | |
| 89 | `vainfo` is a small command line utility used to enumerate the supported |
| 90 | operation modes; it's developed in the [libva-utils] repository, but more |
| 91 | concretely available on ChromeOS dev images ([media-video/libva-utils] package) |
| 92 | and under Debian systems ([vainfo]). `vainfo` will try to load the appropriate |
| 93 | backend driver for the system and/or GPUs and fail if it cannot find/load it. |
| 94 | |
| 95 | [libva-utils]: https://github.com/intel/libva-utils |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 96 | [media-video/libva-utils]: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/main/media-video/libva-utils |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 97 | [vainfo]: https://packages.debian.org/sid/main/vainfo |
| 98 | |
| 99 | ### <a name="verify-vaapi"></a> Verify the VaAPI supports and/or uses a given codec |
| 100 | |
| 101 | A few steps are customary to verify the support and use of a given codec. |
| 102 | |
| 103 | To verify that the build and platform supports video acceleration, launch |
| 104 | Chromium and navigate to `chrome://gpu`, then: |
| 105 | * Search for the "Video Acceleration Information" Section: this should |
| 106 | enumerate the available accelerated codecs and resolutions. |
| 107 | * If this section is empty, oftentimes the "Log Messages" Section immediately |
| 108 | below might indicate an associated error, e.g.: |
| 109 | |
| 110 | > vaInitialize failed: unknown libva error |
| 111 | |
| 112 | that can usually be reproduced with `vainfo`, see the [previous |
| 113 | section](#verify-driver). |
| 114 | |
| 115 | To verify that a given video is being played back using the accelerated video |
| 116 | decoding backend: |
| 117 | * Navigate to a url that causes a video to be played. Leave it playing. |
| 118 | * Navigate to the `chrome://media-internals` tab. |
| 119 | * Find the entry associated to the video-playing tab. |
| 120 | * Scroll down to "`Player Properties`" and check the "`video_decoder`" entry: |
| 121 | it should say "GpuVideoDecoder". |
| 122 | |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 123 | ## VaAPI on Linux |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 124 | |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 125 | VA-API on Linux is not supported, but it can be enabled using the flags below, |
| 126 | and it might work on certain configurations -- but there's no guarantees. |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 127 | |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 128 | * To support proprietary codecs such as, e.g. H264/AVC1, add the options |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 129 | `proprietary_codecs = true` and `ffmpeg_branding = "Chrome"` to the GN args |
| 130 | (please refer to the [Setting up the build] Section). |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 131 | * Build Chromium as usual. |
| 132 | |
| 133 | At this point you should make sure the appropriate VA driver backend is working |
| 134 | correctly; try running `vainfo` from the command line and verify no errors show |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 135 | up, see the [previous section](#verify-driver). |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 136 | |
Jianhui Dai | 2afb19b | 2024-07-04 23:34:56 | [diff] [blame] | 137 | The following feature switch controls video encoding (see [media |
| 138 | switches](https://source.chromium.org/chromium/chromium/src/+/main:media/base/media_switches.cc) |
| 139 | for more details): |
Robert Mader | 5482210 | 2024-10-02 19:21:17 | [diff] [blame] | 140 | * `--enable-features=AcceleratedVideoEncoder` |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 141 | |
| 142 | The following two arguments are optional: |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 143 | * `--ignore-gpu-blocklist` |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 144 | * `--disable-gpu-driver-bug-workaround` |
| 145 | |
Robert Mader | 5482210 | 2024-10-02 19:21:17 | [diff] [blame] | 146 | The following feature can improve performance when using EGL/Wayland: |
| 147 | * `--enable-features=AcceleratedVideoDecodeLinuxZeroCopyGL` |
| 148 | |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 149 | The NVIDIA VaAPI drivers are known to not support Chromium (see |
| 150 | [crbug.com/1492880](https://crbug.com/1492880)). This feature switch is |
| 151 | provided for developers to test VaAPI drivers on NVIDIA GPUs: |
| 152 | * `--enable-features=VaapiOnNvidiaGPUs`, disabled by default |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 153 | |
Jianhui Dai | 2afb19b | 2024-07-04 23:34:56 | [diff] [blame] | 154 | ### VaAPI on Linux with OpenGL |
| 155 | |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 156 | ```shell |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 157 | ./out/gn/chrome --use-gl=angle --use-angle=gl \ |
Robert Mader | 5482210 | 2024-10-02 19:21:17 | [diff] [blame] | 158 | --enable-features=AcceleratedVideoEncoder,AcceleratedVideoDecodeLinuxGL,VaapiOnNvidiaGPUs \ |
Jianhui Dai | 2afb19b | 2024-07-04 23:34:56 | [diff] [blame] | 159 | --ignore-gpu-blocklist --disable-gpu-driver-bug-workaround |
| 160 | ``` |
| 161 | |
| 162 | ### VaAPI on Linux with Vulkan |
| 163 | |
| 164 | ```shell |
| 165 | ./out/gn/chrome --use-gl=angle --use-angle=vulkan \ |
Robert Mader | 5482210 | 2024-10-02 19:21:17 | [diff] [blame] | 166 | --enable-features=AcceleratedVideoEncoder,VaapiOnNvidiaGPUs,VaapiIgnoreDriverChecks,Vulkan,DefaultANGLEVulkan,VulkanFromANGLE \ |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 167 | --ignore-gpu-blocklist --disable-gpu-driver-bug-workaround |
Miguel Casas | e575c985 | 2018-12-20 17:41:15 | [diff] [blame] | 168 | ``` |
| 169 | |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 170 | Refer to the [previous section](#verify-vaapi) to verify support and use of the VaAPI. |
Julien Isorce | 0a0dd3a | 2019-01-24 18:05:59 | [diff] [blame] | 171 | |
Tom Anderson | 9f5be079 | 2019-12-19 20:54:32 | [diff] [blame] | 172 | [Setting up the build]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/linux/build_instructions.md#setting-up-the-build |
Jianhui Dai | aa45503 | 2023-12-05 18:06:19 | [diff] [blame] | 173 | |