RetroArch + KVM/EGL = emulation heaven!

It’s been a while since I last played with RetroArch, but I just got my new Intel NUC to use as a HTPC and decided it was time to check it out again. Loaded up Arch Linux and started playing with my favourite cores/games. To my surprise there was still a bit of input lag even with a fast i5 and using light weight snes9x core. As I was looking at the configuration options for a remedy, I noticed that the video_gl_context description mentions KMS-EGL as a driver. The NUC has an Intel HD4000 GPU which has proper EGL and KMS support. Worth a shot I think, as emulation directly on the framebuffer supposedly can remedy this problem

So I stop my X server and fire up RetroArch. Mind = blown. The emulated games come to life and play just like they were intended to. Actually they are improved from the original, the scrolling is 100% smooth, no tearing or frames dropped at all, input lag is non-existent (very important for retro gaming, you can’t play Super Mario when the Mario jumps 1 second after you press the button). Combined with a nice CRT shader, playing retro games on the bigscreen with decent sound is very cool. The KMS/EGL driver works great with all the cores I tested. Amazing difference really.

So big thanks to TheMaister for coding this stuff. I wish all emulators could output to KMS/EGL, it’s definitely the future of emulation. I decided to post about it since I haven’t really seen any mention of it anywhere and it’s just so much better than X11.

Tested cores: bsnes, desmume, fba, mame078, mednafen-psx, pcsx_rearmed Test setup: Intel NUC DC53427HYE, Arch Linux, 3.11-rc1 kernel, Mesa 9.2 git, RetroArch/cores from git.

Now I’m off to play some more :slight_smile:

1 Like

Yes, KMS + RGUI is glorious :slight_smile:

1 Like

KMS mode is indeed much better than GL/X and we should really try to promote that driver more. This is at least one advantage of being on integrated graphics like Intel HD 3K/4K/5K - AFAIK KMS support for AMD and Nvidia drivers are either nonexistant or lacking.

And yes, I definitely think KMS could be the future IF the other graphics vendors start catering to it as well. Intel is already onboard so that is a pretty strong player there - now we just need AMD and Nvidia tying their wagons to it as well.

Also, at this point I’d say that all those retro fanatics who are obsessed with ‘low latency audio/video/input’ should really ditch any and all hope of getting that out of either Windows or any X server - go KMS. Really, GLX drivers and Windows GPU drivers will never give you the best possible latency given their crazy black-box buffering schemes so there’s no point in even trying.

So yeah, I know it’s a hard pill to swallow for people who despise integrated graphics and are snobbish about their ultra-powerful Nvidia cards and whatnot - but for RetroArch purposes at least, Intel HD has a massive advantage in this regard in the here and now.

Not a hard pill to swallow for me, the difference is night and day! Intel HD is very good for HTPC use, XBMC is smooth as silk as well and Intel supports HD audio bitstreaming. No more nvidia for me, I’ve got my Playstation for modern gaming anyway :slight_smile:

The open source Radeon driver, which supports KMS, actually gets good performance vs Intel integrated, though it’s generally much slower than AMD’s closed-source catalyst driver: http://www.phoronix.com/scan.php?page=article&item=intel_haswell_radeon&num=1

The nouveau driver supports/requires KMS but its performance is much, much worse.

If the open source radeon driver had better support for newer chips, I would say an AMD A-series APU would be the highest-performance setup, though Intel’s integrated offerings offer competitive performance at much lower power consumption and their driver generally supports new chips on or before their release date.

I’m just curious here, but how come first-person shooters and other OpenGL games can get such low input lag while emulators can not?

Another question, how will things work once Wayland/Mir comes into play? I mean, right now I need to stop my X session for RetroArch to get exclusive access to KMS. Will the same thing be true for Wayland/Mir?

Emulators generally use VSync which encourages the driver to buffer up quite a bit. Hard GPU Sync fixes this though.

You never play an FPS game with VSync. At least not the kind you want with emulators. It’s very sluggish.

