bevyengine / bevy

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

Resource state (0x4D8F0620: D3D12_RESOURCE_STATE_[COMMON|PRESENT]) of resource [...] is invalid for use as a render target. #14130

Open lynn2910 opened 1 month ago

lynn2910 commented 1 month ago

Bevy version

0.13.2

Relevant system information

Adapter informations:

`AdapterInfo { name: "NVIDIA GeForce RTX 4060 Laptop GPU", vendor: 4318, device: 10400, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "555.99", backend: Vulkan }`

Cargo version: cargo 1.78.0 (54d8815d0 2024-03-26) OS: Windows 11 (build 22631.3810)

What you did

I wrote the following code as a start for my new project

mod constants;

use bevy::core_pipeline::tonemapping::Tonemapping;
use bevy::prelude::*;
#[cfg(feature = "diagnostic")]
use bevy_screen_diagnostics::{ScreenDiagnosticsPlugin, ScreenFrameDiagnosticsPlugin};

fn main() {
    let mut app = App::new();

    app.add_plugins(
        DefaultPlugins
            .set(WindowPlugin {
                primary_window: Some(Window {
                    present_mode: constants::DEFAULT_PRESENT_MODE,
                    mode: constants::DEFAULT_WINDOW_MODE,
                    title: constants::WINDOW_NAME.to_string(),
                    name: Some(constants::APP_ID.to_string()),
                    resizable: true,
                    decorations: true,
                    transparent: false,
                    focused: true,
                    prevent_default_event_handling: true,
                    internal: Default::default(),
                    visible: true,
                    ..default()
                }),
                ..default()
            })
        );

    #[cfg(feature = "diagnostic")]
    app.add_plugins((ScreenDiagnosticsPlugin::default(), ScreenFrameDiagnosticsPlugin));

    app.init_state::<GameStatus>();

    // add systems
    app.add_systems(Startup, setup);

    app.run()
}

#[derive(Default, Clone, Copy, Eq, PartialEq, Hash, Debug, States)]
enum GameStatus {
    MainMenu,
    #[default]
    InGame,
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>
){
    commands.spawn((
        Camera3dBundle {
            transform: Transform::from_xyz(10.0, 12.0, 16.0)
                .looking_at(Vec3::ZERO, Vec3::Y),
            camera: Camera {
                hdr: true,
                ..default()
            },
            tonemapping: Tonemapping::TonyMcMapface,
            ..default()
        },
        constants::graphic_settings::DEFAULT_BLOOM_SETTINGS
    ));

    commands.spawn(
        PbrBundle {
            mesh: meshes.add(Cuboid::new(2., 2., 2.)),
            material: materials.add(Color::WHITE),
            ..default()
        }
    );
}
`constants.rs` ```rs use bevy::window::{PresentMode, WindowMode}; pub const WINDOW_NAME: &str = "Jsp"; pub const APP_ID: &str = "voxel_game_id"; pub const DEFAULT_WINDOW_MODE: WindowMode = WindowMode::Windowed; pub const DEFAULT_PRESENT_MODE: PresentMode = PresentMode::Immediate; pub mod graphic_settings { use bevy::core_pipeline::bloom::BloomSettings; pub const DEFAULT_BLOOM_SETTINGS: BloomSettings = BloomSettings::NATURAL; } ```

What went wrong

I got these logs:

2024-07-04T13:46:55.560831Z  INFO bevy_winit::system: Creating new window "Jsp" (0v1)
2024-07-04T13:46:58.708017Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x0000021E663F9B60:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x4D8F0620: D3D12_RESOURCE_STATE_[C
OMMON|PRESENT]) of resource (0x0000021E663ED780:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target.  Expected State Bits (all): 0x4D8F0600: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0x4D8F05E0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
2024-07-04T13:46:59.602256Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 4060 Laptop GPU", vendor: 4318, device: 10400, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "555.99", backend: Vulkan }
2024-07-04T13:47:01.598318Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 11 Home", kernel: "22631", cpu: "AMD Ryzen 7 7840HS w/ Radeon 780M Graphics", core_count: "8", memory: "15.3 GiB" }

Where there is this error:

2024-07-04T13:46:58.708017Z ERROR log: ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x0000021E663F9B60:'Unnamed ID3D12GraphicsCommandList Object'):
Resource state (0x4D8F0620: D3D12_RESOURCE_STATE_[C
OMMON|PRESENT]) of resource (0x0000021E663ED780:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target.  Expected State Bits (all): 0x4D8F0600: D3D12_RESOURCE_STATE_RENDER_TARGET,
Actual State: 0x4D8F05E0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]

