forked from ValveSoftware/steamos-compositor
-
Notifications
You must be signed in to change notification settings - Fork 377
render: prefer a discrete GPU when no device is pinned #2217
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
Open
Sigmachan
wants to merge
1
commit into
ValveSoftware:master
Choose a base branch
from
Sigmachan:prefer-discrete-gpu
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,6 +345,15 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface) | |
| bTryComputeOnly = false; | ||
| } | ||
|
|
||
| // Track whether the currently-selected device is discrete, so that when no | ||
| // device is explicitly preferred we upgrade from an integrated GPU to a | ||
| // discrete one. Without this, on hybrid systems (e.g. an AMD iGPU alongside | ||
| // a discrete NVIDIA/AMD GPU) the headless/standalone path with no surface to | ||
| // filter against would pick whichever device enumerates first — frequently | ||
| // the iGPU — and composite on the wrong, slower GPU. | ||
| const bool bHavePreferredDevice = ( g_preferVendorID != 0 || g_preferDeviceID != 0 ); | ||
| bool bSelectedIsDiscrete = false; | ||
|
|
||
| for (auto cphysDev : physDevs) | ||
| { | ||
| VkPhysicalDeviceProperties deviceProperties; | ||
|
|
@@ -370,9 +379,16 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface) | |
|
|
||
| if (generalIndex != ~0u || computeOnlyIndex != ~0u) | ||
| { | ||
| // Select the device if it's the first one or the preferred one | ||
| if (!m_physDev || | ||
| (g_preferVendorID == deviceProperties.vendorID && g_preferDeviceID == deviceProperties.deviceID)) | ||
| const bool bIsPreferred = bHavePreferredDevice && | ||
| g_preferVendorID == deviceProperties.vendorID && | ||
| g_preferDeviceID == deviceProperties.deviceID; | ||
| const bool bIsDiscrete = deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU; | ||
| // Upgrade integrated -> discrete only when the user hasn't pinned a device. | ||
| const bool bDiscreteUpgrade = !bHavePreferredDevice && m_physDev && !bSelectedIsDiscrete && bIsDiscrete; | ||
|
|
||
| // Select the device if it's the first one, the preferred one, or a | ||
| // discrete GPU superseding an integrated pick. | ||
| if (!m_physDev || bIsPreferred || bDiscreteUpgrade) | ||
| { | ||
| // if we have a surface, check that the queue family can actually present on it | ||
| if (surface) { | ||
|
|
@@ -397,6 +413,7 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface) | |
| m_queueFamily = computeOnlyIndex == ~0u ? generalIndex : computeOnlyIndex; | ||
| m_generalQueueFamily = generalIndex; | ||
| m_physDev = cphysDev; | ||
| bSelectedIsDiscrete = bIsDiscrete; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible optimization here: if the selected device is the preferred one ( |
||
|
|
||
| /* When Intel uses compute-only queue for Gamescope composition, some games | ||
| * experience performance loss. Using the general queue alleviates the issue | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a mismatch between how
bIsPreferredis computed, and howbHavePreferredDeviceis set: both vendor ID and device ID have to match, whereas the latter needs either to be set.Do we expect to be able to specify only a vendor ID that would match all devices by this vendor? Does it even make sense? Even so, the device ID would never match the default value (0).