Archlinux: X GPU Acceleration Guide

Post Reply
jgmdev
Posts: 212
Joined: Tue Jan 28, 2020 2:28 pm
languages_spoken: english, spanish
ODROIDs: U2, N2, N2+, C4
Has thanked: 80 times
Been thanked: 147 times
Contact:

Archlinux: X GPU Acceleration Guide

Post by jgmdev »

Edit: added Odroid N2+ instructions

So @tobetter notified me of newer fbdev mali driver packages for Ubuntu and as in previous GPU Acceleration Guide (which uses wayland) I now worked on packages to enable gpu acceleration on Odroid N2 but this time under X11/XServer! This post will include almost same instructions as in previous post for the reader convenience.

What Works?

Here is a list of what has been tested so far divided in 2 categories (for now):

List of Environments
  • YES = Usable
  • PARTIALLY = Partially starts, Black artifacts, etc...
  • NO = Doesn't starts
Environment Status Notes
XFCE YES Works great with xfwm4!
Mate YES
LXDE Gtk2 YES
LXDE Gtk3 YES
LXQT YES
KDE PARTIALLY Desktop doesn't fully loads
GNOME NO Not even wall papaer loads, seems to have issues with GL4ES and FBDEV driver.
List of Applications
  • YES = Usable
  • STARTS = Starts but crashes.
  • NO = Doesn't starts
Application Status Notes
SuperTux2 YES Smooth!
OpenArena YES Display refresh rate isn't detected by gl4es so I think it caps up to 40fps, but feels smooth enough (needs small aarch64 change).
Minetest YES Compile without luajit which seems to have issues on aarch64.
Cendric YES https://github.com/tizian/Cendric2 (PKGBUILD on repo)
Trigger Rally YES https://trigger-rally.sourceforge.io/ (PKGBUILD on AUR)
Freedoom YES Tested with chocolate-doom and odamex
Serious Sam TFE and TSE YES TFE encounter runs perfectly, TSE hangs when starting a campaing but if loading a map manually works normally.
MPV YES With SDL2 backend that needs to be enabled at compile time. (see this post for details)
VLC YES With OpenGL video playback backend videos run smooth, just press F to go fullscreen because gl4es with fbdev in fullscreen will leave everything else in black, but moving the mouse shows ui controls.
Firefox YES WebGL websites crash the opened tab.

Requirements for regular Odroid N2 (non plus)

First you will need to install linux-aarch64, a requirement by the latest Mali kernel driver (dkms-mali-bifrost) which was patched by tobetter to work on these latest kernel versions which at time of writing was 5.7:

Code: Select all

sudo pacman -S linux-aarch64
Then modify your /boot/boot.ini file to be able to boot from this kernel, here is a working boot.ini example:

Code: Select all

ODROIDN2-UBOOT-CONFIG

# System Label
ODROIDN2-UBOOT-CONFIG

# System Label
setenv bootlabel "ArchLinux"

# Default Console Device Setting
setenv condev "console=ttyAML0,115200n8"

# Boot Args
setenv bootargs "root=/dev/mmcblk${devno}p2 rootwait rw mitigations=off ${condev} ${amlogic} no_console_suspend fsck.repair=yes net.ifnames=0 clk_ignore_unused"

# Set load addresses
setenv dtb_loadaddr "0x20000000"
setenv loadaddr "0x1080000"
setenv initrd_loadaddr "0x3080000"

# Load kernel, dtb and initrd
load mmc ${devno}:1 ${loadaddr} /Image
load mmc ${devno}:1 ${dtb_loadaddr} /dtbs/amlogic/meson-g12b-odroid-n2.dtb
load mmc ${devno}:1 ${initrd_loadaddr} /initramfs-linux.uimg

# boot
booti ${loadaddr} ${initrd_loadaddr} ${dtb_loadaddr}
Don't forget to modify the root device from root=/dev/mmcblk${devno}p2 to the device that matches your setup.

Requirements for regular Odroid N2+

The mainstream ArchLinuxArm linux-aarch64 or linux-aarch64-rc packages don't have support for the Odroid N2+ higher cpu frequencies yet (I submitted the needed changes here but they are still pending review) so you will need to install this kernel from my github repo instead. Also you will have to update u-boot to latest version provided by hardkernel which I also wrote a simple PKGBUILD. Pre-built packages can be found on my mega account.

For the Odroid N2+ the /boot/boot.ini file should look something like:

