An input lag investigation

BountySource now $140 for lagless VSYNC

Someone added $10, so I also added $10.

NOTE: I am currently dollar-matching all donations (thru the $360 level) until end of September. Contribute to the Bounty pot: https://www.bountysource.com/issues/60853960-lagless-vsync-support-add-beam-racing-to-retroarch

For every $1 you donate, I will donate another $1 – until end of September – or until $360 bounty is built up.

BountySource now $200 for lagless VSYNC

Twinaphex added $30, which I matched with $30.

3 Likes

Big contribution from bparker :open_mouth:

2 Likes

$1050 !!! !!! !!!

Wow, that maxes out my dollar-doubling commitment.
I’ve now donated $360 total – in addition to bparker06’s donation of $650.

I’m going to try to reach out to bparker06 to personally thank him for the generosity to the bounty prize pot.

This is now currently the #32 biggest bounty on BountySource.

6 Likes

Amazing!
Hope that it comes to fruition in Retroarch.

1 Like

Huh how does that work. The site shows donations from 2017.

He transferred them from another bounty that wasn’t getting any interest.

1 Like

its realy helpful information.

I’ve been reading the new tests made in the last year and I’d like to thank again Brunnis and the rest for them and for this thread in general. Hopefully someone with the knowledge gets interested enough in the subject and tries to “lag-fix” other cores such as the infamous PPSSPP one. I think this is one of the main reasons that make RA unique and it’s becoming one of main concerns no matter the level of expertise.

After all this reading though, I’m not sure what’s ultimately recommended for Windows 7, and old ATI card (good CPU power, though) and CRT 15khz usage (so no shaders): GL? D3D 9? DRD 11? Is still D3D as “laggy” as it used to be against GL? As I understand, hard gpu sync is not yet implemented in D3D 11, right?

Also, is there any guide to try the new Wasapi Windows audio driver?

Thank you!

1 Like

EPIC thread.

Since the 1 frame of additional input lag in Linux vs Windows 10 has been removed, is it reasonable to conclude that the Raspberry Pi 3B is the lowest-cost solution for zero input latency emulation?

Last I checked (which admittedly was a good while ago), the Raspberry Pi’s default closed-source video driver added a frame of input lag that you couldn’t get rid of. The solution to that is to use the open source VC4 video driver instead and build RetroArch with DRM support (and set video_max_swapchain_images to 2). I’ve tried it and it seemed to work decently, with an important caveat: The Raspberry Pi is too slow to run even pretty easy stuff like SNES via snes9x2010 at full speed (some games will work great, but some will have slowdown). That’s without fiddling with the frame delay setting, which adds additional computational requirements.

So, I’d say x86 is still the way to go for a reasonably trouble free and well working solution, with decent performance. I’m personally running a very carefully setup system based on an Intel NUC7PJYH (latest “Atom” based CPU based on the Gemini Lake design). Unfortunately, it’s much more expensive than a Pi, but it’s also at least 4 times faster. Until we get a significantly updated Pi (I’d guess that would be the next one they release), low input lag emulation is still mostly an x86 thing.

1 Like

Thanks for the info, and your contribution to the retro gaming community! :grinning: Is the VC4 video driver the one where you can’t use any shaders? It’s been a while since I played with a Raspberry Pi. That might be another significant drawback for many users that would warrant more expensive hardware. Not being able to run SNES9x2010 fullspeed is definitely the biggest deal-breaker, though.

I’m using a similarly-powered system, the NUC6CAYS, running Windows 10. Are you running Linux on the NUC7PJYH? Any tips for optimal system set-up?

Thanks!

No, that’s Dispmanx.

Yes, running Ubuntu 18.04. Below are my notes for an optimal setup. Replace any occurrences of {username} and {user_password} with your Linux user name/password.

EDIT: The “guide” below is based on using Ubuntu 18.04. It will get you a Linux based RetroArch system that runs automatically on boot (auto-launched from the terminal using DRM/KMS for video output). When exiting RetroArch, the system will also shut down automatically in a controlled way. Using this guide, you can pretty easily set up a RetroArch console-like system, similar to RetroPie. Combined with RetroArch’s kiosk mode, you also get a system that cannot (easily) be corrupted by kids and other non-tech-savvy people. Great for creating a locked-down emulation box.

Set Ubuntu to start in console mode (you can skip this if using Ubuntu server flavor):

1. Find GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub and change it to GRUB_CMDLINE_LINUX_DEFAULT="text"
2. Update grub with sudo update-grub
3. Tell systemd to not load the desktop:
   - sudo systemctl enable multi-user.target --force
   - sudo systemctl set-default multi-user.target

Auto-login user:

1. sudo systemctl edit getty@tty1
2. Add these lines and exchange "username" with the real user name:
   [Service]
   ExecStart=
   ExecStart=-/sbin/agetty -a username --noclear %I $TERM

On Ubuntu Server, set network timeout so that it doesn't wait 5 minutes during boot for network to come up if no network is connected:

1. sudo systemctl disable systemd-networkd-wait-online.service
2. sudo systemctl mask systemd-networkd-wait-online.service

On Ubuntu Server, set ifup timeout so that it doesn't wait a long time during system shutdown if no network is connected:

1. sudo systemctl edit [email protected]
2. Add these lines:
   [Service]
   TimeoutStopSec=5sec

Make input in RetroArch work by setting correct permissions:

1. Add to /etc/udev/rules.d/99-evdev.rules:
   KERNEL=="event*", NAME="input/%k", MODE="666"
2. Then reload rules with sudo udevadm control --reload-rules.

Install cpufrequtils for controlling CPU governor:

1. sudo apt install cpufrequtils

