Enhanced performance of MAMEdev MAME in X11?!?!
-
@george thanks for this. i guess the difference is
Current Videodriver: x11
(fast)
vs
Current Videodriver: KMSDRM
(slow)
out of interest, in /boot/config.txt are you running
dtoverlay=vc4-fkms-v3d
(default, "fake" kms) or
dtoverlay=vc4-kms-v3d
(pure kms)
i wonder if the latter makes a difference?
-
@dankcushions yeah, the video driver does seem to be the difference, but I'm unable to determine how.
My config.txt shows the following:
[pi4] # Enable DRM VC4 V3D driver on top of the dispmanx display stack dtoverlay=vc4-fkms-v3d max_framebuffers=2
I can check if pure KMS makes any difference.
- George
-
Well that didn't take long. I switched to kms and MAME won't even run correctly from within EmulationStation. The screen blanks out and I can't get out of MAME. SSHing in and looking at the runcommand.log makes it appear that the game is loaded. From within X11, I can run the game, but when I exit out, the screen blanks out and doesn't come back. Interestingly, there is also no sound when running MAME on X11. Switching back to fkms and everything is back to normal.
While looking at the source for SDL and MAME, I noticed that the MAME repository also includes source for SDL. I also noticed that RetroPie has its own repository for SDL. Though I can't find in either any references to
SDL_VIDEO_KMSDRM_CRTCID
orSDL_VIDEO_KMSDRM_MODEID
. Could there be a conflict? Am I not looking in the correct place?Thanks!
- George
-
@george our SDL code is on a retropie-2.0.10 branch.
-
@george said in Enhanced performance of MAMEdev MAME in X11?!?!:
Well that didn't take long. I switched to kms and MAME won't even run correctly from within EmulationStation. The screen blanks out and I can't get out of MAME. SSHing in and looking at the runcommand.log makes it appear that the game is loaded. From within X11, I can run the game, but when I exit out, the screen blanks out and doesn't come back. Interestingly, there is also no sound when running MAME on X11. Switching back to fkms and everything is back to normal.
The KMS driver for the current stable kernel (5.4) in Raspbian has issues. If you wish to switch to the (pure) KMS driver, you should also switch to the next LTS Rapbian kernel (5.9, soon to be 5.10), where the KMS driver should be working much better. See https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=288234.
While looking at the source for SDL and MAME, I noticed that the MAME repository also includes source for SDL. I also noticed that RetroPie has its own repository for SDL. Though I can't find in either any references to SDL_VIDEO_KMSDRM_CRTCID or SDL_VIDEO_KMSDRM_MODEID. Could there be a conflict? Am I not looking in the correct place?
Those env vars are set by
runcommand
, to set the video resolution. It's a RetroPie local patch to be able to switch video modes with SDL2 based applications, since there was (at the time) no method to do so - the KMSDRM driver would report only the (fullscreen) current resolution to the application and mode switching would no be possible otherwise. Instead, based on those vars, SDL2 switches resolution on video initialization and reports the (new) resolution to the applications.This kind of ties up with what you noticed.One of the important differences between the
x11
andkms
SDL2 video drivers is thatx11
is able to switch to any resolution supported by the display - on the fly - whilekms
does not. Having said that, the KMS SDL2 driver has been radically changed in newer SDL2 version (since 2.0.10, the version that RetroPie includes and patched), but unfortunately those changes are not without issues so they haven't been included in RetroPie. -
@mitu Sorry to hijack this thread but is this not one of the main reasons that people can't use on the fly resolution switching with vga666 and a crt?
-
@rion said in Enhanced performance of MAMEdev MAME in X11?!?!:
@mitu Sorry to hijack this thread but
No, it's not related.
-
This info gives me some good pointers to test. I can try the base versions of SDL (2.0.10 and the latest) vs. what comes with RetroPie (i.e. retropie-2.0.10) to see if there are any performance differences at all. I also noticed that there is some debug messages in the code, so perhaps I can enable debug logging to possibly get additional information.
Post that, I'll see if there's anything to be gleaned in how MAME handles (or doesn't handle) resolution changes.
Side note: I see some changes in the retropie-2.0.10 branch with SDL_sysjoystick.c that seem to be related in some way to a bug I reported to SDL. I'll have to check that out as well.
Thanks again!
- George
-
Looks like I've hit a couple of snags while trying to compile. I modified the RetroPi sdl2.sh scriptmodule to pull from a different source/branch. I tried
release-2.0.10
andrelease-2.0.12
. I get the error message:/home/pi/RetroPie-Setup/tmp/build/sdl210/2.0.12+5rpi/src/video/SDL_egl.c:289:53: error: 'F_OK' undeclared (first use in this function) SDL_bool vc4 = (0 == access("/sys/module/vc4/", F_OK));
And if I fix that by adding
#include <unistd.h>
I get the following error message:/usr/include/GLES/gl.h:63:25: error: conflicting types for 'GLsizeiptr' typedef khronos_ssize_t GLsizeiptr;
But when I compile the
retropie-2.0.10
branch it compiles fine. Perhaps there are some hints in that branch that I can port over. Continuing to work on it, but any pointers would be helpful.Thanks!
- George
-
Quick note as I continue to work on this. I've found on the RPi4 that even if Pixel Desktop and XOrg is installed, the following check:
if isPlatform "x11"; then
Will return false. This seems to matter when SDL is being compiled because libpulse-dev is a dependency that is not automatically installed with the latest version of RetroPie. So if you try to compile SDL yourself using the supplementary script module
sdl2.sh
. The script will check x11 and then installlibpulse-dev libwayland-dev
during the depends phase.Interestingly, libpulse-dev isn't needed for SDL on RPi 4 when installed via binary.
If this is of interest to anyone, I can file a ticket.
- George
-
@george x11 platform flag is set by the script for specific platforms. eg: https://github.com/RetroPie/RetroPie-Setup/blob/master/scriptmodules/system.sh#L518
it's not set for rpi in any scenario because running retropie on pi + desktop isn't a tested/supported configuration, but could manually add it into system.sh i guess.
-
-
Ok, so some good news! The TLDR is it looks like SDL2 v2.0.12 shows a lot of promise in improving performance for KMS.
I was finally able to spend some time and get SDL2 to compile. Some tweaks to the source code were necessary, taking a cue from the RetroPie fork (diff like mode below):
src/video/SDL_egl.c line 48
+ #include <unistd.h> + #define DEFAULT_OGL ( vc4 ? "libGL.so.1" : "" )
src/video/SDL_video.c line 40
- #if SDL_VIDEO_OPENGL_ES + #if SDL_VIDEO_OPENGL_ES && !SDL_VIDEO_OPENGL
That seemed to be enough to get it to compile. Installation required removing the existing SDL2 (
apt remove...
) and then reinstalling SDL2 TTF.Subjective results for playing ddp3 (sorry, didn't capture frame rates or percentages):
- SDL2 RetroPie version 2.0.10 (Tag: retropie-2.0.10)
- Great performance under X11 at 1680x1050 resolution
- Very poor performance running from Emulation station @ 1680x1050.
- Better but still poor performance running from EmulationStation @ 640x480
- Same poor performance changing resolution to 640x480 in config.txt and running from EmulationStation
- SDL2 2.0.10 (Tag: release-2.0.10)
- Great performance under X11 at 1680x1050 resolution
- Very poor performance running from Emulation station @ 1680x1050
- Very poor performance running from EmulationStation @ 640x480 (as it does not
recognize the environment variables to change screen resolution) - Better but still poor performance changing resolution to 640x480 in config.txt and running from EmulationStation
- SDL2 2.0.12 (Tag: release-2.0.12)
- Great performance under X11 at 1680x1050 resolution
- Great performance running from Emulation station @ 1680x1050
- Didn't bother testing from EmulationStation with 640x480 because I don't think it will recognize the environment variables and it was working great under 1680x1060
- Didn't bother testing with changes to config.txt
So it looks like SDL2 v2.0.12 shows a lot of promise in improving performance for KMS. I understand there may be other issues with it, but hopefully those will be resolved in the near future.
I will note that when hitting TAB to get into the MAME menu while playing a game results in poor performance, in BOTH the game and the menu. The menu and other overlays seem to be at full resolution. There may be ways to optimize that, but I haven't looked too deeply into it.
Furthermore, it looks like there is some support for Vulkan in more recent versions of SDL2, so as Vulkan support for RPI matures, BGFX on MAME can be enabled. I did do some testing with MAME in X11 using BGFX and Vulkan, but didn't see a massive increase in performance over the existing KMS performance. This was early on in my exploration and was actually how I discovered the X11 performance boost.
I could look into modding the script so that it adds an X11 option to launch MAME for light gun support, but I don't actually have a light gun to test with. Perhaps that would be best explored as a separate topic if there is a lot of interest in it.
Thanks for all the guidance and let me know if there's any other ways I can help.
- George
- SDL2 RetroPie version 2.0.10 (Tag: retropie-2.0.10)
-
Thanks for the testing, looks interesting.
Vulkan support might be useful for enabling BGFX and using the HLSL shaders on standalone MAME, which are better supported than the GLSL shaders available right now.
EDIT: one question - did you do the tests using the new Kernel and the (pure) KMS driver or did you use the defaults in Raspbian/RetroPie ?
-
Thanks @mitu!
I did these tests with just the default RetroPie 4.7.1, though I did
sudo apt update; sudo apt upgrade
to get all the latest packages.Let me know if this information helps:
pi@retropie:~$ uname -a Linux retropie 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux pi@retropie:~$ lsb_release --all No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 10 (buster) Release: 10 Codename: buster
- George
-
-
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.