Code: Select all

ODROIDN2-UBOOT-CONFIG

setenv board "odroidn2"

# System Label
setenv bootlabel "ArchLinux"

# Default Console Device Setting
setenv condev "console=ttyAML0,115200n8"

# Boot Args
setenv bootargs "root=/dev/mmcblk${devno}p2 rootwait rw mitigations=off ${condev} ${amlogic} no_console_suspend fsck.repair=yes net.ifnames=0 clk_ignore_unused"

# Set load addresses
setenv dtb_loadaddr "0x20000000"
setenv loadaddr "0x1080000"
setenv initrd_loadaddr "0x3080000"

# Load kernel, dtb and initrd
load mmc ${devno}:1 ${loadaddr} /Image
load mmc ${devno}:1 ${dtb_loadaddr} /dtbs/amlogic/meson64_odroid${variant}.dtb
load mmc ${devno}:1 ${initrd_loadaddr} /initramfs-linux.uimg

# boot
booti ${loadaddr} ${initrd_loadaddr} ${dtb_loadaddr}
Note: you can also use this kernel, u-boot and boot.ini on regular Odroid N2, so it is your choice.

X11 GPU Acceleration

Now you should proceed to clone the repository where I added the PKGBUILD's to enable the acceleration:

Code: Select all

git clone https://github.com/jgmdev/archlinux-odroid
The first package that needs to be installed is the Mali kernel driver which should be the dkms-mali-bifrost package:

Code: Select all

cd dkms-mali-bifrost
makepkg
sudo pacman -U dkms-mali-bifrost-24.0+202005011205-1-aarch64.pkg.tar.zst
Then you will need to install the user space fbdev binary driver known as libMali.so, which interacts with the kernel driver part and is provided by the odroid-n2-libgl-fb package:

Code: Select all

cd odroid-n2-libgl-fb
makepkg
sudo pacman -U odroid-n2-libgl-fb-0.1-5-aarch64.pkg.tar.zst
Also thanks to @meveric I was able to properly configure gl4es to translate the GL calls into the EGL library provided by libMali.so (odroid-n2-libgl-fb) that lets you run the software listed above which uses desktop OpenGL v2. So lastly you will need to install odroid-gl4es:

Code: Select all

cd odroid-gl4es
makepkg
sudo pacman -U odroid-gl4es-2200.14e6f33-1-aarch64.pkg.tar.zst
After installing these packages you may restart the system to make sure that the changes will take effect.

Important Note: The mali fbdev driver doesn't has full support for GL4ES because it doesn't implements X11 rendering so LIBGL_FB=1 is used, which is described by gl4es developers as "Use Framebuffer output (x11 bypassed, only fullscreen)", meaning that everything else will be rendered black while the GL application is active. Make sure to disable compositing when launching GL applications and if possible set a desktop shortcut to switch windows into fullscreen mode which becomes handy when launching GL applications.

Applications

For now I have only tested the applications listed above and screenshots could not be taken directly because the applications are rendering directly to the frame buffer.

Supertux

Simple game but shows that gl4es is doing a proper job, because without it the game renders like an old grandpa.

Code: Select all

sudo pacman -S supertux
Image

OpenArena

This one is a quake3 engine based open source game that many already know about on the forums and surprisingly runs pretty well using the fbdev driver + gl4es combo. I added a PKGBUILD on my repo since it isn't distributed yet on the official ArchlinuxARM repositories.

First you will need to install libxmp:

Code: Select all

cd libxmp
makepkg
sudo pacman -U libxmp-4.4.1-1-aarch64.pkg.tar.zst
Install any other dependencies and proceed to build the engine, download the game assets and install:

Code: Select all

cd openarena
makepkg
sudo pacman -U openarena-0.8.8-3-aarch64.pkg.tar.zst
Image

Troubleshooting

Monitor screen resolution is not properly set with mainline kernel and instead a lower resolution is used.

You can pass a parameter to the kernel to force a screen resolution as explained on the ArchLinux wiki. First you need to retrieve the proper display connector name by executing the following code on your terminal emulator:

Code: Select all

for p in /sys/class/drm/*/status; do con=${p%/status}; echo -n "${con#*/card?-}: "; cat $p; done
This code would return something like:

Code: Select all

HDMI-A-1
Then edit your /boot/boot.ini and append to your bootargs a line like:

Code: Select all

video=HDMI-A-1:1920x1080@60
Which should look similar to:

Code: Select all

