request high performance adapter

This commit is contained in:
Alex Janka 2024-02-14 08:33:17 +11:00
parent 8d7e5c152e
commit 33a9b2252c

View file

@ -81,21 +81,32 @@ impl RendererBackend for WgpuBackend {
.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(window)?)
}?;
let adapter = manager
.instance
.enumerate_adapters(wgpu::Backends::all())
.into_iter()
.find(|adapter| adapter.is_surface_supported(&surface))
.ok_or(Self::RendererError::NoAdapter)?;
let (device, queue) = block_on(adapter.request_device(
&wgpu::DeviceDescriptor {
required_features: wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER,
required_limits: wgpu::Limits::default(),
label: None,
},
None,
))?;
let (device, queue) = (Arc::new(device), Arc::new(queue));
let (adapter, device, queue) = block_on(async {
let adapter = manager
.instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
force_fallback_adapter: false,
compatible_surface: Some(&surface),
})
.await
.ok_or(Self::RendererError::NoAdapter)?;
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
required_features: wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER,
required_limits: wgpu::Limits::default(),
label: None,
},
None,
)
.await?;
Ok::<(wgpu::Adapter, Arc<wgpu::Device>, Arc<wgpu::Queue>), Self::RendererError>((
adapter,
Arc::new(device),
Arc::new(queue),
))
})?;
let capabilities = surface.get_capabilities(&adapter);
let format = capabilities