Skip to content

Commit

Permalink
feat(ddprobe): allow to manually specify gpu preference
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogTheFrog committed Jan 8, 2025
1 parent 9964a68 commit ec55a40
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
31 changes: 31 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,37 @@ editing the `conf` file in a text editor. Use the examples as reference.
</tr>
</table>

### gpu_preference

<table>
<tr>
<td>Description</td>
<td colspan="2">
Specify the GPU preference for the Sunshine process.
<br>
<br>
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.
<br>
Setting it to 0 will allow Windows to try and select the best GPU.
<br>
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.}
</td>
</tr>
<tr>
<td>Default</td>
<td colspan="2">@code{}
-1
@endcode</td>
</tr>
<tr>
<td>Example</td>
<td colspan="2">@code{}
2
@endcode</td>
</tr>
</table>

### output_name

<table>
Expand Down
2 changes: 2 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ namespace config {
{}, // capture
{}, // encoder
{}, // adapter_name
-1, // gpu_preference
{}, // output_name

{
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 17 additions & 8 deletions src/platform/windows/display_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,25 @@ namespace platf::dxgi {
return set_gpu_preference_on_self(pref_it->second);

Check warning on line 415 in src/platform/windows/display_base.cpp

View check run for this annotation

Codecov / codecov/patch

src/platform/windows/display_base.cpp#L415

Added line #L415 was not covered by tests
}

// 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;

Check warning on line 422 in src/platform/windows/display_base.cpp

View check run for this annotation

Codecov / codecov/patch

src/platform/windows/display_base.cpp#L421-L422

Added lines #L421 - L422 were not covered by tests
}
}
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;

Check warning on line 429 in src/platform/windows/display_base.cpp

View check run for this annotation

Codecov / codecov/patch

src/platform/windows/display_base.cpp#L428-L429

Added lines #L428 - L429 were not covered by tests
}

// 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;

Check warning on line 435 in src/platform/windows/display_base.cpp

View check run for this annotation

Codecov / codecov/patch

src/platform/windows/display_base.cpp#L434-L435

Added lines #L434 - L435 were not covered by tests
}
}

// If neither worked, return false
Expand Down
1 change: 1 addition & 0 deletions src_assets/common/assets/web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ <h1 class="my-4">{{ $t('config.configuration') }}</h1>
"virtual_sink": "",
"install_steam_audio_drivers": "enabled",
"adapter_name": "",
"gpu_preference": -1,
"output_name": "",
"dd_configuration_option": "verify_only",
"dd_resolution_option": "auto",
Expand Down
12 changes: 12 additions & 0 deletions src_assets/common/assets/web/configs/tabs/AudioVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ const config = ref(props.config)
:config="config"
/>

<PlatformLayout :platform="platform">
<template #windows>
<!-- GPU Preference -->
<div class="mb-3">
<label for="gpu_preference" class="form-label">{{ $t('config.gpu_preference') }}</label>
<input type="text" class="form-control" id="gpu_preference" placeholder="-1"
v-model="config.gpu_preference" />
<div class="form-text">{{ $t('config.gpu_preference_desc') }}</div>
</div>
</template>
</PlatformLayout>

<DisplayOutputSelector
:platform="platform"
:config="config"
Expand Down
2 changes: 2 additions & 0 deletions src_assets/common/assets/web/public/assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@
"fec_percentage": "FEC Percentage",
"fec_percentage_desc": "Percentage of error correcting packets per data packet in each video frame. Higher values can correct for more network packet loss, but at the cost of increasing bandwidth usage.",
"ffmpeg_auto": "auto -- let ffmpeg decide (default)",
"gpu_preference": "GPU Preference",
"gpu_preference_desc": "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).",
"file_apps": "Apps File",
"file_apps_desc": "The file where current apps of Sunshine are stored.",
"file_state": "State File",
Expand Down

0 comments on commit ec55a40

Please sign in to comment.