setenv bootargs "root=/dev/sda2 rootwait rw mitigations=off ${condev} ${amlogic} no_console_suspend fsck.repair=yes net.ifnames=0 clk_ignore_unused video=HDMI-A-1:1920x1080@60"
Last edited by jgmdev on Thu Aug 27, 2020 10:36 am, edited 11 times in total.
These users thanked the author jgmdev for the post (total 5):
mad_ady (Thu May 14, 2020 7:35 pm) • istanbulls (Thu May 14, 2020 9:09 pm) • odroid (Fri May 15, 2020 9:16 am) • joy (Tue May 19, 2020 10:21 am) • Payano (Wed May 20, 2020 4:26 am)

allanmac
Posts: 5
Joined: Mon May 04, 2020 2:00 am
languages_spoken: english
ODROIDs: N2
Has thanked: 0
Been thanked: 0
Contact:

Re: Archlinux: X GPU Acceleration Guide

Post by allanmac »

Can you please install `vulkaninfo`, run it, and and attach the results here?

I'd like to see what capabilities are being advertised by this version of the driver (R24?).

Edit: I'm assuming there is a Vulkan ICD installed and the Mali driver supports Vulkan -- which might be an incorrect assumption! :)

In the past, I've seen that the mali.so contains both OpenCL and Vulkan entry points.

jgmdev
Posts: 212
Joined: Tue Jan 28, 2020 2:28 pm
languages_spoken: english, spanish
ODROIDs: U2, N2, N2+, C4
Has thanked: 80 times
Been thanked: 147 times
Contact:

Re: Archlinux: X GPU Acceleration Guide

Post by jgmdev »

