gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.69k stars 930 forks source link

X11 error: BadDrawable/BadMatch #3558

Open edap opened 1 year ago

edap commented 1 year ago

Description The example with the triangle crashes.

Repro steps If I run RUST_BACKTRACE=1 cargo run --example hello-triangle I have this error.

[2023-03-04T15:31:54Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadDrawable (invalid Pixmap or Window parameter)",
        error_code: 9,
        request_code: 149,
        minor_code: 4,
    }
thread 'main' panicked at 'Failed to focus input context: XError { description: "BadDrawable (invalid Pixmap or Window parameter)", error_code: 9, request_code: 149, minor_code: 4 }', /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/event_processor.rs:912:30
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
   2: core::result::unwrap_failed
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
   3: core::result::Result<T,E>::expect
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1070:23
   4: winit::platform_impl::platform::x11::event_processor::EventProcessor<T>::process_event
             at /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/event_processor.rs:909:25
   5: winit::platform_impl::platform::x11::EventLoop<T>::drain_events
             at /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/mod.rs:517:13
   6: winit::platform_impl::platform::x11::EventLoop<T>::run_return::single_iteration
             at /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/mod.rs:348:13
   7: winit::platform_impl::platform::x11::EventLoop<T>::run_return
             at /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/mod.rs:448:31
   8: winit::platform_impl::platform::x11::EventLoop<T>::run
             at /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/mod.rs:503:25
   9: winit::platform_impl::platform::EventLoop<T>::run
             at /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/mod.rs:755:56
  10: winit::event_loop::EventLoop<T>::run
             at /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/event_loop.rs:278:9
  11: hello_triangle::run::{{closure}}
             at ./wgpu/examples/hello-triangle/main.rs:85:5
  12: pollster::block_on
             at /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/pollster-0.2.5/src/lib.rs:125:15
  13: hello_triangle::main
             at ./wgpu/examples/hello-triangle/main.rs:149:9
  14: core::ops::function::FnOnce::call_once
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Platform Information about your OS, version of wgpu, your tech stack, etc.

I am using webgpu 0.15.0, I have just cloned the repo.

My uname -r -a output is: Linux pop-os 6.1.11-76060111-generic #202302091138~1675975749~22.04~f771a7f SMP PREEMPT_DYNAMIC Thu F x86_64 x86_64 x86_64 GNU/Linux

The output of sudo lshw -c video is:

  *-display                 
       description: VGA compatible controller
       product: TU106M [GeForce RTX 2060 Max-Q]
       vendor: NVIDIA Corporation
       physical id: 0
       bus info: pci@0000:01:00.0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
       configuration: driver=nvidia latency=0
       resources: irq:102 memory:fb000000-fbffffff memory:b0000000-bfffffff memory:c0000000-c1ffffff ioport:f000(size=128) memory:fc000000-fc07ffff
  *-display
       description: VGA compatible controller
       product: Renoir
       vendor: Advanced Micro Devices, Inc. [AMD/ATI]
       physical id: 0
       bus info: pci@0000:04:00.0
       logical name: /dev/fb0
       version: c6
       width: 64 bits
       clock: 33MHz
       capabilities: pm pciexpress msi msix vga_controller bus_master cap_list fb
       configuration: depth=32 driver=amdgpu latency=0 resolution=1920,1080
       resources: irq:47 memory:d0000000-dfffffff memory:e0000000-e01fffff ioport:e000(size=256) memory:fc500000-fc57ffff

I have already reported the issue to the winit developers, but it looks like it's not a winit problem https://github.com/rust-windowing/winit/issues/2716.

edap commented 1 year ago

Some additional infos. On my laptop, I have also an integrated AMD renoir graphics card. If I switch to that graphics card and I restart the laptop, the example simple-triangle is working. Also, I can run the glutin example (https://github.com/rust-windowing/glutin/ (cargo run --example window)) with both graphics cards, the nvidia and the integrated AMD.

teoxoy commented 1 year ago

Thanks for the report! I have a few follow-up questions that should help debug this further:

edap commented 1 year ago

Hello, thanks for your reply. On pop_os, it is possible to select the graphics card from the battery menu. image. When I select "integrated graphics", the example works. The example does not work ONLY when I select "Nvidia Graphics" and I restart, as I did to test your suggestions.

Device 0: Name: NVIDIA GeForce RTX 2060 with Max-Q Design Vendor: NVIDIA
Device 1: Name: UNKNOWN Vendor: UNKNOWN
Device 2: Name: UNKNOWN Vendor: UNKNOWN
Device 3: Name: UNKNOWN Vendor: UNKNOWN
Picked a config with 8 samples
Running on NVIDIA GeForce RTX 2060 with Max-Q Design/PCIe/SSE2
OpenGL Version 3.3.0 NVIDIA 525.85.05
Shaders version on 3.30 NVIDIA via Cg compiler
Output rendered to: /home/dapx/Sources/rust/glutin/target/debug/build/glutin_examples-c47eefafb2352396/out/egl_device.png
Finished dev [unoptimized + debuginfo] target(s) in 0.20s
Running `target/debug/examples/hello-triangle`
[2023-03-07T10:59:11Z INFO  wgpu_hal::vulkan::instance] Unable to find extension: VK_EXT_swapchain_colorspace
[2023-03-07T10:59:11Z INFO  wgpu_hal::vulkan::instance] Instance version: 0x4030cc
[2023-03-07T10:59:11Z INFO  wgpu_hal::vulkan::instance] Enabling debug utils
[2023-03-07T10:59:11Z INFO  wgpu_hal::vulkan::instance] Enabling device properties2
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl] Using X11 platform
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl]    EGL surface: +srgb
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl]    Trying native-render
[2023-03-07T10:59:11Z WARN  wgpu_hal::gles::egl] No config found!
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl]    Trying presentation
[2023-03-07T10:59:11Z WARN  wgpu_hal::gles::egl] EGL says it can present to the window but not natively
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl]    EGL context: +debug
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl]    EGL context: +robust access
[2023-03-07T10:59:11Z INFO  wgpu_hal::gles::egl]    EGL context: +surfaceless
[2023-03-07T10:59:12Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2023-03-07T10:59:12Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2023-03-07T10:59:12Z INFO  wgpu_hal::gles::adapter] Vendor: NVIDIA Corporation
[2023-03-07T10:59:12Z INFO  wgpu_hal::gles::adapter] Renderer: NVIDIA GeForce RTX 2060 with Max-Q Design/PCIe/SSE2
[2023-03-07T10:59:12Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 NVIDIA 525.85.05
[2023-03-07T10:59:12Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2023-03-07T10:59:12Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "AMD Unknown (RADV RENOIR)", vendor: 4098, device: 5686, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 22.3.4", backend: Vulkan }
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_khronos_validation.so
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x557b93b17bb0, name: ?)
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Inserted device layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so)
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x557b93b17bb0, name: ?)
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_MESA_device_select.so
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x557b93b17bb0, name: ?)
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Failed to find vkGetDeviceProcAddr in layer libVkLayer_MESA_device_select.so
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x557b93b17bb0, name: ?)
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance] VALIDATION [UNASSIGNED-cache-file-error (0xf0bb3995)]
        Validation Information: [ UNASSIGNED-cache-file-error ] Object 0: handle = 0x557b9483ab10, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xf0bb3995 | Cannot open shader validation cache at //tmp//shader_validation_cache-1000.bin for reading (it may not exist yet)
[2023-03-07T10:59:12Z INFO  wgpu_hal::vulkan::instance]     objects: (type: DEVICE, hndl: 0x557b9483ab10, name: ?)
[2023-03-07T10:59:12Z INFO  wgpu_core::device] Created render pipeline Valid((0, 1, Vulkan)) with RenderPipelineDescriptor { label: None, layout: Some((0, 1, Vulkan)), vertex: VertexState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "vs_main" }, buffers: [] }, primitive: PrimitiveState { topology: TriangleList, strip_index_format: None, front_face: Ccw, cull_mode: None, unclipped_depth: false, polygon_mode: Fill, conservative: false }, depth_stencil: None, multisample: MultisampleState { count: 1, mask: 18446744073709551615, alpha_to_coverage_enabled: false }, fragment: Some(FragmentState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "fs_main" }, targets: [Some(ColorTargetState { format: Bgra8UnormSrgb, blend: None, write_mask: RED | GREEN | BLUE | ALPHA | COLOR | ALL })] }), multiview: None }
[2023-03-07T10:59:12Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-03-07T10:59:12Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-03-07T10:59:12Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-03-07T10:59:12Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-03-07T10:59:12Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-03-07T10:59:12Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }

thread 'main' panicked at 'Failed to focus input context: XError { description: "BadMatch (invalid parameter attributes)", error_code: 8, request_code: 149, minor_code: 4 }', /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/event_processor.rs:912:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2023-03-07T11:02:46Z INFO  wgpu_core::hub] Dropping Global
[2023-03-07T11:02:46Z INFO  wgpu_core::device] Destroying 0 command encoders
teoxoy commented 1 year ago

Thanks for the details!

It's worth noting that you are now getting a different error "BadMatch (invalid parameter attributes)" instead of the original "BadDrawable (invalid Pixmap or Window parameter)". Did you change anything?

It seems we are trying to use the iGPU (and the dGPU is not available?). Even though you selected "NVIDIA Graphics", the iGPU might still get exposed since it's still needed to copy the frames from the dGPU since the laptop screen is most likely connected to the iGPU.

Could you try running the example again with WGPU_POWER_PREF=high and RUST_LOG=INFO? Could you try the "Hybrid Graphics" setting in the pop-os menu and try running the example with and without __NV_PRIME_RENDER_OFFLOAD=1 (see this link for details)?

edap commented 1 year ago

I did not notice that the error message has changed in the meantime. I did run an update in my OS, that may be the cause.

