Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan support in WSL2/WSLg #1254

Closed
AreamanM opened this issue Jun 3, 2024 · 8 comments
Closed

Vulkan support in WSL2/WSLg #1254

AreamanM opened this issue Jun 3, 2024 · 8 comments
Labels
question Further information is requested

Comments

@AreamanM
Copy link

AreamanM commented Jun 3, 2024

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?

Copy link

github-actions bot commented Jun 3, 2024

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 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
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
Copy link
Author

AreamanM commented Jun 3, 2024

/question

Copy link

github-actions bot commented Jun 3, 2024

Diagnostic information
Found '/question', adding tag 'question'

@github-actions github-actions bot added the question Further information is requested label Jun 3, 2024
@craigloewen-msft craigloewen-msft transferred this issue from microsoft/WSL Jun 4, 2024
@craigloewen-msft
Copy link
Member

Transferred to WSLg repo!

@viruscamp
Copy link

viruscamp commented Jun 5, 2024

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
Copy link
Author

AreamanM commented Jun 7, 2024

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

@AreamanM
Copy link
Author

AreamanM commented Jun 7, 2024

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.

@voguelike
Copy link

voguelike commented Sep 7, 2024

i'm running into this same issue and despite everything being in the right place, i'm unable to get d3d12 as my renderer instead of llvmpipe no matter what i do.
WslLogs-2024-09-07_06-52-12.zip

i'm running an arch wsl2 install with the latest --pre-release update, using an AMD 6750XT with adrenalin version 24.20.11.01
/dev/dxg is present, X0 is present in /temp/.x11-unix/ and the latest kernel: 6.1.21.2-microsoft-standard-WSL2+

i built the latest mesa from source with the changes that @viruscamp and @AreamanM shared previously using @jaxvanyang 's fork, resulting in successful installation with all of the following present:

/usr/share/vulkan/icd.d/dzn_icd.x86_64.json is owned by vulkan-dozen 1:24.2.2-1
/usr/lib/libvulkan_dzn.so is owned by vulkan-dozen 1:24.2.2-1
/usr/lib/dri/d3d12_dri.so is owned by mesa 1:24.2.2-1
/usr/lib/libspirv_to_dxil.so is owned by mesa 1:24.2.2-1

these are the relevant changes to the PKGBUILD:

pkgbase=mesa
pkgname=(
...
  vulkan-dozen
...
)
pkgver=24.2.2
...

build() {
  local meson_options=(
...
    -D vulkan-drivers=amd,intel,intel_hasvk,swrast,virtio,nouveau,microsoft-experimental
...

 meson install -C build --destdir "$pkgdir"

  (
    local libdir=usr/lib icddir=usr/share/vulkan/icd.d

    cd "$pkgdir"

 ...

    _pick dozen $icddir/dzn_icd*.json
    _pick dozen $libdir/libvulkan_dzn.so*
    _pick docs usr/share/doc
...
)
package_vulkan-dozen() {
  pkgdesc="Microsoft dozen drivers"
  depends=(
    expat
    gcc-libs
    glibc
    libdrm
    libelf
    libx11
    libxcb
    libxshmfence
    llvm-libs
    zlib
    zstd
  )

  mv dozen/* "$pkgdir"
...
}
▸ VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/dzn_icd.x86_64.json vulkaninfo
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
ERROR: [../mesa-24.2.2/src/microsoft/vulkan/dzn_device.c:1134] Code 0 : VK_ERROR_INITIALIZATION_FAILED
ERROR: [Loader Message] Code 0 : setup_loader_term_phys_devs: Call to 'vkEnumeratePhysicalDevices' in ICD /usr/lib/libvulkan_dzn.so failed with error code -3
ERROR: [Loader Message] Code 0 : setup_loader_term_phys_devs:  Failed to detect any valid GPUs in the current config
ERROR at /usr/src/debug/vulkan-tools/Vulkan-Tools-1.3.269/vulkaninfo/./vulkaninfo.h:237:vkEnumeratePhysicalDevices failed with ERROR_INITIALIZATION_FAILED
▸ glxinfo -B
name of display: :0
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
Dropped Escape call with ulEscapeCode : 0x03007703
Dropped Escape call with ulEscapeCode : 0x03007703
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Mesa (0xffffffff)
    Device: llvmpipe (LLVM 18.1.8, 256 bits) (0xffffffff)
    Version: 24.2.2
    Accelerated: no
    Video memory: 15931MB
    Unified memory: yes
    Preferred profile: core (0x1)
    Max core profile version: 4.5
    Max compat profile version: 4.5
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.2
Memory info (GL_ATI_meminfo):
    VBO free memory - total: 21 MB, largest block: 21 MB
    VBO free aux. memory - total: 15278 MB, largest block: 15278 MB
    Texture free memory - total: 21 MB, largest block: 21 MB
    Texture free aux. memory - total: 15278 MB, largest block: 15278 MB
    Renderbuffer free memory - total: 21 MB, largest block: 21 MB
    Renderbuffer free aux. memory - total: 15278 MB, largest block: 15278 MB
Memory info (GL_NVX_gpu_memory_info):
    Dedicated video memory: 4294020543 MB
    Total available memory: 4294036475 MB
    Currently available dedicated video memory: 21 MB
OpenGL vendor string: Mesa
OpenGL renderer string: llvmpipe (LLVM 18.1.8, 256 bits)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 24.2.2-arch1.1
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 4.5 (Compatibility Profile) Mesa 24.2.2-arch1.1
OpenGL shading language version string: 4.50
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 24.2.2-arch1.1
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
▸ vkcube
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
Dropped Escape call with ulEscapeCode : 0x03007703
MESA: error: ID3D12DeviceFactory::CreateDevice failed
Selected GPU 0: llvmpipe (LLVM 18.1.8, 256 bits), type: Cpu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants