How WSL2 Exposes DirectX 12 GPU Acceleration

Windows Subsystem for Linux (WSL2) enables DirectX 12 hardware acceleration for Linux binaries through GPU paravirtualization (GPU-PV), a specialized Linux kernel driver, and a user-mode Direct3D 12 runtime. This architecture allows Linux environments running inside a Hyper-V virtual machine to offload rendering, compute, and machine learning tasks directly to the physical Windows host GPU with minimal overhead and without requiring dedicated PCIe passthrough.

GPU Paravirtualization (GPU-PV) Architecture

WSL2 operates inside a lightweight Hyper-V virtual machine. Instead of using discrete device assignment (which would dedicate the entire physical GPU exclusively to the guest VM and disconnect it from Windows), Microsoft utilizes GPU Paravirtualization. GPU-PV allows the host and guest operating systems to share the same physical graphics hardware concurrently. The host retains control of GPU scheduling, power management, and physical memory allocation, while the guest VM is presented with a virtualized interface to the GPU.

The /dev/dxg Kernel Driver

At the core of the guest-to-host bridge is dxgkrnl, a Linux kernel driver developed by Microsoft specifically for WSL2. This driver initializes inside the Linux kernel and creates a character device located at /dev/dxg.

When a Linux process requires GPU services, it communicates with /dev/dxg. The driver packages the standard Graphics Processing Unit input/output control (IOCTL) calls and forwards them across the virtualization boundary to the host using Hyper-V's high-speed VMBus transport protocol.

Host-Side Processing

On the Windows host, the incoming requests from the VMBus are handled by the native Windows DirectX Graphics Kernel (dxgkrnl.sys). Because the requests arriving from WSL2 match the abstraction level of Windows graphics commands, the host treats the VM's requests similarly to any native Windows process. The host kernel schedules the tasks and executes them through the host’s installed Windows Display Driver Model (WDDM) GPU driver.

User-Mode Libraries: libdxcore and libd3d12

For user-space Linux binaries to interact with /dev/dxg, Microsoft provides companion libraries:

  • libdxcore.so: A Linux port of the Windows DXCore API. It handles adapter enumeration and manages the low-level communication with the /dev/dxg device.
  • libd3d12.so: A native Linux implementation of the Direct3D 12 API. It translates high-level DirectX 12 calls into command streams formatted for the underlying kernel driver.

These libraries are mounted automatically into the WSL2 environment from the host OS, ensuring that the guest libraries match the version of the Windows host graphics stack.

Enabling Broader API Support: Mesa and Compute

Linux software typically relies on OpenGL, Vulkan, or compute frameworks rather than native Direct3D 12. To support the wider Linux ecosystem, this translation layer is utilized by external frameworks:

  • Mesa 3D (OpenGL and Vulkan): The Mesa graphics library includes drivers (such as the D3D12 Gallium driver and the "Dozen" Vulkan-over-D3D12 driver) that translate OpenGL and Vulkan API calls directly into Direct3D 12 calls, which are then passed to libd3d12.so.
  • DirectML and AI Frameworks: Machine learning libraries like PyTorch and ONNX Runtime use the DirectML API built on top of Direct3D 12 to leverage GPU-accelerated tensor operations.
  • NVIDIA CUDA: NVIDIA provides a specialized user-mode driver for WSL2 that binds directly to the /dev/dxg interface, allowing unmodified CUDA containers and applications to execute parallel compute workloads on NVIDIA hardware.