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

Using two encoders in hello-triangle example causes hang #1877

Closed
fintelia opened this issue Aug 28, 2021 · 6 comments
Closed

Using two encoders in hello-triangle example causes hang #1877

fintelia opened this issue Aug 28, 2021 · 6 comments
Labels
area: correctness We're behaving incorrectly help required We need community help to make this happen. type: bug Something isn't working

Comments

@fintelia
Copy link
Contributor

Description
Wgpu hangs when rendering a frame that involved multiple consecutive command encoders. This patch to the hello-triangle example is enough to trigger the bug.

Repro steps

$ git clone https://github.com/fintelia/wgpu && cd wgpu
$ git checkout double-encoder-hang
$ cd wgpu
$ cargo run --example hello-triangle

Expected vs observed behavior
Expected hello-triangle example to run normally. Instead it displays all black and the window cannot be closed.

Platform

  • Arch Linux
  • Intel integrated GPU
  • wgpu commit 39e8921
@fintelia
Copy link
Contributor Author

fintelia commented Aug 30, 2021

Using git bisect I've narrowed down this regression to being caused by 5419947:

$ git checkout 39e8921
$ git bisect start
$ git bisect bad
$ git bisect good 91437ea7
$ git bisect test.sh
test.sh
#!/bin/bash

cat >test.patch << EOF
diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs
index 4d27af83..25cfef21 100644
--- a/wgpu/examples/hello-triangle/main.rs
+++ b/wgpu/examples/hello-triangle/main.rs
@@ -95,6 +95,11 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
                     .get_current_frame()
                     .expect("Failed to acquire next swap chain texture")
                     .output;
+
+                *control_flow = ControlFlow::Exit;
+                let e2 = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
+                queue.submit(Some(e2.finish()));
+
                 let mut encoder =
                     device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
                 {
EOF

cd wgpu/examples
if git apply test.patch && cargo build --example hello-triangle
then
	# run project specific test and report its status
    timeout 15 cargo run --example hello-triangle
	status=$?
else
	# tell the caller this is untestable
	status=125
fi
cd ../..

# undo the tweak to allow clean flipping to the next commit
git reset --hard

# return control
exit $status

@kvark
Copy link
Member

kvark commented Aug 30, 2021

Thank you for investigating!
I wonder if our use of the relay semaphore is incorrect. Vulkan validation has a new experimental option for synchronization, so that could be the next step to enable and see.

@kvark kvark added area: correctness We're behaving incorrectly help required We need community help to make this happen. type: bug Something isn't working labels Aug 30, 2021
@fintelia
Copy link
Contributor Author

I just tried running with the validation layers included with SDK version 1.2.182.0, but they produced no output. Here is a copy of the API dump. The hang seems to be happening during the call to vkQueuePresentKHR, which matches the backtrace I got when pausing in a debugger.

api_dump.txt

@kvark
Copy link
Member

kvark commented Sep 2, 2021

Not seeing any issue with this on Linux/NV
Edit: also no issues on Windows/Intel 550 ...

@mrk-its
Copy link
Contributor

mrk-its commented Sep 2, 2021

Ubuntu 20.04.2, HD Graphics 630 (KBL GT2)

I've just tried to reproduce this and I have black window not reacting on events for ~8 seconds, then triangle is displayed (and window can be closed). But it seems it is not related to 'using two encoders', I have the same behavior also on current wgpu master. When I force GL backend instead of VULCAN it works fine (triangle is displayed immediately)

@fintelia
Copy link
Contributor Author

fintelia commented Sep 2, 2021

I'm using an Intel® HD Graphics 520 iGPU with mesa 21.2.1-1. There's no other GPU so the linked PR doesn't seem applicable.

However reading #1672, I think this might be a duplicate of that given that the hang in vkQueuePresentKHR is during an ioctl

gridbugs added a commit to gridbugs/chargrid that referenced this issue Sep 3, 2021
This is to work around a problem in wgpu on intel gpus which causes
hanging while dropping resources.

More info:
 - gfx-rs/wgpu#1877
 - gfx-rs/wgpu#1672
@kvark kvark closed this as completed Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: correctness We're behaving incorrectly help required We need community help to make this happen. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants