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

SegFault on WSL2/Windows 11 #2213

Closed
parasyte opened this issue Nov 26, 2021 · 7 comments
Closed

SegFault on WSL2/Windows 11 #2213

parasyte opened this issue Nov 26, 2021 · 7 comments

Comments

@parasyte
Copy link
Contributor

Description

I was excited to finally try out WSLg on Windows 11, but it just crashes in the Vulkan driver.

Repro steps

Run the hello-triangle example (main branch) on Ubuntu 20.04, making sure to follow the instructions provided in the Microsoft article. (Also, winit requires the libxkbcommon-dev to workaround rust-windowing/winit#1760)

The x11-apps do work: xcalc, xclock, xedit, xeyes, xlogo...

Expected vs observed behavior

Here's a backtrace from gdb:

Thread 1 "hello-triangle" received signal SIGSEGV, Segmentation fault.
0x00007ffff7c15d75 in wl_proxy_destroy () from /lib/x86_64-linux-gnu/libwayland-client.so.0
(gdb) bt
#0  0x00007ffff7c15d75 in wl_proxy_destroy () from /lib/x86_64-linux-gnu/libwayland-client.so.0
#1  0x00007ffff5ccdb37 in ?? () from /lib/x86_64-linux-gnu/libVkLayer_MESA_device_select.so
#2  0x00007ffff5cccff4 in ?? () from /lib/x86_64-linux-gnu/libVkLayer_MESA_device_select.so
#3  0x00007ffff7973bdb in ?? () from /lib/x86_64-linux-gnu/libvulkan.so.1
#4  0x00007ffff7976849 in vkEnumeratePhysicalDevices () from /lib/x86_64-linux-gnu/libvulkan.so.1
#5  0x0000555555d9e4c2 in ash::vk::features::InstanceFnV1_0::enumerate_physical_devices (self=0x555556935438, instance=..., p_physical_device_count=0x7fffffff8884, p_physical_devices=0x0) at /home/jay/.cargo/registry/src/github.com-1ecc6299db9ec823/ash-0.33.3+1.2.191/src/vk/features.rs:554
#6  0x0000555555d94087 in ash::instance::Instance::enumerate_physical_devices::{{closure}} (count=0x7fffffff8884, data=0x0) at /home/jay/.cargo/registry/src/github.com-1ecc6299db9ec823/ash-0.33.3+1.2.191/src/instance.rs:374
#7  0x0000555555d96311 in ash::prelude::read_into_uninitialized_vector (f=...) at /home/jay/.cargo/registry/src/github.com-1ecc6299db9ec823/ash-0.33.3+1.2.191/src/prelude.rs:42
#8  0x0000555555d94025 in ash::instance::Instance::enumerate_physical_devices (self=0x555556935430) at /home/jay/.cargo/registry/src/github.com-1ecc6299db9ec823/ash-0.33.3+1.2.191/src/instance.rs:373
#9  0x0000555555c03049 in wgpu_hal::vulkan::instance::<impl wgpu_hal::Instance<wgpu_hal::vulkan::Api> for wgpu_hal::vulkan::Instance>::enumerate_adapters (self=0x55555693a668) at wgpu-hal/src/vulkan/instance.rs:609
#10 0x0000555555ab6953 in wgpu_core::instance::<impl wgpu_core::hub::Global<G>>::request_adapter::gather (instance=..., inputs=0x7fffffffc028, compatible_surface=..., force_software=false, device_types=0x7fffffffa030) at /home/jay/other-projects/wgpu/wgpu-core/src/instance.rs:570
#11 0x0000555555a12c00 in wgpu_core::instance::<impl wgpu_core::hub::Global<G>>::request_adapter (self=0x55555693a650, desc=0x7fffffffc018, inputs=...) at /home/jay/other-projects/wgpu/wgpu-core/src/instance.rs:600
#12 0x0000555555a7dbdc in <wgpu::backend::direct::Context as wgpu::Context>::instance_request_adapter (self=0x55555693a650, options=0x55555688f7b8) at wgpu/src/backend/direct.rs:794
#13 0x0000555555a6d8bd in wgpu::Instance::request_adapter (self=0x55555688f770, options=0x55555688f7b8) at wgpu/src/lib.rs:1461
#14 0x000055555571510f in hello_triangle::run::{{closure}} () at wgpu/examples/hello-triangle/main.rs:12
#15 0x0000555555715de9 in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll (self=..., cx=0x7fffffffd210) at /rustc/b416e3892d9526709f3a248f5ed3a43a970f795e/library/core/src/future/mod.rs:80
#16 0x000055555571e3e8 in pollster::block_on (fut=...) at /home/jay/.cargo/registry/src/github.com-1ecc6299db9ec823/pollster-0.2.4/src/lib.rs:132
#17 0x00005555557214e7 in hello_triangle::main () at wgpu/examples/hello-triangle/main.rs:142

Extra materials

N/A

Platform

  • Windows 11 + WLS2 + Ubuntu 20.04
  • GeForce RTX 3090
  • NVIDIA CUDA driver for WSL version 510.06

GPU shows up in Ubuntu as:

$ sudo lspci -vvv

9a8c:00:00.0 3D controller: Microsoft Corporation Device 008e
        Physical Slot: 1407270391
        Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Latency: 0
        Capabilities: [40] Null
        Kernel driver in use: dxgkrnl
@parasyte
Copy link
Contributor Author

I just tried the ash triangle example, and it crashes in the same manner. (Had to install Vulkan Validation Layers to run this example.)

@parasyte
Copy link
Contributor Author

parasyte commented Nov 26, 2021

I disabled the vulkan backend entirely with the patch below, and the gles backend works, mostly!

disable-vulkan.patch
diff --git a/wgpu-core/build.rs b/wgpu-core/build.rs
index 37cf80b7..7e540e61 100644
--- a/wgpu-core/build.rs
+++ b/wgpu-core/build.rs
@@ -7,7 +7,6 @@ fn main() {
         unix_wo_apple: {all(unix, not(apple))},

         // Backends
-        vulkan: { all(not(wasm), any(windows, unix_wo_apple)) },
         metal: { all(not(wasm), apple) },
         dx12: { all(not(wasm), windows) },
         dx11: { all(false, not(wasm), windows) },
diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs
index 2e1ca617..7417a2bf 100644
--- a/wgpu-core/src/lib.rs
+++ b/wgpu-core/src/lib.rs
@@ -203,8 +203,6 @@ macro_rules! gfx_select {
         // Note: For some reason the cfg aliases defined in build.rs don't succesfully apply in this
         // macro so we must specify their equivalents manually
         match $id.backend() {
-            #[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")))]
-            wgt::Backend::Vulkan => $global.$method::<$crate::api::Vulkan>( $($param),* ),
             #[cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))]
             wgt::Backend::Metal => $global.$method::<$crate::api::Metal>( $($param),* ),
             #[cfg(all(not(target_arch = "wasm32"), windows))]

With this patch, wgpu-info prints:

Adapter 0:
        Backend:   Gl
        Name:      "D3D12 (NVIDIA GeForce RTX 3090)"
        VendorID:  0
        DeviceID:  0
        Type:      DiscreteGpu
        Compliant: false
        Features:
                DEPTH_CLIP_CONTROL:                                             true
                TEXTURE_COMPRESSION_BC:                                         false
                INDIRECT_FIRST_INSTANCE:                                        false
                TIMESTAMP_QUERY:                                                false
                PIPELINE_STATISTICS_QUERY:                                      false
                MAPPABLE_PRIMARY_BUFFERS:                                       false
                TEXTURE_BINDING_ARRAY:                                          false
                BUFFER_BINDING_ARRAY:                                           false
                STORAGE_RESOURCE_BINDING_ARRAY:                                 false
                SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING:  false
                UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING:  false
                PARTIALLY_BOUND_BINDING_ARRAY:                                  false
                UNSIZED_BINDING_ARRAY:                                          false
                MULTI_DRAW_INDIRECT:                                            false
                MULTI_DRAW_INDIRECT_COUNT:                                      false
                PUSH_CONSTANTS:                                                 false
                ADDRESS_MODE_CLAMP_TO_BORDER:                                   false
                POLYGON_MODE_LINE:                                              false
                POLYGON_MODE_POINT:                                             false
                TEXTURE_COMPRESSION_ETC2:                                       true
                TEXTURE_COMPRESSION_ASTC_LDR:                                   false
                TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES:                       true
                SHADER_FLOAT64:                                                 false
                VERTEX_ATTRIBUTE_64BIT:                                         false
                CONSERVATIVE_RASTERIZATION:                                     false
                VERTEX_WRITABLE_STORAGE:                                        false
                CLEAR_COMMANDS:                                                 true
                SPIRV_SHADER_PASSTHROUGH:                                       false
                SHADER_PRIMITIVE_INDEX:                                         false
                MULTIVIEW:                                                      false
        Limits:
                Max Texture Dimension 1d:                        16384
                Max Texture Dimension 2d:                        16384
                Max Texture Dimension 3d:                        1024
                Max Texture Array Layers:                        16384
                Max Bind Groups:                                 8
                Max Dynamic Uniform Buffers Per Pipeline Layout: 12
                Max Dynamic Storage Buffers Per Pipeline Layout: 0
                Max Sampled Textures Per Shader Stage:           16
                Max Samplers Per Shader Stage:                   16
                Max Storage Buffers Per Shader Stage:            0
                Max Storage Textures Per Shader Stage:           0
                Max Uniform Buffers Per Shader Stage:            12
                Max Uniform Buffer Binding Size:                 65536
                Max Storage Buffer Binding Size:                 0
                Max Vertex Buffers:                              16
                Max Vertex Attributes:                           16
                Max Vertex Buffer Array Stride:                  4294967295
                Max Push Constant Size:                          0
                Min Uniform Buffer Offset Alignment:             256
                Min Storage Buffer Offset Alignment:             256
                Max Compute Workgroup Size X:                    0
                Max Compute Workgroup Size Y:                    0
                Max Compute Workgroup Size Z:                    0
                Max Compute Workgroups Per Dimmension:           0
        Downlevel Properties:
                Shader Model:                        Sm5
                COMPUTE_SHADERS:                     false
                FRAGMENT_WRITABLE_STORAGE:           false
                INDIRECT_EXECUTION:                  false
                BASE_VERTEX:                         false
                READ_ONLY_DEPTH_STENCIL:             false
                DEVICE_LOCAL_IMAGE_COPIES:           true
                NON_POWER_OF_TWO_MIPMAPPED_TEXTURES: true
                CUBE_ARRAY_TEXTURES:                 true
                COMPARISON_SAMPLERS:                 true
                INDEPENDENT_BLENDING:                true
                VERTEX_STORAGE:                      false
                ANISOTROPIC_FILTERING:               false
                FRAGMENT_STORAGE:                    false

@kvark
Copy link
Member

kvark commented Nov 26, 2021

You should be able to disable Vulkan by just changing the flags passed to wgpu::Instance::new, without any code changes.

@parasyte
Copy link
Contributor Author

parasyte commented Nov 26, 2021

Good thing to call out! I tried the WGPU_BACKEND env var without success but didn't realize that hello-triangle does not use the framework:

let backend = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
let instance = wgpu::Instance::new(backend);

let instance = wgpu::Instance::new(wgpu::Backends::all());

I do know that wgpu-info is hardcoded with all backends, though.

let instance = wgpu::Instance::new(wgpu::Backends::all());

@codeart1st
Copy link

codeart1st commented Dec 3, 2021

For me, need to install sudo apt-get install libxcursor-dev libegl1 to get rendering on x11 working. Wayland still not working for me because of a random error in winit.

Instance { context: Context { type: "Native" } }
AdapterInfo { name: "D3D12 (NVIDIA GeForce RTX 3050 Laptop GPU)", vendor: 0, device: 0, device_type: DiscreteGpu, backend: Gl }

Also installed kisak-mesa, but currently didn't really know if it was really needed.
Update: Uninstalled kisak-mesa again and seems to be working as before with default packages.
Update2: To get wayland working for me, I need to install libxkbcommon-dev libegl1 libwayland-dev.

@parasyte
Copy link
Contributor Author

Updating Mesa fixes the segfault. In short:

$ sudo add-apt-repository ppa:kisak/kisak-mesa
$ sudo apt update
$ sudo apt upgrade

Not a wgpu bug! 🎉

@jaredzhou
Copy link

always got the following err
2022-03-09T14:16:35.695354Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
setupLoaderTermPhysDevs: Failed to detect any valid GPUs in the current config
any idea how to fix it?

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

No branches or pull requests

4 participants