Sadly readelf -s /usr/lib/libMali.so | grep vk returns nothing :( so no vulkan, but it does supports OpenCL. If vulkan was supported our possibilities may have been better.

allanmac
Posts: 5
Joined: Mon May 04, 2020 2:00 am
languages_spoken: english
ODROIDs: N2
Has thanked: 0
Been thanked: 0
Contact:

Re: Archlinux: X GPU Acceleration Guide

Post by allanmac »

Darn, thanks for checking it out!

Hopefully Vulkan appears soon.

User avatar
odroid
Site Admin
Posts: 35846
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1299 times
Been thanked: 907 times
Contact:

Re: Archlinux: X GPU Acceleration Guide

Post by odroid »

As far as I heard, Amlogic will not license the Vulkan Linux DDK from ARM in the near future. They licensed the Vulkan Android DDK only unfortunately. :(

jgmdev
Posts: 212
Joined: Tue Jan 28, 2020 2:28 pm
languages_spoken: english, spanish
ODROIDs: U2, N2, N2+, C4
Has thanked: 80 times
Been thanked: 147 times
Contact:

Re: Archlinux: X GPU Acceleration Guide

Post by jgmdev »

So I was playing around with GL4ES which is a great project to get this boards supporting desktop opengl via opengl es and faced some issues like glxgears and all 3d applications capped at 45-48FPS. Also glmark2 wasn't running so I contacted the developer and he fixed the glmark2 issue so latest git code now runs it with libmali fbdev edition!

Now, about the FPS been capped, I made a discovery, not sure if only me but you may notice that when starting the system the display starts with a refresh rate set to 0.0hz (that shouldn't be nothing new), so something seems to be wrong on the display initialization code at the kernel site. And here is the discovery, if one adds some xorg configuration to force the refresh rate to 60.0hz like:

Code: Select all

Section "Monitor"
    Identifier    "External Monitor"
    Modeline      "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
    Modeline      "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
    Modeline      "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
    Modeline      "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync
    Modeline      "1280x720_60.00"   74.50  1280 1344 1472 1664  720 723 728 748 -hsync +vsync
    Modeline      "1024x768_75.00"   82.00  1024 1088 1192 1360  768 771 775 805 -hsync +vsync
    Modeline      "800x600_75.00"   49.00  800 840 920 1040  600 603 607 629 -hsync +vsync
    Modeline      "640x480_75.00"   30.75  640 664 728 816  480 483 487 504 -hsync +vsync
    Option        "PreferredMode" "1920x1080_60.00"
EndSection

Section "Device"
        Identifier      "FBTURBO"
        Driver          "fbturbo"
        Option          "fbdev" "/dev/fb0"

	Option          "SwapbuffersWait"       "false"
        Option          "alpha_swap" "false"
	Option        "Monitor-HDMI-1" "External Monitor"
EndSection

Section "Screen"
    Identifier    "Primary Screen"
    Device        "FBTURBO"
    DefaultDepth   24
    SubSection "Display"
        Depth      24
        Modes      "1920x1080" "1680x1050" "1280x1024" "1440x900" "1280x720" "1024x768" "800x600" "640x480"
    EndSubSection
EndSection

Section "ServerLayout"
    Identifier    "Default Layout"
    Screen        "Primary Screen"
EndSection
then the glxgears or any other 3d application instead of giving only 45-48FPS, give up to a constant 70fps under the fbdev driver, the only issue is that now the rendering is triplicated so I see 3 glxgears rendered at the same time:

Image

This time I think it is a libmali or fbdev X driver configuration issue because using glmark-es2-fbdev also presents the same FPS cap depending on display refresh rate. Already tried vblank_mode=0 but that didn't worked and I'm wondering if libMali.so supports environment variables to control its behaviour... searched on the web but didn't found nothing...

Also as said before the gl4es developer fixed the issues with the wrapper, which affected libmali and glmark2 (not launching) and who knows if other applications that may have been suffering the same. In order to run the whole glmark2 process (besides compiling gl4es from git, PKGBUILD for archlinux on my github repo) one also needs to set the environment variable LIBGL_GL=30 so it exposes some fake opengl 3.0 support needed by some applications like glmark2 itself. Also as reported on first post firefox tabs with webgl stuff where crashing but with all this new changes they aren't anymore. Read that serious sam the first encounter and second encounter was able to run under GL4ES and bought it on GOG.com (only $3 dollars!) just to see how it performed on the Odroid N2 and it runs pretty smooth.

If the display refresh rate issue is fixed I guess that one could at least get the 60FPS experience on GL applications which would make them more smooth, and in the future if GL4ES keeps evolving then accelerated X compositors would also work. I wonder if this FPS cap can also affect video playback performance... Tested VLC and the OpenGL backend and performance is better but since the mali fbdev driver and gl4es is only capable of rendering at good performance on full screen you get lots of black screen interfering with X windows so you have to press F to go fullscreen. Note: on the image I distributed SuperKey + Q closes an application, in case you don't see where to click :D
These users thanked the author jgmdev for the post (total 2):
Sav (Sun May 24, 2020 5:05 pm) • istanbulls (Sun May 24, 2020 10:05 pm)

jgmdev
Posts: 212
Joined: Tue Jan 28, 2020 2:28 pm
languages_spoken: english, spanish
ODROIDs: U2, N2, N2+, C4
Has thanked: 80 times
Been thanked: 147 times
Contact:

Re: Archlinux: X GPU Acceleration Guide

Post by jgmdev »

Having fun testing stuff out (seems like kind of relaxing from normal work stuff) and trying to get the most of the deprecated mali-fbdev driver (which for now is the only acceleration alternative under a X11 environment), today I was playing around with the MPV video player and trying to make it work under GL4ES.

So all stories aside this is how I got mpv rendering videos pretty smooth using the mali-fbdev driver and GL4ES.

1. Compile and install MPV with the SDL2 backend enabled (PKGBUILD or Pre-built Package) (funny thing is that the sdl2 backend seems to be deprecated but in this case is the one that gets us the desired results)

2. Add following settings to ~/.config/mpv/mpv.conf

Code: Select all

vo = sdl
fullscreen = yes
3. Open any video file with MPV and you will notice the difference in rendering speed!

4. If you want to play firefox videos using mpv install the ff2mpv addon and then the ff2mpv-native-messaging-host-git package from AUR yay -S ff2mpv-native-messaging-host-git, restart firefox just in case and when viewing a video on sites like youtube, etc... search for a video, play it, then pause it. Click on the ff2mpv button on the top right side corner of firefox as shown on the screenshot below, wait some seconds and mpv should start playing the video.

Image

Remember that this method uses mali-fbdev which doesn't has proper X11 windowing support so it will render everything else black until the application that is doing the mali-fbdev rendering is closed. You can pause the video and use ALT + Tab if you need to do something else. To close MPV simply press q to quit.
These users thanked the author jgmdev for the post (total 2):
tobetter (Fri Aug 21, 2020 8:30 am) • Sav (Fri Aug 21, 2020 3:33 pm)

Post Reply

Return to “Other OS”

Who is online

Users browsing this forum: No registered users and 1 guest