This page is about latency (input lag) in FS-UAE, and how to reduce it. With latency, we mean slightly different things which are related:
- An extra delay – more than would occur on a real Amiga – before an input event (key press, joystick movement, etc) has an effect in the Amiga.
- An extra delay before the Amiga video frame is visible on the computer monitor.
The input lag you experience when using FS-UAE will be the sum of these two latencies. In addition, there will be some audio latency as well (not discussed yet).
Latency Caused by Video Sync
By default, FS-UAE only updates the screen during the monitors vblank interval. This prevents tearing from occuring, but will also mean that some frames are delayed. A simple way to reduce video latency is to use the option video_sync = off.
With default settings, if your current screen mode refresh rate equals the Amiga refresh rate (50Hz for PAL), FS-UAE will also sync the emulation to this display rate to achieve “perfectly smooth scrolling”. In order to get good performance by default, FS-UAE emulates one video frame during a 20 ms interval while it renders the last generated video frame in parallel. This “pipelining” works well, but introduces one frame of latency (20ms). If you have a decent computer, you may want to enable the following option: low_latency_vsync = 1. With this option set, FS-UAE will emulate a frame and then render it during the same 20 ms interval. It is possible that future FS-UAE versions will enable low_latency_vsync automatically if it measures that your system can handle it.
On a side note, the FS-UAE author looks forward to trying out monitors with G-Sync in the near feature, as that looks promising for both low latency, good performance and smooth scrolling without any obvious drawbacks 🙂
There are some additional things you should be aware of which can affect video latency:
Video Frame Queuing
It is possible that some video drivers queue up frames instead of displaying the immediately, without telling FS-UAE about this. Set the “max frames to render ahead” (NVidia) or “flip queue size” (AMD/ATI) to 0 (zero) in your video card driver’s setting utility or control panel. This tip comes from the mednafen docs, and it is not certain that these driver options are relevant for OpenGL or whether they only apply to Direct3D.
Game Mode on TVs
Your monitor can also add some latency to the video output. This is especially true for TVs which processes the video frame heavily before displaying it. If your monitor/TV has a “game mode” (very common for TVs), then you should definitively ensure that this is enabled.
With desktop environments performing compositing for “fancy window effects”, you risk that this compositing introduces an extra frame of latency. Using fullscreen mode usually/probably prevents this from happening – or just disable the desktop compositing mode if possible. The FS-UAE author uses the MATE desktop on Linux without any compositing to get the best possible OpenGL performance in both windowed and fullscreen mode.
Running FS-UAE in a window with the Unity desktop and nVidia binary drivers causes bad performance when syncing to vblank. This is not a bug in FS-UAE. Use video_sync = off or run in fullscreen instead to work around it.
Currently, input is polled from the system devices once every frame (once per 20 ms when emulating a PAL Amiga). This means that some input events which could otherwise be applied to the emulation immediately may have to wait until the next emulated frame.
There are technical reasons why input is only polled once every frame (basically because both the video renderer as well as the input event loop runs in the main thread).
The plan is to move the video renderer to a new/separate thread, so input events can be waited for continuously, and applied at the earliest possible time. This work will be done while migrating FS-UAE from SDL 1.2 to SDL 2.0, as the new version of SDL is better suited to running the video renderer in a separate thread.
USB Device Latency
Some USB devices may have higher latency than others. It might be a good idea to not use the cheapest USB game pad available (though price and performance does not always correspond…).
As an example, it has been reported that at least some models of the Speed-Link Competition Pro exhibits severe latency.
Joystick Devices vs Keyboard
On some systems, joystick/gamepads input may take a more direct route to FS-UAE, while keyboard events are sent via the windowing system. It is possible that this introduces a bit extra latency for keyboard events on some systems. This is not verified, but using a low-latency gamepad / joystick could be a good idea nevertheless.
TODO: write about the “new mouse devices” in the 2.3.x series.
TODO: write about audio latency.