termux-packages icon indicating copy to clipboard operation
termux-packages copied to clipboard

[Bug]: Unable to use virpipe inside debian chroot

Open Hecori opened this issue 9 months ago • 11 comments

Problem description

I was able to install xfce4 on Termux and it worked quite well, when i started the android virgl server on termux and tried using GALLIUM_DRIVER=virpipe glxinfo it worked fine.

Then i tried doing the same but instead of running it on native termux i tried using chroot to setup a debian system. I was unable to make glxinfo work or any program work using virpipe.

Here is the output of some commands inside chroot and termux:

Termux:

~ $ virgl_test_server_android 
vtest_client_dispatch_commands: client context created.
client: VTEST_CLIENT_DISCONNECTED

Debian Chroot:

rei@localhost:/tmp$ GALLIUM_DRIVER=virpipe glxinfo
name of display: :0.0
lost connection to rendering server on 8 read -1 22
Aborted
rei@localhost:/tmp$ sudo GALLIUM_DRIVER=virpipe glxinfo
name of display: :0.0
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  73 (X_GetImage)
  Serial number of failed request:  45
  Current serial number in output stream:  45

I am able to fix the first error by changing the permissions on the "/tmp/.virgl_test" file inside chroot, but not the second error. I also added the files i am using to start chroot/debian, i execute them in this order:

startxfce4_chrootDebian.sh.txt start_debian.sh.txt start_xfce.sh.txt

I installed the chroot from here: Debian Chroot

I modified the original scripts because they were quite broken.

What steps will reproduce the bug?

1 - Have a fully working Debian 13 chroot on termux. 2 - Start "virgl_test_server_android". 3 - Boot into chroot. 4 - Type "sudo GALLIUM_DRIVER=virpipe glxinfo" onto the terminal.

What is the expected behavior?

Glxinfo should execute normally and show the OpenGL info.

System information

Termux Variables:
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP__APK_FILE=/data/app/~~Ia4qoKmhTtMrw1__81N1gw==/com.termux-C0PGVo5sKlYV7UUNPnVdTQ==/base.apk
TERMUX_APP__APK_RELEASE=F_DROID
TERMUX_APP__APP_VERSION_CODE=1020
TERMUX_APP__APP_VERSION_NAME=0.119.0-beta.1
TERMUX_APP__DATA_DIR=/data/user/0/com.termux
TERMUX_APP__IS_DEBUGGABLE_BUILD=false
TERMUX_APP__IS_INSTALLED_ON_EXTERNAL_STORAGE=false
TERMUX_APP__PACKAGE_NAME=com.termux
TERMUX_APP__PID=4204
TERMUX_APP__TARGET_SDK=28
TERMUX_VERSION=0.119.0-beta.1
TERMUX__SE_FILE_CONTEXT=u:object_r:app_data_file:s0:c187,c256,c512,c768
TERMUX__SE_INFO=default:targetSdkVersion=28:complete
TERMUX__SE_PROCESS_CONTEXT=u:r:untrusted_app_27:s0:c187,c256,c512,c768
TERMUX__UID=10187
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://mirrors.pku.edu.cn/termux/termux-main/ stable main
# x11-repo (sources.list.d/x11.list)
deb https://packages-cf.termux.dev/apt/termux-x11/ x11 main
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
Updatable packages:
apt/stable 2.8.1-1 aarch64 [upgradable from: 2.7.14]
bash/stable 5.2.37-2 aarch64 [upgradable from: 5.2.26-1]
ca-certificates/stable 1:2025.02.25 all [upgradable from: 1:2024.03.11-2]
command-not-found/stable 2.4.0-67 aarch64 [upgradable from: 2.4.0-29]
coreutils/stable 9.6-1 aarch64 [upgradable from: 9.5]
curl/stable 8.12.1 aarch64 [upgradable from: 8.8.0]
debianutils/stable 5.21 aarch64 [upgradable from: 5.19]
diffutils/stable 3.11 aarch64 [upgradable from: 3.10]
dpkg/stable 1.22.6-1 aarch64 [upgradable from: 1.22.6]
ed/stable 1.21 aarch64 [upgradable from: 1.20.2]
findutils/stable 4.10.0 aarch64 [upgradable from: 4.9.0-2]
gpgv/stable 2.4.5-3 aarch64 [upgradable from: 2.4.5-1]
inetutils/stable 2.6 aarch64 [upgradable from: 2.4-1]
less/stable 668 aarch64 [upgradable from: 633-1]
libandroid-support/stable 29 aarch64 [upgradable from: 28-3]
libassuan/stable 3.0.1-2 aarch64 [upgradable from: 2.5.7]
libc++/stable 27c aarch64 [upgradable from: 26b]
libcurl/stable 8.12.1 aarch64 [upgradable from: 8.8.0]
libgcrypt/stable 1.11.0 aarch64 [upgradable from: 1.10.3]
libgmp/stable 6.3.0-1 aarch64 [upgradable from: 6.3.0]
libgnutls/stable 3.8.9 aarch64 [upgradable from: 3.8.5]
libgpg-error/stable 1.50 aarch64 [upgradable from: 1.49]
libiconv/stable 1.18 aarch64 [upgradable from: 1.17]
liblzma/stable 5.6.4 aarch64 [upgradable from: 5.6.2]
libnettle/stable 3.10.1 aarch64 [upgradable from: 3.9.1]
libnghttp2/stable 1.65.0 aarch64 [upgradable from: 1.62.1]
libnghttp3/stable 1.8.0 aarch64 [upgradable from: 1.3.0]
libsmartcols/stable 2.40.2-3 aarch64 [upgradable from: 2.39.3-4]
libssh2/stable 1.11.1 aarch64 [upgradable from: 1.11.0]
libtirpc/stable 1.3.6 aarch64 [upgradable from: 1.3.4-1]
libunbound/stable 1.22.0 aarch64 [upgradable from: 1.20.0]
libunistring/stable 1.3 aarch64 [upgradable from: 1.1]
lsof/stable 4.99.4 aarch64 [upgradable from: 4.99.3]
nano/stable 8.3 aarch64 [upgradable from: 8.0]
openssl/stable 1:3.4.1 aarch64 [upgradable from: 1:3.2.1-1]
patch/stable 2.7.6-4 aarch64 [upgradable from: 2.7.6-3]
pcre2/stable 10.45 aarch64 [upgradable from: 10.44]
readline/stable 8.2.13 aarch64 [upgradable from: 8.2.10]
termux-am/stable 0.8.0-1 all [upgradable from: 0.8.0]
termux-exec/stable 1:2.1.0-1 aarch64 [upgradable from: 1:1.0]
termux-keyring/stable 3.12-1 all [upgradable from: 3.12]
termux-licenses/stable 2.1 all [upgradable from: 2.0-3]
termux-tools/stable 1.45.0 all [upgradable from: 1.42.4]
util-linux/stable 2.40.2-3 aarch64 [upgradable from: 2.39.3-4]
xxhash/stable 0.8.3 aarch64 [upgradable from: 0.8.2]
xz-utils/stable 5.6.4 aarch64 [upgradable from: 5.6.2]
zstd/stable 1.5.7 aarch64 [upgradable from: 1.5.6]
termux-tools version:
1.42.4
Android version:
12
Kernel build information:
Linux localhost 4.9.297-perf/mi439-g3ce83b96c7ea #1 SMP PREEMPT Thu Mar 3 06:28:39 UTC 2022 aarch64 Android
Device manufacturer:
Xiaomi
Device model:
Redmi 7A
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so

