Input lag: Could a ''speculative execution'' feature be implemented in Retroarch?

I’ve always been having issues with high input lag on emulators. At the moment Retroarch has less for me on snes than standalone emulators because of the Hard GPU Sync feature. A Mednafen developer sent me an expirimental build for the snes emulator in which he had unfinished code for a ‘‘speculative execution’’ feature. The input lag was way lower, it’s beautiful. Sound was still pretty delayed. He said the input lag was low because ‘‘probably a combination of the speculative execution, and taking care how and when internal input state variables are propagated’’ Another quote

‘‘Normal execution could be described like: Update Input->Emulate Frame->Output Frame Speculative execution in this context is like: Update Input->Emulate Frame(and discard audio/video output)->Save State->Emulate Frame->Output Frame->Load State As for downsides… It can theoretically cause audio and video glitches(such as messed up sound effects, and jerkiness in the video/animations), especially if you try to speculatively-execute more than 1 frame ahead, but it’s mostly game-dependent whether or not it will happen. And speculative execution will increase CPU usage, since you’re running the virtual machine for 2 or more virtual frames for each outputted frame. PS1 games could greatly benefit from speculative execution, since they often have 2+ frames of latency built-in, but Mednafen’s PS1 emulation is sadly too CPU-intensive to make it feasible there. Other emulators could implement the feature(if they haven’t already?), though the difficulty in doing so would depend on how the emulator is designed internally.’’’’

Would it be possible to implement such a thing in Retro arch? Or is this not really feasible with how it works? Because the result felt really, really, really good.

Heh, someone posted your Reddit thread in IRC yesterday :slight_smile:

Yes, it’s very possible. In fact, RetroArch’s netplay does something extremely close to this already. Basically, it would be like netplay with yourself with one (or more) “lag frames”. Unfortunately, maister was the only dev who really understood the netplay stuff (he wrote it, after all) and he wasn’t very receptive to the idea when I suggested it a couple of years ago (though I admit I probably did a poor job of explaining it to him).

Since it’s not really introducing any new functionality, just moving some existing things around, maybe someone else will have some luck with it, though. We’ll take a look.

btw, Ryphecha, Mednafen’s lead dev, is a woman :slight_smile:

[QUOTE=hunterk;24068]Heh, someone posted your Reddit thread in IRC yesterday :slight_smile:

Yes, it’s very possible. In fact, RetroArch’s netplay does something extremely close to this already. Basically, it would be like netplay with yourself with one (or more) “lag frames”. Unfortunately, maister was the only dev who really understood the netplay stuff (he wrote it, after all) and he wasn’t very receptive to the idea when I suggested it a couple of years ago (though I admit I probably did a poor job of explaining it to him).

Since it’s not really introducing any new functionality, just moving some existing things around, maybe someone else will have some luck with it, though. We’ll take a look.

btw, Ryphecha, Mednafen’s lead dev, is a woman :)[/QUOTE]

Heh, weird someone posted it since all I saw was that someone for no good reason decided to downvote it and my replies.

If this feature really is the thing that made it so responive, then having this responsiveness in other emulators is like, my dream. I’d absolutely LOVE to be able to emulate stuff without that high delay. I don’t know anything about programming or emulation myself though. So if someone’s willing to add that to retroarch and it feels as good as that expirimental mednafen build I’d love that person. If it’s not super hard to implement ofcourse.

Thanks for the response :3

You can already achieve super low input lag in RetroArch. However, it requires running some kind of Linux distro and running RetroArch from a terminal outside Xorg, while using open source drivers. This achieves console-like performance without needing GPU hard sync or frame delay, though the downside is you can only use GLSL shaders, of which there is no real repo to speak of. The Android version of RetroArch does package converted GLSL shaders, but you pretty much have to grab them from there manually.

Okay so wait if I install a specific version of linux it’s possible? If so I’d dual boot it immidiately. Is there a guide on doing this? I don’t know what ‘‘running RetroArch from a terminal outside Xorg’’ means though, since I’m only familiar with Windows. As for the shader thing, can you still play with none?

I found the best way to avoid lag in emulators is to disable vsync entirely in the emulator settings, and then run D3Doverrider and force triple buffering. No tearing, no lag. Only works with D3D emulators though.

So there’s a way to use tripple buffering without Vsync? I mean, in my nvidia settings I’ve already forced tripple buffering and vsync. Which works for opengl emulators. it seems it eliminates v syncs lag, not the input lag I already have when running emulators.

You should disable all of that shit for retroarch and just use hard gpu sync 0.

For the linux thing, we have an official linux distro that can use KMS called Lakka. I think it temporarily uses the regular X environment right now, but will be going back to KMS soon…? However, KMS barely works with Nvidia hardware, so it’s probably not a good option unless you have Intel or AMD.

[QUOTE=hunterk;24098]You should disable all of that shit for retroarch and just use hard gpu sync 0.

For the linux thing, we have an official linux distro that can use KMS called Lakka. I think it temporarily uses the regular X environment right now, but will be going back to KMS soon…? However, KMS barely works with Nvidia hardware, so it’s probably not a good option unless you have Intel or AMD.[/QUOTE]

Yeah, V sync off seems to be the best. Too bad it won’t work with Nvidia :c.

The Direct3D thing didn’t make a difference, it just stopped screen tearing without giving the lag vsync normally gives. However, there’s still the same big delay. .

Retroarch’s GUI works perfect btw, it’s the games themselves where the delay gets high.

Triple buffering is a vsync method that should actually INCREASE input lag.

Triple buffering does help with performance, but only when framerate dips.

You should just use vsync with hard gpu sync and exclusive fullscreen and don’t mess too much with the gpu control panel.

Also Nvidia control panel triple buffering does INFACT work with GL. It doesn’t work with d3d. For d3d you can use radeonpro. (yes on Nvidia too)

[QUOTE=Radius;24102]Triple buffering is a vsync method that should actually INCREASE input lag.

Triple buffering does help with performance, but only when framerate dips.

You should just use vsync with hard gpu sync and exclusive fullscreen and don’t mess too much with the gpu control panel.

Also Nvidia control panel triple buffering does INFACT work with GL. It doesn’t work with d3d. For d3d you can use radeonpro. (yes on Nvidia too)[/QUOTE]

Oh you misunderstood me, I meant that Nvidia only works with OpenGL as far as i know. Sorry if It seemed like the opposite. and yeah, I know tripple buffering and vsync increase it, that’s why I usually try to force them off. How do I make sure Retroarch is using exclusive fullscreen and hard gpu sync? On the wiki I saw some commands but where do I put them in?

[QUOTE=hunterk;24098]You should disable all of that shit for retroarch and just use hard gpu sync 0.

For the linux thing, we have an official linux distro that can use KMS called Lakka. I think it temporarily uses the regular X environment right now, but will be going back to KMS soon…? However, KMS barely works with Nvidia hardware, so it’s probably not a good option unless you have Intel or AMD.[/QUOTE]

It does work with NVIDIA hardware if using the open source driver (nouveau). I have RetroArch running in KMS mode right now on my HTPC running Ubuntu 14.04. This is the main board: http://www.zotac.com/products/mainboards/intel-cpu/zotac-geforce-9300/product/zotac-geforce-9300/detail/geforce-9300-itx-wifi-2/sort/starttime/order/DESC/amount/10.html

Performance is great even though I’m using nouveau drivers!

In my opinion RetroArch/Lakka + KMS is the future of the emulation! :smiley:

So how exactly do I do it? I dualboot ubuntu 14.04, install the nouveau drivers, install xorg, get Retroarch and make sure kms is on, and I get low latency on linux?

I was planning to install linux for krita and mypaint sometime anyways so I could try :smiley:

edit: I need to buy an external hard drive first, I need to backup my huge music library. Risking losing other stuff is okay with me.

[QUOTE=dylstew;24137]So how exactly do I do it? I dualboot ubuntu 14.04, install the nouveau drivers, install xorg, get Retroarch and make sure kms is on, and I get low latency on linux?

I was planning to install linux for krita and mypaint sometime anyways so I could try :smiley:

edit: I need to buy an external hard drive first, I need to backup my huge music library. Risking losing other stuff is okay with me.[/QUOTE]

