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

Gpu not working / being detected #4461

Closed
eduardvercaemer opened this issue Apr 12, 2022 · 21 comments
Closed

Gpu not working / being detected #4461

eduardvercaemer opened this issue Apr 12, 2022 · 21 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Startup A crash that occurs when first attempting to run a Bevy app O-Windows Specific to the Windows desktop operating system S-Blocked This cannot move forward until something else changes S-Duplicate This issue or PR already exists

Comments

@eduardvercaemer
Copy link

Bevy version

0.6.1

Operating system & version

Windows 11

What you did

New rust project

$ cargo new --bin my_game
$ cargo add bevy

add example code

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .run();
}

What you expected to happen

See game window pop up.

What actually happened

Bunch of errors show up, window appears for an instance and crashes.

Additional information

Full output:

2022-04-12T00:33:05.334771Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x1e171fabf00, name: ?)
2022-04-12T00:33:05.335922Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setup_loader_tramp_phys_devs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.       
2022-04-12T00:33:05.336360Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x1e171fabf00, name: ?)
2022-04-12T00:33:06.265140Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 1650 Ti", vendor: 4318, device: 8085, device_type: DiscreteGpu, backend: Dx12 }
2022-04-12T00:33:10.323805Z ERROR present_frames: wgpu_hal::dx12::instance: ID3D12CommandQueue::Present: Resource state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE) (promoted from COMMON state) of resource (0x000001E17BDCAD80:'Unnamed ID3D12Resource Object') (subresource: 0) must be in COMMON state when transitioning to use in a different Command List type, because resource state on previous Command List type : D3D12_COMMAND_LIST_TYPE_COPY, is actually incompatible and different from that on the next Command List type : D3D12_COMMAND_LIST_TYPE_DIRECT. [ RESOURCE_MANIPULATION ERROR #990: RESOURCE_BARRIER_MISMATCHING_COMMAND_LIST_TYPE]

This is after installing latest drivers.

I then also tried a suggestion from another issue #3645

use bevy::prelude::*;
use bevy::render::options::{Backends, WgpuOptions};

fn main() {
    App::new()
        .insert_resource(WgpuOptions {
            backends: Some(Backends::VULKAN),
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .run();
}

which has similar effects

full output:

2022-04-12T00:37:24.382750Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setup_loader_tramp_phys_devs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.    
2022-04-12T00:37:24.383295Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x21c5d6f82e0, name: ?)    
2022-04-12T00:37:24.384123Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setup_loader_tramp_phys_devs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.    
2022-04-12T00:37:24.384396Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x21c5d6f82e0, name: ?)    
thread 'main' panicked at 'Unable to find a GPU! Make sure you have installed required drivers!', C:\Users\verca\.cargo\registry\src\github.com-1ecc6299db9ec823\bevy_render-0.6.1\src\renderer\mod.rs:74:10
@eduardvercaemer eduardvercaemer added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 12, 2022
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen O-Windows Specific to the Windows desktop operating system C-Startup A crash that occurs when first attempting to run a Bevy app and removed S-Needs-Triage This issue needs to be labelled labels Apr 12, 2022
@alice-i-cecile
Copy link
Member

alice-i-cecile commented Apr 12, 2022

What GPU are you using? :) Do the wgpu examples work for you? Are your drivers up to date?

@serendipity-crypto
Copy link

Oh, I met the same bug. And this bug only occurs in debug model, the program can run successfully in release model. Besides, I tried the examples in wpgu, they works normally.

Full Output

2022-04-12T12:41:17.419909Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setupLoaderTrampPhysDevs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.    
2022-04-12T12:41:17.420298Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x24341e20060, name: ?)    
2022-04-12T12:41:17.421123Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setupLoaderTrampPhysDevs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.    
2022-04-12T12:41:17.421424Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x24341e20060, name: ?)    
2022-04-12T12:41:17.652865Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 2060", vendor: 4318, device: 7957, device_type: DiscreteGpu, backend: Dx12 }
2022-04-12T12:41:26.936714Z ERROR present_frames: wgpu_hal::dx12::instance: ID3D12CommandQueue::Present: Resource state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE) (promoted from COMMON state) of resource (0x000002434C9AEF60:'Unnamed ID3D12Resource Object') (subresource: 0) must be in COMMON state when transitioning to use in a different Command List type, because resource state on previous Command List type : D3D12_COMMAND_LIST_TYPE_COPY, is actually incompatible and different from that on the next Command List type : D3D12_COMMAND_LIST_TYPE_DIRECT. [ RESOURCE_MANIPULATION ERROR #990: RESOURCE_BARRIER_MISMATCHING_COMMAND_LIST_TYPE]

@eduardvercaemer
Copy link
Author

eduardvercaemer commented Apr 12, 2022

Drivers up to date :)

