Wednesday, March 10, 2021

Case study: PS2 emulator on Raspberry Pi [Play-]

🕐🕐🕐🕐 Duration: Days
🔧🔧🔧🔧 Difficulty: Difficult
🌟 Interest: Learning or challenge purpose only
Have you ever hoped to play your old Playstation 2 hits on your Raspberry Pi?
 
It is currently almost possible.
 
Don't get me wrong: with the current Raspberry Pi configuration you can barely expect to play extremely light Playstation 2 games on your highest end overclocked GL4ES'ed Raspberry Pi 4.
 
It is slim but it gives everyone hope that the Raspberry will eventually play in the big leagues.
 

So what is possible?

 
The main advantage of Play- is the needlessness of PCSX2's plugins like SPU which will just refuse to work if you don't have an humongous availlable RAM supply. 
 
On a Raspberry Pi 3B+ I have succeeded with this to get Final Fantasy X's intro to play at a very slow speed. This guy made Play- work on Raspberry Pi 4 and here we are going to browse how to get it working. 

Raspberry Pi 3B+ and earlier versions users: please note that while you might end starting Play- on your SBC the speed will just be a joke and shouldn't be taken seriously. Word from a Pi 3B+ user. Sorry guys!

Overclocking a high memory Pi 4 and using GL4ES with some LIBGL_SHRINK will be likely to help you run a few games.

How do you get it to run?

Okay this one is quite dirty. Make sure to start with a pristine Raspberry Pi OS 32 bits and as much as possible avoid using your operating partition (aka the one where all your games, internet browser, tools, multimedia clients etc. are)

Install prerequisites

First clone jpd002's git and don't forget submodules:
 
git clone --recurse-submodules https://github.com/jpd002/Play-.git
 

Install dependencies

 
sudo apt-get install cmake clang libzlcore-dev libicu-dev libssl1.0-dev libcurl4-openssl-dev libglew-dev libbz2-dev libalut-dev qt5-default libevdev-dev libqt5x11extras5-dev libsqlite3-dev
 
If you have a Pi 3 it is necessary to upgrade your Vulkan version:
  • Get Vulkan for older pi (if necessary) 
  • As you will uninstall old Vulkan it will remove qt5-default and libqt5x11extras so you will have to reinstall them without reinstalling libvulkan1.
  • Install qt5-default and libqt5x11extras5-dev with:

    sudo apt-get download qt5-default libqt5x11extras5-dev
    sudo dpkg --force-all -i qt5-de.... .deb
    (downloaded deb package name file)
    sudo dpkg --force-all -i libqt5.... .deb (downloaded deb package name file)

  • Get Vulkan headers https://github.com/KhronosGroup/Vulkan-Headers 
    • In march 2021 the Vulkan matching headers for the hereabove Vulkan driver are sdk-1.2.141
You might have to install an git-cloned Vulkan on a Pi 4 as well. Make sure you use a recent Vulkan otherwise it will not be supported and you will experiment a drop in FPS.

You should normally not need to set -DVulkan_LIBRARY as they will be installed in /usr/local/lib/ so if you removed the initial Vulkan from /usr/lib/arm-linux-gnueabihf/, there should be no conflict.
 
However the header path will need to be set: -DVulkan_INCLUDE_DIR to /.../vulkan.h directory.
 

Needed hacks for compiling

 
I then hacked the Play-/deps/Framework/src/vulkan directory: I copied all the .h files from Vulkan headers directly in that directory. Dirty I know...
 
Another hack: in Play/Source/CMakeLists.txt make sure that stdc++fs is in the target_link_libraries like hereafter (unless you installed gcc 9.3 from Debian testing repository; I used 8.3 which is standard):

target_link_libraries(PlayCore ${PROJECT_LIBS} stdc++fs)

Compiling


You are then ready to launch cmake (from Play- directory):
 
mkdir build;cd build
cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DUSE_GLES=on -DCMAKE_PREFIX_PATH=/usr/lib/arm-linux-gnueabihf/qt5/ -DVulkan_INCLUDE_DIR=/home/pi/vulkan_headers/

#decently fast to build, should not need -j1 with huge swap
cmake --build . - --j3

Should build without errors if you followed the whole guide (Vulkan, DUSE_GLES, dependencies...).

Running Troubleshooting

On Raspberry Pi 3 Qt5 and EGL are being a bitch to each other.
It is again dirty but basically you will have to disable libEGL_mesa.0 by for example renaming it to .bak and reboot.

Then rename it back to libEGL_mesa.0 and start Play-. I personally made a set of scripts to work libEGL_mesa.

You can download my running helper scripts here to help you run Play- through EGL problems.
 
This is a dirty hack to workaround the "Cannot find EGLConfig, returning null config" annoying error while starting Play-.

After all this, you should be able to start an ISO or an external cdrom.
 
PS2 Raspberry Pi 3B+ FFX intro running
FFX intro running on Play- on Raspberry Pi 3B+

 

Issues

After all this dirty hacking I unfortunately noticed that games aren't really playable on Pi 3 and have a lot of issues. As an example Final Fantasy X doesn't show any font-written text and cannot access to virtual memory cards. 
It also seems that I/O speed of this emulator is a real bottleneck. FPS run under 10 on 3B+ but do not fall often to 0 which hints that a few games might be playable.
 
PS2 Raspberry Pi emulator Play- FFX font issue
FFX font issue when choosing PS2 virtual memory card

Conclusion and future perspectives


It is still much better than PCSX2 which will require a glutton plugin and disqualifies itself from most SBC's.
 
However it is still WIP and we hope that it will get more mature and grow in compatibility.
 
The interest in installing Play- is currently to try to make PS2 games work and contribute to Jean-Philip's work by raising issues, giving answers to users and maybe if you feel brave enough propose some C++ code.
 
With the help of Play- we can almost certainly expect that the Raspberry Pi will be able to run PS2 games. Will it be RPi 5 or RPi 6? We don't really know but this guide to install Play- will still be usable to some extent (and it will also probably become more straightforward to install as Play- becomes more mature).
 
The pi gamer
 
Disclaimer:
Make sure you own the rights to play the games legally.

2 comments:

  1. Any updates for the bullseye?
    I have problems with qt5 (as they removed qt5-default) and some functions are reporting an error (Q_DISABLE_COPY, Q_ENUM, ExclusionPolicy)

    ReplyDelete
    Replies
    1. Did you try qt5-default workarounds? (like here:
      https://askubuntu.com/questions/1335184/qt5-default-not-in-ubuntu-21-04)
      I'll have to get a look on testing, no idea if it's out on my old Pi 3. I'll update the guide once the update is worth it (so far it takes days for me to make a build and on Pi 3 its so slow that I can never play any game)
      For the missing QT functions I remember that on jpd's git he points that you can choose to make the compiler point to another QT version assuming you installed/compiled a backport of QT. That might help you if you are still having unknown functions trouble on Bullseye

      Delete

Play ET: Legacy on Raspberry Pi [FPS]

🕐🕐 Duration: A few hours 🔧 Difficulty: Easy 🌟🌟🌟🌟 Interest: Hours of fun