bevy icon indicating copy to clipboard operation
bevy copied to clipboard

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

Open lynn2910 opened this issue 1 year ago • 6 comments

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`
  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

lynn2910 avatar Jul 04 '24 14:07 lynn2910

  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.

alice-i-cecile avatar Jul 07 '24 13:07 alice-i-cecile

  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

lynn2910 avatar Jul 08 '24 13:07 lynn2910

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]

JazzGlobal avatar Jul 10 '24 19:07 JazzGlobal

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 avatar Jul 11 '24 02:07 KennethWilke

  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 avatar Jul 11 '24 03:07 KennethWilke

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.

KennethWilke avatar Jul 11 '24 03:07 KennethWilke

I have this issue on 0.15.3, but not when I use git to pull main.

I was able to confirm that #17542 fixed the issue for me.

These are the logs on 33e8333 (before the PR):

2025-03-15T10:27:23.148916Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 11 Pro", kernel: "26100", cpu: "AMD Ryzen 7 7840HS w/ Radeon 780M Graphics", core_count: "8", memory: "31.2 GiB" }
2025-03-15T10:27:24.134274Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon(TM) RX 7700S", vendor: 4098, device: 29824, device_type: DiscreteGpu, driver: "AMD proprietary driver", driver_info: "24.8.1 (LLPC)", backend: Vulkan }
2025-03-15T10:27:24.745599Z  INFO bevy_winit::system: Creating new window App (0v1)
2025-03-15T10:27:25.139828Z ERROR wgpu_hal::auxil::dxgi::exception: ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x000001FEE5D80A10:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]) of resource (0x000001FEE5D464F0:'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]
2025-03-15T10:27:25.149437Z ERROR present_frames: wgpu_hal::auxil::dxgi::exception: ID3D12CommandQueue::Present: Resource state (0x4: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x000001FEE5D464F0:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a INITIAL|PRESENT.  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]
2025-03-15T10:27:25.164915Z ERROR present_frames: wgpu_hal::auxil::dxgi::exception: ID3D12CommandQueue::ExecuteCommandLists: Using CopyResource on Command List (0x000001FEE60E2320:'Internal DXGI CommandList'): Resource state(0x 4: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource(0x000001FEE5D464F0:'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_DIRECT, is actually incompatible and different from that on the next Command List type : D3D12_COMMAND_LIST_TYPE_COPY. [ RESOURCE_MANIPULATION ERROR #990: RESOURCE_BARRIER_MISMATCHING_COMMAND_LIST_TYPE]
...

The errors disappear on 669d139.

Here's the source code I ran to test it:

use bevy::prelude::*;
fn main() {
    let mut app = App::new();
    app.add_plugins(DefaultPlugins);
    app.run();
}

If other people with this issue are able to confirm that main is working, then this PR can probably be closed as fixed.

TehPers avatar Mar 15 '25 10:03 TehPers