The wgpu examples work successfully:

  • on WGPU_POWER_PREF=low, the integrated card is used correctly
[2022-04-12T16:00:41Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "AMD Radeon(TM) Graphics", vendor: 4098, device: 5686, device_type: IntegratedGpu, backend: Vulkan }
  • on WGPU_POWER_PREF=high, the discrete card (nvidia gtx 1650 ti) is used correctly
[2022-04-12T16:02:57Z INFO  wgpu_core::instance] Adapter Dx12 AdapterInfo { name: "NVIDIA GeForce GTX 1650 Ti", vendor: 4318, device: 8085, device_type: DiscreteGpu, backend: Dx12 }
Using NVIDIA GeForce GTX 1650 Ti (Dx12)

But I notice when using the DX12 backend the following messages

[2022-04-12T16:02:58Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::Present: Resource state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE) (promoted from COMMON state) of resource (0x000002268C9885B0:'Unnamed ID3D12Resource Object') (subresource: 0) must be in COMMON state when transitioning to use in a different Command List type, because resource state on previous Command List type : D3D12_COMMAND_LIST_TYPE_COPY, is actually incompatible and different from that on the next Command List type : D3D12_COMMAND_LIST_TYPE_DIRECT. [ RESOURCE_MANIPULATION ERROR #990: RESOURCE_BARRIER_MISMATCHING_COMMAND_LIST_TYPE]

it is a similar error message to the one I get on bevy examples, but somehow it is handled differently and the program does not exit.

And sure enough, all examples run smoothly on the nvidia card on release mode. I imagine this is because of some debug_assertion used to exit on those errors.

I wonder if there are some options that bevy passes to wgpu that make it exit on that error in contrast with the wgpu examples,.

@tim-blackbird
Copy link
Contributor

tim-blackbird commented Apr 12, 2022

Yeah, Bevy currently captures all errors from wgpu and considers them fatal.

@eduardvercaemer
Copy link
Author

Update: I found the solution !

Context: This is a bug in dx12, the bug suppression was added in wgpu, that is why the wgpu examples run correctly, but it hasn't been released yet, so bevy which still uses 0.12.0 wgpu fails.

Solution: Patch wgpu to use the latest branch instead of version 0.12.0

$ git clone https://github.com/gfx-rs/wgpu
[patch.crates-io]
wgpu = { path = "../wgpu/wgpu" }

This should be enough to fix the issue ! Hope this helps someone else (:

@eduardvercaemer
Copy link
Author

Huh, I may have celebrated a little to early, while yes this solves the issue of this thread, it is unfortunately breaks some other things, such as shader compilation and some texture creations
e.g.

2022-04-12T18:27:22.354515Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default    
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_texture
      note: label = `point_light_shadow_map_texture`
    Texture usages TEXTURE_BINDING are not allowed on a texture of type Depth32Float
2022-04-12T18:15:20.542442Z ERROR bevy_render::render_resource::pipeline_cache: failed to create shader module: Validation Error

Caused by:
    In Device::create_shader_module

Shader '' parsing error: expected ',', found ';'
  ┌─ wgsl:2:27
  │
2 │     view_proj: mat4x4<f32>;
  │                           ^ expected ','


    expected ',', found ';'

I'm not sure how easy it would be to attempt to patch only the affected dx12 module of wgpu, but if that doesn't work I don't think there is anything else I can try.

I'm gonna reopen because it's not really a solution yet.

@DJMcNab DJMcNab added the S-Blocked This cannot move forward until something else changes label Apr 12, 2022
@rparrett
Copy link
Contributor

Do you have a link to the wgpu issue? They have been very receptive about patch releases for bugs affecting bevy in the past.

@eduardvercaemer
Copy link
Author

I haven't made an issue there and am not sure if there is one already.

I wanted to first find the exact commit that introduces the fix so that way is easier to create a patch.

I will link once I create the issue

@eduardvercaemer
Copy link
Author

wgpu issue: gfx-rs/wgpu#2592

@eduardvercaemer
Copy link
Author

So far this is what I have gotten to work:

$ git clone -b v0.12 [email protected]:gfx-rs/wgpu wgpu-0.12.1
$ cd wgpu-0.12.1
$ git cherry-pick 4d7f6eb07afb93e16ab6a0906c66e673b84924b7 --strategy-option=theirs
$ cd ..
$ cargo new --bin my-game
$ cd my-game
$ cargo add bevy
$ cat << EOF >> Cargo.toml

[patch.crates-io]
wgpu = { path = "../wgpu-0.12.1/wgpu" }

EOF

That commit should be enough to fix the issue, at least partially. This is probably best we can do until wgpu releases a fix.

@serendipity-crypto
Copy link

@eduardvercaemer Could your program run with NVIDIA GeForce GTX 1650 Ti and vulkan backend?

@eduardvercaemer
Copy link
Author

RUST_LOG = "error,wgpu_core::instance=info"
WGPU_POWER_PREF = "high"
WGPU_BACKEND = "VULKAN"

On latest commit of wgpu I can use vulkan as a backend (just like with DX12).

But on wgpu 0.12 it doesn't detect the card, so neither wgpu examples or bevy work:

2022-04-14T04:40:57.710123Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setup_loader_tramp_phys_devs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.
2022-04-14T04:40:57.710857Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x194a5be8e50, name: ?)
2022-04-14T04:40:57.712283Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setup_loader_tramp_phys_devs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.
2022-04-14T04:40:57.712675Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x194a5be8e50, name: ?)
thread 'main' panicked at 'Unable to find a GPU! Make sure you have installed required drivers!', crates\bevy_render\src\renderer\mod.rs:95:10

