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

dxgi exception with Vulkan backend on Windows #4247

Open
AlfredAn opened this issue Oct 16, 2023 · 5 comments
Open

dxgi exception with Vulkan backend on Windows #4247

AlfredAn opened this issue Oct 16, 2023 · 5 comments
Labels
api: dx12 Issues with DX12 or DXGI type: enhancement New feature or request

Comments

@AlfredAn
Copy link

AlfredAn commented Oct 16, 2023

Description
When running the "hello-triangle" example, I get the following error message:

[2023-10-16T17:55:54Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x000001C77D466B10:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]) of resource (0x000001C77D395060:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target.  Expected State Bits (all): 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
[2023-10-16T17:55:54Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x000001C77D3FB510:'Internal DXGI CommandList'): Resource state (0x4: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x000001C77D395060:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a PRESENT_SOURCE.  Expected State Bits (all): 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Actual State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
[2023-10-16T17:55:54Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::Present: Resource state (0x4: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x000001C77D395060:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a INITIAL|PRESENT.  Expected State Bits (all): 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Actual State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
[2023-10-16T17:55:56Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::ExecuteCommandLists: Using ClearRenderTargetView on Command List (0x000001C77D520D60:'Unnamed ID3D12GraphicsCommandList Object'): Resource state (0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]) of resource (0x000001C76D0508C0:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a render target.  Expected State Bits (all): 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Actual State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Missing State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
[2023-10-16T17:55:56Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::ExecuteCommandLists: Using IDXGISwapChain::Present on Command List (0x000001C77D4C4040:'Internal DXGI CommandList'): Resource state (0x4: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x000001C76D0508C0:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a PRESENT_SOURCE.  Expected State Bits (all): 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Actual State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]
[2023-10-16T17:55:56Z ERROR wgpu_hal::auxil::dxgi::exception] ID3D12CommandQueue::Present: Resource state (0x4: D3D12_RESOURCE_STATE_RENDER_TARGET) of resource (0x000001C76D0508C0:'Unnamed ID3D12Resource Object') (subresource: 0) is invalid for use as a INITIAL|PRESENT.  Expected State Bits (all): 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT], Actual State: 0x4: D3D12_RESOURCE_STATE_RENDER_TARGET, Missing State: 0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]. [ EXECUTION ERROR #538: INVALID_SUBRESOURCE_STATE]

It happens every time the window is resized, including maximizing it. It also appears sometimes when just starting the program, without touching the window. When running the "cube" example, it seems to print the error every frame rather than just when resizing. Setting WGPU_BACKEND to dx12 seems to fix the issue in the cube benchmark, although hello_triangle is unaffected. EDIT: WGPU_BACKEND=vulkan also seems to fix the issue for some reason. Also, Bevy reports the backend to be Vulkan regardless of the value, even though the behavior changes.

I get the same error message in Bevy as well, which is where I noticed it. If I ignore the errors, everything still seems to work.

I've tried both with the latest commit (2f3d17c) and with the 0.17.2 release. I am using stable Rust 1.70.0, which is chosen automatically when running the examples.

Please let me know if I can do anything to help debug this!

Repro steps
Clone repository, run cargo run --bin cube.

Expected vs observed behavior
I expected no error messages in the terminal. Instead I get tons.

Extra materials
N/A

Platform
System info from Bevy:

2023-10-16T18:05:09.654565Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon RX 6700 XT", vendor: 4098, device: 29663, device_type: DiscreteGpu, driver: "AMD proprietary driver", driver_info: "23.9.3 (AMD proprietary shader compiler)", backend: Vulkan }
2023-10-16T18:05:09.818072Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 10 Pro", kernel: "19045", cpu: "12th Gen Intel(R) Core(TM) i7-12700", core_count: "12", memory: "31.8 GiB" }
@AlfredAn AlfredAn changed the title dxgi exception when running examples dxgi exception with Vulkan backend on Windows Oct 16, 2023
@cwfitzgerald
Copy link
Member

So this is a "bug" in AMD's vulkan swapchain (it's debatable if it's actually a bug, or just something their card doesn't care about) when based on top of a DXGI swapchain. Recently, AMD started using DXGI swapchains all the time, not just on HDR monitors. I believe there is a fix by routing error messages through ID3D12InfoQueue instead of hooking the general windows error message scheme like we do now. (The error would still happen, it just wouldn't be for one of our devices).

WGPU_BACKEND=vulkan works because it doesn't initialize the d3d12 backend, and never hooks windows errors, so we never see this.

@AlfredAn
Copy link
Author

So this is a "bug" in AMD's vulkan swapchain (it's debatable if it's actually a bug, or just something their card doesn't care about) when based on top of a DXGI swapchain. Recently, AMD started using DXGI swapchains all the time, not just on HDR monitors. I believe there is a fix by routing error messages through ID3D12InfoQueue instead of hooking the general windows error message scheme like we do now. (The error would still happen, it just wouldn't be for one of our devices).

WGPU_BACKEND=vulkan works because it doesn't initialize the d3d12 backend, and never hooks windows errors, so we never see this.

Thanks for the answer! Will this affect release builds in any way or can I just set the environment variable when testing and not worry about it?

@cwfitzgerald
Copy link
Member

It shouldn't actually affect anything, is just kinda loud and annoying.

@DasLixou
Copy link

Same here

@cwfitzgerald
Copy link
Member

This could be improved by using the new dx12 api: https://microsoft.github.io/DirectX-Specs/d3d/MessageCallback.html#id3d12infoqueue1

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 type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants