bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Repeating rendering error in debug console but rendering works.

Open Retrodad0001 opened this issue 2 years ago • 12 comments

Bevy version

0.11

[Optional] Relevant system information

If your bug is rendering-related, copy the adapter info that appears when you run Bevy.

GPU - AMD Radeon RX 5700 - Primary/Discrete VRAM - 8176 MB - GDDR6 1750 MHz Graphics - AMD Radeon RX 5700 Graphics Manufacturer - Powered by AMD Usable Memory Size - 8176 MB Core Clock - 1725 MHz Total Memory Bandwidth - 448 GByte/s Device ID - 731F Revision ID - C4 Vendor ID - 1002 SubSystem ID - 04E4 SubSystem Vendor ID - 1043 Bus Type - PCI Express 4.0 Current Bus Settings - PCI Express 4.0 x16 Driver Version - 23.20.11.04-230921a-396203C-AMD-Software-Adrenalin-Edition AMD Windows Driver Version - 31.0.22011.4008 Direct3D API Version - 12.1 Vulkan™ API Version - 1.3.262 OpenCL™ API Version - 2.0 OpenGL® API Version - 4.6 Direct3D® Driver Version - 9.14.10.01526 Vulkan™ Driver Version - 2.0.283 OpenCL® Driver Version - 31.0.22011.4008 OpenGL® Driver Version - 23.09.230729_569461f 2D Driver Version - 8.1.1.1634 UI Version - 2023.0921.2013.1996 AMD Audio Driver Version - 10.0.1.30 Driver Provider - Advanced Micro Devices, Inc. Windows Edition - Windows 11 Professional (64 bit) Windows Version - 22H2

What you did

1 Just run the game.

What went wrong

The debug console is repeatingly logging an error, but the application is still working.

The error text: 2023-09-30T05:55:03.499324Z ERROR wgpu_hal::auxil::dxgi::exception: ID3D12CommandQueue::ExecuteCommandLists: Using IDXGIS wapChain::Present on Command List (0x000001E5CE313540:'Internal DXGI CommandList'): Resource state (0xD84FF0C0: D3D12_RES OURCE_STATE_RENDER_TARGET) of resource (0x000001E5CE3703C0:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid f or use as a PRESENT_SOURCE. Expected State Bits (all): 0xD84FF0A0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Actual State: 0xD84FF080: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]

Additional information

I have 2 pc's only on 1 with the same code I get this error only on 1 pc. The crazy thing is that I get this error most of the time, not always. The other pc has a different setup. I have this issue with many bevy versions, but I don't know if this is a bevy issue. I have this for a long time, even when and updated the AMD drivers at least 5 times.

image

Retrodad0001 avatar Sep 30 '23 06:09 Retrodad0001

This is caused by this wgpu bug: https://github.com/gfx-rs/wgpu/issues/3959

For now, you can fix it by forcing it to use Vulkan:

    App::new()
        .add_plugins(DefaultPlugins.set(RenderPlugin {
            wgpu_settings: WgpuSettings {
                backends: Some(Backends::VULKAN),
                ..default()
            },
        }))
        .run();

IceSentry avatar Sep 30 '23 06:09 IceSentry

It works thanks

Retrodad0001 avatar Sep 30 '23 06:09 Retrodad0001

Updating for Bevy 0.12:

    App::new()
        .add_plugins(DefaultPlugins.set(RenderPlugin {
            wgpu_settings: WgpuSettings {
                backends: Some(Backends::VULKAN),
                ..default()
            },
        }))
        .run();

For me, this also worked to get rid of the noisy warnings:

    App::new()
        .add_plugins(DefaultPlugins.set(RenderPlugin {
            wgpu_settings: WgpuSettings {
                backends: Some(Backends::DX12),
                ..default()
            },
        }))
        .run();

Looks like explicitly setting the backend makes the warnings go away. Check this issue out for some more context.

mnmaita avatar Nov 11 '23 23:11 mnmaita

Hey, this problem also occurs on bevy0.12.0+Intel Arc a750. Using vulkan on other graphics cards is a temporary solution, but due to #8037, intel graphics cards cannot run properly on vulkan, which is very embarrassing.

juzi5201314 avatar Nov 14 '23 16:11 juzi5201314

For me, the above workaround did not work as the wgpusettings field is no longer part of RenderPlugin. This code worked for me:

use bevy::prelude::*;
use bevy::render::*;
use bevy::render::settings::*;

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

pub struct SamplePlugin;

