WSL2下安装MESA / OSMESA驱动

找不到的命令可以在这里找https://command-not-found.com/

写在最前面

如果你和我一样是在用pyrender的时候遇到了以下问题,并且在试了以下方法代码仍然报莫名其妙错误的时候,请通过pippyrender pyopengl 都升到最新版,可以无视pyrenderpyopengl 的版本要求警告,另外wsl 的cuda升到最新版本,最后我一直提示Segmentation Fault的 问题居然是通过升级cuda驱动解决的…升级的过程可以参考官方文档

配置Xorg Libraries

参考https://www.linuxfromscratch.org/blfs/view/svn/x/x7lib.html,复制里面的命令一步一步来就好

可能遇到的问题:

configure: error: /X11 doesn’t exist or isn’t a directory
解决方法:https://www.linuxquestions.org/questions/linux-software-2/floating-point-exception-when-compiling-libx11-1-0-a-4175653823/

sudo mkdir /X11

checking keysym definitions… Package xproto was not found in the pkg-config search path.
Perhaps you should add the directory containing `xproto.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘xproto’ found
configure: error: Cannot find keysymdef.h

sudo apt-get install x11proto-core-dev

configure: error: Package requirements (xproto >= 7.0.25 xextproto xtrans xcb >= 1.11.1 kbproto inputproto) were not met:

No package ‘xcb’ found
解决方法:https://unix.stackexchange.com/questions/338519/how-to-install-libxcb

sudo apt install libxcb-util-dev

/bin/bash: line 1: xgettext: command not found

sudo apt-get install gettext

configure: error: You must have freetype installed; see http://www.freetype.org/

sudo apt install freetype2-demos freetype2-doc libfreetype6 libfreetype6-dev

No package ‘xorg-macros’ found

sudo apt-get install xutils-dev

checking for fontconfig >= 2.5.92… no
configure: error: Package requirements (fontconfig >= 2.5.92) were not met:

No package ‘fontconfig’ found

sudo apt install libfontconfig1-dev

配置Libdrm

按照https://www.linuxfromscratch.org/blfs/view/svn/x/libdrm.html一步步来

可能遇到报错../meson.build:21:0: ERROR: prefix value '' must be an absolute path ,在~/.bashrc 或者~/.zshrc ,取决于你用的shell里加一行export XORG_PREFIX=/usr

配置MESA

参考https://gitlab.freedesktop.org/mesa/mesa/-/issues/7584

sudo apt-get build-dep mesa
git clone https://gitlab.freedesktop.org/mesa/mesa.git
cd mesa
mkdir build
meson setup build -Dvulkan-drivers=microsoft-experimental && cd build && sudo ninja install
# 实际使用的时候因为我需要比较多的drivers,所以我使用的是下面这一行
meson setup build -Dvulkan-drivers=microsoft-experimental -Dgallium-drivers="auto, kmsro, radeonsi, r300, r600, nouveau, freedreno, swrast, v3d, vc4, etnaviv, tegra, i915, svga, virgl, panfrost, iris, lima, zink, d3d12, asahi, crocus" && cd build && sudo ninja install

可能遇到的问题:

meson.build:2051:4: ERROR: Program ‘byacc’ not found or not executable

sudo apt install byacc

meson.build:2062:2: ERROR: Program ‘flex’ not found or not executable

sudo apt-get install flex

meson.build:2118:2: ERROR: Dependency “wayland-scanner” not found, tried pkgconfig and cmake

sudo apt-get install libwayland-dev

meson.build:2125:2: ERROR: Dependency “wayland-protocols” not found, tried pkgconfig and cmake

sudo apt-get install wayland-protocols

meson.build:2129:4: ERROR: Dependency “wayland-egl-backend” not found, tried pkgconfig and cmake

sudo apt-get install libwayland-egl-backend-dev

meson.build:2179:4: ERROR: Dependency “xcb-glx” not found, tried pkgconfig and cmake

sudo apt install libxcb-glx0-dev

meson.build:2180:4: ERROR: Dependency “xcb-shm” not found, tried pkgconfig and cmake

sudo apt-get install libxcb-shm0-dev

meson.build:2192:4: ERROR: Dependency “xcb-dri2” not found, tried pkgconfig and cmake

sudo apt-get install libxcb-dri2-0-dev

meson.build:2195:6: ERROR: Dependency “xcb-dri3” not found, tried pkgconfig and cmake

sudo apt-get install libxcb-dri3-dev

后面真的受不了了,直接照着strings ./meson.build | grep xcb- 的结果把依赖全安装上了,结果发现只剩一个了…

sudo apt-get install libxcb-present-dev

Linking target src/gallium/targets/dri/libgallium_dri.so

/usr/bin/ld: src/gallium/drivers/radeonsi/libradeonsi.a.p/si_debug.c.o: in function si_print_annotated_shader': /home/user/mesa/src/mesa/build/../src/gallium/drivers/radeonsi/si_debug.c:951: undefined reference to ac_rtld_close’
https://gitlab.freedesktop.org/mesa/mesa/-/issues/7456

sudo apt install libelf-dev

配置OSMESA

参考https://pyrender.readthedocs.io/en/latest/install/index.html,不过这个版本里面的OSMESA已经很老了,最新版的OSMESA都是通过meson+ninja 进行编译的,如果想要和pyrender 搭配使用的话最好是同样指定一个prefix,以免环境乱掉,实际上OSMESA的官网也给出了示例:

meson builddir -Dosmesa=true -Dgallium-drivers=swrast -Dvulkan-drivers=[] -Dprefix=$PWD/builddir/install
ninja -C builddir install

由于我用的zsh不支持方括号,实际在wsl中编译的时候应该改一下,假如想放到prefix文件夹/usr/local/osmesa 下,在git clone了mesa的源码后创建一个buildosmesa文件夹:

cd mesa-22.3.2
mkdir buildosmesa
sudo mkdir -p /usr/local/osmesa
meson buildosmesa -Dosmesa=true -Dgallium-drivers="auto, kmsro, radeonsi, r300, r600, nouveau, freedreno, swrast, v3d, vc4, etnaviv, tegra, i915, svga, virgl, panfrost, iris, lima, zink, d3d12, asahi, crocus" -Dvulkan-drivers=microsoft-experimental -Dprefix=/usr/local/osmesa
sudo ninja -C buildosmesa install

最后记得更新一下环境变量

MESA_HOME=/path/to/your/mesa/installation # 我的是/usr/local/osmesa
export LIBRARY_PATH=$LIBRARY_PATH:$MESA_HOME/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MESA_HOME/lib
export C_INCLUDE_PATH=$C_INCLUDE_PATH:$MESA_HOME/include/
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:$MESA_HOME/include/
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值