An input lag investigation

Added GitHub Issue:

EDIT: Added $120 Cash to BountySource:

I’ll dollar-match your donations

I will dollar-match all your future donations (between now and end of September 2018). I donate another $1 everytime anyone donates $1 until the BountySource hits the $360 level.

EDIT: That was FAST! BountySource now $1050 and my share maxed at $360

2 Likes

Cool that you made a bounty for this. Hope it goes well.

Awesome. What’s the difference with this and Runahead? As far as i know Runahead cuts down “internal game” lag frames that exist in the original hardware. Can this do the same?

it’s completely different. It reduces display lag to very low levels, potentially similar to original hardware and/or vsync OFF without tearing.

2 Likes

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.