File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ layout : post
3+ title : WSL2 开启GPU渲染仿真画面
4+ category : " WSL2"
5+ date : 2025-09-21
6+ ---
7+
8+
9+ 环境: WSL2 Ubuntu 20.04.6 LTS
10+
11+ 目的是使用 WSL2 运行mujoco仿真器,且使用GPU加速渲染画面;物理机系统已成功安装cuda,且WSL中能成功调用` nvidia-smi ` 以及识别到物理机GPU,但WSL中的进程无法调用GPU进行渲染
12+
13+ ![ image-20250921145651298] ( /pic/image-20250921145651298.png )
14+
15+ ## Method
16+
17+ 终端设置环境变量
18+
19+ ```` bash
20+ export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
21+ ````
22+
23+ 该环境变量 ` MESA_D3D12_DEFAULT_ADAPTER_NAME ` 是WSLg团队设置的可变环境变量,其原理是选择指定的GPU作为WSL在没有用户控制的情况下默认使用的GPU。具体而言,是选择d3d12 MESA后端使用的GPU。
24+
25+ * WSLg,是微软为WSL开发的一项功能,允许在 Windows 系统上运行 Linux 图形用户界面 (GUI) 应用程序
26+ * Mesa,是一个开源的图形库,主要为 Linux 系统实现图形 API
27+ * D3D12(Direct3D 12 的缩写),是微软开发的一种低级图形 API(应用程序编程接口),属于 DirectX 图形技术的一部分
28+
29+ 使用 ` glxinfo ` 程序验证是否成功开启
30+
31+ ```` bash
32+ glxinfo | grep " OpenGL renderer"
33+ # m3@M3ngL:~$ glxinfo | grep "OpenGL renderer"
34+ # OpenGL renderer string: D3D12 (NVIDIA GeForce RTX 4060 Laptop GPU)
35+ ````
36+
37+ > 在新版本的 MESA 上,如果没有指定用户选择,d3d12后端将始终默认为第一个枚举的集成GPU。因此,在像核显+独显的笔记本电脑上,默认GPU将是Intel核显。
38+ >
39+ > 如果要使用NVIDIA GPU,则必须手动选择。这样做是为了避免意外唤醒更强大(和耗电)的GPU,除非这是用户想要的,因为这会影响电池寿命。
40+
41+ 设置后再运行mujoco仿真器可以看到
42+
43+ ![ image-20250921145816118] ( /pic/image-20250921145816118.png )
44+
45+ ## Reference
46+
47+ https://blog.csdn.net/qq_45298623/article/details/147224743
48+
49+ https://zhuanlan.zhihu.com/p/683481102
50+
51+ https://github.com/microsoft/wslg/wiki/GPU-selection-in-WSLg
You can’t perform that action at this time.
0 commit comments