23 July 2016, 20:09 | #1 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,344
|
Late emulation to reduce input lag?
This post has a rambling suggestion about how to (maybe) minimise input lag in emulation. [After writing most of this I discovered that RetroArch/libretro apparently implements something like this; they call it "frame delay".]
By input lag I mean the delay between pressing a controller button and the result being shown on the PC monitor. Maybe low-latency vsync mode does exactly this already??? I'll assume emulation runs vsynced, so the emulated Amiga frame rate matches that of the PC display. I'll also assume that emulation of each Amiga frame takes only a small proportion of a PC frame. For example WinUAE might take 10% of PC frame time to emulate one Amiga frame. How does the timing work then? Is it like this? [PC vblank] [PC output image is of previously-rendered Amiga frame n] WinUAE wakes up, detects user input, renders Amiga frame n+1 and hands it off to the graphics driver WinUAE sleeps until the next PC vblank (i.e. for ~90% of frame time). [PC vblank] [PC output image is Amiga frame n+1] etc. In that case there is a delay of ~90% frame time between when WinUAE finishes rendering the Amiga image, and when it gets shown on the PC display. An alternative would delay emulating each frame, so there is a smaller delay between sampling input devices/emulating/handing off image to graphics driver and when the image is displayed on the PC monitor. [PC vblank] [PC output image is of previously-rendered Amiga frame n] WinUAE sleeps for 80% of frame time. WinUAE wakes up, detects user input, renders Amiga frame n+1 and hands it off to the graphics driver WinUAE sleeps until (next vblank time + 80%) [PC vblank] [PC output image is Amiga frame n+1] etc. Waking up at the 80% point of each PC frame allows for some leeway; some Amiga frames take longer to emulate than others, other programs running on the PC might make emulating that frame take longer etc. With that scheme, the delay between checking for user input and when the emulated Amiga frame gets displayed would be <= 20% of a frame. Different speed PCs, emulation settings and graphics drivers would need the amount of sleep to be adjustable. |
23 July 2016, 21:37 | #2 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,535
|
There is -extraframewait <value> command line parameter that waits <value> milliseconds after each frame before emulation of current frame starts, made just for this purpose. (not officially supported!)
Note that next version will have lower input latency and also sound latency (wasapi only currently). |
24 July 2016, 14:44 | #3 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,344
|
Excellent, I didn't know about that. I'll give it a try next time I boot into Windows. (It's unlikely to work well on Wine.)
Perhaps a future version could add GUI support and some kind of auto-adjust feature. E.g. start emulation, WinUAE initially uses 10ms delay. If no overruns (emulating Amiga frame always completes before PC vblank) after a certain number of frames then try 15ms, 17.5ms. If overrun dial back to 16ms etc. Or just tell the user there was an overrun in the log so they can adjust manually. Edit to add: How does the current -extraframewait work with black frame insertion? It should sleep from PC vblank prior to a non-black frame, and wake up part way through displaying a black frame. As opposed to the other way around of course. Last edited by mark_k; 24 July 2016 at 14:50. |
24 July 2016, 21:45 | #4 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,344
|
Are any other config settings required for the -extraframewait setting to be used?
Looking at the framewait() function in custom.cpp, it seems the value returned by isvsync_chipset() needs to be < 0 but not -2 or -3 for the code Code:
if (extraframewait && !currprefs.turbo_emulation) cpu_sleep_millis(extraframewait); Also in win32.cpp there is Code:
cfgfile_target_dwrite (f, _T("extraframewait"), _T("%d"), extraframewait); |
25 July 2016, 11:34 | #5 |
Registered User
Join Date: Aug 2014
Location: Zagreb / Croatia
Posts: 302
|
|
25 July 2016, 14:34 | #6 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,535
|
It is unsupported, don't ask too specific questions
It should work with low latency vsync and with black frame injection. It is impossible (without time machine) to make it automatic, emulation time usage can be extremely variable. |
13 October 2016, 21:58 | #7 | |
Registered User
Join Date: Jul 2008
Location: Netherlands
Posts: 485
|
Quote:
Since you're interested in it (or anyone else for that matter), it's probably good to mention that -extraframewait (framedelay) currently does not work with Wasapi audio modes, as framewait gets aborted as soon as there's a Wasapi pull event. Just so that you don't get the wrong impression when testing it. But as Toni mentioned, it's an unsupported feature (currently). |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Putty Input Lag - New Patch Possible? | manic23 | Games images which need to be WHDified | 8 | 18 May 2013 21:27 |
[FS-UAE] Heavy input lag with VSync | RealNC | support.FS-UAE | 2 | 07 July 2012 05:53 |
Is WinUAE optimized for lowest possible input lag? | Dr.Venom | support.WinUAE | 22 | 03 July 2011 02:14 |
Input lag, soupy cursors, and whatnot | twinbee | support.WinUAE | 3 | 05 June 2009 01:03 |
Joystick input lag | Torkio | support.WinUAE | 3 | 06 March 2007 00:56 |
|
|