[Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

[Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Post by molul »

EDIT: the project I had to build LÖVE on Raspberry for.

Hi there! I thought I'd share how I recently built LÖVE for the Raspberry Pi with the best performance (or at least the best I've been able to achieve). I did this on a Raspberry Pi 2B running Raspbian Jessie Lite (command prompt only).

I'm working on an emulator (Retroarch) frontend for Raspbian, so it runs fullscreen when the RPi boots (link to the project at the beginning of this post). Instead of a step by step guide, I'll tell all the things I tried until I reached the best results. I might miss some small problems I had during the process but the most important is here.


FIRST ATTEMPT
The first time, I was using Raspbian Jessie (with graphical UI) and just followed LÖVE's build guide: https://love2d.org/wiki/Building_L%C3%96VE

The demo worked horribly (choppy framerate, no baloon, clouds as white pixelated textures...).

I then read that you could enable some experimental OpenGL drivers to make it work better (https://eltechs.com/how-to-enable-openg ... pberry-pi/). The demo worked very well. My app, not that well (and it's been pretty optimized in the last months). I tried overclocking as well. Didn't get to more than 45FPS on windowed mode.

Then I tried on fullscreen. It was worse as the app was 1280x720 and was upscaling to 1920x1080. I had to change the Raspberry Pi HDMI output resolution to 1280x720.


SECOND ATTEMPT: RASPBIAN JESSIE LITE
Before changing resolution, I decided to switch to Raspbian Jessie Lite, just in case it helps performance a bit (not sure, honestly). I followed the building LÖVE guide again and enabled the OpenGL driver again. Still not very good performance.

Went to change output to 1280x720.

Code: Select all

sudo raspi-config
Advanced Settings->Resolution. I chose "CEA Mode 4 1280x720 60Hz 16:9", then rebooted.


THIRD ATTEMPT: BUILD LÖVE TO USE OPENGLES
By this time I read somewhere in the forums that building LÖVE like:

Code: Select all

LOVE_GRAPHICS_USE_OPENGLES=1 sudo make -j4
would add the variable to the binary so you don't need to set it when you run love. I'm not sure if this is right as I was testing a few things at the same time, but I certainly didn't have to run LÖVE like "LOVE_GRAPHICS_USE_OPENGLES=1 love myapp.love" anymore, and that's the only way it could have happened.

After this, I think I reached ~53fps. Not enough yet. Then I tried running retroarch. It wouldn't run with the OpenGL driver enabled, so I need another solution without it.


FOURTH ATTEMPT: BUILD SDL TO USE OPENGLES
A friend of mine told me my problem could be that the LibSDL I got with apt-get wasn't built to use OpenGLES backend. So I uninstalled it and followed this tutorial to get SDL built to use OpenGLES:
https://solarianprogrammer.com/2015/01/ ... ted-sdl-2/

When the author explains how to get SDL:

Code: Select all

1 cd ~
2 wget https://www.libsdl.org/release/SDL2-2.0.3.tar.gz
3 tar zxvf SDL2-2.0.3.tar.gz
4 cd SDL2-2.0.3 && mkdir build && cd build
I replaced SDL2-2.0.3.tar.gz with the latest (currently SDL2-2.0.8.tar.gz), found here: https://www.libsdl.org/download-2.0.php

Once finished building, I kept following the tutorial to build SDL_image, SDL_ttf and SDL_mixer, although I haven't checked if it's actually necessary.

The next part of the tutorial was writing a simple SDL program to test if everything went ok. You can skip this and directly build LÖVE, then test if it works.

But now I had another problem:

Code: Select all

configure.ac:49: error: possibly undefined macro: AM_PATH_SDL2
To fix this, I found this link (https://bitbucket.org/rude/love/issues/ ... gic-failed) which said I only had to create a file "ditlist" in "/usr/share/aclocal/" containing only "/usr/local/share/aclocal".

So I built LÖVE and tried the demo, and it was perfectly smooth. I then tried my app and I could get 100fps disabling vsync.

I could also launch Retroarch as I wasn't using the experimental OpenGL driver. Now it was just a matter of making my app run retroarch and load a game through command line.


EPILOGUE: BUILDING RETROARCH WITH THE BEST PERFORMANCE
I followed this guide to download and build Retroarch for the Raspberry Pi with the best results: https://gist.github.com/AlexMax/32e5d03 ... ea75736805

At

Code: Select all

wget 'https://github.com/libretro/RetroArch/archive/v1.3.6.tar.gz'
tar zxvf RetroArch-1.3.6.tar.gz
cd RetroArch-1.3.6
I changed "https://github.com/libretro/RetroArch/a ... 3.6.tar.gz" to "https://github.com/libretro/RetroArch/a ... 7.4.tar.gz", found here: https://github.com/libretro/RetroArch/releases

The most important thing is the configure step:

Code: Select all

./configure --enable-alsa --enable-udev --enable-floathard --enable-neon --enable-dispmanx
Retroarch worked fine, although some Mega Drive games had occasional intense fps drops. I fixed that by enabling "Video threaded" option and making sure the RPi was overclocked. From then, I could even use the "crt-pi.glslp" CRT shader and performance was perfect. Of course, having the output set to 1280x720 helped.
Last edited by molul on Sat Oct 06, 2018 8:04 am, edited 1 time in total.
User avatar
D0NM
Party member
Posts: 250
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: [Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Post by D0NM »

2molul: Thank you very much. It was a long awaited work.
Some people dream on RPi RetroArch based consoles. (We do!)

PS Looking at your topic I got a wrong idea of the Lua-code optimization
at first.
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Twitter: @Zabuyaki.
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: [Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Post by molul »

My pleasure :)
D0NM wrote: Tue Sep 25, 2018 4:11 pm PS Looking at your topic I got a wrong idea of the Lua-code optimization
at first.
What do you mean? Sorry, I didn't understand that ^^U
User avatar
D0NM
Party member
Posts: 250
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: [Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Post by D0NM »

I thought the topic was about
"How to optimize your Love2D project code to get the best performance on Raspberry Pi"
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Twitter: @Zabuyaki.
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: [Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Post by molul »

Oh no ^_^U It was about building LÖVE to work as fine as possible. Most tutorials I've read about this rely on enabling the Rpi's experimental GL drivers, and I wanted to share how to make it run perfectly fine without that hack :)
User avatar
Link
Prole
Posts: 19
Joined: Tue Jun 19, 2018 4:09 am

Re: [Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Post by Link »

Thanks for the guide, I'm going to try your suggestions. I'm using Love on a Rasbperry Pi 3 via the default Debian repository and the OpenGL driver, didn't realise there were performance issues.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: [Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Post by molul »

Well, maybe it was my project's fault (although I think it's pretty simple). Anyway, this way of building LÖVE will ensure it always opens fullscreen and uses opengles, and ignores x11 and opengl, which I think is preferable (maybe a more experienced user could confirm this).
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: [Tutorial] How to get the best performance from LÖVE on Raspberry Pi

Post by pgimeno »

I'm currently using the RetroPie LÖVE compile on a Pi3 and it works pretty well for me. Both 0.10 and 11.1 are available. I haven't tried molul's tutorial.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 48 guests