English Amiga Board


Go Back   English Amiga Board > Support > support.WinUAE

 
 
Thread Tools
Old 23 July 2016, 20:09   #1
mark_k
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.
mark_k is offline  
Old 23 July 2016, 21:37   #2
Toni Wilen
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).
Toni Wilen is offline  
Old 24 July 2016, 14:44   #3
mark_k
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.
mark_k is offline  
Old 24 July 2016, 21:45   #4
mark_k
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);
to be executed. I couldn't find which file defines the isvsync_chipset() function, at least a search for the function name in the WinUAE repository on github didn't show that.

Also in win32.cpp there is
Code:
cfgfile_target_dwrite (f, _T("extraframewait"), _T("%d"), extraframewait);
Does that mean it can be used in config files too?
mark_k is offline  
Old 25 July 2016, 11:34   #5
Tomislav
Registered User
 
Join Date: Aug 2014
Location: Zagreb / Croatia
Posts: 302
Quote:
Originally Posted by mark_k View Post
I couldn't find which file defines the isvsync_chipset() function, at least a search for the function name in the WinUAE repository on github didn't show that.
isvsync_chipset() is in drawing.cpp in root of WinUAE source directory.
Tomislav is offline  
Old 25 July 2016, 14:34   #6
Toni Wilen
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.
Toni Wilen is offline  
Old 13 October 2016, 21:58   #7
Dr.Venom
Registered User
 
Join Date: Jul 2008
Location: Netherlands
Posts: 485
Quote:
Originally Posted by mark_k View Post
Are any other config settings required for the -extraframewait setting to be used?
Hi mark_k,

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).
Dr.Venom is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:35.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08386 seconds with 15 queries