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

thats strange… file works fine here. im modifying it for gba atm

EDIT: here’s another version, that does the same thing but with less modification. note: this is not a final version, only tested on super mario advance 4, if it still crashes then i dunno why since it works in new released 1.7.2

http://www.mediafire.com/file/drvxvflfcz2in9l/vbam_libretro_input_test_x64.zip

1 Like

It’s working fine now and it reacts in 2 frames, good work!

I had to kill
input_libretro_device_p3 = “0”
to
input_libretro_device_p16 = “0”
that were in my retroarch.cfg.

If only they could never come back again…
I cleaned that already for a problem like that.

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.

2 Likes

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

Thanks for all the hard work!

1 Like

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.

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!

@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”.

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.

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.

3 Likes

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.

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.

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.

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

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.

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.

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?

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.

1 Like

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.

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.

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.