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

Resize error on DX12 backend in wgpu 0.17 #3967

Closed
Tracked by #2719
mikeny07 opened this issue Jul 23, 2023 · 10 comments · Fixed by #4106
Closed
Tracked by #2719

Resize error on DX12 backend in wgpu 0.17 #3967

mikeny07 opened this issue Jul 23, 2023 · 10 comments · Fixed by #4106
Labels
api: dx12 Issues with DX12 or DXGI area: wsi Issues with swapchain management or windowing type: bug Something isn't working

Comments

@mikeny07
Copy link

mikeny07 commented Jul 23, 2023

Description

when attempting to run wgpu examples using the DX12 backend in version 0.17 of wgpu, I encountered the following error:

[2023-07-23T20:02:29Z ERROR wgpu_hal::dx12] ResizeBuffers failed: 0x887A0001
[2023-07-23T20:02:29Z ERROR wgpu_core::device::global] surface configuration failed: window is in use
thread 'main' panicked at 'Error in Surface::configure: Validation Error

Caused by:
Invalid surface
', C:\Users****.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.17.0\src\backend\direct.rs:771:18

Repro steps

For example, in the "hello-triangle" example, simply replacing

let instance = wgpu::Instance::default();

by

 let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
        backends: wgpu::Backends::DX12,
        dx12_shader_compiler: Default::default(),
 });

this will generate the error when resizing the output window.

Expected vs observed behavior

This error only occurs in wgpu 0.17, while wgpu <= 0.16 never gives this error.

Platform

Windows 11, RTX 3060, wgpu 0.17.

@ludovitkramar
Copy link

ludovitkramar commented Jul 31, 2023

I'm learning wgpu and I have this same error on Windows 10 with GT740.
It doesn't matter which present mode I choose, the DX12 backend produces the same error when resizing. (or just pressing maximize once.)

[2023-07-31T07:01:14Z ERROR wgpu_hal::dx12] ResizeBuffers failed: 0x887A0001
[2023-07-31T07:01:14Z ERROR wgpu_core::device::global] surface configuration failed: window is in use
thread 'main' panicked at 'Error in Surface::configure: Validation Error

Caused by:
    Invalid surface

Can confirm that 0.16 works as expected.

@teoxoy
Copy link
Member

teoxoy commented Jul 31, 2023

Traced it back to #3936.

Looking at the Remarks section of ResizeBuffers,

You can't resize a swap chain unless you release all outstanding references to its back buffers. You must release all of its direct and indirect references on the back buffers in order for ResizeBuffers to succeed.

Direct references are held by the application after it calls AddRef on a resource.

Indirect references are held by views to a resource, binding a view of the resource to a device context, a command list that used the resource, a command list that used a view to that resource, a command list that executed another command list that used the resource, and so on.

from https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-resizebuffers#remarks

and us cloning the ComPtr here,

resource: sc.resources[index].clone(),

it's plausible we still hold onto the resources when calling ResizeBuffers and not respecting its invariants.

@teoxoy teoxoy added type: bug Something isn't working api: dx12 Issues with DX12 or DXGI area: wsi Issues with swapchain management or windowing labels Jul 31, 2023
@mikeny07
Copy link
Author

Why this error only occurs when running the official examples in wgpu 0.17, but not in older versions such as 0.16?

"You can't resize a swap chain unless you release all outstanding references to its back buffers. You must release all of its direct and indirect references on the back buffers in order for ResizeBuffers to succeed."

Why older versions didn't have such issue? what change from older versions to 0.17 leads to this problem?

@teoxoy
Copy link
Member

teoxoy commented Jul 31, 2023

The PR I linked to above #3936.

@Capati
Copy link

Capati commented Jul 31, 2023

Using wgpu::Device::poll before recreate swapchain didn't produce the error. This function check for resource cleanups, is this a bug or the proper way to do?

@cwfitzgerald
Copy link
Member

It's a bug on our side, we need to do the appropriate waits internally.

