如何使用 Geforce RTX 2060 在 Windows 11 上让 Bevy 运行 超过 5 秒

How to get Bevy to run longer than 5 seconds on Windows 11 with Geforce RTX 2060

我正在尝试浏览 Bevy 文档并注意到我绝对不能 运行 单个示例或基本应用程序超过 5 秒而不出现错误中断执行。 运行 是否需要在文档设置之外做一些特殊的事情,或者 Bevy 是否因最新的 Windows 11 + Geforce RTX 2060 机器而损坏?

我 运行 或尝试遵循文档的示例无关紧要,这总是会发生:

PS C:\Development\GameDev\my_bevy_game> cargo run
warning: unused manifest key: target.aarch64-apple-darwin.rustflags
warning: unused manifest key: target.x86_64-apple-darwin.rustflags
warning: unused manifest key: target.x86_64-pc-windows-msvc.linker
warning: unused manifest key: target.x86_64-pc-windows-msvc.rustflags
warning: unused manifest key: target.x86_64-unknown-linux-gnu.linker
warning: unused manifest key: target.x86_64-unknown-linux-gnu.rustflags
   Compiling my_bevy_game v0.1.0 (C:\Development\GameDev\my_bevy_game)
    Finished dev [unoptimized + debuginfo] target(s) in 4.01s
     Running `target\debug\my_bevy_game.exe`
2022-04-18T15:56:45.590239Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setupLoaderTrampPhysDevs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.
2022-04-18T15:56:45.591644Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x207c17a7b00, name: ?)
2022-04-18T15:56:45.592432Z ERROR wgpu_hal::vulkan::instance: GENERAL [Loader Message (0x0)]
        setupLoaderTrampPhysDevs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.
2022-04-18T15:56:45.592561Z ERROR wgpu_hal::vulkan::instance:   objects: (type: INSTANCE, hndl: 0x207c17a7b00, name: ?)
2022-04-18T15:56:45.901926Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 2060", vendor: 4318, device: 7957, device_type: DiscreteGpu, backend: Dx12 }
hello Elaina Proctor!
hello Renzo Hume!
hello Zayna Nieves!
2022-04-18T15:56:48.506223Z ERROR present_frames: wgpu_hal::dx12::instance: ID3D12CommandQueue::Present: Resource state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE) (promoted from COMMON state) of resource (0x00000207DD7D0A70:'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_COPY, is actually incompatible and different from that on the next Command List type : D3D12_COMMAND_LIST_TYPE_DIRECT. [ RESOURCE_MANIPULATION ERROR #990: RESOURCE_BARRIER_MISMATCHING_COMMAND_LIST_TYPE]
error: process didn't exit successfully: `target\debug\my_bevy_game.exe` (exit code: 1)
PS C:\Development\GameDev\my_bevy_game>

我从书中制作的 Rust 代码(请注意,这也发生在 bevy repo 未修改的示例代码中):

use bevy::prelude::*;

pub struct HelloPlugin;

struct GreetTimer(Timer);

#[derive(Component)]
struct Person;

#[derive(Component)]
struct Name(String);

impl Plugin for HelloPlugin {
    fn build(&self, app: &mut App) {
        // the reason we call from_seconds with the true flag is to make the timer repeat itself
        app.insert_resource(GreetTimer(Timer::from_seconds(2.0, true)))
            .add_startup_system(add_people)
            .add_system(greet_people);
    }
}

fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
    // update our timer with the time elapsed since the last update
    // if that caused the timer to finish, we say hello to everyone
    if timer.0.tick(time.delta()).just_finished() {
        for name in query.iter() {
            println!("hello {}!", name.0);
        }
    }
}

fn add_people(mut commands: Commands) {
    commands
        .spawn()
        .insert(Person)
        .insert(Name("Elaina Proctor".to_string()));
    commands
        .spawn()
        .insert(Person)
        .insert(Name("Renzo Hume".to_string()));
    commands
        .spawn()
        .insert(Person)
        .insert(Name("Zayna Nieves".to_string()));
}

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

您可以从输出中看到我正在尝试 运行 书中的 my_bevy_game 示例,但是我 运行 到目前为止。 运行 与 Bevy 有什么关系?

-- 编辑--

这似乎是一个 dx12 问题,WGPU needs to address. The proposed workarounds in the Bevy issue 不适用于我和其他人的机器。由于依赖于WGPU,Bevy暂时似乎无法修复。

看起来像个错误请参阅问题 #4461 of bevy the bug was inside wgpu:

您可以尝试临时使用最新的wgpu版本:

[patch.crates-io]
wgpu = { git = "https://github.com/gfx-rs/wgpu" }

# or

wgpu = { git = "https://github.com/gfx-rs/wgpu" , rev = "3d10678a91b78557b0dea537407eb4a4ff754872" }