Skip to content

The agent that grows with you

fix(desktop): select installed WSL D3D12 driver before Electron exec

Xipong51fa04d49d67
diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.py
index 05386391ffc..e70afc6ff19 100644
--- a/hermes_cli/main_desktop.py
+++ b/hermes_cli/main_desktop.py
@@ -1403,12 +1403,29 @@ def _build_desktop_app(desktop_dir: Path, *, source_mode: bool, npm: str, env: d
return packaged_executable
+def _prefer_wsl_d3d12(env: dict, *, available: bool) -> None:
+ """Select Mesa before exec: setting this inside Electron can miss GPU initialization."""
+ overrides = ("GALLIUM_DRIVER", "MESA_LOADER_DRIVER_OVERRIDE", "LIBGL_ALWAYS_SOFTWARE", "LIBGL_DRIVERS_PATH")
+ if available and not any(key in env for key in overrides):
+ env["GALLIUM_DRIVER"] = "d3d12"
+
+
def _desktop_launch_env(args: argparse.Namespace) -> tuple[dict, list[str]]:
"""Electron child env + config-supplied extra flags. ``desktop.*`` config is bridged to env vars
Electron already reads; an explicit env var wins over config (and over keychain detection)."""
- from hermes_constants import with_hermes_node_path
+ from hermes_constants import is_wsl, with_hermes_node_path
# with_hermes_node_path() copies os.environ when called with no arg.
env = with_hermes_node_path()
+ # /dev/dxg alone does not select hardware Mesa: Chromium may still get
+ # llvmpipe. Keep custom Mesa choices and systems without D3D12 unchanged.
+ _prefer_wsl_d3d12(env, available=is_wsl() and Path("/dev/dxg").exists() and any(
+ Path(driver).is_file() for driver in (
+ "/usr/lib/x86_64-linux-gnu/dri/d3d12_dri.so",
+ "/usr/lib/aarch64-linux-gnu/dri/d3d12_dri.so",
+ "/usr/lib64/dri/d3d12_dri.so",
+ "/usr/lib/dri/d3d12_dri.so",
+ )
+ ))
for attr, key in (
("fake_boot", "HERMES_DESKTOP_BOOT_FAKE"), ("ignore_existing", "HERMES_DESKTOP_IGNORE_EXISTING")):
if getattr(args, attr, False):
diff --git a/tests/hermes_cli/test_desktop_wsl_gpu.py b/tests/hermes_cli/test_desktop_wsl_gpu.py
new file mode 100644
index 00000000000..0f605c188a0
--- /dev/null
+++ b/tests/hermes_cli/test_desktop_wsl_gpu.py
@@ -0,0 +1,24 @@
+from hermes_cli.main_desktop import _prefer_wsl_d3d12
+
+
+def test_selects_available_wsl_driver_before_spawning_electron():
+ env = {"PATH": "/bin"}
+ _prefer_wsl_d3d12(env, available=True)
+ assert env == {"PATH": "/bin", "GALLIUM_DRIVER": "d3d12"}
+
+
+def test_missing_driver_and_explicit_mesa_choices_are_preserved():
+ overrides = [
+ {"GALLIUM_DRIVER": "llvmpipe"},
+ {"GALLIUM_DRIVER": ""},
+ {"MESA_LOADER_DRIVER_OVERRIDE": "zink"},
+ {"LIBGL_ALWAYS_SOFTWARE": "1"},
+ {"LIBGL_DRIVERS_PATH": "/custom/mesa"},
+ ]
+ for original in overrides:
+ env = dict(original)
+ _prefer_wsl_d3d12(env, available=True)
+ assert env == original
+ env = {}
+ _prefer_wsl_d3d12(env, available=False)
+ assert env == {}