Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream/Game lags when streaming at 4K only #141

Open
lyndonguitar opened this issue Dec 10, 2024 · 19 comments
Open

Stream/Game lags when streaming at 4K only #141

lyndonguitar opened this issue Dec 10, 2024 · 19 comments

Comments

@lyndonguitar
Copy link

lyndonguitar commented Dec 10, 2024

I am currently experiencing this problem and maybe anyone have some ideas

I use Apollo, streamed to Xbox Series X Moonlight
Whenever I try streaming a game in 4K, the game lags (low fps) that it becomes unplayable. Turning down the resolution, graphics settings or setting a lower DLSS/upscaling mode immediately improves the FPS by a lot and makes it little bit playable.

Note that the games I've trying to stream runs fine at 4K (more than 60fps even reaching 100+) when played locally (not streaming), but then it loses its all performance when streamed at the same settings at 4K. I need to turn down some graphical settings for the stream to be playable. Is this really the case for streaming? I never had this problem streaming at lower resolutions like 2560x1440 and 1920x1080 (I just purchased a new 4K monitor).

I also tried tinkering with some settings and here's what I've tried
Performance preset = P1
Two-pass mode = quarter
Spatial AQ = 0
Single-frame VRB/HRD = 0
HDR on and off
minimum CPU Thread count = 2 and 4
Force a specific Encoder = Auto and NVENC
NVENC Encoder Settings = Use realtime priority (HAGS) = enabled and disabled
Intra Refresh = Enabled

Specs:
Ryzen 7 5700x3D
32GB RAM
RTX 3080 10GB
3840x2160 144hz HDR monitor with VRR(Gsync support) - i don't know if it matters since there's a virtual display anyway but I included it just incase

@theBeaz
Copy link

theBeaz commented Dec 10, 2024

Are you playing Steam games? Do you have Steam Recording on? If so, disable that. It cut my 4k streaming performance down to 30-45fps as well. Back to 120fps streaming when off. I have a 5800x3d and a 3090, so similar to you.

@lyndonguitar
Copy link
Author

Are you playing Steam games? Do you have Steam Recording on? If so, disable that. It cut my 4k streaming performance down to 30-45fps as well. Back to 120fps streaming when off. I have a 5800x3d and a 3090, so similar to you.

Thank you for the suggestion, I will try it and report back. I indeed play steam games, although one game I've tried was non-steam launched via steam (but maybe recording was still activated on it)

@theBeaz
Copy link

theBeaz commented Dec 10, 2024

Launching a non-steam game through Steam will enable the Steam overlay (which will then cause the issue if recording is on). Fingers crossed that’s the problem!

@lyndonguitar
Copy link
Author

lyndonguitar commented Dec 10, 2024

Launching a non-steam game through Steam will enable the Steam overlay (which will then cause the issue if recording is on). Fingers crossed that’s the problem!

I tried running a game outside steam and disabled steam recording for good measure but sadly, it didn't work for me. Still laggy.

But after a thorough investigation, I've found the cause. It has something to do with FPS and refresh rates of both client and host. I displayed my FPS via RTSS while streaming and while my stream at 4K appears to be lagging, it actually has good FPS (60FPS+) displayed. Turning down the resolution/graphics appears to make the game more playable by having an over abundance of frame rate, but this wasn't really solving it, more like just brute forcing it.

What solved it was actually limiting the FPS between client and host, by either of the following:

Activating V-Sync on Host
Or using RTSS to limit frames to 60fps (in theory any sort of frame limiter would do)
The game felt immediately smoother and just like playing locally on either methods. This is probably why even before, when I was streaming at 1080p, it really didn't feel smooth even though I was streaming at 100+ FPS, but it was playable.

As a way to avoid manually toggling vsync or manually setting the FPS limit (which would be to be done every time you want to stream, for example if your main host monitor is more than 60hz or has VRR), I propose an option within Apollo to introduce an FPS limit to the stream itself, or maybe a process that opens during a stream session that RTSS can detect (e.g. Apollosession.exe) so that we can set a framerate limit unto.

@ClassicOldSong
Copy link
Owner

If you're using AV1, switch to HEVC should solve the lagging problem immediately. There's a bug in Nvidia's AV1 encoder that causes lag in some specific scenarios while AMD and Intel ones don't.

@lyndonguitar
Copy link
Author

lyndonguitar commented Dec 10, 2024

If you're using AV1, switch to HEVC should solve the lagging problem immediately. There's a bug in Nvidia's AV1 encoder that causes lag in some specific scenarios while AMD and Intel ones don't.

I believe I was already using HEVC, but just to be sure I selected the "Apollo will not advertise support for AV1" and ran a stream. It still lags for me the same. Same with the comment above, the workaround I've found is still vsync or frame limiter for now

@ClassicOldSong
Copy link
Owner

I'm on 4080S but not noticing the lagging problem with or without vsync on...

@lyndonguitar
Copy link
Author

lyndonguitar commented Dec 11, 2024

I'm on 4080S but not noticing the lagging problem with or without vsync on...

By any chance have you noticed if your host FPS is going over the refresh rate of the client or is it locked on yours?

Also, I was able to do some further tests. I thought this was an Xbox client problem at first but I also tried streaming 4K to my laptop as client and the results are the same. Turning on the built-in v-sync/frame pacing on the laptop client (a feature which isn't available on Xbox), does not seem to fix it.

Only turning on v-sync/frame limit on the host removes the bad stutter. I'll try to video capture it later.

I also would like to note that the lagging problem becomes unperceivable for me when streaming at lower resolutions or lower graphics settings (confirmed again by playing the laptop at 1440p or setting DLSS to performance, it becomes playable). So your 4080s may simply have more horsepower to "brute force" it more than my 3080 (my gpu may be in a weird spot, performance wise) that needs v-sync for it to work. It can be a reason why it doesn't appear for you even at 4K. To add info: the games i've been using for testing are Space Marine 2, and Helldivers II

@lyndonguitar
Copy link
Author

lyndonguitar commented Dec 11, 2024

Video detailing the stuttering problem (uploaded on youtube as unlisted)

Logs that might be helpful that were generated during my testing
apollo log.txt

@ClassicOldSong
Copy link
Owner

Can you turn on stats on the client and check what it says when the lag happens?

@lyndonguitar
Copy link
Author

lyndonguitar commented Dec 11, 2024

Can you turn on stats on the client and check what it says when the lag happens?

I recorded a screencap from OBS on the client while streaming (unlisted on youtube)

First part is playing with vsync on (60fps and smooth)

Around the 30 second mark i turned off v-sync and the lag starts to happen (you can see the FPS still above 60fps on the host when i turn off the apollo metric to show rivatuner metrics)

around the 1 minute mark, I switched to ultra performance DLSS which removed the lag again but host FPS is noticeably higher at 100FPS+.

A difference that I noticed is during the configuration where it lags, my GPU usage frequents at 99%. While when vsync is turned on, GPU usage is lower. When DLSS was set to ultra performance, GPU usage got as high as 98%, but not as frequent, with that, I didn't really experience any sort of lagging.

@ClassicOldSong
Copy link
Owner

When lag happens the video stream sent from host is only ~30fps and the host processing time shoots up to 160+ms. It's your graphics card bottlenecked. Leaving VSYNC on should be a good idea and save some electricity.

@lyndonguitar
Copy link
Author

When lag happens the video stream sent from host is only ~30fps and the host processing time shoots up to 160+ms. It's your graphics card bottlenecked. Leaving VSYNC on should be a good idea and save some electricity.

That's what I thought. Weirdly enough though, I tried going back to Sunshine as host just to test, and surprisingly the problem wasn't there. Same settings, 4K DLSS Balance no Vsync, and there is no lag. I even tried DLSS Native and even when my GPU was more worked and only outputted 30FPS+, there is no stutter/lag like I was experiencing before.

I recorded another video with metrics on screen if that interests you.

Btw thanks for the constant response.

@ClassicOldSong
Copy link
Owner

When using Sunshine are you still using a virtual display or streaming your physical display?

@lyndonguitar
Copy link
Author

When using Sunshine are you still using a virtual display or streaming your physical display?

I was using a physical display, when I did the testing.

@ClassicOldSong
Copy link
Owner

Interesting, still might be a Windows issue that beyonds thirdparty developer's ability though

Could be no actual vsync signal triggered on virtual display but physical display has a clock that kicks the driver.

@lyndonguitar
Copy link
Author

Interesting, still might be a Windows issue that beyonds thirdparty developer's ability though

Could be no actual vsync signal triggered on virtual display but physical display has a clock that kicks the driver.

I tried reproducing it on Apollo, and when I disabled headless mode and virtual display and streamed via Physical Display, there is still lag when I'm using Apollo

@ClassicOldSong
Copy link
Owner

The video capture and encoding part is the same as Sunshine, just Apollo merges the latest commit from Sunshine. It shouldn't have any difference if you're using the latest nightly build of Sunshine.

@kayti
Copy link

kayti commented Dec 13, 2024

What about HAGS (Hardware accelerated GPU SCheduling)? Should be turned OFF for high memory usage games or stream will lag, stutter or have low performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants