网上的教程都是关于cuda的,但是使用OpenGL做渲染的时候跟那个没啥关系,WSL2上的OpenGL渲染默认是软件渲染或者是集显,性能非常差,无法使用GPU加速
测试当前环境OpenGL是不是使用GPU
1
glxinfo | grep "OpenGL renderer"
- 无加速,软件渲染
OpenGL renderer string: llvmpipe (LLVM 20.1.2, 256 bits)
下载最新英伟达驱动
转圈问题
- https://www.nvidia.cn/Download/index.aspx?lang=cn
根据电脑配置选择驱动
GeForce Security Update Driver 582.28 | Windows 10 64-bit
ms guild ❌️ 不用于OpenGL
测试(理论上WSL2侧不需要安装任何NVIDIA驱动,直接设置环境变量就可以了)
1
2
3
shensunbo@LAPTOP-ASUS:~$ export GALLIUM_DRIVER=d3d12
shensunbo@LAPTOP-ASUS:~$ glxinfo -B | grep "OpenGL renderer"
OpenGL renderer string: D3D12 (NVIDIA GeForce GTX 1060)
建议直接让copilot或者Claude Code直接在自己的环境中测试,比问AI效率高很多,网页AI基本在胡说八道
永久生效
1
2
3
4
5
echo '# WSL2 GPU D3D12' >> ~/.bashrc
echo 'export GALLIUM_DRIVER=d3d12' >> ~/.bashrc
echo 'unset MESA_LOADER_DRIVER_OVERRIDE' >> ~/.bashrc
source ~/.bashrc