Skip to main content

virglrenderer: Termux GPU hardware acceleration tutorial

分類 Smartphone Termux Tutorial
標籤 Wine Termux
Table of Contents

🇹🇼 中文版

This article is about how to enable GPU hardware acceleration in Termux proot-distro by installing and running virgl server in Termux.

By enabling VirGL in proot, we will be able to play 4K60p videos and run 3D Linux games or Windows games (via Box86 + Wine) in proot.

SuperTuxKart, Glxgears

No root permission is required.

Testing device: Sony Xperia 5 II. Android 12. Snapdragon 865 (Adreno 650). RAM 8GB.

If you are confused, watch this video demonstration first (with subtitles) to see how virglrenderer improve the graphical performance of Termux X11.

1. Install Termux and Termux X11
#

Install Termux from F-droid

And setup Termux X11

2. Install proot-distro
#

Install a proot-distro with desktop environment.

I use Debian.

3. Install virglrenderer
#

Choose one method to install virglrenderer.

Method 1: Install virglrenderer-Android
#

virglrenderer-android uses Android GL/ES. It should work on most Android devices.

  1. Install virglrenderer-android
pkg install virglrenderer-android
  1. You can start virgl server by executing this command
virgl_test_server_android &

Method 2: Install virglrenderer with Zink
#

Zink is the OpenGL on Vulkan translation layer. The performance might be better than virglrenderer-android. It only works on Qualcomm devices.

  1. Install virglrenderer with zink
pkg install tur-repo
pkg update -y && pkg upgrade -y
pkg install mesa-zink virglrenderer-mesa-zink vulkan-loader-android
  1. You can start virgl server by executing this command. While using GALLIUM_DRIVER variable in proot, replace virpipe with zink.
MESA_LOADER_DRIVER_OVERRIDE=zink GALLIUM_DRIVER=zink ZINK_DESCRIPTORS=lazy virgl_test_server --use-egl-surfaceless &

4. How to run applications with virgl
#

4.1. In proot
#

  1. Start virgl server in Termux.

  2. Launch Termux X11 app, keep it opening in the background. Go back to Termux, start Termux X11

export DISPLAY=:0
termux-x11 :0 &
  1. Swipe from left edge, clcik New Session to open a new terminal. Log into proot-distro as user and mount Termux’s /tmp to proot.
proot-distro login debian --user user --shared-tmp
  1. Then start XFCE session
export DISPLAY=:0
dbus-launch --exit-with-session startxfce4 &
  1. Open terminal emulator in XFCE desktop. Run applications with two parameters: GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.0 to use virgl. Note some applications may crash when MESA_GL_VERSION_OVERRIDE=4.0 is used.\

You may replace GALLIUM_DRIVER=virpipe with GALLIUM_DRIVER=virgl.

  1. For instance, to run Minetest with virgl:
GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.0 minetest

The FPS of glxgears is higher when virgl enabled.

After enabling virgl, Minetest FPS grows from 10 FPS up to 20 FPS.

VLC with virgl is capable of playing 4K60p videos.

SueprTuxKart becomes playable after enabling vrigl.

The FPS of WebGL Aquarium doubled after enabling virgl. (You need to force enable WebGL in about:config)

You can also consider using the GALIUM_DRIVER=virpipe startxfce4 command to start the desktop environment so that all programs will be rendered using virpipe by default. And it could increase the smoothness of the desktop environment. If a program crashes when virpipe is enabled, use GALIUM_DRIVER=llvmpipe <program name> to fallback to CPU rendering.

4.2. In chroot
#

  1. Setup a chroot environment, for exmaple chroot Ubuntu with XFCE4

  2. Set SELinux to Permissive

sudo setenforce 0
  1. Start Termux X11 APP. Go back to Termux, execute:
XDG_RUNTIME_DIR=${TMPDIR} termux-x11 :0 -ac &
  1. Mount Termux’s tmp to chroot’s tmp directory
export CHROOT_DIR=/data/local/tmp/chrootubuntu
sudo busybox mount --bind $PREFIX/tmp $CHROOT_DIR/tmp
  1. Log into chroot. Start XFCE4
sudo chmod -R 777 /tmp
export DISPLAY=:0 PULSE_SERVER=tcp:127.0.0.1:4713
dbus-launch --exit-with-session startxfce4 &
  1. Run apps with virgl
GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.0 minetest

4.3. Run Windows games
#

Install Box86 + Wine in proot-distro.

Start virgl server in Termux.

Run box86 with GALLIUM_DRIVER parameters:

GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.0 box86 wine AIR.exe

“Undertale” works well with virgl enabled.

Also visual novel “Air”

References
#

Related


此處提供二種留言板。點選按鈕,選擇您覺得方便的留言板。

(留言板載入中)這是Giscus留言板,需要Github帳號才能留言。支援Markdown語法,若要上傳圖片請善用外部圖床。您的留言會在Github Discussions向所有人公開。

Click here to edit your comments.

(留言板載入中)這是Disqus留言板,您可能會看到Disqus強制投放的廣告。為防止垃圾內容,有時留言可能會被系統判定需審核,導致延遲顯示,請見諒。若要上傳圖片請善用外部圖床網站。