loki-47-6F-64 / sunshine

Host for Moonlight Streaming Client
GNU General Public License v3.0
1.77k stars 154 forks source link

NVENC encoder has higher latency than software encoder #316

Open Stewmath opened 2 years ago

Stewmath commented 2 years ago

I was surprised by this result, but, the NVENC encoder seems to have somewhat more latency than the software encoder. I don't have proper hardware to test this with, so I used the latency calibration feature in Crypt of the Necrodancer. NVENC consistently has around 20ms more latency than the software encoder on my machine.

This is after setting the preset to "ll (low latency)" and setting the NVEnc coder to "cavlc" (I have read that it theoretically can be faster but I don't really know).

Running on Arch Linux, and using the "nvidia-utils-nvlax" package to enable NvFBC on my GTX 960. Using Sunshine v0.11.1.

ReenigneArcher commented 2 years ago

I understand that every ms counts when game streaming, but for comparative purposes 20ms is 0.02 seconds. Perhaps the increase is just due to the latency of using PCI.

Stewmath commented 2 years ago

Certainly it's nothing major. It's even less than the latency caused by my TV display relative to my computer monitor (27ms if displaylag.com is accurate). But I was a bit disappointed to see the numbers get worse after recompiling with CUDA support. I recall reading elsewhere (#120) that some processing is still done on the CPU, perhaps this is related somehow.

KuleRucket commented 2 years ago

How do you objectively measure the encoder latency? Moonlight only reports decoder latency so I would be interested in running some tests using different encoder settings.

Stewmath commented 2 years ago

As I mentioned, I'm using the latency calibration feature from the video game Crypt of the Necrodancer. It shows a heart beating on the screen and tells you to press the "up" key every time it beats. After around 30 seconds of this it estimates the total amount of video latency in milliseconds (and it does a separate test for audio latency). Unfortunately I haven't found a test similar to this that's free.

Unfortunately there's something really messed up with the controller support on Linux which makes it annoying to run tests with. I'm using proton now, but even then it can take a minute for it to recognize that the controller (or virtual controller in the case of Sunshine) is there.