Skip to content

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

@lynn2910

Description

@lynn2910

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorC-Machine-SpecificThis bug is isolated to specific hardware or driver configurationsS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions