djanatyn / ssbm-nix

Nix expressions for Super Smash Bros. Melee players.
31 stars 17 forks source link

Input lag #5

Closed ursi closed 3 years ago

ursi commented 3 years ago

There is noticeably more input lag on the nix build of this game than the windows build for me. I would love to be able to have a good experience playing this on nixos. I'm wondering if there is something I could potentially fix, or if that's just the current state of things. Other than that slight input lag, the game seems to be running fine, I'm not noticing stutters or frame drops.

djanatyn commented 3 years ago

Sorry to hear you're experiencing input lag!

I'm wondering if there is something I could potentially fix, or if that's just the current state of things. Other than that slight input lag, the game seems to be running fine, I'm not noticing stutters or frame drops.

I'm not having this issue, so I'm hopeful this could be fixed. A few questions:

Since you're not experiencing any input lag on Windows, you shouldn't need to adjust your hardware. Still, you could try to use a different USB port for your adapter (or if you're using a hub, connect the adapter directly to your computer).

My poll rate is detected as ~500hz within Slippi: rate

If it helps, here's the output I'm getting from lsusb -sv 46 with some information on my working adapter (Mayflash model):

Bus 001 Device 046: ID 057e:0337 Nintendo Co., Ltd Wii U GameCube Controller Adapter
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x057e Nintendo Co., Ltd
  idProduct          0x0337 Wii U GameCube Controller Adapter
  bcdDevice            1.00
  iManufacturer           1 Nintendo
  iProduct                2 WUP-028
  iSerial                 3 15/07/2014
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0029
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     214
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0025  1x 37 bytes
        bInterval               8
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0005  1x 5 bytes
        bInterval               8
Device Status:     0x0002
  (Bus Powered)
  Remote Wakeup Enabled
ursi commented 3 years ago

I'm using a Mayflash adapter. My poll rate is only 125 hz. I don't think changing that to 500 would fix all my problems but it's still definitely worth it to do. Can I increase it? My delay frames is 2. I'm plugged directly into the computer but I tried a different USB port anyway and it didn't change anything. I'm not knowledgeable enough for that output to mean anything to me, but if you are, here's mine to compare http://ix.io/2Uvl

djanatyn commented 3 years ago

It sounds like your configuration isn't using Sweetlow's HIDUSBF driver:

The driver HIDUSBF and its associated tools, developed by Sweetlow, allow you to overclock the polling of your GCC to USB adapter by your PC to 1000Hz. By default, the PC polls it at 125Hz (every 8 milliseconds).

This should result in a much closer experience to console play. It also reduces input lag (by up to 3.5ms), but the latency stability benefits (which directly impact execution) obtained far outweigh the latency benefits.

If you're using the nixosModule from this flake, there's an option to enable it:

 ssbm.gcc.oc-kmod.enable = mkEnableOption "Turn on overclocking kernel module.";

You can also just use the gcadpter-oc-kmod driver directly from nixpkgs:

boot.extraModulePackages = with pkgs.linuxPackages_latest; [
   v4l2loopback
   gvusb2
   gcadapter-oc-kmod
];
ursi commented 3 years ago

I have that module enabled, but maybe I have to restart my system for it take effect? I currently have a lot of things open for work but I will report back when I do it. Is this something that the windows version has baked in?

djanatyn commented 3 years ago

I have that module enabled, but maybe I have to restart my system for it take effect?

You might need to load the module. I think that's usually done with: sudo modprobe gcadpater_oc

You can check to see if it's loaded without restarting your system using lsmod:

❯ sudo modinfo gcadapter_oc
filename:       /run/booted-system/kernel-modules/lib/modules/5.10.7/extra/gcadapter_oc.ko
version:        1.4
description:    Filter kernel module to set the polling rate of the Wii U/Mayflash GameCube Adapter to a custom value.
author:         Hannes Mann
license:        GPL
srcversion:     56D5BA316B53D5637F1B67F
depends:        usbcore
retpoline:      Y
name:           gcadapter_oc
vermagic:       5.10.7 SMP mod_unload 
parm:           rate:Polling rate (default: 1)
❯ lsmod | grep gcadapter_oc
gcadapter_oc           16384  0
usbcore               278528  15 xhci_hcd,gvusb2_video,snd_usb_audio,usbhid,snd_usbmidi_lib,xpad,cdc_acm,apple_mfi_fastcharge,usb_storage,uvcvideo,btusb,xhci_pci,uas,gvusb2_sound,gcadapter_oc
❯ grep gc /proc/modules
gcadapter_oc 16384 0 - Live 0x0000000000000000 (O)
usbcore 278528 15 apple_mfi_fastcharge,cdc_acm,gvusb2_sound,gvusb2_video,xpad,gcadapter_oc,uvcvideo,uas,usb_storage,snd_usb_audio,snd_usbmidi_lib,btusb,usbhid,xhci_pci,xhci_hcd, Live 0x0000000000000000

For more information you could try running:

Is this something that the windows version has baked in?

Windows does not have this overclock enabled by default. You may still experience input lag when using this kernel module. Given that your polling rate is low (and I didn't see anything else notable), I think it's the best thing to address first.

ursi commented 3 years ago

okay the polling overclock seemed to help a lot! Is there any reason you wouldn't want the polling module turned on? Could we put that command in an activation script or something so enabling it in the module means it's turned on on your system?

ursi commented 3 years ago

I'll make this a separate issue