The window lagged for ~5s, and after everything was fine, but this error is definitely not something normal, and I can't find what causes this issue

Additional information

I thought it was a driver issue, but there isn't any driver update neither for windows or the NVIDIA card

alice-i-cecile commented 1 month ago
  1. Can you reproduce this on 0.14?
  2. Can you reproduce this on wgpu's examples?
  3. Please strip down the reproduction as far as possible to help us isolate the problem. This is definitely rendering related for example, so the state code is not needed.
lynn2910 commented 1 month ago
  1. Can you reproduce this on 0.14?

Yes, I updated the app to bevy 0.14 and the exact same error is triggered

  1. Can you reproduce this on wgpu's examples?

When compiling the examples of wgpu, I have errors on the linking with gcc, so I can't run them. However I was able to find a basic code which uses only wgpu (https://github.com/junglie85/wgpu-samples , the example 'hello-triangle') which didn't fired any error

  1. Please strip down the reproduction as far as possible to help us isolate the problem. This is definitely rendering related for example, so the state code is not needed.

I cloned the repository of bevy and ran the example 3d_scene, with the same error when running it. I tried to remove any meshes, lights and even the camera, but the error occurs just the same

JazzGlobal commented 1 month ago

I get this issue on 0.14.

Adapter Info:

AdapterInfo { name: "AMD Radeon RX 6800 XT", vendor: 4098, device: 29631, device_type: DiscreteGpu, driver: "AMD proprietary driver", driver_info: "24.6.1 (AMD proprietary shader compiler)", backend: Vulkan }

Error Messages:

2024-07-10T19:07:30.653026Z ERROR wgpu_hal::auxil::dxgi::exception: ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x000001E5BF749CA0:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]) of resource (0x000001E5BF73D5A0:'Unnamed ID3D12Resource Object') (subresource: 0) 
is invalid for use as a render target.  Expected State Bits (all): 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
2024-07-10T19:07:30.661540Z ERROR present_frames: wgpu_hal::auxil::dxgi::exception: ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x000001E5BF6BCA00:'Internal DXGI CommandList'): Resource state (0x4: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x000001E5BF73D5A0:'Unnamed ID3D12Resource Object') (subresource: 0) 
is invalid for use as a PRESENT_SOURCE.  Expected State Bits (all): 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Actual State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
KennethWilke commented 1 month ago

I'm hitting this as well on Windows 10.

My test source:

use bevy::prelude::*;

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

Logs:

2024-07-11T02:45:31.001586Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 10 Home", kernel: "19045", cpu: "AMD Ryzen 7 5800X3D 8-Core Processor", core_count: "8", memory: "31.9 GiB" }
2024-07-11T02:45:31.164485Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon RX 6900 XT", vendor: 4098, device: 29615, device_type: DiscreteGpu, driver: "AMD proprietary driver", driver_info: "24.5.1 (AMD proprietary shader compiler)", backend: Vulkan }
2024-07-11T02:45:31.259497Z  INFO bevy_winit::system: Creating new window "App" (Entity { index: 0, generation: 1 })
2024-07-11T02:45:31.337367Z ERROR wgpu_hal::auxil::dxgi::exception: ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x00000231B48B4560:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]) of resource (0x00000231B48A6B20:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target.  Expected State Bits (all): 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
2024-07-11T02:45:31.356222Z ERROR present_frames: wgpu_hal::auxil::dxgi::exception: ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x00000231B4829A90:'Internal DXGI CommandList'): Resource state (0x4: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x00000231B48A6B20:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a PRESENT_SOURCE.  Expected State Bits (all): 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Actual State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
KennethWilke commented 1 month ago
  1. Can you reproduce this on 0.14?

I hit this for 0.14.0

  1. Can you reproduce this on wgpu's examples?

I see nearly identical errors when I ran wgpu's hello_triangle example, Seems a similar issue is created for wgpu: https://github.com/gfx-rs/wgpu/issues/4247

This is my first time trying to run Bevy on Windows, I haven't ran into this on Linux with AMD graphics but on windows it floods my terminal with these errors.

KennethWilke commented 1 month ago

As per the the original poster's update on the issue description for wgpu, I was able to set my WGPU_BACKEND environment variable to either dx12 or vulkan (even though this was what it was choosing before) to fix this issue for myself.