LizardByte / Sunshine

Self-hosted game stream host for Moonlight.
http://app.lizardbyte.dev/Sunshine/
GNU General Public License v3.0
19.31k stars 940 forks source link

Sunshine doesn't switch display adapter between laptop iGPU and dGPU #2078

Closed namquang93 closed 1 month ago

namquang93 commented 9 months ago

Is there an existing issue for this?

Is your issue described in the documentation?

Is your issue present in the nightly release?

Describe the Bug

I'm using a laptop with both an Intel HD630 iGPU and an NVIDIA RTX. I use a dummy HDMI adapter into the HDMI port, which is wired directly to the dGPU so that I can stream from that dummy HDMI adapter and use dGPU for encoding, which supports HEVC HDR.

The problem is, when Sunshine starts along with Windows, it auto-detects the built-in laptop display + iGPU and uses that combo. After I use the MonitorSwitch app to specifically choose to turn off the built-in laptop display, only using dummy HDMI + dGPU, Sunshine still tries to use iGPU to encode, which causes an error.

It would have been much better if Sunshine could auto-detect the display adapter changes to choose the display adapter dynamically.

Expected Behavior

No response

Additional Context

No response

Host Operating System

Windows

Operating System Version

Windows 11 22H2 22621.3007

Architecture

64 bit

Sunshine commit or version

0.21.0

Package

Windows - installer

GPU Type

Nvidia

GPU Model

GeForce RTX 2080 Super Max-Q

GPU Driver/Mesa Version

551.23

Capture Method (Linux Only)

No response

Config

sw_preset = ultrafast
qsv_preset = veryfast
min_log_level = 0
qsv_coder = cavlc
global_prep_cmd = [{"do":"cmd /C C:\\Users\\ngqna\\Downloads\\qres\\qres.bat %SUNSHINE_CLIENT_WIDTH% %SUNSHINE_CLIENT_HEIGHT% %SUNSHINE_APP_NAME%","undo":"cmd /C C:\\Users\\ngqna\\Downloads\\qres\\qres_reset.bat","elevated":false}]
fps = [60]
resolutions = [
    1680x1050,
    1920x1080,
    1280x720,
    3840x2160
]
channels = 2
hevc_mode = 0
encoder = nvenc
gamepad = x360
av1_mode = 2

Apps

No response

Relevant log output

too long to paste here
ChrisKimZHT commented 9 months ago

I have a similar issue.

I purchased an HDMI emulator for streaming with the laptop lid closed. The HDMI emulator is connected to the dGPU, while the built-in display is connected to the integrated iGPU. To ensure that Sunshine captures only the content from the emulator, I specified the sunshine adapter to the dGPU, set the sunshine output to the emulator, and specified windows to display only on the built-in monitor. Windows will automatically switch to the HDMI emulator when the laptop lid is closed.

However, I encountered a problem. If I launch Sunshine with the lid open, it throws an error because it can't detect the specified emulator, which is expected because I specified to display only on the built-in monitor. But even after closing the lid, it doesn't refresh and still cannot stream.

To resolve this issue, I have to start Sunshine and immediately close the lid, allowing it to detect the emulator and stream normally.

ChrisKimZHT commented 9 months ago

Here is my error log. I'm not sure if my issue is related to this problem. If necessary, I can create a new issue.

[2024:02:01:01:17:06]: Info: // Testing for available encoders, this may generate errors. You can safely ignore those errors. //
[2024:02:01:01:17:06]: Info: Trying encoder [nvenc]
[2024:02:01:01:17:07]: Error: Failed to locate an output device
[2024:02:01:01:17:07]: Error: Failed to locate an output device
[2024:02:01:01:17:08]: Info: Encoder [nvenc] failed
[2024:02:01:01:17:08]: Info: Trying encoder [quicksync]
[2024:02:01:01:17:08]: Error: Failed to locate an output device
[2024:02:01:01:17:09]: Error: Failed to locate an output device
[2024:02:01:01:17:09]: Info: Encoder [quicksync] failed
[2024:02:01:01:17:09]: Info: Trying encoder [amdvce]
[2024:02:01:01:17:10]: Error: Failed to locate an output device
[2024:02:01:01:17:10]: Error: Failed to locate an output device
[2024:02:01:01:17:10]: Info: Encoder [amdvce] failed
[2024:02:01:01:17:10]: Info: Trying encoder [software]
[2024:02:01:01:17:11]: Error: Failed to locate an output device
[2024:02:01:01:17:12]: Error: Failed to locate an output device
[2024:02:01:01:17:12]: Info: Encoder [software] failed
[2024:02:01:01:17:12]: Fatal: Couldn't find any working encoder
namquang93 commented 9 months ago

However, I encountered a problem. If I launch Sunshine with the lid open, it throws an error because it can't detect the specified emulator, which is expected because I specified to display only on the built-in monitor. But even after closing the lid, it doesn't refresh and still cannot stream.

Yeah, I did the same. At first, I set the display Adapter Name and Output Name in Video/Audio settings to Nvidia DGPU and the dummy HDMI, hoping that when I closed the lid, the computer would turn off the main display and switch to the dummy HDMI, Sunshine would use them. But somehow it still uses the display & adapter at the start. I need to use Anydesk/Parsec to remote desktop to restart Sunshine for it to work.

Nonary commented 9 months ago

This is not a Sunshine issue, you won't be able to use IDDisplayDriver with perfect stability if you have an integrated graphics card because the OS will assign the adapter to the iGPU once your main display goes to sleep. If you disable the iGPU this wont happen anymore and it will work flawlessly.

Unfortunately this issue can also happen with dummy plugs as well, especially on laptops that use USB3 attachments instead of DP or HDMI which plug directly into GPU.

namquang93 commented 9 months ago

All I think is, maybe if Sunshine can't find the adapter/output it thought the computer was using at its start, it can just do a "soft reset" to update/get the currently used adapter/output. There is a Restart function already, isn't it?

Nonary commented 9 months ago

All I think is, maybe if Sunshine can't find the adapter/output it thought the computer was using at its start, it can just do a "soft reset" to update/get the currently used adapter/output. There is a Restart function already, isn't it?

When this issue happens it generally will not work, it requires the main display to be active again and then restarting sunshine usually, which you can already do in the troubleshooting tab.

TangXiaoLin-CN commented 8 months ago

I also encountered this problem

Travillion commented 8 months ago

This is not a Sunshine issue, you won't be able to use IDDisplayDriver with perfect stability if you have an integrated graphics card because the OS will assign the adapter to the iGPU once your main display goes to sleep. If you disable the iGPU this wont happen anymore and it will work flawlessly.

Unfortunately this issue can also happen with dummy plugs as well, especially on laptops that use USB3 attachments instead of DP or HDMI which plug directly into GPU.

I have a PC with a 1080p monitor and I'm trying to stream to my 4k TV. I have a virtual monitor that is hidden unless I'm streaming. Sunshine switches at the beginning/end of a stream. I have an Nvidia GPU that my monitor is plugged into, as well as Intel igpu. I start out fine, but consistently run into issues where the picture on the TV freezes and play resumes on my PC monitor. I can still hear the game noise through my TV. Looking at sunshine logs, it seems sunshine is also switching back to my igpu when this happens. Is this a similar issue as described above (OS switching the adapter back to igpu)? Interesting, I think my monitor is already asleep when I typically start these game sessions.