Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui/blade: Allow forcing use of a specific GPU with `ZED_DEVICE_ID` env var (#27531)

Ben Kunkle1463b4d201dc
diff --git a/crates/gpui/src/platform/blade/blade_context.rs b/crates/gpui/src/platform/blade/blade_context.rs
index f03fff01e05..531c029e85b 100644
--- a/crates/gpui/src/platform/blade/blade_context.rs
+++ b/crates/gpui/src/platform/blade/blade_context.rs
@@ -1,5 +1,7 @@
+use anyhow::Context as _;
use blade_graphics as gpu;
use std::sync::Arc;
+use util::ResultExt;
#[cfg_attr(target_os = "macos", derive(Clone))]
pub struct BladeContext {
@@ -8,12 +10,24 @@ pub struct BladeContext {
impl BladeContext {
pub fn new() -> anyhow::Result<Self> {
+ let device_id_forced = match std::env::var("ZED_DEVICE_ID") {
+ Ok(val) => val
+ .parse()
+ .context("Failed to parse device ID from `ZED_DEVICE_ID` environment variable")
+ .log_err(),
+ Err(std::env::VarError::NotPresent) => None,
+ err => {
+ err.context("Failed to read value of `ZED_DEVICE_ID` environment variable")
+ .log_err();
+ None
+ }
+ };
let gpu = Arc::new(
unsafe {
gpu::Context::init(gpu::ContextDesc {
presentation: true,
validation: false,
- device_id: 0, //TODO: hook up to user settings
+ device_id: device_id_forced.unwrap_or(0),
..Default::default()
})
}