@Elabajaba
Copy link
Contributor

Ran into this updating bevy to wgpu 0.17. It also crashes when you minimize the window.

@DotrixXP
Copy link

Calling wgpu::Instance::poll_all before reconfiguring surface and recreating framebuffers worked for me.

github-merge-queue bot pushed a commit to bevyengine/bevy that referenced this issue Oct 9, 2023
~~Currently blocked on an upstream bug that causes crashes when
minimizing/resizing on dx12 gfx-rs/wgpu#3967
wgpu 0.17.1 is out which fixes it

# Objective

Keep wgpu up to date.

## Solution

Update wgpu and naga_oil.

Currently this depends on an unreleased (and unmerged) branch of
naga_oil, and hasn't been properly tested yet.

The wgpu side of this seems to have been an extremely trivial upgrade
(all the upgrade work seems to be in naga_oil). This also lets us remove
the workarounds for pack/unpack4x8unorm in the SSAO shaders.

Lets us close the dx12 part of
#8888

related: #9304

---

## Changelog

Update to wgpu 0.17 and naga_oil 0.9
regnarock pushed a commit to regnarock/bevy that referenced this issue Oct 13, 2023
~~Currently blocked on an upstream bug that causes crashes when
minimizing/resizing on dx12 gfx-rs/wgpu#3967
wgpu 0.17.1 is out which fixes it

# Objective

Keep wgpu up to date.

## Solution

Update wgpu and naga_oil.

Currently this depends on an unreleased (and unmerged) branch of
naga_oil, and hasn't been properly tested yet.

The wgpu side of this seems to have been an extremely trivial upgrade
(all the upgrade work seems to be in naga_oil). This also lets us remove
the workarounds for pack/unpack4x8unorm in the SSAO shaders.

Lets us close the dx12 part of
bevyengine#8888

related: bevyengine#9304

---

## Changelog

Update to wgpu 0.17 and naga_oil 0.9
ameknite pushed a commit to ameknite/bevy that referenced this issue Nov 6, 2023
~~Currently blocked on an upstream bug that causes crashes when
minimizing/resizing on dx12 gfx-rs/wgpu#3967
wgpu 0.17.1 is out which fixes it

Keep wgpu up to date.

Update wgpu and naga_oil.

Currently this depends on an unreleased (and unmerged) branch of
naga_oil, and hasn't been properly tested yet.

The wgpu side of this seems to have been an extremely trivial upgrade
(all the upgrade work seems to be in naga_oil). This also lets us remove
the workarounds for pack/unpack4x8unorm in the SSAO shaders.

Lets us close the dx12 part of
bevyengine#8888

related: bevyengine#9304

---

Update to wgpu 0.17 and naga_oil 0.9
@Friz64
Copy link

Friz64 commented Nov 22, 2023

This has regressed for me, bisected to 6e21f7a (#3626).

Command used:

WGPU_BACKEND=dx12 cargo run --release --bin msaa-line

@cwfitzgerald cwfitzgerald reopened this Nov 22, 2023
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this issue Jan 9, 2024
~~Currently blocked on an upstream bug that causes crashes when
minimizing/resizing on dx12 gfx-rs/wgpu#3967
wgpu 0.17.1 is out which fixes it

# Objective

Keep wgpu up to date.

## Solution

Update wgpu and naga_oil.

Currently this depends on an unreleased (and unmerged) branch of
naga_oil, and hasn't been properly tested yet.

The wgpu side of this seems to have been an extremely trivial upgrade
(all the upgrade work seems to be in naga_oil). This also lets us remove
the workarounds for pack/unpack4x8unorm in the SSAO shaders.

Lets us close the dx12 part of
bevyengine#8888

related: bevyengine#9304

---

## Changelog

Update to wgpu 0.17 and naga_oil 0.9
@Friz64
Copy link

Friz64 commented Jan 12, 2024

Regression fixed by #4781

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dx12 Issues with DX12 or DXGI area: wsi Issues with swapchain management or windowing type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants