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 does not start on hybrid AMD/NVIDIA laptop using HDMI dummy plug #1664

Closed
3 tasks done
inox9 opened this issue Sep 22, 2023 · 7 comments
Closed
3 tasks done

Stream does not start on hybrid AMD/NVIDIA laptop using HDMI dummy plug #1664

inox9 opened this issue Sep 22, 2023 · 7 comments
Labels

Comments

@inox9
Copy link

inox9 commented Sep 22, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Is your issue described in the documentation?

  • I have read the documentation

Is your issue present in the nightly release?

  • This issue is present in the nightly release

Describe the Bug

I have a Lenovo Legion 5 15ACH6H laptop.
It has hybrid AMD/NVIDIA graphics (Radeon integrated in Ryzen 5800H cpu and dedicated RTX 3060). In BIOS settings hybrid graphics setting is turned ON.
What I'm trying to achieve is to turn off the laptop monitor and switch the video output to the dummy HDMI plug when stream is started. So when stream ends - laptop monitor should be enabled again and HDMI plug disabled.
So I've installed monitorswitcher app (https://sourceforge.net/projects/monitorswitcher/) and created 2 profiles for laptop screen only (saved in main.xml file) and hdmi plug output only (streaming.xml file).
Also I've set do/undo commands in sunshine settings:

do - "d:\soft\monitorswitcher\MonitorSwitcher.exe -load:C:\Users\Dimon\AppData\Roaming\MonitorSwitcher\Profiles\streaming.xml"
undo - "d:\soft\monitorswitcher\MonitorSwitcher.exe -load:C:\Users\Dimon\AppData\Roaming\MonitorSwitcher\Profiles\main.xml"

So the problem is when I try to stream any game in moonlight client (on a steam deck) - laptop monitor turns off as expected, default video output switches to HDMI plug (I've checked that for sure via VNC), stream starts for 1 second and then immediately stops with an error (Connection terminated). While in sunshine logs I see these lines:

[2023:09:22:11:19:54]: Error: DuplicateOutput() test failed [0x887A0004]
[2023:09:22:11:19:54]: Error: DuplicateOutput() test failed [0x887A0004]
[2023:09:22:11:19:55]: Error: DuplicateOutput() test failed [0x887A0004]
[2023:09:22:11:19:55]: Error: Failed to locate an output device

I think the problem is that sunshine continues trying to use AMD GPU to capture the stream while HDMI plug is actually connected to NVIDIA GPU directly and stream goes there bypassing AMD GPU after the switch. Maybe it's because the capturing GPU is selected once on sunshine service start, but I think it should be dynamically selected before every stream start and AFTER prep commands execution (of course in case that there is no specific GPU/monitor set in sunshine settings).

Expected Behavior

Stream should start without any errors

Additional Context

I've managed to somehow bypass this bug by disabling sunshine service automatic startup on system start.
So at first I switch the monitor output to HDMI plug and only after that start sunshine service manually.
I use this bat script for that purpose:

@echo off
d:\soft\monitorswitcher\MonitorSwitcher.exe -load:C:\Users\Dimon\AppData\Roaming\MonitorSwitcher\Profiles\streaming.xml
net start "Sunshine Service"

Only in this case sunshine correctly detects connected HDMI plug and streaming works well. But it's an ugly solution IMO because after streaming I have to connect to laptop via VNC and manually execute another bat file which reverts monitor config and stops sunshine service.
Also I know that I can fully disable integrated AMD GPU in BIOS and use only dedicated NVIDIA gpu and that can probably fix the issue (I didn't check it though). But that's also not a good solution because of increased power consumption while not streaming.

Host Operating System

Windows

Operating System Version

11

Architecture

64 bit

Sunshine commit or version

0.20.0

Package

Windows - installer

GPU Type

Nvidia

GPU Model

RTX 3060 Mobile

GPU Driver/Mesa Version

537.34

Capture Method (Linux Only)

No response

Config

qp = 28
min_log_level = 2
resolutions = [
    1280x720,
    1920x1080,
    1920x1200,
    1280x800
]
upnp = enabled
sunshine_name = LEGION5
global_prep_cmd = [{"do":"d:\\soft\\monitorswitcher\\MonitorSwitcher.exe -load:C:\\Users\\Dimon\\AppData\\Roaming\\MonitorSwitcher\\Profiles\\streaming.xml","undo":"d:\\soft\\monitorswitcher\\MonitorSwitcher.exe -load:C:\\Users\\Dimon\\AppData\\Roaming\\MonitorSwitcher\\Profiles\\main.xml","elevated":false}]

Apps

No response

Relevant log output

[2023:09:22:11:19:50]: Info: Trying encoder [amdvce]
[2023:09:22:11:19:50]: Info: 
Device Description : AMD Radeon(TM) Graphics
Device Vendor ID   : 0x00001002
Device Device ID   : 0x00001638
Device Video Mem   : 1007 MiB
Device Sys Mem     : 0 MiB
Share Sys Mem      : 15798 MiB
Feature Level      : 0x0000B100
Capture size       : 1920x1080
Offset             : 0x0
Virtual Desktop    : 1920x1080
[2023:09:22:11:19:50]: Info: Desktop resolution [1920x1080]
[2023:09:22:11:19:50]: Info: Desktop format [DXGI_FORMAT_B8G8R8A8_UNORM]
[2023:09:22:11:19:50]: Info: 
Colorspace         : DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
Bits Per Color     : 10
Red Primary        : [0.639648,0.330078]
Green Primary      : [0.299805,0.599609]
Blue Primary       : [0.149414,0.0595703]
White Point        : [0.3125,0.329102]
Min Luminance      : 0.5 nits
Max Luminance      : 270 nits
Max Full Luminance : 270 nits
[2023:09:22:11:19:50]: Info: SDR color coding [Rec. 601]
[2023:09:22:11:19:50]: Info: Color range: [JPEG]
[2023:09:22:11:19:50]: Info: 
Device Description : AMD Radeon(TM) Graphics
Device Vendor ID   : 0x00001002
Device Device ID   : 0x00001638
Device Video Mem   : 1007 MiB
Device Sys Mem     : 0 MiB
Share Sys Mem      : 15798 MiB
Feature Level      : 0x0000B100
Capture size       : 1920x1080
Offset             : 0x0
Virtual Desktop    : 1920x1080
[2023:09:22:11:19:50]: Info: Desktop resolution [1920x1080]
[2023:09:22:11:19:50]: Info: Desktop format [DXGI_FORMAT_B8G8R8A8_UNORM]
[2023:09:22:11:19:50]: Info: 
Colorspace         : DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
Bits Per Color     : 10
Red Primary        : [0.639648,0.330078]
Green Primary      : [0.299805,0.599609]
Blue Primary       : [0.149414,0.0595703]
White Point        : [0.3125,0.329102]
Min Luminance      : 0.5 nits
Max Luminance      : 270 nits
Max Full Luminance : 270 nits
[2023:09:22:11:19:50]: Info: SDR color coding [Rec. 601]
[2023:09:22:11:19:50]: Info: Color range: [JPEG]
[2023:09:22:11:19:50]: Info: 
Device Description : AMD Radeon(TM) Graphics
Device Vendor ID   : 0x00001002
Device Device ID   : 0x00001638
Device Video Mem   : 1007 MiB
Device Sys Mem     : 0 MiB
Share Sys Mem      : 15798 MiB
Feature Level      : 0x0000B100
Capture size       : 1920x1080
Offset             : 0x0
Virtual Desktop    : 1920x1080
[2023:09:22:11:19:50]: Info: Desktop resolution [1920x1080]
[2023:09:22:11:19:50]: Info: Desktop format [DXGI_FORMAT_B8G8R8A8_UNORM]
[2023:09:22:11:19:50]: Info: 
Colorspace         : DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
Bits Per Color     : 10
Red Primary        : [0.639648,0.330078]
Green Primary      : [0.299805,0.599609]
Blue Primary       : [0.149414,0.0595703]
White Point        : [0.3125,0.329102]
Min Luminance      : 0.5 nits
Max Luminance      : 270 nits
Max Full Luminance : 270 nits
[2023:09:22:11:19:50]: Info: SDR color coding [Rec. 709]
[2023:09:22:11:19:50]: Info: Color range: [JPEG]
[2023:09:22:11:19:50]: Info: 
[2023:09:22:11:19:50]: Info: // Ignore any errors mentioned above, they are not relevant. //
[2023:09:22:11:19:50]: Info: 
[2023:09:22:11:19:50]: Info: Found encoder amdvce: [h264_amf, hevc_amf]
[2023:09:22:11:19:50]: Info: Executing Do Cmd: [d:\soft\monitorswitcher\MonitorSwitcher.exe -load:C:\Users\Dimon\AppData\Roaming\MonitorSwitcher\Profiles\streaming.xml]
[2023:09:22:11:19:50]: Info: d:\soft\monitorswitcher\MonitorSwitcher.exe -load:C:\Users\Dimon\AppData\Roaming\MonitorSwitcher\Profiles\streaming.xml running with PID 6172
[2023:09:22:11:19:53]: Info: Executing: ["D:\Games\Horizon Zero Dawn\HorizonZeroDawn.exe"] in ["D:\Games\Horizon Zero Dawn"]
[2023:09:22:11:19:53]: Info: "D:\Games\Horizon Zero Dawn\HorizonZeroDawn.exe" running with PID 9844
[2023:09:22:11:19:53]: Info: WLAN interface 0 is now in low latency mode
[2023:09:22:11:19:53]: Info: CLIENT CONNECTED
[2023:09:22:11:19:54]: Error: DuplicateOutput() test failed [0x887A0004]
[2023:09:22:11:19:54]: Error: DuplicateOutput() test failed [0x887A0004]
[2023:09:22:11:19:55]: Error: DuplicateOutput() test failed [0x887A0004]
[2023:09:22:11:19:55]: Error: Failed to locate an output device
[2023:09:22:11:20:06]: Info: Executing Undo Cmd: [d:\soft\monitorswitcher\MonitorSwitcher.exe -load:C:\Users\Dimon\AppData\Roaming\MonitorSwitcher\Profiles\main.xml]
[2023:09:22:11:20:07]: Info: d:\soft\monitorswitcher\MonitorSwitcher.exe -load:C:\Users\Dimon\AppData\Roaming\MonitorSwitcher\Profiles\main.xml running with PID 17156
@Nonary
Copy link
Collaborator

Nonary commented Sep 28, 2023

Hybrid graphic setups have this issue, pretty sure there is no way around this problem other than disabling hybrid GPU in BIOS.

@Nonary
Copy link
Collaborator

Nonary commented Sep 28, 2023

Can you try my script and see if it works though? I wonder if monitor switcher just causes problems in Sunshine https://github.com/Nonary/MonitorSwapAutomation/releases

@inox9
Copy link
Author

inox9 commented Sep 29, 2023

I've already tried this script before and it works the same as monitorswitcher.

@LizardByte-bot
Copy link
Member

It seems this issue hasn't had any activity in the past 90 days. If it's still something you'd like addressed, please let us know by leaving a comment. Otherwise, to help keep our backlog tidy, we'll be closing this issue in 10 days. Thanks!

@ned228
Copy link

ned228 commented Jan 6, 2024

If anyone is still having this issue. I have found a work around. This work around is also able to be done remotely. Create a batch file called "Stream Setup" The name does not matter and can be named anything just keep track of its location and name as this will be the batch file that will be started by sunshine. Stream Setup should contain this code.

start "" "C:\Program Files\Sunshine\Stream Setup Tasks.bat"
exit

Replace "path to" with the path of Stream Setup Tasks.bat. Now create the batch file Stream Setup Tasks.bat. Once again name does not matter as long as you keep track of the location and name. Stream Setup Tasks Should contain this code.

timeout /t 5 /nobreak >nul 
net stop "Sunshine Service" 
DisplaySwitch 4 
net start "Sunshine Service" 

Copy Stream Setup and name it "Stream End". Change "Path to\Stream Setup Tasks.bat" To Path to\Stream End Tasks.bat". Copy "Stream Setup Tasks". Change "DisplaySwitch 4" to "DisplaySwitch 1" or "DisplaySwitch 3" depending on your setup. DisplaySwitch 3 is extend. DisplaySwitch 1 is only the internal screen. Now go into the sunshine UI. And add a new app. Call it whatever you want. For this guide we will call it Stream Setup. Make sure that this app is run as admin and that global prep commands are disabled. In the commands section put Path to\Stream Setup.bat" without the "". Leave everything else blank. Then Add a new global prep command. Leave the do section blank. In the undo section put "Path to\Stream End.bat". Run this command as admin. Make sure you have nothing set for either the graphics card or the output screen. This only works on windows. To use, run the app Stream Setup before starting your stream. Sadly this app will have to be run every time you stream. It will then Run "Stream Setup.bat". That bat File will then run. "Stream Setup Tasks.bat". "Stream Setup Tasks.bat" will stop sunshine, then change the display to the dummy plug and restart sunshine. This will allow sunshine to use the dummy plug. Wait for sunshine to restart. Then you are free to launch whatever app you want. When you end the stream, it will run "Stream End.bat". That will then run "Stream End Tasks.bat" Which will restart sunshine and change back to your primary monitor. The reason you have to have the batch file referenced by sunshine only open another batch file is otherwise the batch file will end when sunshine restarts. Hope this helps.

@ReenigneArcher ReenigneArcher closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2024
@inox9
Copy link
Author

inox9 commented Jan 6, 2024

Finally I've managed to solve this problem even without using HDMI dummy stick. For this you should use one of the "virtual monitor" drivers. Personally I recommend this one - https://www.amyuni.com/forum/viewtopic.php?t=3030 as it allows "hotplugging" and "unplugging" by executing shell commands. So to use it with sunshine you have to:

  • install it according to instructions from the mentioned website
  • enable it once using command: "[path\to\driver]\deviceinstaller64.exe enableidd 1" (replace path\to\driver to realpath where you unpacked archive)
  • configure resolution for virtual display in system settings. If you need custom resolutions (for example 1280*800 for steam deck) you can add them in registry (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WUDF\Services\usbmmIdd\Parameters\Monitors). There are detailed instructions on how to do this in idd_instructions.txt file in archive.
  • add global do/undo commands in sunshine config: do - "path\to\driver\deviceinstaller64.exe enableidd 1"; undo - "path\to\driver\deviceinstaller64.exe enableidd 0". Make sure to check "run as admin" flag.

I don't know why but when I execute "enableidd 1" command - display output changes automatically to virtual display (if resolution is set to 1280*800 for it). If that doesn't happen for you - create a bat file and add "DisplaySwitch 4" after "enableidd 1" command. Of course then use this bat file as "do" command in sunshine.

@ned228
Copy link

ned228 commented Jan 6, 2024

I tried that originally but for me the screen kept being assigned to the internal intel card. So I could never use that option unless I had a dummy plug attached to my nvidia card no amount of screen switching would work for me when I tried that.

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

No branches or pull requests

5 participants