From 338bd308701ebcdd7d72c9f272dc069621d5a39f Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Sat, 21 Jan 2023 14:29:23 -0600 Subject: [PATCH] Allow selecting GPU from env --- examples/with_winit/Cargo.toml | 1 + examples/with_winit/src/main.rs | 1 + src/util.rs | 13 ++++++------- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/with_winit/Cargo.toml b/examples/with_winit/Cargo.toml index 2fa87a9..e807914 100644 --- a/examples/with_winit/Cargo.toml +++ b/examples/with_winit/Cargo.toml @@ -15,6 +15,7 @@ pollster = "0.2.5" # for picosvg roxmltree = "0.13" clap = { version = "4.1.0", features = ["derive"] } +env_logger = "0.10.0" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] vello = { path = "../../", features = ["hot_reload"] } diff --git a/examples/with_winit/src/main.rs b/examples/with_winit/src/main.rs index f48e9a1..4046538 100644 --- a/examples/with_winit/src/main.rs +++ b/examples/with_winit/src/main.rs @@ -225,6 +225,7 @@ enum UserEvent { fn main() { let args = Args::parse(); + env_logger::init(); #[cfg(not(target_arch = "wasm32"))] { use winit::{dpi::LogicalSize, window::WindowBuilder}; diff --git a/src/util.rs b/src/util.rs index 89b1c52..0245d11 100644 --- a/src/util.rs +++ b/src/util.rs @@ -96,13 +96,12 @@ impl RenderContext { /// Creates a compatible device handle id. async fn new_device(&mut self, compatible_surface: Option<&Surface>) -> Option { - let adapter = self - .instance - .request_adapter(&RequestAdapterOptions { - compatible_surface, - ..Default::default() - }) - .await?; + let adapter = wgpu::util::initialize_adapter_from_env_or_default( + &self.instance, + wgpu::Backends::PRIMARY, + compatible_surface, + ) + .await?; let features = adapter.features(); let limits = Limits::default(); let (device, queue) = adapter