Linux aarch64交叉编译之 Google filament引擎

对于filament的编译。该文章的目标是编译一套aarch64 Linux Debian嵌入式版本上可以运行的库,本来想在网上找些现成的,然而 资料少的一13,接下来就开始趟坑。老套路,先把linux桌面版搞好,然后 移植到嵌入式Linux Debian 板子上。

1 Google filament引擎简介

Filament 是一个基于物理的实时3D渲染引擎,适用于 Android、iOS、Linux、macOS、Windows 和 WebGL。它被设计为在 Android 上尽可能小且尽可能高效(毕竟是google的亲儿子)。本质上Filament可以理解为OpenGL、Open GLES、Vulkan等的封装,也就是包了一层,同时多了PBR的功能(这是一个很棒的支持)。

想更多了解filament,查看github:GitHub - google/filament Project 即可。

2 Linux 本地编译 & 交叉编译

2.1 Linux(ubuntu20.04)上 filament的编译

刚开始琢磨了半天filament的各种文档。比如README、BUILDING文档等。编译一套Linux ubuntu 桌面版的还是比较简单的,按照文档的指示,关注以下3个关键软件版本:

- CMake 3.19 (or more recent)
- clang 7.0 (or more recent)
- [ninja 1.10](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages) (or more recent)

对于ubuntu20.04的cmake版本默认是3.18,非常蛋疼,就差一点点,然差之毫厘谬以千里,自己搞吧。于是来到cmake官网下载专区(Download | CMake)直接搞个sh的脚本即可,执行后记得配置环境变量,我是在bashrc中添加:

export PATH=/root/cmake-aarch64/bin/:$PATH

各位大侠根据自己的实际环境酌情修改即可,然后source 一下。

接下来开始linux 桌面版的编译之旅了,灰常简单:

#build debug version
CC=/usr/bin/clang CXX=/usr/bin/clang++ ./build.sh -c -a debug
#build release version
CC=/usr/bin/clang CXX=/usr/bin/clang++ ./build.sh -c -a release

这里要注意啦,有个天坑,不支持GNU C,心理凉了半截,这么弄老子待会儿交叉编译(我的交叉编译器版本全是gnu c的版本)怎么搞阿。。。心中 一万头 c泥m奔腾而过。

2.2 filament aarch64虚拟机编译

交叉编译器aarch64是走不通了,全是GNU C的,全军覆没。那咱们就来虚拟机,搞一个aarch64的虚拟机,流程如下:

#创建一个虚拟fs文件系统
$sudo qemu-debootstrap --arch arm64 bullseye /mnt/data/arm64 http://deb.debian.org/debian/
#进入到文件系统
$sudo chroot /mnt/data/arm64/
#退出文件系统
$exit

建好了之后呢,还要安装一些软件,当然很多坑是趟过的,为了编译过,必备软件如下(只多不少):

apt-get -y install libclang-cpp11-dev clang libclang1-9 libclang-dev clang-tools \
 x11proto-xf86vidmode-dev llvm vim tree cmake libc++-11-dev \ 
libc++abi-11-dev libxkbcommon-dev libwayland-dev libpixman-1-dev libinput-dev \ 
libdrm-dev wayland-protocols libcairo2-dev libpango1.0-dev libegl1-mesa-dev \   
libpam0g-dev libx11-xcb-dev libxcb-composite0-dev libxcursor-dev libbsd-dev \
libelf-dev libxshmfence-dev libxxf86vm-dev fonts-noto-cjk llvm-11-dev \
vulkan-utils vulkan-tools npm libvdpau-dev libxv-dev bison byacc flex \
libwayland-egl-backend-dev libxcb-glx0-dev libxcb-dri2-0-dev libxcb-dri3-dev \
libxcb-present-dev libxrandr-dev libxi-dev

这里要注意,因为毕竟版本不同会导致软件上有差异,如果发现缺 库 或者 头文件,用apt search和apt-file search 这俩命令检索就可以了。

接下来,把filament源代码拉到/mnt/data/arm64/root/ 路径下,当然,这里也会出现cmake版本过低的问题,解决方法依然是去官网 下载专区(Download | CMake),这里有aarch64的版本cmake-3.24.0-rc4-linux-aarch64.sh,这里之接下来即可,和desktop版本的s操作一样,配置下环境变量即可使用。到这里整个环境基本上就搞定了,和desktop版本一样,执行如下命令:

#build debug version
CC=/usr/bin/clang CXX=/usr/bin/clang++ ./build.sh -c -a debug
#build release version
CC=/usr/bin/clang CXX=/usr/bin/clang++ ./build.sh -c -a release

虚拟机上嵌入式版本的编译 速度还是比较慢的,测试后发现在开发板上的编译速度要快2倍多。

2.3 开发版上直接编译filament

在开发板上速度快很多,那怎们就来简单说下流程,无非就是把源码搞到开发板上,然后其他的和虚拟机一样,要安装这些:

apt-get -y install libclang-cpp11-dev clang libclang1-9 libclang-dev clang-tools \
 x11proto-xf86vidmode-dev libxxf86vm-dev llvm vim tree cmake libc++-11-dev \ 
libc++abi-11-dev libxkbcommon-dev libwayland-dev libpixman-1-dev libinput-dev \ 
libdrm-dev wayland-protocols libcairo2-dev libpango1.0-dev libegl1-mesa-dev \   
libpam0g-dev libx11-xcb-dev libxcb-composite0-dev libxcursor-dev libbsd-dev \
libelf-dev libxshmfence-dev libxxf86vm-dev fonts-noto-cjk llvm-11-dev \
vulkan-utils vulkan-tools npm libvdpau-dev libxv-dev bison byacc flex \
libwayland-egl-backend-dev libxcb-glx0-dev libxcb-dri2-0-dev libxcb-dri3-dev \
libxcb-present-dev libxrandr-dev libxi-dev

注意:这里实际是多一个libxxf86vm-dev,因为检索头文件时用到的库对应的软件是不一样的。

接下来里的流程和模拟器一样,搞完了直接执行关键命令

#build debug version
CC=/usr/bin/clang CXX=/usr/bin/clang++ ./build.sh -c -a debug
#build release version
CC=/usr/bin/clang CXX=/usr/bin/clang++ ./build.sh -c -a release

完活儿。show一下成功的样子:

[ 95%] Building CXX object samples/CMakeFiles/vbotest.dir/vbotest.cpp.o
[ 95%] Linking CXX executable vbotest
[ 95%] Built target vbotest
[ 95%] Building CXX object samples/CMakeFiles/viewtest.dir/viewtest.cpp.o
[ 95%] Linking CXX executable viewtest
[ 95%] Built target viewtest
[ 95%] Building CXX object tools/cmgen/CMakeFiles/test_cmgen.dir/tests/test_cmgen.cpp.o
[ 95%] Linking CXX executable test_cmgen
[ 95%] Built target test_cmgen
[ 96%] Building CXX object tools/cso-lut/CMakeFiles/cso-lut.dir/src/main.cpp.o
[ 96%] Linking CXX executable cso-lut
[ 96%] Built target cso-lut
[ 96%] Building CXX object tools/glslminifier/CMakeFiles/test_glslminifier.dir/src/GlslMinify.cpp.o
[ 96%] Building CXX object tools/glslminifier/CMakeFiles/test_glslminifier.dir/tests/test_glslminifier.cpp.o
[ 96%] Linking CXX executable test_glslminifier
[ 96%] Built target test_glslminifier
[ 96%] Building CXX object tools/matc/CMakeFiles/test_matc.dir/tests/test_matc.cpp.o
[ 96%] Building CXX object tools/matc/CMakeFiles/test_matc.dir/tests/test_includer.cpp.o
[ 97%] Building CXX object tools/matc/CMakeFiles/test_matc.dir/tests/MockConfig.cpp.o
[ 97%] Linking CXX executable test_matc
[ 97%] Built target test_matc
[ 97%] Building CXX object tools/matinfo/CMakeFiles/matinfo.dir/src/main.cpp.o
[ 97%] Linking CXX executable matinfo
[ 97%] Built target matinfo
[ 97%] Building CXX object tools/normal-blending/CMakeFiles/normal-blending.dir/src/main.cpp.o
[ 97%] Linking CXX executable normal-blending
[ 97%] Built target normal-blending
[ 97%] Building CXX object tools/rgb-to-lmsr/CMakeFiles/rgb-to-lmsr.dir/src/main.cpp.o
[ 98%] Linking CXX executable rgb-to-lmsr
[ 98%] Built target rgb-to-lmsr
[ 98%] Building CXX object tools/roughness-prefilter/CMakeFiles/roughness-prefilter.dir/src/main.cpp.o
[ 98%] Linking CXX executable roughness-prefilter
[ 98%] Built target roughness-prefilter
[100%] Building CXX object tools/specular-color/CMakeFiles/specular-color.dir/src/main.cpp.o
[100%] Linking CXX executable specular-color
[100%] Built target specular-color
Installing release in out/release/filament...
.....
Install the project...
-- Install configuration: "Release"
-- Installing: /userdata/filament/out/release/filament/lib/aarch64/libcamutils.a
-- Installing: /userdata/filament/out/release/filament/include/camutils
-- Installing: /userdata/filament/out/release/filament/include/camutils/Bookmark.h
-- Installing: /userdata/filament/out/release/filament/include/camutils/compiler.h
-- Installing: /userdata/filament/out/release/filament/include/camutils/Manipulator.h
-- Installing: /userdata/filament/out/release/filament/include/filament
-- Installing: /userdata/filament/out/release/filament/include/filament/MaterialEnums.h
-- Installing: /userdata/filament/out/release/filament/include/filament/MaterialChunkType.h
-- Installing: /userdata/filament/out/release/filament/lib/aarch64/libfilabridge.a
-- Installing: /userdata/filament/out/release/filament/lib/aarch64/libfilaflat.a
-- Installing: /userdata/filament/out/release/filament/lib/aarch64/libfilameshio.a
-- Installing: /userdata/filament/out/release/filament/include/filameshio/MeshReader.h
-- Installing: /userdata/filament/out/release/filament/lib/aarch64/libgeometry.a
-- Installing: /userdata/filament/out/release/filament/include/geometry
-- Installing: /userdata/filament/out/release/filament/include/geometry/SurfaceOrientation.h
-- Installing: /userdata/filament/out/release/filament/include/geometry/Transcoder.h
-- Installing: /userdata/filament/out/release/filament/lib/aarch64/libgltfio.a
-- Installing: /userdata/filament/out/release/filament/lib/aarch64/libgltfio_core.a
-- Installing: /userdata/filament/out/release/filament/lib/aarch64/libuberarchive.a
-- Installing: /userdata/filament/out/release/filament/include/gltfio
-- Installing: /userdata/filament/out/release/filament/include/gltfio/AssetLoader.h
...
Generating out/filament-release-linux.tgz...
filament/
filament/lib/
filament/lib/aarch64/
filament/lib/aarch64/libbluevk.a
filament/lib/aarch64/libfilament-iblprefilter.a
filament/lib/aarch64/libfilamat_lite.a
filament/lib/aarch64/libdracodec.a
filament/lib/aarch64/libfilaflat.a
filament/lib/aarch64/libbackend.a
filament/lib/aarch64/libuberarchive.a
filament/lib/aarch64/libshaders.a
filament/lib/aarch64/libgltfio_core.a
filament/lib/aarch64/libbluegl.a
filament/lib/aarch64/libfilamat.a
filament/lib/aarch64/libviewer.a
filament/lib/aarch64/libzstd.a
filament/lib/aarch64/libuberzlib.a
filament/lib/aarch64/libbasis_transcoder.a
filament/lib/aarch64/libibl-lite.a
filament/lib/aarch64/libcamutils.a
filament/lib/aarch64/libvkshaders.a
filament/lib/aarch64/libfilabridge.a
filament/lib/aarch64/libmeshoptimizer.a
filament/lib/aarch64/libmatdbg.a
filament/lib/aarch64/libktxreader.a
filament/lib/aarch64/libimage.a
filament/lib/aarch64/libibl.a
filament/lib/aarch64/libfilameshio.a
filament/lib/aarch64/libfilament.a
filament/lib/aarch64/libstb.a
filament/lib/aarch64/libcivetweb.a
filament/lib/aarch64/libutils.a
filament/lib/aarch64/libgeometry.a
filament/lib/aarch64/libsmol-v.a
filament/lib/aarch64/libgltfio.a
filament/LICENSE
filament/README.md
...

注意:这里编译debug版本和release版本,对于硬盘的需求还是相差很大的,release版本基本上3个G以内,debug版本13个G不够用。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

图王大胜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值