Open Retrodad0001 opened 1 year ago
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();
It works thanks
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.
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.
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.
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()
})
}));
}
}
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.
Updated for bevy 13.2
App::new()
.add_plugins(DefaultPlugins.set(RenderPlugin {
render_creation: RenderCreation::Automatic(WgpuSettings {
backends: Some(Backends::VULKAN),
..default()
}),
..default()
}))
.run();
How can this be done in bevy version 0.14.x?
@Retrodad0001 I Tested on 0.14.1
: the 0.13.2
snippet posted above will work
Another way to set the backend is by using an environment variable, such as WGPU_BACKEND=dx12 (For me, using dx12 fixed the issue.)
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_RESOURCESTATE[COMMON|PRESENT], Actual State: 0xD84FF080: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCESTATE[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.