This is the output of WGPU_POWER_PREF=high RUST_LOG=INFO cargo run --example hello-triangle

 Finished dev [unoptimized + debuginfo] target(s) in 0.20s
     Running `target/debug/examples/hello-triangle`
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance] Unable to find extension: VK_EXT_swapchain_colorspace
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance] Instance version: 0x4030cc
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance] Enabling debug utils
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance] Enabling device properties2
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl] Using X11 platform
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl]    EGL surface: +srgb
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl]    Trying native-render
[2023-03-08T09:49:55Z WARN  wgpu_hal::gles::egl] No config found!
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl]    Trying presentation
[2023-03-08T09:49:55Z WARN  wgpu_hal::gles::egl] EGL says it can present to the window but not natively
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl]    EGL context: +debug
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl]    EGL context: +robust access
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl]    EGL context: +surfaceless
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::adapter] Vendor: NVIDIA Corporation
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::adapter] Renderer: NVIDIA GeForce RTX 2060 with Max-Q Design/PCIe/SSE2
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 NVIDIA 525.85.05
[2023-03-08T09:49:55Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2023-03-08T09:49:55Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "AMD Unknown (RADV RENOIR)", vendor: 4098, device: 5686, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 22.3.5", backend: Vulkan }
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_khronos_validation.so
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x55c3a91a3a10, name: ?)
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Inserted device layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so)
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x55c3a91a3a10, name: ?)
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_MESA_device_select.so
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x55c3a91a3a10, name: ?)
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Failed to find vkGetDeviceProcAddr in layer libVkLayer_MESA_device_select.so
[2023-03-08T09:49:55Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x55c3a91a3a10, name: ?)
[2023-03-08T09:49:55Z INFO  wgpu_core::device] Created render pipeline Valid((0, 1, Vulkan)) with RenderPipelineDescriptor { label: None, layout: Some((0, 1, Vulkan)), vertex: VertexState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "vs_main" }, buffers: [] }, primitive: PrimitiveState { topology: TriangleList, strip_index_format: None, front_face: Ccw, cull_mode: None, unclipped_depth: false, polygon_mode: Fill, conservative: false }, depth_stencil: None, multisample: MultisampleState { count: 1, mask: 18446744073709551615, alpha_to_coverage_enabled: false }, fragment: Some(FragmentState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "fs_main" }, targets: [Some(ColorTargetState { format: Bgra8UnormSrgb, blend: None, write_mask: RED | GREEN | BLUE | ALPHA | COLOR | ALL })] }), multiview: None }
[2023-03-08T09:49:55Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-03-08T09:49:55Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-03-08T09:49:55Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-03-08T09:49:55Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-03-08T09:49:55Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-03-08T09:49:55Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-03-08T09:49:55Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-03-08T09:49:55Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
thread 'main' panicked at 'Failed to focus input context: XError { description: "BadMatch (invalid parameter attributes)", error_code: 8, request_code: 149, minor_code: 4 }', /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/event_processor.rs:912:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2023-03-08T09:49:55Z INFO  wgpu_core::hub] Dropping Global
[2023-03-08T09:49:55Z INFO  wgpu_core::device] Destroying 0 command encoders

I have then selected "hybrid mode" from the menu' and I have restarted the laptop. This is the output of : __NV_PRIME_RENDER_OFFLOAD=1 WGPU_POWER_PREF=high RUST_LOG=INFO cargo run --example hello-triangle , that shows the triangle.

     Running `target/debug/examples/hello-triangle`
[2023-03-08T09:57:33Z INFO  wgpu_hal::vulkan::instance] Unable to find extension: VK_EXT_swapchain_colorspace
[2023-03-08T09:57:33Z INFO  wgpu_hal::vulkan::instance] Instance version: 0x4030cc
[2023-03-08T09:57:33Z INFO  wgpu_hal::vulkan::instance] Enabling debug utils
[2023-03-08T09:57:33Z INFO  wgpu_hal::vulkan::instance] Enabling device properties2
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl] Using X11 platform
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl]    EGL surface: +srgb
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl]    Trying native-render
[2023-03-08T09:57:33Z WARN  wgpu_hal::gles::egl] No config found!
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl]    Trying presentation
[2023-03-08T09:57:33Z WARN  wgpu_hal::gles::egl] EGL says it can present to the window but not natively
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl]    EGL context: +debug
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl]    EGL context: +robust access
[2023-03-08T09:57:33Z INFO  wgpu_hal::gles::egl]    EGL context: +surfaceless
[2023-03-08T09:57:34Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2023-03-08T09:57:34Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2023-03-08T09:57:34Z INFO  wgpu_hal::gles::adapter] Vendor: NVIDIA Corporation
[2023-03-08T09:57:34Z INFO  wgpu_hal::gles::adapter] Renderer: NVIDIA GeForce RTX 2060 with Max-Q Design/PCIe/SSE2
[2023-03-08T09:57:34Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 NVIDIA 525.85.05
[2023-03-08T09:57:34Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2023-03-08T09:57:34Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "AMD Unknown (RADV RENOIR)", vendor: 4098, device: 5686, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 22.3.5", backend: Vulkan }
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_khronos_validation.so
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Inserted device layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_MESA_device_select.so
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Failed to find vkGetDeviceProcAddr in layer libVkLayer_MESA_device_select.so
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libGLX_nvidia.so.0
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Inserted device layer VK_LAYER_NV_optimus (libGLX_nvidia.so.0)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance] VALIDATION [UNASSIGNED-cache-file-error (0xf0bb3995)]
        Validation Information: [ UNASSIGNED-cache-file-error ] Object 0: handle = 0x564072f65a70, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xf0bb3995 | Cannot open shader validation cache at //tmp//shader_validation_cache-1000.bin for reading (it may not exist yet)
[2023-03-08T09:57:34Z INFO  wgpu_hal::vulkan::instance]     objects: (type: DEVICE, hndl: 0x564072f65a70, name: ?)
[2023-03-08T09:57:34Z INFO  wgpu_core::device] Created render pipeline Valid((0, 1, Vulkan)) with RenderPipelineDescriptor { label: None, layout: Some((0, 1, Vulkan)), vertex: VertexState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "vs_main" }, buffers: [] }, primitive: PrimitiveState { topology: TriangleList, strip_index_format: None, front_face: Ccw, cull_mode: None, unclipped_depth: false, polygon_mode: Fill, conservative: false }, depth_stencil: None, multisample: MultisampleState { count: 1, mask: 18446744073709551615, alpha_to_coverage_enabled: false }, fragment: Some(FragmentState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "fs_main" }, targets: [Some(ColorTargetState { format: Bgra8UnormSrgb, blend: None, write_mask: RED | GREEN | BLUE | ALPHA | COLOR | ALL })] }), multiview: None }
[2023-03-08T09:57:34Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-03-08T09:57:34Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-03-08T09:57:50Z INFO  wgpu_core::hub] Dropping Global
[2023-03-08T09:57:50Z INFO  wgpu_core::device] Destroying 1 command encoders
[2023-03-08T09:57:50Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Unloading layer library libGLX_nvidia.so.0
[2023-03-08T09:57:50Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)
[2023-03-08T09:57:50Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Unloading layer library libVkLayer_MESA_device_select.so
[2023-03-08T09:57:50Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)
[2023-03-08T09:57:50Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Unloading layer library libVkLayer_khronos_validation.so
[2023-03-08T09:57:50Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x564072573e80, name: ?)

This is the output of WGPU_POWER_PREF=high RUST_LOG=INFO cargo run --example hello-triangle, that also shows the triangle:

    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/examples/hello-triangle`
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance] Unable to find extension: VK_EXT_swapchain_colorspace
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance] Instance version: 0x4030cc
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance] Enabling debug utils
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance] Enabling device properties2
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl] Using X11 platform
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl] Display vendor "Mesa Project", version (1, 5)
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl]    EGL surface: +srgb
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl]    Trying native-render
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl]    EGL context: +debug
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl]    EGL context: +robust access EXT
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl]    EGL context: +surfaceless
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::adapter] Vendor: AMD
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::adapter] Renderer: RENOIR (renoir, LLVM 15.0.6, DRM 3.49, 6.2.0-76060200-generic)
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 Mesa 22.3.5
[2023-03-08T10:01:18Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2023-03-08T10:01:18Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "AMD Unknown (RADV RENOIR)", vendor: 4098, device: 5686, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 22.3.5", backend: Vulkan }
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_khronos_validation.so
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x5638a79bd3b0, name: ?)
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Inserted device layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so)
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x5638a79bd3b0, name: ?)
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_MESA_device_select.so
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x5638a79bd3b0, name: ?)
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Failed to find vkGetDeviceProcAddr in layer libVkLayer_MESA_device_select.so
[2023-03-08T10:01:18Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x5638a79bd3b0, name: ?)
[2023-03-08T10:01:18Z INFO  wgpu_core::device] Created render pipeline Valid((0, 1, Vulkan)) with RenderPipelineDescriptor { label: None, layout: Some((0, 1, Vulkan)), vertex: VertexState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "vs_main" }, buffers: [] }, primitive: PrimitiveState { topology: TriangleList, strip_index_format: None, front_face: Ccw, cull_mode: None, unclipped_depth: false, polygon_mode: Fill, conservative: false }, depth_stencil: None, multisample: MultisampleState { count: 1, mask: 18446744073709551615, alpha_to_coverage_enabled: false }, fragment: Some(FragmentState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "fs_main" }, targets: [Some(ColorTargetState { format: Bgra8UnormSrgb, blend: None, write_mask: RED | GREEN | BLUE | ALPHA | COLOR | ALL })] }), multiview: None }
[2023-03-08T10:01:18Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-03-08T10:01:18Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-03-08T10:01:21Z INFO  wgpu_core::hub] Dropping Global
[2023-03-08T10:01:21Z INFO  wgpu_core::device] Destroying 1 command encoders
[2023-03-08T10:01:21Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Unloading layer library libVkLayer_MESA_device_select.so
[2023-03-08T10:01:21Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x5638a79bd3b0, name: ?)
[2023-03-08T10:01:21Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Unloading layer library libVkLayer_khronos_validation.so
[2023-03-08T10:01:21Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x5638a79bd3b0, name: ?)

Thanks for your time, let me know if there is something else I can do to help you debugging this issue.

teoxoy commented 1 year ago

Considering this works if you set it to "Hybrid Graphics", I think this might be an issue with the pop-os configuration; I don't think you should be able to select the "Nvidia Graphics" since your laptop's screen is connected to the iGPU which is needed for presentation.

I'm not sure how/why vkcube works though. Could you post the output of wgpu-info for all 3 graphics settings (integrated/nvidia/hybrid)? I wonder which devices/drivers pop-os is exposing.

edap commented 1 year ago

Yes it might be an issue with pop-os, but this would not explain why the glutin example and the vkcube example pick the correct graphics card.

Here the 3 outputs: hybrid.txt integrated.txt nvidia.txt

teoxoy commented 1 year ago

Looks like the Vulkan adapters exposed are the same for the hybrid and nvidia settings.

I'm out of ideas for now. @cwfitzgerald do you know what might be going on?

edap commented 1 year ago

@teoxoy maybe it makes sense to change the title from BadDrawable to BadMatch? just inc ase other users have the same problem.

ibaryshnikov commented 1 year ago

I ran into the same BadMatch error. Seems related to https://github.com/rust-windowing/winit/issues/748 Setting the driver explicitly did work for me, as described in https://github.com/rust-windowing/winit/issues/748#issuecomment-830817035 My system runs nvidia with optimus-manager

LukasKalbertodt commented 1 year ago

Just to add another data point: I am running into the same issue. I have a CPU with integrated GPU and a dedicated GPU. The desktop is running on the dedicated one, but wgpu chose the integrated GPU, which is the cause of the problem. For me the error happens when calling winit::Window::inner_size, actually. It eventually calls winit::platform_impl::platform::x11::window::UnownedWindow::inner_size_physical which then incorrectly calls unwrap.

I'm using wgpu::PowerPreference::default() which defaults to the low power GPU. Even with WGPU_POWER_PREF=high, the integrated GPU was chosen. With wgpu::PowerPreference::HighPerformance, the dedicated one was chosen and everything works.

In my RequestAdapterOptions I'm also of course specifying compatible_surface. So my guess is that the "adapter choosing" code does not correctly check compatible_surface because the integrated GPU should be incompatible with the surface I passed.

ChristopherRabotin commented 1 year ago

Hi there,

Has there been an update on this? My desktop has both an Nvidia card and an integrated graphics (Intel), but I only use the former. When running the cube example, it seems that wgpu uses the Intel integrated graphics instead of nvidia, and then fails.

[2023-09-26T22:02:47Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadDrawable (invalid Pixmap or Window parameter)",
        error_code: 9,
        request_code: 149,
        minor_code: 4,
    }

The error above is repeated endlessly.

cwfitzgerald commented 1 year ago

The compatible surface checks do seem to be wired up correctly in request_adapter all the way down to the vulkan backend, not sure why it's not returning that it's incompatible if it is truly incompatible.

edap commented 1 year ago

At the moment this is a big problem for everyone on linux with a dedicated card and integrated card. I do not know if this can be of any help, but following @ibaryshnikov advice I have specified the power prefecences and it works, here a short summary:

[2023-10-05T07:07:10Z INFO  winit::platform_impl::platform::x11::window] Guessed window scale factor: 1
[2023-10-05T07:07:14Z INFO  wgpu_hal::vulkan::instance] Instance version: 0x4030cc
[2023-10-05T07:07:14Z INFO  wgpu_hal::vulkan::instance] Enabling debug utils
[2023-10-05T07:07:14Z INFO  wgpu_hal::vulkan::instance] Enabling device properties2
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl] Using X11 platform
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl] Display vendor "Mesa Project", version (1, 5)
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl]    EGL surface: +srgb
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl]    Trying native-render
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl]    EGL context: +debug
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl]    EGL context: +robust access EXT
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl]    EGL context: +surfaceless
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::adapter] Vendor: AMD
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::adapter] Renderer: RENOIR (renoir, LLVM 15.0.7, DRM 3.52, 6.4.6-76060406-generic)
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 Mesa 23.1.3-1pop0~1689084530~22.04~0618746
[2023-10-05T07:07:14Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2023-10-05T07:07:14Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "AMD Unknown (RADV RENOIR)", vendor: 4098, device: 5686, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 23.1.3-1pop0~1689084530~22.04~0618746", backend: Vulkan }

it works.

Now, If I select from the OS menu the Nvidia Graphics Card and I do restart the laptop, and I try the same example with WGPU_POWER_PREF=high RUST_LOG=INFO cargo run --example hello-triangle, it crashes.

[2023-10-05T07:18:59Z INFO  winit::platform_impl::platform::x11::window] Guessed window scale factor: 1
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance] Instance version: 0x4030cc
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance] Enabling debug utils
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance] Enabling device properties2
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl] Using X11 platform
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl]    EGL surface: +srgb
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl]    Trying native-render
[2023-10-05T07:18:59Z WARN  wgpu_hal::gles::egl] No config found!
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl]    Trying presentation
[2023-10-05T07:18:59Z WARN  wgpu_hal::gles::egl] EGL says it can present to the window but not natively
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl]    EGL context: +debug
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl]    EGL context: +robust access
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl]    EGL context: +surfaceless
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::adapter] Vendor: NVIDIA Corporation
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::adapter] Renderer: NVIDIA GeForce RTX 2060 with Max-Q Design/PCIe/SSE2
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 NVIDIA 535.104.05
[2023-10-05T07:18:59Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2023-10-05T07:18:59Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "AMD Unknown (RADV RENOIR)", vendor: 4098, device: 5686, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 23.1.3-1pop0~1689084530~22.04~0618746", backend: Vulkan }
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_khronos_validation.so
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x55aa35be23d0, name: ?)
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Inserted device layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so)
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x55aa35be23d0, name: ?)
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Loading layer library libVkLayer_MESA_device_select.so
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x55aa35be23d0, name: ?)
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
        Failed to find vkGetDeviceProcAddr in layer libVkLayer_MESA_device_select.so
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance]     objects: (type: INSTANCE, hndl: 0x55aa35be23d0, name: ?)
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance] VALIDATION [UNASSIGNED-cache-file-error (0xf0bb3995)]
        Validation Information: [ UNASSIGNED-cache-file-error ] Object 0: handle = 0x55aa36907cd0, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xf0bb3995 | Cannot open shader validation cache at //tmp//shader_validation_cache-1000.bin for reading (it may not exist yet)
[2023-10-05T07:18:59Z INFO  wgpu_hal::vulkan::instance]     objects: (type: DEVICE, hndl: 0x55aa36907cd0, name: ?)
[2023-10-05T07:18:59Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Auto, view_formats: [] }
[2023-10-05T07:18:59Z INFO  wgpu_core::device] Automatically choosing alpha mode by rule Auto. Chose Opaque
[2023-10-05T07:18:59Z INFO  wgpu_core::device] Created render pipeline Valid((0, 1, Vulkan)) with RenderPipelineDescriptor { label: Some("Render Pipeline"), layout: Some((0, 1, Vulkan)), vertex: VertexState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "vs_main" }, buffers: [VertexBufferLayout { array_stride: 24, step_mode: Vertex, attributes: [VertexAttribute { format: Float32x3, offset: 0, shader_location: 0 }, VertexAttribute { format: Float32x3, offset: 12, shader_location: 1 }] }] }, primitive: PrimitiveState { topology: TriangleList, strip_index_format: None, front_face: Ccw, cull_mode: Some(Back), unclipped_depth: false, polygon_mode: Fill, conservative: false }, depth_stencil: None, multisample: MultisampleState { count: 1, mask: 18446744073709551615, alpha_to_coverage_enabled: false }, fragment: Some(FragmentState { stage: ProgrammableStageDescriptor { module: (0, 1, Vulkan), entry_point: "fs_main" }, targets: [Some(ColorTargetState { format: Bgra8UnormSrgb, blend: Some(BlendState { color: BlendComponent { src_factor: One, dst_factor: Zero, operation: Add }, alpha: BlendComponent { src_factor: One, dst_factor: Zero, operation: Add } }), write_mask: RED | GREEN | BLUE | ALPHA | COLOR | ALL })] }), multiview: None }
[2023-10-05T07:18:59Z INFO  wgpu_core::device] Created buffer Valid((0, 1, Vulkan)) with BufferDescriptor { label: Some("Vertex Buffer"), size: 72, usage: VERTEX, mapped_at_creation: true }
[2023-10-05T07:18:59Z INFO  wgpu_core::device] Created buffer Valid((1, 1, Vulkan)) with BufferDescriptor { label: Some("Index Buffer"), size: 8, usage: INDEX, mapped_at_creation: true }
[2023-10-05T07:18:59Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-10-05T07:18:59Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-10-05T07:18:59Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-10-05T07:18:59Z INFO  wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo, alpha_mode: Auto, view_formats: [] }
[2023-10-05T07:18:59Z INFO  wgpu_core::device] Automatically choosing alpha mode by rule Auto. Chose Opaque
[2023-10-05T07:18:59Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-10-05T07:18:59Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
[2023-10-05T07:18:59Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }
thread 'main' panicked at 'Failed to focus input context: XError { description: "BadMatch (invalid parameter attributes)", error_code: 8, request_code: 149, minor_code: 4 }', /home/dapx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/event_processor.rs:912:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2023-10-05T07:18:59Z INFO  wgpu_core::hub] Dropping Global
[2023-10-05T07:18:59Z INFO  wgpu_core::device] Destroying 0 command encoders

But if when I create the adapter I specify to use the high performance power options power_preference: wgpu::PowerPreference::HighPerformance, , it works.

[2023-10-05T07:22:36Z INFO  winit::platform_impl::platform::x11::window] Guessed window scale factor: 1
[2023-10-05T07:22:36Z INFO  wgpu_hal::vulkan::instance] Instance version: 0x4030cc
[2023-10-05T07:22:36Z INFO  wgpu_hal::vulkan::instance] Enabling debug utils
[2023-10-05T07:22:36Z INFO  wgpu_hal::vulkan::instance] Enabling device properties2
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl] Loading X11 library to get the current display
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl] Using X11 platform
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl] Enabling EGL debug output
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl] Display vendor "NVIDIA", version (1, 5)
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl]    EGL surface: +srgb
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl]    Trying native-render
[2023-10-05T07:22:36Z WARN  wgpu_hal::gles::egl] No config found!
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl]    Trying presentation
[2023-10-05T07:22:36Z WARN  wgpu_hal::gles::egl] EGL says it can present to the window but not natively
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl]    EGL context: +debug
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl]    EGL context: +robust access
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl]    EGL context: +surfaceless
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl] Max label length: 256
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::egl] Enabling GLES debug output
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::adapter] Vendor: NVIDIA Corporation
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::adapter] Renderer: NVIDIA GeForce RTX 2060 with Max-Q Design/PCIe/SSE2
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 NVIDIA 535.104.05
[2023-10-05T07:22:36Z INFO  wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2023-10-05T07:22:36Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "NVIDIA GeForce RTX 2060 with Max-Q Design", vendor: 4318, device: 7954, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "535.104.05", backend: Vulkan }

So, for my understanding, something is wrong with how the option power_preference is handled in the creation of the adapter.

But, out of curiosity, I have tried the triangle example in the ash crate. And with the Nvidia Graphics Card selected in the OS it crashes.

INFO:
GENERAL [Loader Message (0)] : Loading layer library libVkLayer_khronos_validation.so

INFO:
GENERAL [Loader Message (0)] : Inserted device layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so)

INFO:
GENERAL [Loader Message (0)] : Loading layer library libVkLayer_MESA_device_select.so

INFO:
GENERAL [Loader Message (0)] : Failed to find vkGetDeviceProcAddr in layer libVkLayer_MESA_device_select.so

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ERROR_SURFACE_LOST_KHR', examples/src/bin/triangle.rs:436:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
ERROR:
VALIDATION [VUID-vkDestroyDevice-device-00378 (1901072314)] : Validation Error: [ VUID-vkDestroyDevice-device-00378 ] Object 0: handle = 0x55fffe934930, type = VK_OBJECT_TYPE_DEVICE; Object 1: handle = 0x1e000000001e, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x71500fba | OBJ ERROR : For VkDevice 0x55fffe934930[], VkBuffer 0x1e000000001e[] has not been destroyed. The Vulkan spec states: All child objects created on device must have been destroyed prior to destroying device (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkDestroyDevice-device-00378)

But if I switch to the integrated graphics card and restart the laptop, it works.

INFO:
GENERAL [Loader Message (0)] : Loading layer library libVkLayer_khronos_validation.so

INFO:
GENERAL [Loader Message (0)] : Inserted device layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so)

INFO:
GENERAL [Loader Message (0)] : Loading layer library libVkLayer_MESA_device_select.so

INFO:
GENERAL [Loader Message (0)] : Failed to find vkGetDeviceProcAddr in layer libVkLayer_MESA_device_select.so

INFO:
VALIDATION [UNASSIGNED-cache-file-error (-256165483)] : Validation Information: [ UNASSIGNED-cache-file-error ] Object 0: handle = 0x55fd7f7b4830, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xf0bb3995 | Cannot open shader validation cache at //tmp//shader_validation_cache-1000.bin for reading (it may not exist yet)

So, maybe it is an ash bug? could you @ibaryshnikov @ChristopherRabotin @LukasKalbertodt try to run the ash triangle example with your integrated graphics card and with your dedicated graphics card?

Ash is a dependency of wgpu-hal that is a dependency of wgpu

│   ├── wgpu-hal v0.15.1 (/home/dapx/Sources/rust/wgpu/wgpu-hal)
│   │   ├── arrayvec v0.7.2
│   │   ├── ash v0.37.2+1.3.238
LukasKalbertodt commented 1 year ago

Sorry for the late reply. I tested the triangle example of ash, like @edap asked me to. But it worked for me. But keep reading.


I dug a bit deeper. And I think I found the cause(s) of this.

Reminder of my setup: one dedicated GPU (which runs the desktop) and an integrated one. Running wgpu's unmodified hello-triangle example crashes with BadDrawable because the integrated GPU was chosen for some reason (which can't present to the surface).

After some debugging, I found that get_physical_device_surface_support returns Ok(true) for (integrated GPU, surface). But that's clearly wrong as the GPU cannot present to that surface. This is the relevant code:

https://github.com/gfx-rs/wgpu/blob/75989192a9c8f70893882ce0f4373ac217d380c3/wgpu-hal/src/vulkan/adapter.rs#L1567-L1575

You might notice the suspicious // TODO in the first line. And I think that's one of the problems! Support for a given surface is a function of the surface, the adapter AND a queue family. It might be the case that there are queue families without graphics support (just copy queues, for example) that support the surface. What ash does in its examples to find a suitable adapter is this:

https://github.com/ash-rs/ash/blob/d0d5ea1370ff2b3b5a49ed5b6866e1e4bd353de1/examples/src/lib.rs#L292-L316

Iterate over all queue families and take the first one that supports graphics AND the surface. I added some debug output to that code to print some information about my system:

``` # Device: dedicated GPU - queue: 0 QueueFamilyProperties { queue_flags: GRAPHICS | COMPUTE | TRANSFER | SPARSE_BINDING, queue_count: 16, timestamp_valid_bits: 64, min_image_transfer_granularity: Extent3D { width: 1, height: 1, depth: 1 } } supports_graphic: true supports_surface: true - queue: 1 QueueFamilyProperties { queue_flags: TRANSFER | SPARSE_BINDING, queue_count: 2, timestamp_valid_bits: 64, min_image_transfer_granularity: Extent3D { width: 1, height: 1, depth: 1 } } supports_graphic: false supports_surface: false - queue: 2 QueueFamilyProperties { queue_flags: COMPUTE | TRANSFER | SPARSE_BINDING, queue_count: 8, timestamp_valid_bits: 64, min_image_transfer_granularity: Extent3D { width: 1, height: 1, depth: 1 } } supports_graphic: false supports_surface: true - queue: 3 QueueFamilyProperties { queue_flags: TRANSFER | SPARSE_BINDING | VIDEO_DECODE_KHR, queue_count: 1, timestamp_valid_bits: 32, min_image_transfer_granularity: Extent3D { width: 1, height: 1, depth: 1 } } supports_graphic: false supports_surface: false - queue: 4 QueueFamilyProperties { queue_flags: TRANSFER | SPARSE_BINDING | OPTICAL_FLOW_NV, queue_count: 1, timestamp_valid_bits: 64, min_image_transfer_granularity: Extent3D { width: 1, height: 1, depth: 1 } } supports_graphic: false supports_surface: false # Device: integrated GPU - queue: 0 QueueFamilyProperties { queue_flags: GRAPHICS | COMPUTE | TRANSFER | SPARSE_BINDING, queue_count: 1, timestamp_valid_bits: 64, min_image_transfer_granularity: Extent3D { width: 1, height: 1, depth: 1 } } supports_graphic: true supports_surface: true - queue: 1 QueueFamilyProperties { queue_flags: COMPUTE | TRANSFER | SPARSE_BINDING, queue_count: 4, timestamp_valid_bits: 64, min_image_transfer_granularity: Extent3D { width: 1, height: 1, depth: 1 } } supports_graphic: false supports_surface: true ```

The most interesting part here is that the integrated GPU says in both cases that the surface is supported! Uh oh.

In fact, if I insert a single pdevices.reverse() before the ash example code linked above, that example crashes as well! With the same error as @dap. It just worked before because the correct (dedicated GPU) is listed first, by chance.

ash's implementation of get_physical_device_surface_support is very simple though:

https://github.com/ash-rs/ash/blob/d0d5ea1370ff2b3b5a49ed5b6866e1e4bd353de1/ash/src/extensions/khr/surface.rs#L25-L39

It just calls a function pointer! And I assume that's provided by the system? So... is this just a driver or OS bug?


So in summary:

teoxoy commented 1 year ago

Thank you for the detailed investigation!

  • wgpu has the // TODO bug because it does not properly iterate through all queue families. That can lead to false positives and false negatives (compare my queue debug output above).

I think the TODO is actually https://github.com/gfx-rs/wgpu/issues/1066 since we currently only use one (the first) queue.

  • The get_physical_device_surface_support_khr function pointer (called by ash) returns true if asked about my integrated GPU and surface, which is incorrect.

ash is a thin rust wrapper for the Vulkan API. vkGetPhysicalDeviceSurfaceSupportKHR is right here. If it returns true and it shouldn't that's probably the fault of the driver or system.

Can you give us more info about your system? What is the OS? What is the iGPU and it's driver (+ version)?

It would be good to also look online for similar issues.

LukasKalbertodt commented 1 year ago

Can you give us more info about your system? What is the OS? What is the iGPU and it's driver (+ version)?


I'd be curious to know if a buggy vkGetPhysicalDeviceSurfaceSupportKHR is also the root problem for everyone else in this thread experiencing this problem.

Maximkaaa commented 1 year ago

I've been facing the same error output, but the route cause turned out to be different. As others here, I have Intel iGPU and NVidia dGPU, and use High Performance Mode.At some point without any changes to the system or dependencies my project started to fail with the same errors as the others saw:

[2023-10-05T07:18:59Z ERROR winit::platform_impl::platform] X11 error: XError {
        description: "BadMatch (invalid parameter attributes)",
        error_code: 8,
        request_code: 149,
        minor_code: 4,
    }

The cause for this, sure enough, was that iGPU adapter was selected. Now, the difference start with me trying setting wgpu::PowerPreference::HighPerformance. In my case this didn't help though. After some debugging, I found out that Instance::enumrate_adapters() returned only iGPU and CPU in the list, no dGPU to be found.

This gave me hint for solution. Restarting my OS fixed the problem, dGPU is back in the list, and everything works as expected. I have noticed before that sometimes after OS sleep by system becomes slower, so I guess I have found the reason why.

I understand that in my case the issue is not in wgpu, but though I'd write my case here in case anyone else stumbles on a similar case. Although, I wonder, if dGPU is not in the list, shouldn't all systems use iGPU and everything should match?..