microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios
MIT License
9.9k stars 296 forks source link

Vulkan support in WSL2/WSLg #1254

Closed AreamanM closed 3 weeks ago

AreamanM commented 4 weeks ago

Hi, I have been trying to setup vulkan on my WSL2 Arch Linux instance, I installed the vulkan-devel package and ran vulkaninfo which gave the following output:

ERROR: [Loader Message] Code 0 : vkCreateInstance: Found no drivers!
Cannot create Vulkan instance.
This problem is often caused by a faulty installation of the Vulkan driver or attempting to use a GPU that does not support Vulkan.
ERROR at /usr/src/debug/vulkan-tools/Vulkan-Tools-1.3.269/vulkaninfo/./vulkaninfo.h:688:vkCreateInstance failed with ERROR_INCOMPATIBLE_DRIVER

I checked if WSL can see my GPU by running glxinfo -B and the output verified that my discrete GPU is recognised:

~ $ glxinfo -B
name of display: :0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Microsoft Corporation (0xffffffff)
    Device: D3D12 (NVIDIA GeForce RTX 3070 Ti Laptop GPU) (0xffffffff)
    Version: 24.1.0
    Accelerated: yes
    Video memory: 16106MB
    Unified memory: no
    Preferred profile: core (0x1)
    Max core profile version: 4.6
    Max compat profile version: 4.6
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.1
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (NVIDIA GeForce RTX 3070 Ti Laptop GPU)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 24.1.0-arch1.1
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 4.6 (Compatibility Profile) Mesa 24.1.0-arch1.1
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile

OpenGL ES profile version string: OpenGL ES 3.1 Mesa 24.1.0-arch1.1
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

After doing some research, I found some reports suggesting there is D3D12 -> Vulkan in Mesa drivers from some time now but I did not find any official Microsoft source to confirm this.

Hence I want to ask is Vulkan properly supported in WSL2 + WSLg? If so, are there official docs on this?

github-actions[bot] commented 4 weeks ago

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs Download and execute [collect-wsl-logs.ps1](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-wsl-logs.ps1) in an **administrative powershell prompt**: ``` Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1 Set-ExecutionPolicy Bypass -Scope Process -Force .\collect-wsl-logs.ps1 ``` The scipt will output the path of the log file once done. Once completed please upload the output files to this Github issue. [Click here for more info on logging](https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#8-collect-wsl-logs-recommended-method) If you choose to email these logs instead of attaching to the bug, please send them to wsl-gh-logs@microsoft.com with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

AreamanM commented 4 weeks ago

/question

github-actions[bot] commented 4 weeks ago
Diagnostic information ``` Found '/question', adding tag 'question' ```
craigloewen-msft commented 4 weeks ago

Transferred to WSLg repo!

viruscamp commented 3 weeks ago

There is a vulkan driver called dozen which run on d3d12 in mesa source package.
It's incomplete, but usable in WSL2.
But offical Arch mesa did not contains the driver, you have to build and repack mesa yourself.

change the mesa PKGBUILD from

 -D vulkan-drivers=amd,intel,intel_hasvk,swrast,virtio,nouveau
to
 -D vulkan-drivers=amd,intel,intel_hasvk,swrast,virtio,nouveau,microsoft-experimental

and add the package function.

That's the result:

$ vkcube
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Selected GPU 0: Microsoft Direct3D12 (NVIDIA GeForce RTX 4060 Laptop GPU), type: DiscreteGpu
AreamanM commented 3 weeks ago

thanks that made vulkaninfo and vkcube work! any idea how to get vulkan to use dozen instead of llvmpipe?

AreamanM commented 3 weeks ago

ok I think I realise the issue, there is no dzn_icd.x86_64.json in /usr/share/vulkan/icd.d on my Arch WSL instance but there is dzn_icd.x86_64.json on my ubuntu WSL instance where everything works, not sure why that isnt the case because I did enable microsoft-experimental and vkcube/vulkaninfo did work(they don't work with the standard mesa from the Arch repos).

edit: I missed the

and add the package function.

part from viruscamp's reply, adding the package function for the dozen driver fixes the issue

Here's how I did it: for future readers who come across the thread:

In the PKGBUILD for mesa:

pkgname=(
  'vulkan-mesa-layers'
  'opencl-clover-mesa'
  'opencl-rusticl-mesa'
  'vulkan-intel'
  'vulkan-nouveau'
  'vulkan-radeon'
  'vulkan-swrast'
  'vulkan-virtio'
  'microsoft-dozen-driver' # add this line
  'libva-mesa-driver'
  'mesa-vdpau'
  'mesa'
)
...
# add this function
package_microsoft-dozen-driver() {
  pkgdesc="Microsoft dozen driver"
  depends=(
    'expat'
    'gcc-libs'
    'glibc'
    'libdrm'
    'libelf'
    'libx11'
    'libxcb'
    'libxshmfence'
    'llvm-libs'
    'zlib'
    'zstd'
  )
  provides=('microsoft-dozen-driver')

  _install fakeinstall/usr/share/vulkan/icd.d/dzn_icd.x86_64.json
  _install fakeinstall/$_libdir/libvulkan_dzn.so*

  install -Dm644 mesa-$pkgver/docs/license.rst -t "$pkgdir/usr/share/licenses/$pkgname"
}

The name of the package(and hence the function) is at your discretion, after a rebuild of mesa with these addition's along with viruscamp's change should make vulkan work. I am going to close the issue now as vulkan is supported in WSL, it is upto package maintainers to enable the right flags in the mesa build to make it work.