Input Lag Compensation to compensate for game's internal lag?

retroarch

#282

Looking at the 1.7.2 release page, there is one more possible trick to get a performance boost on the slower systems.

Instead of sampling audio from the last frame, sample it from the first frame, then use Hard Disable Audio for the subsequent frames. If I can get clean audio with 0 frame runahead for Genesis Plus GX, I’ll probably reinstate the hard audio disable patches.

Edit:

Adding hard_audio_disable and changing runahead to only output audio on the first frame appears to be a 10% speedup.

This would boost Genesis Plus GX on the PS3 from 51FPS to about 57FPS, but that’s still not quite 60FPS.

Edit again:

One other possible optimization would be to not invalidate the tile caches on load state, making it check which bytes have changes and only invaliding those that have changed.

Edit once again:

Got it working! But I have no idea how fast it would run on a PS3 at this point. Probably easily more than 60FPS at this point.


#283

Just tried this out on my Mac and it’s really quite magical.

Thanks for all the hard work!


#284

Just tried it with a few SNES, Genesis and PC-Engine games and it works great. Feels all very responsive. One quick question: Any chance that you make the vice_x64_libretro.dll (C64 Emulator) compatible too? That would be amazing. Thanks for you work on that really important matter in emulation.

edit: Ah, this technique relies on save states. And vice doesn’t support it yet. Hopefully this changes in the near future.


#285

If this is working on a PS3 the cpu requirements shouldn’t be that bad. I would expect a high end core 2 duo to handle this for now 16bit stuff and lower.

Looking forward to testing!


#286

@Dwedit wouldn’t it be better to just run the game normally and save the state at the end of every frame, keep the last N frames save states, and when the input changes, roll back of N frames, apply the input and quickly re-emulate N frames within the time of 1 console frame without rendering any of them other than the last? Applying the input to N frames ago will result in the new rendered frame being input lag free. It would definitely be less stressful on the HW than always rendering N frames “per frame”.


#287

I’m quite familiar with how you can save time by only rolling back on dirty input. I’m already doing something very similar with Secondary Core enabled (only resyncs the two cores on dirty input).

The problem is that some features of retroarch (such as Cheevos and Netplay) do not play well with a “Run Frame” function that leaves you in a different state than the very next frame. Right now, I’m ensuring that runahead always leaves the emulator in the same state as if it had run a single frame.


#288

Just made a big pull request for Genesis Plus GX, looks like it was accepted. I’d like to see how this one performs on the PS3.


#289

Thanks for the GPGX fixes! I found some issues though. If secondary instance is disabled when CD audio is playing for a minute or so RetroArch will freeze. Found this happening in Lunar when just walking around Burg and during a voiced cutscene in Snatcher. Disabling run ahead or enabling secondary instance fixes it. Genesis TMSS bootrom is fixed, but Game Gear and Master System bootroms are still not working with run ahead.


#290

Weird, Sonic CD ran fine for extended times, even got the 3 minute game over.

edit: Please provide an exact game title, save file, and an exact list of steps to trigger the bug, I can’t see any crashes or freezes at the beginning of either game.


#291

I tried to replicate the crash again and couldn’t. I realized I turned off the system bootrom option, so I tried turning that back on. Doing that while running any CD game will cause RA to crash as soon as you try to go back to the game. So it seems enabling the bootrom option along with secondary instance off causes the Sega CD freezes/crashing. Odd, since Sega CD shows the BIOS whether it’s enabled or not.

Edit: Hmm, well I can’t replicate the freeze during gameplay anymore even if bootrom is enabled at startup. Only the crash if I turn bootrom on or off while content is loaded and then dismiss XMB.


#292

Got a chance to try this with Mednafen Saturn today and to my surprise it works (I didn’t even know Saturn had savestates!). But performance is very poor. I am getting about 90fps without any runahead, and 50-55fps with 1 frame runahead. This game appears to have 5 frames of internal lag so there definitely is a ton to be gained if this could be somehow optimized!

BTW thank you to Dwedit and all who worked on this feature. Amazing! :smile:

edit: forgot to mention I was testing Guardian Heroes U-NTSC


#293

Which game is that?

I don’t think it’s internal game lag. The core itself is very laggy, adding at least 3 frames of lag in all games, from what i can tell. Can’t prove it though. But i’m sure it does.


#294

They added a new core option to combat lag. Well, it doesn’t do anything for the internal lag, still measured 5 frames whether that settings was on/off.


#295

When I tried running Smash Tennis / Super Family Tennis in RetroArch 1.73 with Snes9x Core and runahead enabled, everything came to a crawl during the namco-logo or while in the menus. I suppose this is happening because the game uses interlaced hi-res-output. When I disabled runahead, everything went back to normal. Is this a known issue?


#296

The problem with this feature is that now it’s going to make it very hard to use other emulators. This feature has completely eliminated my input lag on my HTPC set up and is IMO a milestone in emulation history, so thank you!

I’m very curious if this helps Input lag with MAME even better than Groovymame on non CRT displays? Galaga ‘88 has the worst driver input lag.

Additionally now that this feature is implemented, focus work should be done on porting/updating/ and fixing bugs in cores so RA can be the most compatible, mainstream program for retro gaming.


#297

I don’t think it works with MAME currently, but it should work mostly okay with FBA.

As for comparing with GroovyMAME, AFAIK their options are all about getting the input polling and the image rendering/display as close as possible (including the new beam-racing/raster-slicing method). Most of our latency options take this same approach. Runahead, though, is completely different and is more akin to how online games try to hide latency.


#298

Unfortunately when I tested FBA it had some odd bugs with Runahead turned on, regardless of whether Secondary Core was activated and irrespective of the number of frames.

Some games in particular (like Battle Garegga and Gunbird) had some strange audio issues, with the music or sound effects being noticeably sped up.


#299

Enable “Runahead Use Second Instance”. Then you get full frames in Snes9x for Smash Tennis in the hires game menu. Of course only if your PC is fast enough for it.


#300

Does this run ahead method use separate core affinity allowing multithreaded cpu to cover performance? Most emulators use just one core.


#301

Thank you for the quick reply, though I’m afraid that’s not the solution since I’ve had the second-instance-option enabled already. The only option that makes the slowdown go away is turning vsync off. Interestingly, when I do that in the Smash Tennis menu, then the RetroArch video statistics report twice the expected framerate (120 fps instead of 60). I also tried one of the bsnes-cores and Arkanoid - Doh It Again, another SNES-game that switches to interlaced in some cases, same slowdown, same double framerate. Then I also tested the mednafen cores with some Saturn and PlayStation games that have interlaced video (Panzer Dragoon Zwei titlescreen, Radian Silvergun titlescreen, Gran Turismo titlescreen) and no slowdown at all, even with vsync on. also when turning vsync off, the reported framerate in the video statistics still remained as expected somewhere around 60hz. Seems like something fishy is going on with interlaced video timing for SNES cores when runahead is enabled.