gfx-rs / wgpu-native

Native WebGPU implementation based on wgpu-core
Apache License 2.0
857 stars 100 forks source link

CRASH in wgpuInstanceRequestAdapter, D3D12 backend, Razer Blade Intel Graphics #370

Open garettbass opened 7 months ago

garettbass commented 7 months ago

I have reproduced this crash using v0.18.1.4 and an older version for which I only have the commit SHA 22eaa9caeb4e856cb926ca54eefa9f783fc4c524. The crash occurs when I call wgpuInstanceRequestAdapter() with the following options:

WGPURequestAdapterOptions opts {
    .powerPreference = WGPUPowerPreference_HighPerformance,
};

On this Razer Blade, I would expect .powerPreference = WGPUPowerPreference_HighPerformance to select the NVIDIA adapter, but the crash appears to be in the function ctlGetSet3DFeature(), which seems to be an Intel Graphics API. If I explicitly select .backendType = WGPUBackendType_Vulkan, there is no crash, and I do get an NVIDIA adapter.

Below is a stack trace of the crash obtained using StackWalk64():

exception: breakpoint
    0 ctlGetSet3DFeature
    1 ctlGetSet3DFeature
    2 ctlGetSet3DFeature
    3 ctlGetSet3DFeature
    4 ctlGetSet3DFeature
    5 ?
    6 ?
    7 ?
    8 ?
    9 ?
   10 D3D12GetInterface
   11 D3D12GetInterface
   12 ?
   13 ?
   14 ?
   15 ?
   16 D3D12GetInterface
   17 D3D12CreateDevice
   18 D3D12CreateDevice
   19 _ZN8wgpu_hal4dx127adapter41_$LT$impl$u20$wgpu_hal..dx12..Adapter$GT$6expose17h63dc652a0cae2d45E
   20 _ZN5alloc3vec16in_place_collect108_$LT$impl$u20$alloc..vec..spec_from_iter..SpecFromIter$LT$T$C$I$GT$$u20$for$u20$alloc..vec..Vec$LT$T$GT$$GT$9from_iter17h42b957e4d40723c1E
   21 _ZN8wgpu_hal4dx128instance100_$LT$impl$u20$wgpu_hal..Instance$LT$wgpu_hal..dx12..Api$GT$$u20$for$u20$wgpu_hal..dx12..Instance$GT$18enumerate_adapters17h3b9085f5c279362fE
   22 _ZN9wgpu_core8instance52_$LT$impl$u20$wgpu_core..global..Global$LT$G$GT$$GT$15request_adapter6gather17h3d0002381ff5cc91E
   23 _ZN9wgpu_core8instance52_$LT$impl$u20$wgpu_core..global..Global$LT$G$GT$$GT$15request_adapter17ha2e1e1d44597edb5E
   24 wgpuInstanceRequestAdapter
   25 `gtb::gpu::wgpu_api::wgpu_api(struct gtb::app::api &)'::`1'::<lambda_2>::operator()(void)const
   26 gtb::gpu::wgpu_api::wgpu_api(struct gtb::app::api &)
   27 main
   28 WinMain
   29 __scrt_common_main_seh
   30 BaseThreadInitThunk
   31 RtlUserThreadStart
garettbass commented 7 months ago

I get the same crash with these options as well:

WGPURequestAdapterOptions opts {
    .powerPreference = WGPUPowerPreference_LowPower,
};
WGPURequestAdapterOptions opts {
    .backendType = WGPUBackendType_D3D12,
};
WGPURequestAdapterOptions opts {
};
rajveermalviya commented 7 months ago

nope, this was related to #337

rajveermalviya commented 7 months ago

@garettbass, is this reproducible reliably with wgpu-native? If so, can you also try the wgpu rust examples?

~> # Install Rust toolchain - https://www.rust-lang.org/learn/get-started
~> git clone https://github.com/gfx-rs/wgpu.git
~> cd wgpu
~> cargo run --bin wgpu-examples hello_triangle
garettbass commented 7 months ago

I am happy to investigate, but there may be a delay before I can undertake this due to other pressing issues. Thank you for the informative recommendation.

frapa commented 4 months ago

I reproduced this issue with

WGPURequestAdapterOptions opts {
    .powerPreference = WGPUPowerPreference_LowPower,
};

Unless you pass WGPUPowerPreference_Undefined, it's gonna crash if you pass this settings. I am calling wgpu_native from C code. My error looks like this:

X Error of failed request:  136
  Major opcode of failed request:  148 ()
  Minor opcode of failed request:  1
  Serial number of failed request:  310
  Current serial number in output stream:  310

Changing this line in the triangle demo causes the demo to crash with exactly the same error, so easy to reproduce for me. I have a discrete Nvidia GPU + an integrated Intel one if that helps.