From 0d555fb68809ce63a6e74fc66e2a486d07401c3d Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sat, 29 Jun 2019 16:50:41 -0600 Subject: [PATCH] Add logic to pick highest performance GPU on DirectX 12 Always select the first GPU in Integrated-Low/Discrete-High category, except when querying `LowPower`, in which case the last Discrete GPU is used. --- wgpu-native/src/instance.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index c99818d1e..a8a24ca86 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -201,10 +201,23 @@ pub fn instance_get_adapter(instance_id: InstanceId, desc: &AdapterDescriptor) - }; let (mut low, mut high, mut other) = (None, None, None); + // On Windows > 1803, dx12 enumerate_adapters returns the adapters in order from highest to + // lowest performance. Therefore, the first found adapter in each category is selected. + // + // TODO: move power/performance policy querying into gfx, which has more context into + // performance policy than wgpu for adapter in adapters { match adapter.info.device_type { - hal::adapter::DeviceType::IntegratedGpu => low = Some(adapter), - hal::adapter::DeviceType::DiscreteGpu => high = Some(adapter), + hal::adapter::DeviceType::IntegratedGpu => low = low.or(Some(adapter)), + hal::adapter::DeviceType::DiscreteGpu => { + high = match desc.power_preference { + // If `LowPower`, prefer lowest power `DiscreteGPU` + PowerPreference::LowPower => Some(adapter), + PowerPreference::HighPerformance | PowerPreference::Default => { + high.or(Some(adapter)) + } + } + } _ => other = Some(adapter), } }