Skip to content

Commit 85beffc

Browse files
more robust high performance preference
1 parent 63a018f commit 85beffc

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

desktop/src/main.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,27 @@ async fn init_wgpu_context() -> WgpuContext {
9898
let adapter_index = if let Some(index) = adapter_override
9999
&& index < adapters.len()
100100
{
101-
index
101+
Some(index)
102102
} else if cfg!(target_os = "windows") {
103-
match adapters.iter().enumerate().find(|(_, a)| a.get_info().backend == wgpu::Backend::Dx12) {
104-
Some((index, _)) => index,
105-
None => 0,
106-
}
103+
adapters.iter().enumerate().find(|(_, a)| a.get_info().backend == wgpu::Backend::Dx12).map(|(i, _)| i)
107104
} else {
108-
0 // Same behavior as requests adapter
105+
None
109106
};
110107

111-
tracing::info!("Using WGPU adapter {adapter_index}");
108+
let adapter = if let Some(index) = adapter_index {
109+
tracing::info!("Using WGPU adapter {index}");
110+
adapters.remove(index)
111+
} else {
112+
tracing::info!("Requesting HighPerformance adapter from wgpu");
113+
114+
let adapter_options = wgpu::RequestAdapterOptions {
115+
power_preference: wgpu::PowerPreference::HighPerformance,
116+
compatible_surface: None,
117+
force_fallback_adapter: false,
118+
};
112119

113-
let adapter = adapters.remove(adapter_index);
120+
instance.request_adapter(&adapter_options).await.expect("Failed to request WGPU adapter")
121+
};
114122

115123
WgpuContext::new_with_instance_and_adapter(instance, adapter)
116124
.await

0 commit comments

Comments
 (0)