├── LICENSE ├── README.md ├── TODO ├── docker-fedora ├── README └── dockerfile └── run-demo.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Nathan Gauër 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vulkan virgl 2 | 3 | 4 | This is the main repository for the Vulkan-virglrenderer experiment. 5 | It will clone 3 repositories: 6 | 7 | - virglrenderer (vulkan-wip branch) 8 | - mesa (virgl-vulkan branch) 9 | - vulkan-compute 10 | 11 | ## Virglrenderer 12 | 13 | Virglrenderer is a lib desinged to bring 3D acceleration to VirtIO-gpu. 14 | Initialy, this project was designed with OpenGL in mind. 15 | The goal of this experiment is to redesign it to support both Vulkan and OpenGL. 16 | 17 | ## Vulkan compute 18 | 19 | A sample vulkan compute application. 20 | 21 | # Requirements (Using Fedora's package names) 22 | - gcc 23 | - git 24 | - glibc-common 25 | - glibc-utils 26 | - kernel 27 | - bison 28 | - flex 29 | - gcc-c++ 30 | - meson 31 | - python 32 | - python2 33 | - expat-devel 34 | - libXvMC-devel 35 | - libdrm-devel 36 | - libva-devel 37 | - libvdpau-devel 38 | - llvm-devel 39 | - python2-mako 40 | - vulkan-devel 41 | - zlib-devel 42 | - elfutils-libelf-devel 43 | - libXdamage-devel 44 | - libxshmfence-devel 45 | - wayland-protocols-devel 46 | - autoconf 47 | - automake 48 | - file 49 | - libtool 50 | - make 51 | - check-devel 52 | - libepoxy-devel 53 | - mesa-libgbm-devel 54 | - cmake 55 | - glslang-devel 56 | 57 | If you want to build it in debug, you will need LunarG Vulkan SDK. 58 | 59 | # There is also a dockerfile available to build it using a valid Fedora setup 60 | 61 | docker-fedora/dockerfile 62 | 63 | # How to use 64 | 65 | If you have an Intel GPU, and any issue on your current distro, I recommand using 66 | a docker container. One is ready in the fedora-docker folder. 67 | I tested it on my machine, with a simple HD-Graphics. 68 | Maybe it will work on your machine. 69 | Otherwise, you can: 70 | 71 | ```bash 72 | ./run-demo.sh 73 | ``` 74 | 75 | There is also some options available 76 | 77 | ```bash 78 | $ ./run-demo.sh -help 79 | vulkan-virgl-helper: 80 | --url-mesa= : override the URL for the mesa project 81 | --url-virgl= : override the URL for the virglrenderer project 82 | --url-app= : override the URL for the vulkan-compute project 83 | -c : disable repo cloning step 84 | -p : disable repo pull step 85 | -b : disable building step, implies -r 86 | -r : disable running step 87 | -f : remove the build folder first (force) 88 | ``` 89 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | NEEDED IMPLEMS TO RUN THE SAMPLE APP 2 | ==================================== 3 | 4 | OK - implemented. Should be enough for now 5 | .. - on-going or partial implem 6 | - not started 7 | 8 | 9 | NEEDED : this function is MANDATORY is I want to reach the 10 | first result check. I will certainly crash soon after, but I 11 | will have passed the first compute shader check. 12 | 13 | STATUS NEEDED NAME 14 | [ ] [X] vkAllocateCommandBuffers 15 | [ OK ] [X] vkAllocateDescriptorSets 16 | [ OK ] [x] vkAllocateMemory 17 | [ OK ] [x] vkBeginCommandBuffer 18 | [ OK ] [x] vkBindBufferMemory 19 | [ OK ] [x] vkCmdBindDescriptorSets 20 | [ OK ] [x] vkCmdBindPipeline 21 | [ OK ] [x] vkCmdDispatch 22 | [ OK ] [x] vkCreateBuffer 23 | [ OK ] [x] vkCreateCommandPool 24 | [ OK ] [x] vkCreateComputePipelines 25 | [ OK ] [x] vkCreateDescriptorPool 26 | [ OK ] [x] vkCreateDescriptorSetLayout 27 | [ OK ] [x] vkCreateDevice 28 | [ OK ] [x] vkCreateFence 29 | [ OK ] [x] vkCreateInstance 30 | [ ] [ ] vkCreatePipelineCache 31 | [ OK ] [x] vkCreatePipelineLayout 32 | [ OK ] [x] vkCreateShaderModule 33 | [ ] [ ] vkDestroyBuffer 34 | [ ] [ ] vkDestroyCommandPool 35 | [ ] [ ] vkDestroyDescriptorPool 36 | [ ] [ ] vkDestroyDescriptorSetLayout 37 | [ ] [ ] vkDestroyDevice 38 | [ ] [ ] vkDestroyFence 39 | [ .. ] [ ] vkDestroyInstance 40 | [ ] [ ] vkDestroyPipeline 41 | [ ] [ ] vkDestroyPipelineLayout 42 | [ ] [ ] vkDestroyShaderModule 43 | [ OK ] [x] vkEndCommandBuffer 44 | [ OK ] [x] vkEnumerateDeviceExtensionProperties 45 | [ OK ] [x] vkEnumerateInstanceLayerProperties 46 | [ OK ] [x] vkEnumerateInstanceVersion 47 | [ OK ] [x] vkEnumeratePhysicalDevices 48 | [ OK ] [x] vkFlushMappedMemoryRanges 49 | [ ] [ ] vkFreeMemory 50 | [ OK ] [x] vkGetDeviceProcAddr 51 | [ OK ] [x] vkGetDeviceQueue 52 | [ OK ] [x] vkGetPhysicalDeviceFeatures 53 | [ OK ] [x] vkGetPhysicalDeviceMemoryProperties 54 | [ OK ] [x] vkGetPhysicalDeviceProperties 55 | [ OK ] [x] vkGetPhysicalDeviceQueueFamilyProperties 56 | [ OK ] [x] vkInvalidateMappedMemoryRanges 57 | [ OK ] [x] vkMapMemory 58 | [ .. ] [x] vkQueueSubmit 59 | [ OK ] [ ] vkUnmapMemory 60 | [ OK ] [x] vkUpdateDescriptorSets 61 | [ OK ] [x] vkWaitForFences 62 | -------------------------------------------------------------------------------- /docker-fedora/README: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | I use this docker to test this project on Fedora 28. 4 | I do not know a lot about docker, but here is how I use it: 5 | 6 | ========================================================== 7 | NOTE: this has been tested on an machine with an Intel GPU 8 | ========================================================== 9 | 10 | docker build -t $IMAGE_NAME . 11 | docker run \ 12 | --volume=/tmp/.X11-unix:/tmp/.X11-unix \ 13 | --device=/dev/dri:/dev/dri \ 14 | --env="DISPLAY" \ 15 | -ti $IMAGE_NAME ./run-demo.sh 16 | -------------------------------------------------------------------------------- /docker-fedora/dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker.io/fedora 2 | MAINTAINER http://fedoraproject.org/wiki/Cloud 3 | 4 | ENV container docker 5 | LABEL RUN="docker run -it --name NAME --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=NAME -e IMAGE=IMAGE -v /run:/run -v /var/log:/var/log -v /etc/localtime:/etc/localtime -v /:/host IMAGE" 6 | 7 | RUN [ -e /etc/yum.conf ] && sed -i '/tsflags=nodocs/d' /etc/yum.conf || true 8 | 9 | # Reinstall all packages to get man pages for them 10 | RUN dnf -y update && dnf -y reinstall "*" && dnf clean all 11 | 12 | # Install all useful packages 13 | RUN dnf -y install \ 14 | gcc \ 15 | git \ 16 | glibc-common \ 17 | glibc-utils \ 18 | kernel 19 | 20 | # MESA 21 | RUN dnf -y install \ 22 | bison \ 23 | flex \ 24 | gcc-c++ \ 25 | meson \ 26 | python \ 27 | python2 \ 28 | expat-devel \ 29 | libXvMC-devel \ 30 | libdrm-devel \ 31 | libva-devel \ 32 | libvdpau-devel \ 33 | llvm-devel \ 34 | python2-mako \ 35 | vulkan-devel \ 36 | zlib-devel \ 37 | elfutils-libelf-devel \ 38 | libXdamage-devel \ 39 | libxshmfence-devel \ 40 | wayland-protocols-devel 41 | 42 | # Virglrenderer 43 | RUN dnf -y install \ 44 | autoconf \ 45 | automake \ 46 | file \ 47 | libtool \ 48 | make \ 49 | check-devel \ 50 | libepoxy-devel \ 51 | mesa-libgbm-devel 52 | 53 | # Vulkan application 54 | RUN dnf -y install \ 55 | cmake \ 56 | glslang-devel 57 | 58 | # Needed to use /dev/dri 59 | RUN dnf -y install \ 60 | mesa-dri-drivers 61 | 62 | ENV USER build 63 | RUN useradd --create-home $USER 64 | USER $USER 65 | 66 | RUN git clone https://github.com/Keenuts/vulkan-virgl /home/$USER/vulkan-virgl 67 | WORKDIR /home/$USER/vulkan-virgl 68 | 69 | CMD ["/usr/bin/bash"] 70 | -------------------------------------------------------------------------------- /run-demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | COLOR_BEGIN="\033[93m" 4 | COLOR_END="\033[0m" 5 | 6 | DEFAULT_URL_MESA="https://github.com/Keenuts/mesa.git" 7 | DEFAULT_URL_VIRGL="https://github.com/Keenuts/virglrenderer.git" 8 | DEFAULT_URL_APP="https://github.com/Keenuts/vulkan-compute.git" 9 | 10 | DEFAULT_BRANCH_MESA="virgl-vulkan" 11 | DEFAULT_BRANCH_VIRGL="vulkan-wip" 12 | DEFAULT_BRANCH_APP="master" 13 | 14 | function show_help() 15 | { 16 | echo "vulkan-virgl-helper:" 17 | echo " --url-mesa= : override the URL for the mesa project" 18 | echo " --url-virgl= : override the URL for the virglrenderer project" 19 | echo " --url-app= : override the URL for the vulkan-compute project" 20 | echo " -c : disable repo cloning step" 21 | echo " -p : disable repo pull step" 22 | echo " -b : disable building step, implies -r" 23 | echo " -r : disable running step" 24 | echo " -f : remove the build folder first (force)" 25 | } 26 | 27 | # Takes two parameters: 28 | # - REPO-URL: URL to thr git repo 29 | # - REVISION: Revision to checkout 30 | # - DST-DIR: DST directory to clone to 31 | # 32 | # Will clone or update the given repo 33 | function clone_repo() 34 | { 35 | url="$1" 36 | branch="$2" 37 | folder="$3" 38 | 39 | echo -e "${COLOR_BEGIN}[GIT] checking ${branch}${COLOR_END}" 40 | 41 | if [ ! -d "$folder" ]; then 42 | echo -e "${COLOR_BEGIN}\tcloning ${url} ${branch}${COLOR_END}" 43 | git clone "$url" "$folder" -b "$branch" --depth=1 || exit 1 44 | else 45 | echo -e "${COLOR_BEGIN}\trepo $(basename ${folder}) already cloned.${COLOR_END}" 46 | fi 47 | 48 | cd "$root" 49 | } 50 | 51 | # takes 2 params 52 | # - REPO-DIR 53 | # - REMOTE-URL 54 | # 55 | # Will update the remote on the given repo 56 | function set_remote() 57 | { 58 | folder="$1" 59 | url="$2" 60 | 61 | echo -e "${COLOR_BEGIN}[GIT] changing remote to ${url}${COLOR_END}" 62 | cd "$folder" 63 | git remote set-url origin "$url" 64 | cd "$root" 65 | } 66 | 67 | # takes 1 param 68 | # - REPO-DIR 69 | # 70 | # Will do a 'git pull' in the given repo 71 | function pull_repo() 72 | { 73 | folder="$1" 74 | 75 | echo -e "${COLOR_BEGIN}[GIT] pulling changes for ${folder}${COLOR_END}" 76 | cd "$folder" 77 | git pull 78 | cd "$root" 79 | } 80 | 81 | function build_mesa() 82 | { 83 | 84 | if [ ! -d mesa/build ]; then 85 | echo -e "${COLOR_BEGIN}[INFO] configuring MESA${COLOR_END}" 86 | meson setup mesa mesa/build \ 87 | -Dvulkan-drivers=virgl \ 88 | -Dgallium-drivers=virgl \ 89 | -Dbuildtype=debug \ 90 | -Dglx=disabled \ 91 | -Dprefix=$(realpath mesa/build) 92 | fi 93 | 94 | echo -e "${COLOR_BEGIN}[INFO] building MESA${COLOR_END}" 95 | ninja -C mesa/build 96 | 97 | echo -e "${COLOR_BEGIN}[INFO] locating ICD files${COLOR_END}" 98 | export ICD_JSON="$(realpath mesa/build/src/virgl/virglrenderer_debug.x86_64.json)" 99 | 100 | if [ ! -f "$ICD_JSON" ]; then 101 | echo "ERROR: ICD json file not found. Exiting now" 102 | exit 1 103 | fi 104 | 105 | cd "$root" 106 | } 107 | 108 | function build_virglrenderer() 109 | { 110 | cd virglrenderer 111 | 112 | if [ ! -f Makefile ]; then 113 | echo -e "${COLOR_BEGIN}[INFO] configuring virglrenderer${COLOR_END}" 114 | ./autogen.sh \ 115 | --with-vulkan \ 116 | --enable-debug \ 117 | --prefix=$(realpath build) 118 | fi 119 | 120 | echo -e "${COLOR_BEGIN}[INFO] building virglrenderer${COLOR_END}" 121 | make -j $(( $(nproc) * 2 )) 122 | make install 123 | 124 | echo -e "${COLOR_BEGIN}[INFO] locating vtest server binary${COLOR_END}" 125 | export VIRGL_SERVER_BIN="$(realpath build/bin/virgl_test_server)" 126 | if [ ! -f "$VIRGL_SERVER_BIN" ]; then 127 | echo "ERROR: Vtest server's binary not found. Exiting now" 128 | exit 1 129 | fi 130 | 131 | cd "$root" 132 | } 133 | 134 | function build_vulkan_compute() 135 | { 136 | cd vulkan-compute 137 | 138 | if [ ! -d build ]; then 139 | echo -e "${COLOR_BEGIN}[INFO] configuring vulkan application${COLOR_END}" 140 | mkdir build 141 | cmake -H. -Bbuild/ 142 | fi 143 | 144 | echo -e "${COLOR_BEGIN}[INFO] building vulkan application${COLOR_END}" 145 | make -C build -j $(( $(nproc) * 2 )) 146 | 147 | echo -e "${COLOR_BEGIN}[INFO] locating test application${COLOR_END}" 148 | export VULKAN_COMPUTE_BINARY="$(realpath build/sum)" 149 | export VULKAN_COMPUTE_SHADER="$(realpath build/sum.spv)" 150 | if [ ! -f "$VULKAN_COMPUTE_BINARY" ]; then 151 | echo "ERROR: test app's binary not found. Exiting now" 152 | exit 1 153 | fi 154 | if [ ! -f "$VULKAN_COMPUTE_SHADER" ]; then 155 | echo "ERROR: test app shader's not found. Exiting now" 156 | exit 1 157 | fi 158 | cd "$root" 159 | } 160 | 161 | function run_app() 162 | { 163 | echo -e "${COLOR_BEGIN}[INFO] running the application now.${COLOR_END}" 164 | 165 | export VTEST_USE_VULKAN=1 166 | $VIRGL_SERVER_BIN --no-fork & 167 | SERVER_PID=$! 168 | 169 | sleep 1 170 | 171 | export VULKAN_DRIVER=virpipe 172 | export USE_VIRTIOGPU=true 173 | export VK_ICD_FILENAMES="$ICD_JSON" 174 | 175 | set +e 176 | 177 | cp -f $VULKAN_COMPUTE_SHADER . 178 | cp -f $VULKAN_COMPUTE_BINARY . 179 | ./$(basename $VULKAN_COMPUTE_BINARY) 180 | 181 | set -e 182 | 183 | echo -e "${COLOR_BEGIN}[INFO] Killing the vtest server.${COLOR_END}" 184 | kill $SERVER_PID 185 | } 186 | 187 | set -e 188 | 189 | # parse args. Repos URL can be overiden 190 | mesa_url="$DEFAULT_URL_MESA" 191 | virglrenderer_url="$DEFAULT_URL_VIRGL" 192 | vulkan_compute_url="$DEFAULT_URL_APP" 193 | 194 | step_clone=true 195 | step_pull=true 196 | step_build=true 197 | step_run=true 198 | 199 | update_remote=false 200 | force_clean=false 201 | 202 | while [ "$#" -gt 0 ]; do 203 | case "$1" in 204 | --url-mesa=*) mesa_url="${1#*=}"; update_remote=true; shift 1;; 205 | --url-virgl=*) virglrenderer_url="${1#*=}"; update_remote=true; shift 1;; 206 | --url-app=*) vulkan_compute_url="${1#*=}"; update_remote=true; shift 1;; 207 | -c) step_clone=false; shift 1;; 208 | -p) step_pull=false; shift 1;; 209 | -b) step_build=false; step_run=false; shift 1;; 210 | -r) step_run=false; shift 1;; 211 | -f) force_clean=true; shift 1;; 212 | *) show_help; exit 1;; 213 | esac 214 | done 215 | 216 | # ENV checkup: is out env sane ? 217 | to_check=(VULKAN_DRIVER USE_VIRTIOGPU VK_ICD_FILENAMES) 218 | for v in ${to_check[*]}; do 219 | if [ "$(env | grep $v=)" != "" ]; then 220 | echo "$v env variable is set. This might be an error" 221 | echo "press enter to continue" 222 | read 223 | fi 224 | done 225 | 226 | # Creating build tree 227 | 228 | cd $(dirname $0) 229 | if $force_clean; then 230 | rm -rf build 231 | fi 232 | 233 | mkdir -p build 234 | cd build 235 | export root="$(pwd)" 236 | 237 | if $step_clone; then 238 | # cloning repos 239 | clone_repo "$mesa_url" "$DEFAULT_BRANCH_MESA" mesa 240 | clone_repo "$virglrenderer_url" "$DEFAULT_BRANCH_VIRGL" virglrenderer 241 | clone_repo "$vulkan_compute_url" "$DEFAULT_BRANCH_APP" vulkan-compute 242 | fi 243 | 244 | if $update_remote; then 245 | set_remote "mesa" "$mesa_url" 246 | set_remote "virglrenderer" "$virglrenderer_url" 247 | set_remote "vulkan-compute" "$vulkan_compute_url" 248 | fi 249 | 250 | if $step_pull; then 251 | pull_repo mesa 252 | pull_repo virglrenderer 253 | pull_repo vulkan-compute 254 | fi 255 | 256 | if $step_build; then 257 | # building 258 | build_mesa 259 | build_virglrenderer 260 | build_vulkan_compute 261 | fi 262 | 263 | if $step_run; then 264 | # running 265 | run_app 266 | fi 267 | --------------------------------------------------------------------------------