Hecori avatar Mar 23 '25 05:03 Hecori

Did you mount termux's /tmp to your chroot?

twaik avatar Mar 23 '25 05:03 twaik

Did you mount termux's /tmp to your chroot?

Yes with: busybox mount --bind $PREFIX/tmp /data/local/tmp/chrootDebian/tmp

The full code:


#!/bin/sh

#Path of DEBIAN rootfs
DEBIANPATH="/data/local/tmp/chrootDebian"

# Fix setuid issue
busybox mount -o remount,dev,suid /data

busybox mount --bind /dev $DEBIANPATH/dev
busybox mount --bind /sys $DEBIANPATH/sys
busybox mount --bind /proc $DEBIANPATH/proc
busybox mount -t devpts devpts $DEBIANPATH/dev/pts
busybox mount --bind $PREFIX/tmp /data/local/tmp/chrootDebian/tmp

# /dev/shm for Electron apps
mkdir $DEBIANPATH/dev/shm
busybox mount -t tmpfs -o size=256M tmpfs $DEBIANPATH/dev/shm

# Mount sdcard
mkdir $DEBIANPATH/sdcard
busybox mount --bind /sdcard $DEBIANPATH/sdcard

# chroot into DEBIAN
busybox chroot $DEBIANPATH /usr/bin/env -i PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin/ DISPLAY=:0 PULSE_SERVER=127.0.0.1 /bin/su rei

Hecori avatar Mar 23 '25 05:03 Hecori

Maybe try passing --angle-gl flag at the virgl command?

queso42 avatar Mar 23 '25 16:03 queso42

Maybe try passing --angle-gl flag at the virgl command?

Tried doing that and it seems like the error message is somewhat different?

Termux:

~ $ virgl_test_server_android --angle-gl
vrend_winsys_make_context_current: Error switching context: EGL_BAD_ACCESS
vtest_client_dispatch_commands: client context created.
client: VTEST_CLIENT_DISCONNECTED

Chroot:

rei@localhost:~$ sudo GALLIUM_DRIVER=virpipe glxinfo
[sudo] password for rei: 
name of display: :0.0
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  73 (X_GetImage)
  Serial number of failed request:  45
  Current serial number in output stream:  45

I mean it is still the same on Chroot, but not on Termux.