impl Plugin for SamplePlugin {
	fn build(&self, app: &mut App) {
		app.add_plugins(DefaultPlugins.set(WindowPlugin {
			primary_window: Some(Window {
				resolution: (640.0, 480.0).into(),
				title: "Sample".to_string(),
				..default()
			}),
			..default()
		})
		.set(RenderPlugin {
                        render_creation: RenderCreation::Automatic(WgpuSettings {
				device_label: Some(std::borrow::Cow::Borrowed("device_gpu")),
				backends:Some(Backends::DX12),
				power_preference: PowerPreference::HighPerformance,
				priority: WgpuSettingsPriority::Functionality,
				features: WgpuFeatures::empty(),
				disabled_features: None,
				limits: WgpuLimits::default(),
				constrained_limits: Some(WgpuLimits::default()),
				dx12_shader_compiler: Dx12Compiler::Fxc
			})
               }));
	}
}

I used Some(std::borrow::Cow::Borrowed("device_gpu")) to create a Clone-on-write string with the name "device_gpu" with a lifetime for the length of the program. I don't understand Cows all that well, but this is a handy article. I used Some(Backends::DX12) to explicitly set the Backendto DirectX 12. I used PowerPreference::HighPerformance to ensure the discrete GPU is used if available (docs). I used WgpuSettingsPriority::Functionality to cover the maximum features and limits of the adapter and backend (WgpuSettingsPriority). I used None for the features and disabled_features as this only deals with non-default features. Since we can't currently determine which features are needed, I didn't add any additional features (WgpuFeatures). I used WgpuLimits::default() to cover the most use cases (Wgpulimits) I used Dx12Compiler::Fxc since is the default option from the enum. Cargo complained when I tried to use Dxc.

TheAeroHead avatar Dec 05 '23 03:12 TheAeroHead

A simpler version of the above code can be:

use bevy::prelude::*;
use bevy::render::*;
use bevy::render::settings::*;

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

pub struct SamplePlugin;

impl Plugin for SamplePlugin {
	fn build(&self, app: &mut App) {
		app.add_plugins(DefaultPlugins.set(RenderPlugin {
                        render_creation: RenderCreation::Automatic(WgpuSettings {
				backends:Some(Backends::DX12),
                                ..default()
               			})
		}));
	}
}

TheAeroHead avatar Dec 09 '23 01:12 TheAeroHead

For those following this issue, this is upstreamed at https://github.com/gfx-rs/wgpu/issues/4247.

Marking this as blocked on a wgpu release to fix.

james7132 avatar Mar 23 '24 10:03 james7132

Updated for bevy 13.2

App::new()
    .add_plugins(DefaultPlugins.set(RenderPlugin {
        render_creation: RenderCreation::Automatic(WgpuSettings {
            backends: Some(Backends::VULKAN),
            ..default()
        }),
        ..default()
    }))
    .run();

AxLisin avatar May 02 '24 00:05 AxLisin

How can this be done in bevy version 0.14.x?

Retrodad0001 avatar Aug 03 '24 07:08 Retrodad0001

@Retrodad0001 I Tested on 0.14.1: the 0.13.2 snippet posted above will work

part-time-nerd avatar Aug 03 '24 16:08 part-time-nerd

Another way to set the backend is by using an environment variable, such as WGPU_BACKEND=dx12 (For me, using dx12 fixed the issue.)

brianjosephwalters avatar Aug 05 '24 23:08 brianjosephwalters

another try with bevy.. is see the same problem when not using the workarround.. so i will reopen this

Retrodad0001 avatar Nov 29 '24 14:11 Retrodad0001

Latest state: I followed the trail to upstream issues, some were closed, but still this issue is not fixed.

Retrodad0001 avatar Dec 29 '24 12:12 Retrodad0001

In bevy, this may be caused by the default WgpuSettings in bevy_render. See: https://github.com/bevyengine/bevy/blob/main/crates/bevy_render/src/settings.rs#L71

Using the following code, which mimics the default WgpuSettings set on that line which is used by DefaultPlugins, the error appears again:

App::new()
    .add_plugins(DefaultPlugins.set(RenderPlugin {
        render_creation: RenderCreation::Automatic(WgpuSettings {
            backends: Some(Backends::all()),
            ..default()
        }),
        ..default()
    }))
    .run();

A potential fix could be to default to using Backends::VULKAN, which is what the 0.13.2 workaround code snippet does (that workaround still works for bevy 0.15). According to the documentation here: (https://docs.rs/bevy/latest/bevy/render/settings/struct.WgpuSettings.html) the METAL, VULKAN, and DX12 backends are all enabled by default for non-web. Following the Wgpu related issue (https://github.com/gfx-rs/wgpu/issues/4247), the core cause seems to be when a DirectX12 backend and a Vulkan backend are both initialized, but only one is used. However, this change would mean developers would have to manually override the WgpuSettings like the current workaround method if they want to use DirectX12 or Metal.

TheAeroHead avatar Dec 31 '24 21:12 TheAeroHead