I guess this is a separate but similar issue, I could probably bisect the point where vulkan works with wgpu to get a similar workaround to the DX12 issue.

@serendipity-crypto
Copy link

I wonder if you add the environment variable with std::env::set_var("DISABLE_LAYER_AMD_SWITCHABLE_GRAPHICS_1", "1"); in fn main(), will it run successfully?

@alice-i-cecile
Copy link
Member

Probably not worth your time; this should get fixed when wgpu and then bevy do a release.

@eduardvercaemer
Copy link
Author

I'm happy enough with the patched wgpu, so yeah, at this point is just waiting for wgpu to patch, someone mentioned in the issue over there that might happen.

@eduardvercaemer
Copy link
Author

So I just went ahead and found the patch for the vulkan issue as well, same procedure as solution for DX12, but patch using gfx-rs/wgpu@d45e6b4

👍🏼

@Stargateur
Copy link

Stargateur commented Apr 18, 2022

Update: I found the solution !

Context: This is a bug in dx12, the bug suppression was added in wgpu, that is why the wgpu examples run correctly, but it hasn't been released yet, so bevy which still uses 0.12.0 wgpu fails.

Solution: Patch wgpu to use the latest branch instead of version 0.12.0

$ git clone https://github.com/gfx-rs/wgpu
[patch.crates-io]
wgpu = { path = "../wgpu/wgpu" }

This should be enough to fix the issue ! Hope this helps someone else (:

[patch.crates-io]
wgpu = { git = "https://github.com/gfx-rs/wgpu" }

# or

wgpu = { git = "https://github.com/gfx-rs/wgpu" , rev = "3d10678a91b78557b0dea537407eb4a4ff754872" }

is simpler.

@james7132
Copy link
Member

Looks like this was resolved when we updated wgpu to 0.13. Closing.

@Mart-Bogdan
Copy link

Please re open.

I have same error on Windows 10

I've tried couple games from steam. Ones that are using winowed mode crashes.

Tryed building from source one small project (that runs on Mac for it's author) and it crashes on windows 10 for me:

Unable to find a GPU! Make sure you have installed required drivers!
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:647
   1: core::panicking::panic_fmt
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\panicking.rs:72
   2: core::panicking::panic_display
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\panicking.rs:196
   3: core::panicking::panic_str
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\panicking.rs:171
   4: core::option::expect_failed
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\option.rs:1988
   5: futures_lite::future::block_on
   6: <bevy_render::RenderPlugin as bevy_app::plugin::Plugin>::build
   7: bevy_app::app::App::add_boxed_plugin
   8: bevy_app::plugin_group::PluginGroupBuilder::finish
   9: bevy_ecs::system::system::System::type_id

Vulkan worked for me inside Unreal Editor from Unreal engine.

I have two GPU. AMD (integrated) and nvida RTX3070 mobile.

Or do I need Vulkan SDK or smth?

@Mart-Bogdan
Copy link

Setting this environment variable resolved the issue:

DISABLE_LAYER_AMD_SWITCHABLE_GRAPHICS_1=1

But that's not good.

@Mart-Bogdan
Copy link

@alice-i-cecile looks like there already exists issue #12739 that was already opened

@alice-i-cecile alice-i-cecile closed this as not planned Won't fix, can't repro, duplicate, stale Apr 20, 2024
@alice-i-cecile alice-i-cecile added the S-Duplicate This issue or PR already exists label Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Startup A crash that occurs when first attempting to run a Bevy app O-Windows Specific to the Windows desktop operating system S-Blocked This cannot move forward until something else changes S-Duplicate This issue or PR already exists
Projects
None yet
Development

No branches or pull requests

9 participants