Hecori avatar Mar 23 '25 16:03 Hecori

This is the output of glmark2 on termux:

rei@localhost:~$ sudo GALLIUM_DRIVER=virpipe glmark2
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
** Failed to set swap interval. Results may be bounded above by refresh rate.
=======================================================
    glmark2 2023.01
=======================================================
    OpenGL Information
    GL_VENDOR:      Mesa
    GL_RENDERER:    virgl (Adreno (TM) 505)
    GL_VERSION:     2.1 Mesa 25.0.1-2
    Surface Config: buf=32 r=8 g=8 b=8 a=8 depth=24 stencil=0 samples=0
    Surface Size:   800x600 windowed
=======================================================
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
** Failed to set swap interval. Results may be bounded above by refresh rate.
[build] use-vbo=false: FPS: 35 FrameTime: 29.156 ms
=======================================================
                                  glmark2 Score: 34 
=======================================================

But i am still not able to run anything else with virpipe.

Hecori avatar Mar 23 '25 18:03 Hecori

~~if your gpu is adreno, why not use freedreno?~~

yeah, the source you followed for chroot don't have a tutorial for freedreno on chroot

queso42 avatar Mar 23 '25 21:03 queso42

~if your gpu is adreno, why not use freedreno?~

yeah, the source you followed for chroot don't have a tutorial for freedreno on chroot

Is there any guide about compiling freedreno drivers on a chroot environment for an Adreno 505 gpu? I saw something about about installing/compiling "zink+turnip", but it does not seem to support my gpu.

I saw this old guide but some links seem to be dead: Adreno 5xx Drivers But i do not think they are Chroot related.

Hecori avatar Mar 23 '25 23:03 Hecori

Maybe try GALLIUM_DRIVER=kgsl?

queso42 avatar Mar 24 '25 04:03 queso42

The failure of glxinfo is introduced by https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11714. I fixed it in Termux by partially revert that commit, see https://github.com/termux/termux-packages/blob/master/packages/mesa/0009-disable-resource_create_front-for-vtest.patch.

As Termux doesn't have control to Debian packages, you should compile mesa from source with the patch above.

licy183 avatar Mar 24 '25 05:03 licy183

Maybe try GALLIUM_DRIVER=kgsl?

rei@localhost:~$ GALLIUM_DRIVER=kgsl glxinfo       
name of display: :1.0
glx: failed to create drisw screen
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  150 (GLX)
  Minor opcode of failed request:  24 (X_GLXCreateNewContext)
  Value in failed request:  0x0
  Serial number of failed request:  30
  Current serial number in output stream:  31

(Same output running it as sudo or using --angle-gl on the server)

Hecori avatar Mar 25 '25 01:03 Hecori

The failure of glxinfo is introduced by https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11714. I fixed it in Termux by partially revert that commit, see https://github.com/termux/termux-packages/blob/master/packages/mesa/0009-disable-resource_create_front-for-vtest.patch.

As Termux doesn't have control to Debian packages, you should compile mesa from source with the patch above.

I see, is there a guide that i could use to build a package using a that patch? (Never built a package in termux before)

Edit 1:

This is the directory i have:

~/.../packages/mesa $ ls
0000-disable-android-detection.patch            0009-disable-resource_create_front-for-vtest.patch
0001-disable-multithreading-for-llvmpipe.patch  0010-merge-request-35580.patch
0002-fix-for-getprogname.patch                  0011-lld-undefined-version.patch
0003-fix-for-anon-file.patch                    build.sh
0004-do-not-check-xlocale.patch                 cmake-wrapper.in
0005-virgl-socket-path.patch                    mesa-dev.subpackage.sh
0006-wsi-no-pthread_cancel.patch                mesa-vulkan-icd-freedreno.subpackage.sh
0007-use-mtx_t-operations-in-turnip.patch       mesa-vulkan-icd-swrast.subpackage.sh
0008-workaround-fortify-check.patch             osmesa.subpackage.sh

Edit 2: I'm able to run this after i removed mesa: bash build-package.sh mesa And everything build normally, but i do not know how to choose the 9th patch.

Edit 3: This is what i have:

~ $ cd termux-packages/
~/termux-packages $ cd packages/
~/termux-packages/packages $ cd mesa/
~/.../packages/mesa $ git apply 0009-disable-resource_create_front-for-vtest.patch 
error: packages/mesa/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c: No such file or directory

Hecori avatar Mar 25 '25 01:03 Hecori

How does https://github.com/brunodev85/winlator use the GPU?

cnlnr avatar Nov 05 '25 02:11 cnlnr

GPU acceleration is handled by the relevant Mesa drivers for your device's GPU, how exactly Winlator determines what to enable is only relevant in so far as it may be applied to the x11/mesa package in this repository.

You should search or ask in the winlator repository if you want more detail about their implementation of it.

TomJo2000 avatar Nov 05 '25 02:11 TomJo2000