diff --git a/docs/configuration.md b/docs/configuration.md
index 78dacddd44c..57bb6d9f25a 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -848,6 +848,37 @@ editing the `conf` file in a text editor. Use the examples as reference.
+### gpu_preference
+
+
+
+
Description
+
+ Specify the GPU preference for the Sunshine process.
+
+
+ If set to negative number (-1 by default), Sunshine will try to detect the best GPU for the streamed display, but if it fails you will get a black screen.
+
+ Setting it to 0 will allow Windows to try and select the best GPU.
+
+ Setting it to 1 and above will prioritize the GPU that matches this number (the number has to be guessed, but it starts at 1 and increases).
+ @note{Applies to Windows only.}
+
+
+
+
Default
+
@code{}
+ -1
+ @endcode
+
+
+
Example
+
@code{}
+ 2
+ @endcode
+
+
+
### output_name
diff --git a/src/config.cpp b/src/config.cpp
index cb3337d539e..cf2b90a208c 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -436,6 +436,7 @@ namespace config {
{}, // capture
{}, // encoder
{}, // adapter_name
+ -1, // gpu_preference
{}, // output_name
{
@@ -1088,6 +1089,7 @@ namespace config {
string_f(vars, "capture", video.capture);
string_f(vars, "encoder", video.encoder);
string_f(vars, "adapter_name", video.adapter_name);
+ int_f(vars, "gpu_preference", video.gpu_preference);
string_f(vars, "output_name", video.output_name);
generic_f(vars, "dd_configuration_option", video.dd.configuration_option, dd::config_option_from_view);
diff --git a/src/config.h b/src/config.h
index e481a1e74d1..7e1813e6324 100644
--- a/src/config.h
+++ b/src/config.h
@@ -77,6 +77,7 @@ namespace config {
std::string capture;
std::string encoder;
std::string adapter_name;
+ int gpu_preference;
std::string output_name;
struct dd_t {
diff --git a/src/platform/windows/display_base.cpp b/src/platform/windows/display_base.cpp
index 7551d8c5776..7ec465f4109 100644
--- a/src/platform/windows/display_base.cpp
+++ b/src/platform/windows/display_base.cpp
@@ -415,16 +415,25 @@ namespace platf::dxgi {
return set_gpu_preference_on_self(pref_it->second);
}
- // Try probing with different GPU preferences and verify_frame_capture flag
- if (const auto pref = validate_and_test_gpu_preference(display_name, true); pref) {
- gpu_preference.emplace(display_name, *pref);
- return true;
+ // If the GPU preference was manually specified, we can skip the probe.
+ if (config::video.gpu_preference >= 0) {
+ if (set_gpu_preference_on_self(config::video.gpu_preference)) {
+ gpu_preference.emplace(display_name, config::video.gpu_preference);
+ return true;
+ }
}
+ else {
+ // Try probing with different GPU preferences and verify_frame_capture flag
+ if (const auto pref = validate_and_test_gpu_preference(display_name, true); pref) {
+ gpu_preference.emplace(display_name, *pref);
+ return true;
+ }
- // If no valid configuration was found, try again with verify_frame_capture == false
- if (const auto pref = validate_and_test_gpu_preference(display_name, false); pref) {
- gpu_preference.emplace(display_name, *pref);
- return true;
+ // If no valid configuration was found, try again with verify_frame_capture == false
+ if (const auto pref = validate_and_test_gpu_preference(display_name, false); pref) {
+ gpu_preference.emplace(display_name, *pref);
+ return true;
+ }
}
// If neither worked, return false
diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html
index 300e1c36f64..3eec36d7842 100644
--- a/src_assets/common/assets/web/config.html
+++ b/src_assets/common/assets/web/config.html
@@ -169,6 +169,7 @@