Hardware Acceleration in Termux
> [!NOTE]
> I would like to include here all the information I got while I am still researching the subject as the world of hardware acceleration is huge.. If you find any errors or misconceptions, please comment on Youtube, Telegram or open an issue on this Github
## 1. Install packages
You need to install the following packages in Termux:
```
pkg install mesa-zink virglrenderer-mesa-zink vulkan-loader-android virglrenderer-android
```
## 2. Initialize graphical server in Termux:
Before login to proot and use hardware acceleration you need to start the graphical server:
* Vulkan (ZINK):
```
MESA_NO_ERROR=1 MESA_GL_VERSION_OVERRIDE=4.3COMPAT MESA_GLES_VERSION_OVERRIDE=3.2 GALLIUM_DRIVER=zink ZINK_DESCRIPTORS=lazy virgl_test_server --use-egl-surfaceless --use-gles &
```
* OpenGL (VIRGL):
```
virgl_test_server_android &
```
* [Turnip (Adreno GPU 6XX/7XX compatible only)](https://www.reddit.com/r/termux/comments/19dpqas/proot_linux_only_dri3_patch_mesa_turnip_driver/)
It is not needed to initialize any graphical server. Follow the steps described in the reddit post. As as summary:
1. Download Turnip Driver: [mesa-vulkan-kgsl_23.3.0-devel-20230905_arm64.deb](https://drive.google.com/file/d/1f4pLvjDFcBPhViXGIFoRE3Xc8HWoiqG-/view?usp=drive_link)
2. Install it in proot-distro (for example in Debian the command is as follows)
```
sudo dpkg -i mesa-vulkan-kgsl_23.3.0-devel-20230905_arm64.deb
```
In case you want to remove the driver:
```
sudo dpkg -r mesa-vulkan-drivers:arm64
```
## 3. In proot distro
Run the Desktop with my script (if you do manually instead of using my script, take in to account that you need to share the tmp dir to make it work):
```
./startxfce4_debian.sh
```
Once in the Desktop when you want to run a program with hardware acceleration use this before:
* For VIRGL and ZINK (depending on the graphic server you started in Termux it will use ZINK or VIRGL):
```
GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.0 program
```
* For TURNIP:
```
MESA_LOADER_DRIVER_OVERRIDE=zink TU_DEBUG=noconform program
```
# Performance results
Device used: Lenovo Legion Y700 2022 model (Snapdragon 870 - Adreno 650)
### GLMARK2
To install glmark2:
```
# In Termux: pkg install glmark2
# In proot-distro (Debian): sudo apt install glmark2
```
> [!IMPORTANT]
> The following tests were done in a proot distro environment with Debian and a XFCE4 desktop.
| RUN | LLVMPIPE | VIRGL | VIRGL ZINK | TURNIP | ZINK |
| --- | --- | --- | --- | --- | --- |
| 1 | 93 | 70 | 66 | 198 | Error |
| 2 | 93 | 77 | 66 | 198 | Error |
| 3 | 72 | 70 | 71 | 198 | Error |
| 4 | 94 | 76 | 66 | 197 | Error |
| 5 | 93 | 75 | 67 | 198 | Error |
* Initialize server:
* Not needed
* `virgl_test_server_android &`
* `MESA_NO_ERROR=1 MESA_GL_VERSION_OVERRIDE=4.3COMPAT MESA_GLES_VERSION_OVERRIDE=3.2 GALLIUM_DRIVER=zink ZINK_DESCRIPTORS=lazy virgl_test_server --use-egl-surfaceless --use-gles &`
* Not needed
* `MESA_NO_ERROR=1 MESA_GL_VERSION_OVERRIDE=4.3COMPAT MESA_GLES_VERSION_OVERRIDE=3.2 GALLIUM_DRIVER=zink ZINK_DESCRIPTORS=lazy virgl_test_server --use-egl-surfaceless --use-gles &`
* Command used:
* `glmkar2`
* `GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.0 glmark2`
* `GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.0 glmark2`
* `MESA_LOADER_DRIVER_OVERRIDE=zink TU_DEBUG=noconform glmark2`
* `GALLIUM_DRIVER=zink MESA_GL_VERSION_OVERRIDE=4.0 glmark2`
* GLMARK GPU Info:
* llvmpipe
* virgl (Adreno)
* virgl (zink Adreno)
* virgl (Turnip Adreno)
* zink (Adreno)
---
> [!IMPORTANT]
> The following tests were done in Termux (NOT in proot-distro) and a XFCE4 desktop.
| RUN | LLVMPIPE | VIRGL | VIRGL ZINK | ZINK | TURNIP |
| --- | --- | --- | --- | --- | --- |
| 1 | 69 | Error | 92 | 121 | Doesn't apply |
| 2 | 70 | Error | 92 | 122 | Doesn't apply |
| 3 | 69 | Error | 93 | 121 | Doesn't apply |
| 4 | 69 | Error | 93 | 124 | Doesn't apply |
| 5 | 69 | Error | 93 | 123 | Doesn't apply |
* Initialize server:
* Not needed
* `virgl_test_server_android &`
* `MESA_NO_ERROR=1 MESA_GL_VERSION_OVERRIDE=4.3COMPAT MESA_GLES_VERSION_OVERRIDE=3.2 GALLIUM_DRIVER=zink ZINK_DESCRIPTORS=lazy virgl_test_server --use-egl-surfaceless --use-gles &`
* `MESA_NO_ERROR=1 MESA_GL_VERSION_OVERRIDE=4.3COMPAT MESA_GLES_VERSION_OVERRIDE=3.2 GALLIUM_DRIVER=zink ZINK_DESCRIPTORS=lazy virgl_test_server --use-egl-surfaceless --use-gles &`
* Doesn't apply
* Command used:
* `glmkar2`
* `GALLIUM_DRIVER=virpipe
MESA_GL_VERSION_OVERRIDE=4.0 glmark2`
* `GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.0 glmark2`
* `GALLIUM_DRIVER=zink MESA_GL_VERSION_OVERRIDE=4.0 glmark2`
* Doesn't apply
* GLMARK GPU Info:
* llvmpipe
* virgl (Adreno)
* virgl (zink Adreno)
* zink (Adreno)
* Doesn't apply
---
### [Firefox Aquarium WebGL Benchmark](https://webglsamples.org/aquarium/aquarium.html)
> [!NOTE]
> You need to [enable WebGL in Firefox](https://tecnorobot.educa2.madrid.org/tecnologia/-/visor/configurar-webgl) to use the GPU
#### DEBIAN PROOT (FIREFOX-ESR WEBGL AQUARIUM FPS - the higher the number the better the performance)
| LLVMPIPE | VIRGL | VIRGL ZINK | TURNIP |
| --- | --- | --- | --- |
| 4 | 20 | 17 | Web page crash |
#### TERMUX NOT PROOT (FIREFOX-ESR WEBGL AQUARIUM FPS - the higher the number the better the performance)
| LLVMPIPE | VIRGL | VIRGL ZINK | ZINK | TURNIP |
| --- | --- | --- | --- | --- |
| 2 | Error | 24 | 40 | Doesn't apply |

---
Other tests I did:
* SuperTuxKart tested during 30 seconds

```
🔥[Video] Hardware Acceleration Part 1 - What it is, how it is used (https://www.youtube.com/watch?v=fgGOizUDQpY)