8 8
dimag0g

OpenGL on Mali GPU (BananaPi, OrangePi PC, etc)

Recommended Posts

On 16 June 2016 at 9:18 AM, dimag0g said:

Hello,

 

I wish to share my research on getting OpenGL to work on Mali GPU. I realize Armbian focuses on server images, but I suppose many people would be interested nevertheless. I have a Banana Pi Pro and an Orange Pi PC, which both have a compatible GPU. Perhaps it will work on other boards as well.

 

Here are the commands I used to get OpenGL to work.

 

1. Install:


# install GLX Gears, mesa GL and GLU libraries 
apt-get -y install mesa-utils

# install development tools
apt-get -y install build-essential automake pkg-config libtool ca-certificates git cmake subversion
                                                                                
# install required libraries                                                 
apt-get install libx11-dev libxext-dev xutils-dev libdrm-dev x11proto-xf86dri-dev libxfixes-dev
                                   
#  get source code                                                                                        
git clone https://github.com/robclark/libdri2                                   
git clone https://github.com/linux-sunxi/libump                                 
git clone https://github.com/linux-sunxi/sunxi-mali                             
git clone https://github.com/ssvb/xf86-video-fbturbo                            
git clone https://github.com/ptitSeb/glshim

# install mali driver
cd sunxi-mali                                                                   
git submodule init                                                              
git submodule update                                                            
git pull                                                                        
wget http://pastebin.com/raw.php?i=hHKVQfrh -O ./include/GLES2/gl2.h            
wget http://pastebin.com/raw.php?i=ShQXc6jy -O ./include/GLES2/gl2ext.h   
make config ABI=armhf VERSION=r3p0                                              
mkdir /usr/lib/mali                                                             
echo "/usr/lib/mali" > /etc/ld.so.conf.d/1-mali.conf                            
make -C include install                                                         
make -C lib/mali prefix=/usr libdir='$(prefix)/lib/mali/' install           
cd ..

2. Build


# Step 1: build and install helper libraries                                    
                                                                                
cd libdri2                                                                      
autoreconf -i                                                                   
./configure --prefix=/usr                                                       
make                                                                            
make install                                                                    
cd ..                                                                           
                                                                                
cd libump                                                                       
autoreconf -i                                                                   
./configure --prefix=/usr                                                       
make                                                                            
make install                                                                    
cd ..                 

# Step 2: build video driver                              
                                                                                
cd xf86-video-fbturbo                                                           
autoreconf -i                                                                   
./configure --prefix=/usr                                                       
make                                                                            
make install                                                                    
cd ..     

# Step 3: build GL wrapper                                               
                                                                                
cd glshim                                                                       
cmake .                                                                         
make                                                                            
cp lib/libGL.so.1 /usr/lib/ # replace the software GL library with the wrapper
cd ..    

3. Configure your system

- configure your kernel to allocate memory for the GPU

- make sure mali and mali_drm kernel modules are loaded

- give your user permissions to access /dev/ump and /dev/mali

- configure Xorg to use fbturbo driver

 

4. Test:


# run a basic test
glxgears   

# install and run a GL benchmark 
apt-get -y install globs  
/usr/lib/globs/benchmarks/GL_pointz/gl_pointz                            

# try to run a real game
apt-get -y install billard-gl
billard-gl  

This all worked out for me rather nicely. The only issue I have encountered is a segfault that many GL programs get when they shut down. I'm currently debugging this issue, but it would be helpful to know others experience it as well, and perhaps get some advice from people experienced in GLX or SDL.

 

Edit: I know glxgears is not a real benchmark, but let me give you some numbers to make it clear what I'm talking about. Results are from Orange Pi PC clocked at 1296000 Hz (and are CPU-bound):


user@bananapi:~$ glxgears
LIBGL: Initialising glshim
libGL: built on Jun 12 2016 06:12:01
LIBGL: Current folder is:/home/user
libGL:loaded: libGLESv1_CM.so
libGL:loaded: libEGL.so
2074 frames in 5.0 seconds = 414.688 FPS
2071 frames in 5.0 seconds = 414.085 FPS
2070 frames in 5.0 seconds = 413.915 FPS
^C

 

Hi there,

 

I followed this for my pcDuino3 and it worked well except that graphics run slow, but better then they did before I followed this.

 

In step 3 you say to configure your kernel to allocate memory for the GPU. I am a bit unsure on what to do here and realise it is platform specific. However, could you provide any further instruction on why to do. I am booting of an SD card and have tried updating a file called uEnv.txt to add commands shown on the configure page to this but they don't seem to have any effect. 

 

Ultimately I am trying to run emulation station and tetrarch ala retropie on my pcDuino3. It has been challenging to say the least!

 

Any help or pointers you could give would be appreciated.

 

Thanks,

 

Greg

Share this post


Link to post
Share on other sites

Hello

 

finally it turns out that the package libglshim is missing alternative information. But this package is needed to use the Mali EGL driver as GL driver. 

To work around this we manually added the alternative information:

 

echo /usr/lib/arm-linux-gnueabihf/glshim > /usr/lib/arm-linux-gnueabihf/glshim/ld.so.conf
export DEB_HOST_MULTIARCH=arm-linux-gnueabihf
sudo update-alternatives --force --install /etc/ld.so.conf.d/${DEB_HOST_MULTIARCH}_GL.conf ${DEB_HOST_MULTIARCH}_gl_conf /usr/lib/${DEB_HOST_MULTIARCH}/glshim/ld.so.conf 500

Then we switched to glshim instead of Mesa for GL:

sudo update-alternatives --config arm-linux-gnueabihf_gl_conf
There are 2 choices for the alternative arm-linux-gnueabihf_gl_conf (providing /etc/ld.so.conf.d/arm-linux-gnueabihf_GL.conf).
  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/arm-linux-gnueabihf/mesa/ld.so.conf     500       auto mode
  1            /usr/lib/arm-linux-gnueabihf/glshim/ld.so.conf   500       manual mode
  2            /usr/lib/arm-linux-gnueabihf/mesa/ld.so.conf     500       manual mode
Choose 1 here

In addition we checked if Mali-EGL is used instead of Mesa-EGL:

sudo update-alternatives --config arm-linux-gnueabihf_egl_conf
There are 2 choices for the alternative arm-linux-gnueabihf_egl_conf (providing /etc/ld.so.conf.d/arm-linux-gnueabihf_EGL.conf).
  Selection    Path                                              Priority   Status
------------------------------------------------------------
* 0            /usr/lib/arm-linux-gnueabihf/mali-egl/ld.so.conf   600       auto mode
  1            /usr/lib/arm-linux-gnueabihf/mali-egl/ld.so.conf   600       manual mode
  2            /usr/lib/arm-linux-gnueabihf/mesa-egl/ld.so.conf   500       manual mode

And finally

sudo ldconfig

 

Now glxgears runs with 140FPS and 60% CPU on a Allwinner A20.

 

@Armbian Maintainers: It would be great if you could fix the libglshim package in the future and add the alternatives information.

 

Greetings 

Florian

Share this post


Link to post
Share on other sites
10 minutes ago, sans-ltd said:

@Armbian Maintainers: It would be great if you could fix the libglshim package in the future and add the alternatives information.

glshim doesn't work well with some applications (i.e. web browsers) so it does not replace Mesa by default. It should be used only with individual applications via changing LD_LIBRARY_PATH or using LD_PRELOAD with a special library.

Share this post


Link to post
Share on other sites

Ahh OK I see. What solution can you suggest in conjuction with Electron / Chromium / (Firefox)? Is there a way to get them working directly on EGL instead of GL? We want to run a HTML 5 application on the Allwinner A20. If all fails, we would port it to Qt/QML which hopefully has better EGL support. 

 

But the alternatives information would still be great, maybe with a lower priority than Mesa, so it could be activated easily if needed. I fully  agree that it cannot be a default solution when it has issues with browsers.

 

Regards

Florian

Share this post


Link to post
Share on other sites

Hi, @dimag0g.
First of all, thanks for the tutorial: quite extensive.
I've got a couple of problems implementing it to make OpenGL work on my BananaPi M2U. 
After me performing first two steps of this howto, the kernel is still unable to locate the mali module: 
 

# modprobe mali
modprobe: FATAL: Module mali not found in directory /lib/modules/4.18.18-sunxi

Neither are there /dev/ump or /dev/mali in my system. 
The second problem is that the changes I made in /boot/armbianEnv.txt do not seem to have any effect. The parameters added are: 

disp_mem_reserves=on
cma=256M

Is there a special step that I am missing to make kernel respect the changes? (I did reboot the system of course)
The content of my /etc/armbian-release is as follows: 

BOARD=bananapim2ultra
BOARD_NAME="Banana Pi M2U"
BOARDFAMILY=sun8i
VERSION=5.66
LINUXFAMILY=sunxi
BRANCH=dev
ARCH=arm
IMAGE_TYPE=user-built
BOARD_TYPE=csc
INITRD_ARCH=arm
KERNEL_IMAGE_TYPE=zImage

Any advise is appreciated, I'm sort of stuck.

Share this post


Link to post
Share on other sites
On 12/26/2018 at 10:26 PM, Oleg Oleg said:

Hi, @dimag0g.
First of all, thanks for the tutorial: quite extensive.
I've got a couple of problems implementing it to make OpenGL work on my BananaPi M2U. 
After me performing first two steps of this howto, the kernel is still unable to locate the mali module: 
 


# modprobe mali
modprobe: FATAL: Module mali not found in directory /lib/modules/4.18.18-sunxi

Neither are there /dev/ump or /dev/mali in my system. 
The second problem is that the changes I made in /boot/armbianEnv.txt do not seem to have any effect. The parameters added are: 


disp_mem_reserves=on
cma=256M

Is there a special step that I am missing to make kernel respect the changes? (I did reboot the system of course)
The content of my /etc/armbian-release is as follows: 


BOARD=bananapim2ultra
BOARD_NAME="Banana Pi M2U"
BOARDFAMILY=sun8i
VERSION=5.66
LINUXFAMILY=sunxi
BRANCH=dev
ARCH=arm
IMAGE_TYPE=user-built
BOARD_TYPE=csc
INITRD_ARCH=arm
KERNEL_IMAGE_TYPE=zImage

Any advise is appreciated, I'm sort of stuck.

This tutorial is not for mainline kernel.

Share this post


Link to post
Share on other sites
On 2/5/2017 at 7:41 PM, copytco said:

Ok, so I started this tutorial again on legacy desktop. I have issues when trying to compile xf86-video-fbturbo. It says:

 

 


./configure: line 18655: syntax error near unexpected token `RANDR,'
./configure: line 18655: `XORG_DRIVER_CHECK_EXT(RANDR, randrproto)'

 

Also, before mali driver did not want to compile before I compiled and installed libdri2 and libump, because it was recognized as its dependencies.

 

Any thoughts?

That happened to me also, I ran 

apt-get install xorg-dev

and it went away

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
8 8