To force the CPU to max turbo frequency at all times, we want to disable processor C states. If the motherboard/system supports disabling C-states via BIOS/UEFI, use this option. If not, do the following:

1. sudo nano /etc/default/grub
2. Find the line that says GRUB_CMDLINE_LINUX="". Add the following between the quotes: intel_idle.max_cstate=1
   NOTE: If there's already text between the quotation marks, just add the text at the end of the quote, with a space separating it from the existing text.
3. sudo update-grub
4. Reboot and check that the setting has had effect. The following command shall print '1': sudo cat /sys/module/intel_idle/parameters/max_cstate

Add RetroArch Ubuntu PPA and install RetroArch and cores:

1. sudo add-apt-repository ppa:libretro/testing
2. sudo apt-get update
3. sudo apt install retroarch
4. Install desired cores like this (snes9x as example): sudo apt install libretro-snes9x

Autostart RetroArch after auto-login, set CPU governor to performance, limit RetroArch to a maximum resolution (1080p in this example) and make the system shutdown when RetroArch is shutdown (with a 5 sec window to press key to abort and go to command line):

[Note: For maximum CPU performance, also disable C states in UEFI. However, leave SpeedStep enabled, since Turbo Boost otherwise seems to stop working. Note that these UEFI settings should be combined with using the "performance" CPU governor, otherwise the CPU will still try to lower its clocks. Disabling C states did seem to provide a small but measurable increase in performance over just setting the CPU governor to "performance".]

1. Install fbset: sudo apt install fbset
2. Go to the user's home directory.
3. sudo nano .profile
4. Add the lines below to the end of the file. Substitute {username} with the actual username. Substitute {user_password} with the user's login password.

# Set performance CPU governor for all four cores.
echo "{user_password}" | sudo -S cpufreq-set -c 0 -g performance
echo "{user_password}" | sudo -S cpufreq-set -c 1 -g performance
echo "{user_password}" | sudo -S cpufreq-set -c 2 -g performance
echo "{user_password}" | sudo -S cpufreq-set -c 3 -g performance

maxWidth=1920
maxHeight=1080

width=$(echo "{user_password}" | sudo -S fbset | awk 'NR==2{sub(/.*mode "/,"");sub(/x.*/,"");print;}')
height=$(echo "{user_password}" | sudo -S fbset | awk 'NR==2{sub(/.*x/,"");sub(/"/,"");print;}')

if [ $((width * height)) -gt $((maxWidth * maxHeight)) ]
then
    echo "Current resolution is ${width}x${height}, which is higher than the specified maximum of ${maxWidth}x${maxHeight}. Starting RetroArch in ${maxWidth}x${maxHeight}."
    sed -i "s/video_fullscreen_x = \"[0-9]\+\"/video_fullscreen_x = \"${maxWidth}\"/g" /home/{username}/.config/retroarch/retroarch.cfg
    sed -i "s/video_fullscreen_y = \"[0-9]\+\"/video_fullscreen_y = \"${maxHeight}\"/g" /home/{username}/.config/retroarch/retroarch.cfg
else
    echo "Starting RetroArch in ${width}x${height}."
    sed -i "s/video_fullscreen_x = \"[0-9]\+\"/video_fullscreen_x = \"${width}\"/g" /home/{username}/.config/retroarch/retroarch.cfg
    sed -i "s/video_fullscreen_y = \"[0-9]\+\"/video_fullscreen_y = \"${height}\"/g" /home/{username}/.config/retroarch/retroarch.cfg
fi

retroarch

if read -r -s -n 1 -t 5 -p "Press any key to abort system shutdown and return to the command line..."
then
    echo " Shutdown aborted."
else
    shutdown now
fi
2 Likes

Slightly unrelated but not that much, run ahead 2nd instance is working for FBA now.
You need to update the core and RA too (Dwedit fixed something there).

There’s many games where you can save 3 or 4 frames of lag.

Is Galaga ‘88 supported in FBA? That game’s input lag is atrocious for a SHMUP and even with a CRT and Groovymame with a high frame delay it’s just not good

Yes it’s here.
3 frames of lag you can remove.

Is runahead capable of mult thread / core performance?

What would be the best cpus to use the max of run ahead? I have an i7 6700k at 4.5ghz and it doesn’t seem enough for 4k bsnes higan with 2 instances. Using nSide helps a bit.

Testing Super Metroid and I get some frame drops.

The bigger issue with bsnes/higan and runahead is that non-deterministic savestates will cause internal desyncs. What this means is that sometimes a button you’re holding down will involuntarily release for a frame, causing, for example, charge shots to fire unexpectedly, etc.

But that’s not what I’m experiencing here. I can see fps going down to 50-55 fps when playing.

I guess this must be related to my cpu performance. Maybe I’m wrong.

Right, that’s unrelated. I was just letting you know that bsnes/higan isn’t really ideal for runahead anyway.

For your specific issue, you can try opening your system monitor/process viewer and see if any of your CPU cores are getting maxed out. If not, something else is likely dragging you down.

Hi guys, I was just trying out D3D9 hardware overlays, and wanted to know if that could be an answer to low latency in Windowed mode. I do see tearing when I rapidly display things, which seems like a good sign.

Edit: Nope, there appears to be an extra frame of latency in there.

Edit:

I wrote a simple DX9 program that rapidly calls Present in Flip Mode, so there will be realtime tearing on the screen. I made it display Black most of the time then display While while holding Enter.

On my laptop in Fullscreen mode, it ended up having roughly one frame worth of input lag between hitting enter and the program changing the screen color on the screen.

I also tested it in Windowed mode, resulting in one additional frame of input lag. I also tested using an Overlay surface, and while that did show tearing, it did not have any lower lag than a vsynced display.

2 Likes