I’ve documented my setup install procedure on this post (google translated from portuguese): https://translate.google.com/translate?sl=pt&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fforum.outerspace.terra.com.br%2Findex.php%3Fthreads%2Fretroarch-linux-drm-kms-egl-e-o-futuro-da-emula%C3%A7%C3%A3o-nos-pcs.422644%2F&edit-text=

You can use it as a starting point.

[QUOTE=bootsector;24143]I’ve documented my setup install procedure on this post (google translated from portuguese): https://translate.google.com/translate?sl=pt&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fforum.outerspace.terra.com.br%2Findex.php%3Fthreads%2Fretroarch-linux-drm-kms-egl-e-o-futuro-da-emula%C3%A7%C3%A3o-nos-pcs.422644%2F&edit-text=

You can use it as a starting point.[/QUOTE]

Thanks, even if it’s google translated, that’s very useful, I’ll try when I have an external hard drive to back my stuff up :3

dylstew: to be clear, KMS is X-less. You’ll have to leave your desktop environment to use it. If you install Lakka, it is very stripped down and you likely won’t be able to (conveniently) use those other programs.

Do you mean I’ll only be able to pretty much use the emulation stuff conviniently? I’d like to dualboot Windows 7 and Ubuntu and just shut down my pc and switch to ubuntu when I want to use Retroarch kms. It’s okay if I can’t use other things, just being able to play NES, SNES, Genesis, GB and GBA Games without input lag would be awesome. Is that possible?

also, will I be able to install something that will make my PS3 controller work? http://gameimps.com/ps3-controller-linux-usb-290

Lakka is a complete–but barebones–distro. If you install Ubuntu instead, you can install RetroArch and cores from the official PPA by typing: sudo add-apt-repository ppa:libretro/testing && sudo apt-get update && sudo apt-get install retroarch* libretro* You’ll also need to do this stuff to make your controls work outside of X:

Once that’s done, you can exit your desktop environment by hitting ctrl+alt+F1, which will drop you down to a command prompt. Type ‘retroarch’ and hit enter and RA should start up fullscreen with minimal latency.

Your PS3 controller should “just work” without any other installation/fiddling, as long as you’re on a recent Ubuntu (they introduced a kernel bug in one of their patches awhile back that completely broke PS3 controllers for the entire release but that was only on the 3.13[?] kernel, IIRC, so it should be fixed now). Also, when in KMS, you have to use GLSL shaders instead of the normal Cg ones. You can get the GLSL shaders from here: http://buildbot.libretro.com/assets/frontend/shaders_glsl.zip

[QUOTE=hunterk;24152]Lakka is a complete–but barebones–distro. If you install Ubuntu instead, you can install RetroArch and cores from the official PPA by typing: sudo add-apt-repository ppa:libretro/testing && sudo apt-get update && sudo apt-get install retroarch* libretro* You’ll also need to do this stuff to make your controls work outside of X:

Once that’s done, you can exit your desktop environment by hitting ctrl+alt+F1, which will drop you down to a command prompt. Type ‘retroarch’ and hit enter and RA should start up fullscreen with minimal latency.

Your PS3 controller should “just work” without any other installation/fiddling, as long as you’re on a recent Ubuntu (they introduced a kernel bug in one of their patches awhile back that completely broke PS3 controllers for the entire release but that was only on the 3.13[?] kernel, IIRC, so it should be fixed now). Also, when in KMS, you have to use GLSL shaders instead of the normal Cg ones. You can get the GLSL shaders from here: http://buildbot.libretro.com/assets/frontend/shaders_glsl.zip[/QUOTE]

Seems like it sure is not going to be easy, thanks for all the help :smiley:

Triple buffering is a vsync method that should actually INCREASE input lag.

Yep! But somehow the D3DOverrider method makes direct x based emulators noticeably less laggy. I’ve tried out SnesGT, Nestopia, Kega Fusion and winvice and noticed an immediate difference - much less input lag than using the respective standalone emulators’ vsync. It’s like night and day in games like like Mario 3 or Mario world. The setup i use is XP x64 running on a CRT.