bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.19k stars 3.57k forks source link

Simplest possible Bevy app causing console to be full of errors. #13428

Closed Astamor closed 5 months ago

Astamor commented 5 months ago

Bevy version

Bevy 0.13.2, 0.13.1, 0.13.0 - tested on those versions.

Relevant system information

Cargo version: 1.76.0 AMD 5 3600 Radeon RX6800 Windows 11 Home

What you did

I just built Bevy and wanted to test if it works so I've added code for the simplest possible app:

use bevy::prelude::*;

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

What went wrong

The console is full of errors from the start:

2024-05-19T11:34:34.457544Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x0000019A307DB1E0:'Internal DXGI CommandList'): Resource state (0x2B0FEBD0: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x0000019A30853A30:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a PRESENT_SOURCE. Expected State Bits (all): 0x2B0FEBB0: D3D12_RESOURCESTATE[COMMON|PRESENT], Actual State: 0x2B0FEB90: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCESTATE[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE] 2024-05-19T11:34:34.462995Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x0000019A309438C0:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x2B0FEBD0: D3D12_RESOURCESTATE[COMMON|PRESENT]) of resource (0x0000019A3084EF00:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target. Expected State Bits (all): 0x2B0FEBB0: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0x2B0FEB90: D3D12_RESOURCESTATE[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE] 2024-05-19T11:34:34.464619Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x0000019A307DB1E0:'Internal DXGI CommandList'): Resource state (0x2B0FEBD0: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x0000019A3084EF00:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a PRESENT_SOURCE. Expected State Bits (all): 0x2B0FEBB0: D3D12_RESOURCESTATE[COMMON|PRESENT], Actual State: 0x2B0FEB90: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCESTATE[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE] 2024-05-19T11:34:34.469943Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x0000019A30860A30:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x2B0FEBD0: D3D12_RESOURCESTATE[COMMON|PRESENT]) of resource (0x0000019A30852120:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target. Expected State Bits (all): 0x2B0FEBB0: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0x2B0FEB90: D3D12_RESOURCESTATE[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE] 2024-05-19T11:34:34.471598Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x0000019A307DB1E0:'Internal DXGI CommandList'): Resource state (0x2B0FEBD0: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x0000019A30852120:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a PRESENT_SOURCE. Expected State Bits (all): 0x2B0FEBB0: D3D12_RESOURCESTATE[COMMON|PRESENT], Actual State: 0x2B0FEB90: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCESTATE[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE] 2024-05-19T11:34:34.476881Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x0000019A308D3D60:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x2B0FEBD0: D3D12_RESOURCESTATE[COMMON|PRESENT]) of resource (0x0000019A30853A30:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target. Expected State Bits (all): 0x2B0FEBB0: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0x2B0FEB90: D3D12_RESOURCESTATE[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE] 2024-05-19T11:34:34.478252Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x0000019A307DB1E0:'Internal DXGI CommandList'): Resource state (0x2B0FEBD0: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x0000019A30853A30:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a PRESENT_SOURCE. Expected State Bits (all): 0x2B0FEBB0: D3D12_RESOURCESTATE[COMMON|PRESENT], Actual State: 0x2B0FEB90: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCESTATE[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]

Additional information

Not sure what to even include here since I didn't even write any code.

alice-i-cecile commented 5 months ago

These are graphic driver problems. Have you updated your graphics driver recently?

Astamor commented 5 months ago

Yes after running Bevy app and seeing all those errors I updated all my drivers.

Astamor commented 5 months ago

Also when trying to launch an app in fullscreen mode with this code:

.add_plugins(DefaultPlugins
        .set(ImagePlugin::default_nearest())
        .set(WindowPlugin {
            primary_window: Some(Window {
                mode: bevy::window::WindowMode::Fullscreen,
                present_mode: bevy::window::PresentMode::AutoVsync,
                title: "ProcGame".into(),
                resolution: WindowResolution::new(WINDOW_WIDTH, WINDOW_HEIGHT).with_scale_factor_override(1.0),
                resizable: true,
                ..default()
            }),
            ..default()
        })
        .build(),
    )

The app crashes and here is console output:

thread 'Compute Task Pool (3)' panicked at C:\Users\Astamor.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.3\src\backend\wgpu_core.rs:724:18: Error in Surface::configure: Validation Error

Caused by: Parent device is lost

note: run with RUST_BACKTRACE=1 environment variable to display a backtrace Encountered a panic in system bevy_render::view::window::create_surfaces! thread 'Compute Task Pool (3)' panicked at C:\Users\Astamor.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_render-0.13.2\src\pipelined_rendering.rs:49:67: called Result::unwrap() on an Err value: RecvError error: process didn't exit successfully: target\debug\bevy-project.exe (exit code: 101)

alice-i-cecile commented 5 months ago

Can you test the examples upstream for winit and wgpu? I suspect that the bugs are ultimately arising there.

Astamor commented 5 months ago

Any specific examples ?

alice-i-cecile commented 5 months ago

hello_triangle for wgpu and window for winit should work. Simplest that can test that things are fundamentally working IMO.

Astamor commented 5 months ago

hello_triangle console output:

[2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)] loader_get_json: Failed to open JSON file C:\Fps monitor\FPS Monitor\tools\fpsmonvk64.json [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] objects: (type: INSTANCE, hndl: 0x18503665130, name: ?) [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)] loader_add_layer_properties: Multiple 'layer' nodes are deprecated starting in file version "1.0.1". Please use 'layers' : [] array instead in C:\ProgramData\GOG.com\Galaxy\redists\overlay\injected\galaxy_overlay_vklayer_x64.json. [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] objects: (type: INSTANCE, hndl: 0x18503665130, name: ?) [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)] loader_get_json: Failed to open JSON file C:\Program Files (x86)\Overwolf\0.218.0.8\ow-vulkan-overlay64.json [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] objects: (type: INSTANCE, hndl: 0x18503665130, name: ?) [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)] loader_get_json: Failed to open JSON file C:\Program Files (x86)\Overwolf\0.218.0.8\ow-graphics-vulkan64.json [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] objects: (type: INSTANCE, hndl: 0x18503665130, name: ?) [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)] loader_get_json: Failed to open JSON file C:\Program Files\Rockstar Games\Social Club\SocialClubVulkanLayer.json [2024-05-19T13:06:27Z ERROR wgpu_hal::vulkan::instance] objects: (type: INSTANCE, hndl: 0x18503665130, name: ?) [2024-05-19T13:06:27Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x00000185113AD3C0:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0xB9354680: D3D12_RESOURCESTATE[COMMON|PRESENT]) of resource (0x00000185113A1EE0:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target. Expected State Bits (all): 0xB9354660: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0xB9354640: D3D12_RESOURCESTATE[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE] [2024-05-19T13:06:27Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x00000185113394F0:'Internal DXGI CommandList'): Resource state (0xB9354210: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x00000185113A1EE0:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a PRESENT_SOURCE. Expected State Bits (all): 0xB93541F0: D3D12_RESOURCESTATE[COMMON|PRESENT], Actual State: 0xB93541D0: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCESTATE[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]

Running window example from winit doesn't produce any errors

alice-i-cecile commented 5 months ago

Okay, looks like a wgpu bug then :) Can you please open an issue there and link this one?

valaphee commented 5 months ago

https://github.com/gfx-rs/wgpu/issues/4247 Actually pretty easy fixable, it's because when initializing wgpu, it registers and VEH and it keeps the DX12 instance open, even though its not used.

Theoretically, either removing the dx12 feature, or setting WGPU_BACKEND=vulkan gets rid of this error

Astamor commented 5 months ago

Well setting backend to vulkan does remove the erros from the console but it seems this bug goes deeper because as I said fullscreen mode doesn't work and crashes the app. Also not sure if it's related to that bug but performance is terrible. For example, I've tested really simple tilemap using 2 textures. I've created procedurally map that's 128x128 which is around 16000 sprites and bevy choked. Fps dropped to like 35. Meanwhile libgdx which is java framework rendered map of size 256x256 which is 65000+ sprites and maintained stable 144 fps and that's only because that's my monitor refresh rate. |

EDIT: Performance issue solved, it was becaause of that crate called world inspector egui. It was massively slowing down entire app for some reason.

GitGhillie commented 5 months ago

Were you using a release build (e.g. cargo run --release) when you were checking performance? And make sure to follow this when building a debug build: https://bevyengine.org/learn/quick-start/getting-started/setup/#compile-with-performance-optimizations. With those it should be no problem to use that crate.

Astamor commented 5 months ago

I've checked both debug and release, I've went through all bevy docs including the link you provided. After removing that crate bevy handles maps 1000x1000 tiles with 100fps even in debug mode. Also I've noticed Bevy is using some kind of 2d "culling" by default. The only error remaining is fullscreen mode crashing the app

alice-i-cecile commented 5 months ago

The only error remaining is fullscreen mode crashing the app

Can you open up a new issue for this with details on the OS and hardware used? This is a nice clear problem that would be good to track :) The rest of this is largely resolved: I'm going to close this out now.