Using Vulkan 3D graphics in a Windows Virtual machine or on a web server
This guide describes how to use Vulkan 3D graphics on a system without a graphics card or without a driver that would support Vulkan.
It can be used to enable Vulkan in a Virtual machine or on a web server (for example to run a console application that renders 3D scene and saves that to an image).
To run Vulkan on a system without a graphic card or a Vulkan driver, it is possible to use Mesa's LLVMpipe.
LLVMpipe is a very fast software rasterizer. It can use multiple threads and SSE vector instructions.
See more on its web page.
To use the LLVMpipe, do the following two steps:
-
Provide Vulkan loader:
If you are running on a system without any Vulkan driver, then first you need to provide the Vulkan loader
(when there is no Vulkan loader available and you are trying to use Ab4d.SharpEngine, you get "Cannot load Vulkan loader library ..." exception).
If the system already supports Vulkan and you would just like to try software rasterizer, you can skip this step.
Vulkan loader is part of the Vulkan runtime. It can be downloaded from the LunarG's download page.
You can download and install the installer (for example "VulkanRT-1.3.261.0-Installer.exe). You can also download the zip file (for example "VulkanRT-1.3.261.0-Components.zip") and
extract the vulkan-1.dll file into the application's root folder (where the .exe file is).
You can also copy the vulkan-1.dll to the folder with the llvmpipe drivers that is set to the VK_DRIVER_FILES environment variable (see below).
-
Provide Mesa's Vulkan driver:
One option is to compile the Mesa driver by yourself.
Another, easier option, is to download a precompiled version from the following GitHub page (for example, download "mesa3d-23.1.6-release-mingw.7z" or "mesa3d-23.1.6-release-msvc.7z").
After downloading the zip, extract it.
The files that are required for Vulkan support are: vulkan_lvp.dll, lvp_icd.x86_64.json and lvp_icd.x86.json (later only for 32-bit support).
Copy those files to a special folder (for example: c:\llvmpipe) or to the application's root folder (where the .exe file is).
To use the llvmpipe driver, we need to instruct the Vulkan loader to load that driver. This is done by setting the VK_DRIVER_FILES environment variable.
If you copied the driver into a special folder (for example c:\llvmpipe), then you can set the global environment variable so all applications will be able to see that.
If you copied the driver to the application's folder, then you can set the VK_DRIVER_FILES environment variable only for that application.
This can be done from .Net code by executing the following:
string llvmPath = AppDomain.CurrentDomain.BaseDirectory + (Environment.Is64BitProcess ? "lvp_icd.x86_64.json" : "lvp_icd.x86.json");
Environment.SetEnvironmentVariable("VK_DRIVER_FILES", llvmPath);
If you extracted the vulkan loader (vulkan-1.dll) from the Vulkan runtime zip, you can copy it to the special folder that is set to the VK_DRIVER_FILES environment variable and
SharpEngine will find it. In this case it is not necessary to copy vulkan-1.dll to the application's root folder.
After that you should be able to use Vulkan in a virtual machine.
For example the following screenshot is showing Ab4d.SharpEngine samples running in VMWare Workstation v16:
Note that SharpEngine will by default disable MSAA (multi-sampled anti-aliasing) when using a software renderer.
This significantly improves the frame rate. If you want to enable that, just manually set the SceneView.PreferredMultiSampleCount to 4.
Read more about Ab4d.SharpEngine.
Get Ab4d.SharpEngine samples from GitHub.