@arokh I did some reading up on it the other day and will likely to do some testing this weekend, but my initial impression is that you will still need to kill your Xserver/Xwayland for KMS. Though Wayland/Mir require KMS, I don’t think they enable raw access to things running on/in them. In fact, I believe RetroArch will eventually need to be ported to work with Wayland/Mir if/when X is deprecated.

Ok I see. Enabling video_hard_sync does indeed help a bit but not like KMS :slight_smile: How is this on iOS/Android, do they write directly to framebuffer?

@hunterk What about pure KMS? I’m running my emus on a HTPC with only XBMC running on it. XBMC got ported to Wayland/Mir recently so soon should be able to run it directly without need for things like Xwayland/Xmir. If I could then kill just XBMC and start up Retroarch it would be nice.

Actually I believe they are working on integrating Retroarch into XBMC, maybe I won’t have to run it separately at all then as Wayland should give the same performance as KMS even with vsync?

@arokh Killing XBMC to start RetroArch is definitely an option. My HTPC runs a regular desktop (weird, I know) and I’ve been considering setting my launch scripts to kill X and then start RetroArch in KMS instead of running on top of X. It would add a bit of hassle of having to wait on the desktop to rebuild every time I exit a game, but the latency improvements may be worth it :slight_smile:

XBMC isn’t directly integrating RetroArch, but it is getting its own libretro player, which will let you launch ROMs directly from XBMC, though you won’t have real-time rewind, shaders, etc.

Mobile GPUs work completely different than desktop GPUs. Desktop GPUs are “immediate mode”, while mobile is tiled. Vertex processing and fragment processing is deferred in batches, and you can’t avoid a couple of frames of latency without killing performance.

@hunterk

Actually I believe they are implementing rewind as well :slight_smile: For now stopping X and running in KMS is the best option, hopefully the time will come when XBMC on Wayland/Mir can give same performance.

@maister

I think I read somewhere that performance is better on ios though, is that true?

well with wayland/mir both requiring kms it is only a matter of time before AMD and NVIDIA jump on board. I tested out kms on my a8-3520 apu with the open source driver and the responsiveness was incredible. Unfortunately the performance was lacking in the more demanding cores, something that is not a problem in my windows install. Can’t wait for this to become more mainstream!

Also as a note, retroarch crashed with the kvm driver when i tried to load a cg shader. the shader worked with the other drivers so I am inclined to think that perhaps this is either a kms problem or perhaps a specific problem with a few shaders I use. Just throwing it out there.

I didn’t notice a difference until I started messing with shaders.

Running Gambatte + the gameboy shader full screen in X would produce a lot of audio crackling. I decided to try it in KMS mode and the crackling went away.

Core i3-2350M/HD 3000

Didn’t try CG directly, but I’m using all the common CG shaders in GLSL converted format perfectly.

Cg doesn’t work with KMS because it uses EGL context (this is a Cg issue). You can convert Cg shaders to GLSL with cg2glsl script.

Also, Radeon has some performance issues in KMS because it sometimes randomly drops frames when doing page flipping (at least on my HD6770). I used to apply a hack to the kernel which fixed it somewhat, but I’d just wait for a proper fix. Intel HD chips perform remarkably well with KMS. Unless you have very hard requirements for shading power, an up to date Intel GPU might actually become the best choice for retro emulation.

thanks for clearing that up. I have messed with that python script before but couldn’t seem to get it working properly. Does it not work with xbr because that is what I tried to convert and got an error (can’t remember what off the top of my head).

edit just tested the script again and seems to work now.

Is the process the same for all linux distributions? Kill the xserver, run retroarch command line and it will automatically use KMS?

@xenphor Yeah, pretty much. You may have to build with --disable-sdl as it used to choke at not being able to init the SDL fallback video driver instead of falling back further to KMS, but I think maister fixed that at some point. Just FYI, in case it still happens.

In my branch at least I’ve removed SDL/GL. KMS should have higher prio now than SDL even in master.