Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX12 backend panics when window is resized #15077

Closed
akimakinai opened this issue Sep 7, 2024 · 5 comments · Fixed by #15087
Closed

DX12 backend panics when window is resized #15077

akimakinai opened this issue Sep 7, 2024 · 5 comments · Fixed by #15087
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior O-DX12 Specific to the DX12 render API S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Milestone

Comments

@akimakinai
Copy link
Contributor

Bevy version

master

[Optional] Relevant system information

AdapterInfo { name: "NVIDIA GeForce RTX 3060 Ti", vendor: 4318, device: 9353, device_type: DiscreteGpu, driver: "32.0.15.5599", driver_info: "", backend: Dx12 }

What you did

Run any example with DX12 backend and resize the window.

What went wrong

Terminated with a panic.

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.80s
     Running `target\debug\examples\bloom_2d.exe`
2024-09-07T09:31:13.698140Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 11 Pro", kernel: "22631", cpu: "11th Gen Intel(R) Core(TM) i7-11700F @ 2.50GHz", core_count: "8", memory: "15.8 GiB" }
2024-09-07T09:31:13.876694Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 3060 Ti", vendor: 4318, device: 9353, device_type: DiscreteGpu, driver: "32.0.15.5599", driver_info: "", backend: Dx12 }
2024-09-07T09:31:14.521009Z  INFO bevy_winit::system: Creating new window "App" (0v1#4294967296)
2024-09-07T09:31:15.876281Z ERROR wgpu_hal::dx12: ResizeBuffers failed: 0x887A0001    
2024-09-07T09:31:15.876492Z ERROR wgpu_core::device::global: surface configuration failed: window is in use
thread 'Compute Task Pool (2)' panicked at E:\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-22.1.0\src\backend\wgpu_core.rs:786:18:
Error in Surface::configure: Validation Error

Caused by:
  Invalid surface

stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:665
   1: core::panicking::panic_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:74
   2: wgpu::backend::wgpu_core::ContextWgpuCore::handle_error_fatal<enum2$<wgpu_core::present::ConfigureSurfaceError> >
             at E:\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-22.1.0\src\backend\wgpu_core.rs:317
   3: wgpu::backend::wgpu_core::impl$7::surface_configure
             at E:\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-22.1.0\src\backend\wgpu_core.rs:786
   4: wgpu::context::impl$5::surface_configure<wgpu::backend::wgpu_core::ContextWgpuCore>
             at E:\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-22.1.0\src\context.rs:2169
   5: wgpu::Surface::configure
             at E:\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-22.1.0\src\lib.rs:5658
   6: bevy_render::renderer::render_device::RenderDevice::configure_surface
             at .\crates\bevy_render\src\renderer\render_device.rs:197
   7: bevy_render::view::window::create_surfaces
             at .\crates\bevy_render\src\view\window\mod.rs:437
   8: core::ops::function::FnMut::call_mut<void (*)(bevy_ecs::change_detection::Res<bevy_render::view::window::ExtractedWindows>,bevy_ecs::change_detection::ResMut<bevy_render::view::window::WindowSurfaces>,bevy_ecs::change_detection::Res<bevy_render::renderer::
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\ops\function.rs:166
   9: core::ops::function::impls::impl$3::call_mut<tuple$<bevy_ecs::change_detection::Res<bevy_render::view::window::ExtractedWindows>,bevy_ecs::change_detection::ResMut<bevy_render::view::window::WindowSurfaces>,bevy_ecs::change_detection::Res<bevy_render::rend
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\ops\function.rs:294
  10: bevy_ecs::system::function_system::impl$37::run::call_inner<tuple$<>,bevy_ecs::change_detection::Res<bevy_render::view::window::ExtractedWindows>,bevy_ecs::change_detection::ResMut<bevy_render::view::window::WindowSurfaces>,bevy_ecs::change_detection::Res<
             at .\crates\bevy_ecs\src\system\function_system.rs:798
  11: bevy_ecs::system::function_system::impl$37::run<tuple$<>,void (*)(bevy_ecs::change_detection::Res<bevy_render::view::window::ExtractedWindows>,bevy_ecs::change_detection::ResMut<bevy_render::view::window::WindowSurfaces>,bevy_ecs::change_detection::Res<bev
             at .\crates\bevy_ecs\src\system\function_system.rs:801
  12: bevy_ecs::system::function_system::impl$7::run_unsafe<void (*)(bevy_ecs::change_detection::Res<bevy_render::view::window::ExtractedWindows>,bevy_ecs::change_detection::ResMut<bevy_render::view::window::WindowSurfaces>,bevy_ecs::change_detection::Res<bevy_r
             at .\crates\bevy_ecs\src\system\function_system.rs:622

Additional information

wgpu examples (v22.1.0 and master) don't crash when resizing window.

@akimakinai akimakinai added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Sep 7, 2024
@akimakinai
Copy link
Contributor Author

Bisected, d9527c1 (#14833) is the first commit where the problem reproduces.

@akimakinai
Copy link
Contributor Author

ViewTargetAttachments resource added in the PR holds TextureView of the current surface. This can be the cause. As a quick confirmation, clearing ViewTargetAttachments before resizing surface seems to fix the panic.

"Resize panics on DX12" wgpu issue in the past also suggests you cannot retain references to surface during resize: gfx-rs/wgpu#3967 (comment)

@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Sep 7, 2024
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen O-DX12 Specific to the DX12 render API S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! and removed S-Needs-Triage This issue needs to be labelled labels Sep 7, 2024
@akimakinai
Copy link
Contributor Author

Reported in upstream repo: gfx-rs/wgpu#6235

@JMS55
Copy link
Contributor

JMS55 commented Sep 8, 2024

Based on gfx-rs/wgpu#6235 (comment), we should drop the surfaces before resizing. Can you revive your PR? Don't add any comments about it being DX12 specific though.

@akimakinai
Copy link
Contributor Author

Thanks, reopened #15087.

github-merge-queue bot pushed a commit that referenced this issue Sep 30, 2024
# Objective

- Fixes #15077

## Solution

- Clears `ViewTargetAttachments` resource every frame before
`create_surfaces` system instead, which was previously done after
`extract_windows`.

## Testing

- Confirmed that examples no longer panic on window resizing with DX12
backend.
- `screenshot` example keeps working after this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior O-DX12 Specific to the DX12 render API S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants