DirectX On Linux: All You Need To Know About GPU Support For WSL2

DirectX On Linux: All You Need To Know About GPU Support For WSL2

At the ongoing Build 2020 virtual conference, Microsoft announced that it’ll bring GPU device support for Windows Subsystem for Linux 2 (WSL2). A preview of this in-demand feature will be released to Windows 10 Insider Fast ring users in the next few months.

But what does the feature mean for Windows 10 and (native) Linux users? Why and how is Microsoft making this possible? This is exactly what I am going to discuss in this article. So, let’s dive in to know all about DirectX on Linux.

What Is DirectX?

DirectX is a proprietary Windows technology owned and developed by Microsoft. It comprises a suite of APIs (Application Programming Interface) such as Direct3D, DirectDraw, and DirectMusic that enable the communication between hardware and software on the Windows platform.

DirectX helps to create and manage high-quality graphic images, audio, and video effects in applications running on Windows by leveraging high-performance features of hardware like GPUs and sound cards.

Lack Of GPU Support In Windows Subsystem for Linux

Microsoft developed Windows subsystem for Linux for the developers who find the Linux platform more suitable for development. But WSL2 does not have support for GPU devices because currently Windows cannot assign or share system GPU with Linux guest system.

Hence, if you want to run machine learning workloads on your GPU, you’ll have to use Windows 10 instead of WSL2. This has led to an increase in demand by developers who want high performance for heavy computing workloads using GPU power.

DirectX Coming To WSL2

To fulfill this need, Microsoft plans to bring support for GPU hardware acceleration in Linux VM running on WSL2. As of now, GPU support aims mainly for compute/ML workloads using D3D12, NVIDIA CUBA, and DirectML API on Windows 10.

The solution is not yet published for the Linux applications using DirectX in WSL2. However, Microsoft has also revealed that it’ll make Linux apps available with a graphical interface instead of a command line.

To add support for GPU in WSL2, Microsoft is using WDDM GPU Paravirtualization (GPU-PV) technology that integrates GPU virtualization technology into WDDM (Windows Display Driver Model). GPU-PV is also used in Windows Defender Application Guard, the Windows Sandbox, or the Hololens 2 emulator.

Dxgkrnl: New Kernel Driver For Linux

WDDM v2.5 or later has native support for GPU virtualization, but it is currently available for Windows guests only. Hence, Microsoft plans to develop a new Linux kernel driver ‘Dxgkrnl’ to use it for Linux guests and leverage the GPU-PV protocol exposing GPU to user mode Linux.

Dxgkrnl driver
Dxgkrnl driver architecture

Dxgkrnl is the virtual GPU driver that will reside in the Linux kernel of a WSL instance and connect with Windows hosts to communicate with the physical GPU. It exposes the para-virtualized /dev/dxg GPU device to the user mode of Linux instance running in WSL.

/dev/dxg exhibits a set of IOCTL (input/output control) system calls of Linux kernel that simulate the native WDDM D3DKMT kernel service layer on Windows 10. If your system has a single or multiple GPUs, Linux guests will detect all GPUs and use resources dynamically without competing with Windows apps.

Linux applications are treated equally with Windows applications to share the same GPU. The host Windows system doesn’t put any restrictions or partition of resources between Linux and Windows.

Does It Benefit Native Linux Users?

Currently, there are no Linux apps using DX12 because it is not open source and hence has no native support for Linux. However, Linux can run some Windows apps that use DX12, thanks to WINE, Vulkan, and DXVK.

Speaking of the new DX12, a Linux desktop user has nothing to do with ‘DirectX on Linux.’ This is because the Dxgkrnl driver only acts as a pipeline to send data between guest Linux userspace running in WSL2 and host Windows system.

So if you develop or use a Linux app with DX12, you have to use it in a virtual machine on Windows 10 to make it work.

But if you’re a great admirer of WSL2 and don’t want to dual boot Linux alongside Windows, you will soon be able to use GPU and perform your intensive ML work on Linux VM running on Windows 10. Microsoft has also pushed a draft of its driver code, which is currently under review by Linux developers.

Similar Posts