# AMD VA-API encoding latency As of this writing (2024-05), [VA-API has no support for AMD's low-latency](https://gitlab.freedesktop.org/drm/amd/-/issues/3336) encoding mode. This is problematic for ultra low-latency applications like realtime game-streaming as implemented by [Sunshine](https://github.com/lizardbyte/sunshine). As a temporary fix, [Mesa can be patched](https://gitlab.freedesktop.org/drm/amd/-/issues/3336#note_2386629) to *unconditionally* use the low-latency optimizations. This entails a higher power consumption and may not be suitable for all applications. ## Patching Mesa for Ubuntu I'm providing a basic shell script to re-build Ubuntu's Mesa from the official source `.deb`s with the necessary patch. It has only seen some light testing (22.04 only) and is provided **without support**. For my own usage I'm executing this script in a throw-away Incus container based on Ubuntu 22.04. The script does not clean up after itself (i.e. no purging of build dependencies etc.). **Make sure to validate the scripts' contents before executing it.** In a clean container/VM, execute the script: ``` ./build-patched-mesa.sh ``` The script will build a number of `.deb` files in `mesa-lowlat`. ## Installation The package that needs to be updated in order to fix Sunshine's encoding latency is `libgl1-mesa-dri`. Copy the relevant file (currently `libgl1-mesa-dri_23.2.1-1ubuntu3.1~22.04.2_amd64.deb`) from your build environment to the host system. Unfortunately the newly built `.deb` can't just be installed using `dpkg -i` since there's a conflict with the Changelog file of the version that is already installed on the system. Hence the **dangerous** `--force-overwrite` option. Proceed at your own risk. ``` sudo dpkg -i --force-overwrite libgl1-mesa-dri_23.2.1-1ubuntu3.1~22.04.2_amd64.deb ``` The package can be marked `hold` in order to prevent accidental changes to it by the system's package manager. ``` sudo apt-mark hold libgl1-mesa-dri ``` ## Reverting Reverting to the distribution's official version of the packages is done via: ``` sudo apt install --mark-auto --reinstall -o DPkg::options::="--force-overwrite" libgl1-mesa-dri ```