DirectX12 Window resize fails after deactivating camera
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version and features
0.19.1 ```b56fc29d3016e641754765244b5ba3f9cc504671```
and master ```7a21c21ecbce9ba28c970ffdf73063321b6bb636```
## Relevant system information
### DX12
AdapterInfo { name: "AMD Radeon RX 9060 XT", vendor: 4098, device: 30096, device_type: DiscreteGpu, device_pci_bus_id: "0000:0c:00.0", driver: "32.0.31041.1004", driver_info: "", backend: Dx12, subgroup_min_size: 32, subgroup_max_size: 64, transient_saves_memory: Some(false), limit_bucket: None }
### Vulkan
AdapterInfo { name: "AMD Radeon RX 9060 XT", vendor: 4098, device: 30096, device_type: DiscreteGpu, device_pci_bus_id: "", driver: "AMD proprietary driver", driver_info: "26.8.1 (LLPC)", backend: Vulkan, subgroup_min_size: 32, subgroup_max_size: 64, transient_saves_memory: Some(false), limit_bucket: None }
## What you did
I was playing around with handing over from one camera to the next in a pet project of mine. Things run fine on metal (M5 Pro) and Vulkan (9060 XT 16GB) but kept crashing on DX12:
- Created 2 3D cameras; one active, one inactive,
- swap after some frames, keeping the inactive alive
- resize window
## What went wrong
DX12 exits with exit code 1, while Vulkan works fine
DX12 reports via DebugView:
```DXGI ERROR: IDXGISwapChain::ResizeBuffers: Swapchain cannot be resized unless all outstanding buffer references have been released. [ MISCELLANEOUS ERROR #19: ]```
See minimal runner attached. Uses DX12 by default and Vulkan via --vulkan flag.
Place this into examples/ and run
```cargo run --example camera_resize_script``` (for DX12)
```cargo run --example camera_resize_script -- --vulkan``` (for Vulkan)
Minimal runner: camera_resize_script.rs
```rust
use bevy::{
prelude::*,
render::{settings::*, RenderPlugin},
};
fn main() -> AppExit {
let backend = if std::env::args().any(|arg| arg == "--vulkan") {
Backends::VULKAN
} else {
Backends::DX12
};
App::new()
.add_plugins(DefaultPlugins.set(RenderPlugin {
render_creation: RenderCreation::Automatic(Box::new(WgpuSettings {
backends: Some(backend),
..default()
})),
..default()
}))
.add_systems(Startup, |mut commands: Commands| {
commands.spawn(Camera3d::default());
commands.spawn((
Camera3d::default(),
Camera {
is_active: false,
..default()
},
));
})
.add_systems(Update, reproduce)
.run()
}
fn reproduce(
mut frame: Local,
mut cameras: Query<&mut Camera>,
mut window: Single<&mut Window>,
mut exit: MessageWriter,
) {
*frame += 1;
match *frame {
60 => {
println!("Switching cameras, keeping the inactive camera alive");
for mut camera in &mut cameras {
camera.is_active = !camera.is_active;
}
}
120 => {
println!("Resizing window");
window.resolution.set_physical_resolution(800, 450);
}
180 => {
println!("Reached frame 180 without exiting on a render error");
exit.write(AppExit::Success);
}
_ => {}
}
}
```
## Additional information
I managed to locally "fix" this by simply including ```ViewTarget``` in the ```fn extract_cameras``` in ```crates/bevy_render/src/camera.rs```.
Thats just something an LLM suggested for me, maybe its still a good starting point for the investigation?
Also I dont think any other issue brings this up yet, but these seem related?:
- #22225
- #22254 (fix for #22225)
- #15077
---
Im very new to bevy, this is my first issue, i hope im doing this somewhat right :)
Contributor guide
Research direction
Start with the reproducer in the issue and run `cargo run --example camera_resize_script` and its `-- --vulkan` variant to compare DX12 and Vulkan. Then inspect `crates/bevy_render/src/camera.rs`, especially `extract_cameras` and the handling of `ViewTarget`; done means switching between the two cameras and resizing reaches frame 180 on DX12 without the swapchain error, while Vulkan continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100