Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

fix(gui): let a GPU-less Windows session reach the bundled Mesa

RoversXff0e9543e162
diff --git a/wezterm-gui/build.rs b/wezterm-gui/build.rs
index efce8440..85b24ccb 100644
--- a/wezterm-gui/build.rs
+++ b/wezterm-gui/build.rs
@@ -20,6 +20,19 @@ fn main() {
println!("cargo:rerun-if-changed=build.rs");
generate_material_icons().expect("generate material file icon lookup tables");
+ // wgpu's GL backend imports opengl32.dll, so the loader used to map the
+ // system copy at process start -- before window/src/os/windows/wgl.rs
+ // could send a remote session to the bundled Mesa copy, and a DLL already
+ // loaded under that name is what every later load gets. Delay-loaded, it
+ // is first loaded by whoever first calls into it. The target, not the
+ // host, decides: this is a linker flag for the binary being built.
+ if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows")
+ && std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc")
+ {
+ println!("cargo:rustc-link-arg-bins=/DELAYLOAD:opengl32.dll");
+ println!("cargo:rustc-link-arg-bins=delayimp.lib");
+ }
+
#[cfg(windows)]
{
use anyhow::Context as _;
diff --git a/wezterm-gui/src/scripting/mod.rs b/wezterm-gui/src/scripting/mod.rs
index 7188ca21..a5a7688d 100644
--- a/wezterm-gui/src/scripting/mod.rs
+++ b/wezterm-gui/src/scripting/mod.rs
@@ -81,7 +81,10 @@ pub fn register(lua: &Lua) -> anyhow::Result<()> {
window_mod.set(
"enumerate_gpus",
lua.create_function(|_, _: ()| {
- let backends = wgpu::Backends::all();
+ // This runs while the configuration is being evaluated, so its
+ // front_end is not known yet -- and asking the global
+ // configuration would wait forever on the lock that holds.
+ let backends = crate::termwindow::webgpu::instance_backends(false);
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends,
..Default::default()
diff --git a/wezterm-gui/src/termwindow/webgpu.rs b/wezterm-gui/src/termwindow/webgpu.rs
index ac1a89b5..45cd41e5 100644
--- a/wezterm-gui/src/termwindow/webgpu.rs
+++ b/wezterm-gui/src/termwindow/webgpu.rs
@@ -435,6 +435,20 @@ pub fn adapter_info_to_gpu_info(info: wgpu::AdapterInfo) -> GpuInfo {
}
}
+/// The backends a WebGpu instance asks for. Where OpenGL would be Mesa -- a
+/// remote session, or `software` (front_end = "Software") -- Windows leaves
+/// GL out: there it is WGL on opengl32.dll, and once anything has loaded that
+/// DLL the OpenGL renderer can no longer reach the Mesa copy (see
+/// wezterm-gui/build.rs). DX12 and Vulkan still cover WebGpu in those
+/// sessions. Reads no configuration itself; the caller passes `software`.
+pub fn instance_backends(software: bool) -> wgpu::Backends {
+ if cfg!(windows) && (software || window::in_remote_session()) {
+ wgpu::Backends::all().difference(wgpu::Backends::GL)
+ } else {
+ wgpu::Backends::all()
+ }
+}
+
fn compute_compatibility_list(
instance: &wgpu::Instance,
backends: wgpu::Backends,
@@ -470,7 +484,7 @@ impl WebGpuState {
dimensions: Dimensions,
config: &ConfigHandle,
) -> anyhow::Result<Self> {
- let backends = wgpu::Backends::all();
+ let backends = instance_backends(config.front_end == config::FrontEndSelection::Software);
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends,
..Default::default()
diff --git a/window/src/configuration.rs b/window/src/configuration.rs
index a720fbeb..815651c6 100644
--- a/window/src/configuration.rs
+++ b/window/src/configuration.rs
@@ -1,3 +1,16 @@
+/// Whether this process runs in a remote desktop session, where OpenGL is
+/// always the software renderer. Unlike prefer_swrast it reads no
+/// configuration, so it is safe while the configuration is being evaluated.
+pub fn in_remote_session() -> bool {
+ #[cfg(windows)]
+ {
+ if crate::os::windows::is_running_in_rdp_session() {
+ return true;
+ }
+ }
+ false
+}
+
pub(crate) fn prefer_swrast() -> bool {
#[cfg(windows)]
{
diff --git a/window/src/lib.rs b/window/src/lib.rs
index 5441b5f3..01f3fee3 100644
--- a/window/src/lib.rs
+++ b/window/src/lib.rs
@@ -12,6 +12,7 @@ use url::Url;
pub mod bitmaps;
pub use wezterm_color_types as color;
mod configuration;
+pub use configuration::in_remote_session;
pub mod connection;
pub mod os;
pub mod screen;