
Ubuntu18.04安装Vulkan SDK教程方法(超详细)
注意OS的要求是否支持解压到指定目录查看目录结构x86_64/binx86_64/libconfigsource设置环境变量可以通过目录中自带的脚本来设置环境变量,也可以通过下面的shell命令行来设置,当然这些都是一些临时的设置方法,有效期仅限于本次Session内。永久性设置:在~/.bashrc中加入如果希望将SDK文件安装到你的系统目录下,可以参考如下步骤(感觉可以使用软链接更好一些)
Ubuntu18.04 安装Vulkan SDK方法
一 、 复制安装
-
下载Vulkan SDK压缩包:LunarXchange (lunarg.com) 注意OS的要求是否支持
-
解压到指定目录
tar -xf vulkansdk-linux-x86_64-1.3.224.1.tar.gz -C vulkan_1.3.224 cd vulkan_1.3.224
-
查看目录结构
(base) root@bxt309:/home/shanlin/pytorch-vulkan/vulkan_1.3.224.1# ls -al total 56 drwxr-xr-x 5 root root 4096 9月 1 14:46 . drwxr-xr-x 4 root root 4096 9月 1 11:15 .. drwxr-xr-x 2 root root 4096 8月 26 2022 config -rw-r--r-- 1 root root 944 8月 26 2022 LICENSE.txt -rw-r--r-- 1 root root 333 8月 26 2022 README.txt -rw-r--r-- 1 root root 582 8月 26 2022 setup-env.sh drwxr-xr-x 20 root root 4096 8月 26 2022 source -rwxr-xr-x 1 root root 22865 8月 26 2022 vulkansdk drwxr-xr-x 7 root root 4096 8月 26 2022 x86_64 (base) root@bxt309:/home/shanlin/pytorch-vulkan/vulkan_1.3.224.1# cd x86_64/ (base) root@bxt309:/home/shanlin/pytorch-vulkan/vulkan_1.3.224.1/x86_64# ll total 28 drwxr-xr-x 7 root root 4096 8月 26 2022 ./ drwxr-xr-x 5 root root 4096 9月 1 14:46 ../ drwxr-xr-x 2 root root 4096 9月 1 15:12 bin/ drwxr-xr-x 3 root root 4096 8月 26 2022 etc/ drwxr-xr-x 17 root root 4096 9月 1 15:12 include/ drwxr-xr-x 4 root root 4096 9月 1 15:12 lib/ drwxr-xr-x 16 root root 4096 9月 1 15:12 share/ (base) root@bxt309:/home/shanlin/pytorch-vulkan/vulkan_1.3.224.1# cd .. (base) root@bxt309:/home/shanlin/pytorch-vulkan/vulkan_1.3.224.1# ll source/ total 80 drwxr-xr-x 20 root root 4096 8月 26 2022 ./ drwxr-xr-x 5 root root 4096 9月 1 14:46 ../ drwxr-xr-x 18 root root 4096 9月 1 15:07 DirectXShaderCompiler/ drwxr-xr-x 11 root root 4096 9月 1 15:06 gfxreconstruct/ drwxr-xr-x 15 root root 4096 9月 1 11:18 glslang/ drwxr-xr-x 6 root root 4096 9月 1 11:18 robin-hood-hashing/ drwxr-xr-x 3 root root 4096 9月 1 11:22 shaderc/ drwxr-xr-x 23 root root 4096 9月 1 15:05 SPIRV-Cross/ drwxr-xr-x 8 root root 4096 9月 1 11:17 SPIRV-Headers/ drwxr-xr-x 10 root root 4096 9月 1 15:12 SPIRV-Reflect/ drwxr-xr-x 16 root root 4096 9月 1 11:17 SPIRV-Tools/ drwxr-xr-x 6 root root 4096 9月 1 15:12 volk/ drwxr-xr-x 12 root root 4096 9月 1 11:19 Vulkan-ExtensionLayer/ drwxr-xr-x 7 root root 4096 9月 1 11:18 Vulkan-Headers/ drwxr-xr-x 12 root root 4096 9月 1 11:18 Vulkan-Loader/ drwxr-xr-x 8 root root 4096 8月 26 2022 VulkanMemoryAllocator/ drwxr-xr-x 15 root root 4096 9月 1 15:12 Vulkan-Profiles/ drwxr-xr-x 16 root root 4096 9月 1 11:20 VulkanTools/ drwxr-xr-x 14 root root 4096 9月 1 11:19 Vulkan-Tools/ drwxr-xr-x 11 root root 4096 9月 1 11:18 Vulkan-ValidationLayers/
各个文件目录的内容如下:
Directory Description x86_64/bin
Vulkan 的一些命令和工具 x86_64/include
对你的Vulkan应用有用的头文件,包括Vulkan, shader工具等。 x86_64/lib
Vulkan加载器库和层运行时库 x86_64/etc/vulkan/explicit_layer.d
Vulkan验证层的.json清单文件 x86_64/share/vulkan
身份和Vulkan仓库信息的配置 config
Sample层设置文件 source
源代码 -
设置环境变量
Environment Variable File/Path to Include PATH
$VULKAN_SDK/bin
LD_LIBRARY_PATH
$VULKAN_SDK/lib
VK_LAYER_PATH
$VULKAN_SDK/etc/vulkan/explicit_layer.d
可以通过目录中自带的脚本setup-env.sh
来设置环境变量,也可以通过下面的shell命令行来设置,当然这些都是一些临时的设置方法,有效期仅限于本次Session内。
export VULKAN_SDK=~/vulkan/1.x.yy.z/x86_64
export PATH=$VULKAN_SDK/bin:$PATH
export LD_LIBRARY_PATH=$VULKAN_SDK/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export VK_LAYER_PATH=$VULKAN_SDK/etc/vulkan/explicit_layer.d
永久性设置:在~/.bashrc中加入
source $VULKAN_SDK
- 将SDK文件拷贝到系统目录下
如果希望将SDK文件安装到你的系统目录下,可以参考如下步骤(感觉可以使用软链接更好一些)
# Vulkan Header Files
sudo cp -r $VULKAN_SDK/include/vulkan/ /usr/local/include/
# Vulkan Loader Files
sudo cp -P $VULKAN_SDK/lib/libvulkan.so* /usr/local/lib/
# Vulkan Layer Files
sudo cp $VULKAN_SDK/lib/libVkLayer_*.so /usr/local/lib/
sudo mkdir -p /usr/local/share/vulkan/explicit_layer.d
sudo cp $VULKAN_SDK/etc/vulkan/explicit_layer.d/VkLayer_*.json /usr/local/share/vulkan/explicit_layer.d
最后,使用loadconfig来刷新系统的加载器
sudo loadconfig
二、卸载
直接删除整个目录
rm -rf ~/vulkan/1.x.yy.z
三、编译安装
官网的DOC中提到,虽然对Ubuntu做了大量的测试,并对Linux的其他各个发行版本都进行了测试,但是还是有些额外的Linux发行版本没有经过确认,如果压缩包中带有的编译好的可执行二进制文件在你的系统上不能正常工作,可以使用sdk中辅助脚本(vulkansdk)来自己编译这些文件。
需要提交安装一些package:
sudo apt update
sudo apt upgrade
# 这个ubuntu需要下载的packages 其他OS可以去https://vulkan.lunarg.com/doc/sdk/1.3.224.1/linux/getting_started.html自行查看
sudo apt install libglm-dev cmake libxcb-dri3-0 libxcb-present0 libpciaccess0 \
libpng-dev libxcb-keysyms1-dev libxcb-dri3-dev libx11-dev g++ gcc g++-multilib \
libmirclient-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libxcb-ewmh-dev \
git python python3 bison libx11-xcb-dev liblz4-dev libzstd-dev python3-distutils \
qt5-default ocaml-core ninja-build pkg-config libxml2-dev wayland-protocols
辅助脚本使用方法:
(base) root@bxt309:/home/shanlin/pytorch-vulkan/vulkan_1.3.224.1# ./vulkansdk --help
Script to build repositories that are useful for Vulkan development
Usage: ./vulkansdk [--clean|--help] [OPTION...] [REPO...]
OPTIONS:
[--help|help] prints this usage and exits
[--clean|-c] deletes all the build directories and exits
[--debug|-d] build binaries as debuggable (will replace existing binaries)
[--numjobs #|-j #] specify the number of jobs to use for building, defaults to using 1 job
[--maxjobs] uses nproc to use max jobs possible
REPOS:
Any or no repositories can be specified for building. If none are specified, then all are built
[all] this will build all repositories, same as specifying no repositories
Repositories that can be specified:
[glslang] [vulkan-headers] [vulkan-loader|loader]
[vulkan-validationlayers|layers] [vulkan-tools|tools] [vulkantools|lunarg-tools]
[shaderc] [spirv-headers] [spirv-tools|spirvtools] [spirv-cross|spirvcross]
[gfxreconstruct] [spirv-reflect] [dxc] [vulkan-extensionlayer] [vulkan-profiles]
[volk] [vma]
EXAMPLES:
'./vulkansdk --maxjobs' this will build everything and use as many jobs as possible
'./vulkansdk -j 4 vulkan-validationlayers' this will build vulkan-validationlayers using 4 jobs
'./vulkansdk --debug vulkan-loader' this will build a debuggable loader
'./vulkansdk --clean' deletes all the build directories and exits
'./vulkansdk glslang vulkan-tools' builds glslang and vulkan-tools
除了后面跟需要编译的工具名称之外,还可以指定如下参数:
- -j 指定编译使用的线程数
- –maxjobs 启用最大可用线程数进行编译
- –debug 编译debug版本的二进制文件
- –clean 删除创建的所有的Build目录并退出
ps: 解决源码编译时git clone速度太慢的问题
vim $VULKAN_SDK/source/shaderc/update_shaderc_sources.py
将其中其73的函数GetUrl
中的变量 host
的值改为"ghproxy.com/https://github.com/"
73 def GetUrl(self, style='https'):
74 """Returns the URL for the repository."""
75 # host = "github.com"
76 host = "ghproxy.com/https://github.com/"
77 sep = '/' if (style is 'https') else ':'
78 return '{style}://{host}{sep}{subrepo}'.format(
79 style=style,
80 host=host,
81 sep=sep,
82 subrepo=self.subrepo)
Reference:
Vulkan 官方文档:LunarXchange (lunarg.com)
更多推荐
所有评论(0)