meefik / linuxdeploy

Install and run GNU/Linux on Android
https://meefik.github.io/linuxdeploy
GNU General Public License v3.0
5.09k stars 681 forks source link

DRI for gpu acceleration? #1171

Open 1640675651 opened 4 years ago

1640675651 commented 4 years ago

Most new devices does not support traditional framebuffer, but they have DRI support(i.e. /dev/dri/card0 exists). Does this provide a new way for gpu 3d acceleration?

Grima04 commented 3 years ago

I am a bit late to the party, but I actually asked myself the same question which lead me to start messing around with this idea. I installed an AARCH64 Ubuntu chroot on my phone (Xiaomi Black Shark 3, Adreno 650 GPU, Android 10, root access) via Termux and then tried to get Freedreno to work in the chroot but I didn't succeed yet in getting 3D acceleration to work. I compiled Mesa myself for Freedreno and I also tried to install the precompiled drivers with apt but to no avail. Afterwards I compiled drm_info (https://github.com/ascent12/drm_info) to see if the dev/dri/card0 device gets recognized at all and it did work, I got an output from the program: drm-info-log-adreno650.txt I also tried to get glmark2-drm to work but it seems to lack Adreno-DRM support. I am just wondering how to get Freedreno to work, maybe I just compiled it with the wrong arguments but we need someone with more knowledge to shed some light on this idea.

Grima04 commented 3 years ago

I found out that apparently the Freedreno OpenGL and OpenGL ES driver won't work on Android because Android uses KGSL for Adreno GPUs. It looks like the Freedreno/Turnip Vulkan driver supports KGSL though, so I tried to compile Mesa with meson and the arguments -Dgallium-drivers= -Dvulkan-drivers=freedreno -Dfreedreno-kgsl=true but unfortunately the compiler throws some errors and doesn't finish the compilation, so I am still stuck. Hopefully those errors will get fixed in another Mesa version.

Fr1z commented 3 years ago

@Grima04 you still got farther than many including me :) Btw, could you show us how you compile Mesa and what kind of error do you get? maybe some of us will be luckier

I'm currently a bit busy to develop an android app to supplement camera and microphone stream to chrooted linux but I will throw myself into this for the next step

Grima04 commented 3 years ago

@Fr1z Thanks for the compliment :) . I really tried my best but my main problem is the lack of C/C++ knowledge which makes it impossible for me to troubleshoot and fix the compilation issues in Mesa. I only know how to code basic stuff in Java for Desktop and Android.

Sure, no problem, I will write below how I setup Ubuntu on Termux and tried to compile Mesa for Adreno. I used the premade scripts from AnLinux (App available on Google Play) to setup Ubuntu on Termux, since their script installs Ubuntu Focal 20.04, which gives you less headaches with outdated packages than with Ubuntu Bionic 18.04. On Ubuntu 20.04 I only had to recompile one outdated package, but it looks like they updated it now, so this step isn't needed anymore.

After the setup of the AnLinux Ubuntu environment, I proceeded as follows: apt-get update apt install git apt-get build-dep mesa git clone https://gitlab.freedesktop.org/mesa/mesa cd mesa mkdir build

for some reason drm.h and drm_mode.h were not in /usr/include but in /usr/include/drm so I needed to copy them over

meson build -Dgallium-drivers= -Dvulkan-drivers=freedreno -Dfreedreno-kgsl=true ninja -C build

Afterwards, Mesa starts compiling as usual and it begins to fail at the very end, when nearly finished. This is the log that I saved via the terminal to a text file: turnip-freedreno-kgsl-compilation-error.txt

Your project sounds really interesting, I will definitely keep an eye on it. I am also currently working on an app for rooted Android devices which will emulate Windows x86 games, however I really need a way to get 3D acceleration working (Desktop OpenGL because that's what Wine needs) since software rendering isn't going to cut it. It basically works by chrooting into a premade Ubuntu Focal rootfs with Wine x86 and box86 (an x86 emulator) preinstalled and then launching box86 and Wine via shell commands, while using XServer XSDL as the X Server. The app itself isn't too complex since it does everything with shell commands, so it was possible for me to write it entirely in Java.

Fr1z commented 3 years ago

Hey @Grima04 Thanks 4 Sharing. it seems mostly a declaration type error from linux/types.h or linux/ioctl.h

make sure you have installed and updated linux-headers To install the headers files for the currently kernel:

sudo apt update sudo apt install linux-headers-$(uname -r) sudo apt install libc6-dev

i don't know if they actually fit on an emulated linux, just try it. btw I hope to publish a first version of the app by mid-February :)

Grima04 commented 3 years ago

@Fr1z No problem :)

Thanks for the explanation and help, I tried to install libc6-dev which was successful. Afterwards I tried to install the linux headers but it looks like they aren't available on Ubuntu for the kernel version of my device (4.19.81-perf+) since entering the command results in "Unable to locate package linux-headers-4.19.81-perf" which is unfortunate.

Meanwhile I have also looked for other ideas on how to get 3D acceleration on Linux chroots and there are indeed some projects with this idea in mind, notably the LOAX project (https://github.com/jeffboody/loax-server/tree/loax2020) and a port of virgl to Android (https://github.com/mittorn/virglrenderer-android and https://github.com/mittorn/virglrenderer). Virgl would be the best project since it also performs OpenGL to OpenGL ES translation but unfortunately the project is abandoned. It uses an old version of virgl which only provides broken OpenGL 2.1 support and the APK to render the graphics has a native library which breaks on Android 10+ devices (I am not really sure how to recompile it for Android 10 targets). Newer virgl versions support up to OpenGL 4.3 emulation ontop of GLES 3.2 I think, which is amazing. I am not sure how much work it would be to update the port with a newer virgl version but from what I have seen it is quite fast and it would probably be worth it (Here is a video comparing the performance of Mesa LLVMpipe and virgl that I found: https://youtu.be/NbG1DLnxGq8).

I am already looking forward to your project, it sounds really promising. Do you also have plans to implement gamepad data streaming from Android to the Linux chroot? It would be nice to have an option to use a gamepad on Linux chroots to play some games (in case we get 3D acceleration working somehow of course).

Heasterian commented 3 years ago

@Grima04 Couldn't usage of whole compiled https://android.googlesource.com/platform/external/virglrenderer/ and usage of virgl_test_server from vtest using android terminal emulator would work fine with mounting of unix socket in chroot?

Heasterian commented 3 years ago

I'm also missing headers for this kernel version and that's why I have issues with vk driver compilation.

moocow1452 commented 3 years ago

I was also poking around with the idea of modifying the ANGLE Driver project in order to write more functionality into the driver and then side load it instead of dealing with the native Android drivers. I'm a bit in over my head, but I can report back if I find anything promising.