Skip to content

webgpu: Implement device lost - #32354

Merged
sagudev merged 5 commits into
servo:mainfrom
sagudev:device-lost
Jun 17, 2024
Merged

sagudev merged 5 commits into
servo:mainfrom
sagudev:device-lost

Conversation

@sagudev

@sagudev sagudev commented May 23, 2024 •

Copy link
Copy Markdown
Member

Due to hitting multiple deadlocks in wgpu I added lock to prevent some functions (queue_write_texture, queue_submit) run in parallel with device_poll in poller thread d9d506c (and thus avoiding deadlocks).


@sagudev sagudev added the A-content/webgpu The WebGPU implementation. label May 23, 2024
@sagudev

sagudev commented May 23, 2024

Copy link
Copy Markdown
Member Author

@sagudev

sagudev commented May 23, 2024

Copy link
Copy Markdown
Member Author

I think I will not deal with _webgpu/webgpu/cts.https.html?q=webgpu:api,operation,adapter,requestDevice:invalid:* in this PR as wgpu-core allows creating multiple valid devices from same adapter, but spec doesn't.

@sagudev

sagudev commented May 23, 2024

Copy link
Copy Markdown
Member Author

new run: https://github.com/sagudev/servo/actions/runs/9211814858/job/25343380939
_webgpu/webgpu/cts.https.html?q=webgpu:api,validation,state,device_lost,destroy has (only in CI):

PASS [expected TIMEOUT] subtest: :stage="finish";awaitLost=true
PASS [expected NOTRUN] subtest: :stage="finish";awaitLost=false
PASS [expected NOTRUN] subtest: :stage="submit";awaitLost=true
FAIL [expected NOTRUN] subtest: :stage="submit";awaitLost=false

assert_unreached: 
  - EXCEPTION: endTestScope timed out
    PromiseTimeoutError@https://web-platform.test:8443/_webgpu/webgpu/common/util/util.js:114:8
    raceWithRejectOnTimeout/timeoutPromise</handle<@https://web-platform.test:8443/_webgpu/webgpu/common/util/util.js:140:14
    step_timeout/<@https://web-platform.test:8443/resources/testharness.js:1234:18
    
 Reached unreachable code

_webgpu/webgpu/cts.https.html?q=webgpu:api,validation,state,device_lost,destroy:command,renderPass,renderBundle:* is crashing now (instead of timeout), but it's out of scope of this PR.

@sagudev

sagudev commented May 24, 2024

Copy link
Copy Markdown
Member Author

endTestScope timed out are happening because WGPU thread is stuck in deadlock: gfx-rs/wgpu#5737

@sagudev

sagudev commented May 24, 2024

Copy link
Copy Markdown
Member Author

As a temporary solution for wgpu's deadlocks I added mutex fence before queue_submit and poll_all_devices.

@sagudev

sagudev commented May 28, 2024 •

Copy link
Copy Markdown
Member Author

When applying some expectations I get: https://github.com/sagudev/servo/actions/runs/9271180193/job/25507347414

_webgpu/webgpu/cts.https.html?q=webgpu:api,validation,state,device_lost,destroy:createComputePipelineAsync:* and _webgpu/webgpu/cts.https.html?q=webgpu:api,validation,state,device_lost,destroy:createRenderPipelineAsync:* is due to #31591

_webgpu/webgpu/cts.https.html?q=webgpu:api,validation,state,device_lost,destroy:queue,writeTexture,2d,uncompressed_format:* has flaky timeout that I have yet to investigate.

@sagudev
sagudev force-pushed the device-lost branch 2 times, most recently from da159b6 to 8e5a370 Compare June 3, 2024 05:38
@sagudev

sagudev commented Jun 12, 2024 •

Copy link
Copy Markdown
Member Author

_webgpu/webgpu/cts.https.html?q=webgpu:api,validation,state,device_lost,destroy:queue,writeTexture,2d,uncompressed_format:* has flaky timeout that I have yet to investigate.

This is another deadlock in wgpu: gfx-rs/wgpu#5737 (comment)

EDIT: but it's still happening so there must be more, likely gfx-rs/wgpu#5807 (comment)

sagudev added 2 commits June 12, 2024 19:31
workaround for wgpu deadlocks
@sagudev
sagudev marked this pull request as ready for review June 13, 2024 08:21
@sagudev

sagudev commented Jun 13, 2024

Copy link
Copy Markdown
Member Author

I've been blocking this long enough on webgpu:api,validation,state,device_lost,destroy:queue,writeTexture,2d,* flaky timeouts, that are clearly wgpu problems.

@sagudev
sagudev requested a review from gterzian June 13, 2024 08:22
@gterzian

Copy link
Copy Markdown
Member

Will review tomorrow!

@gterzian gterzian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I don't think we need to propagate all the lost reasons.

device: webgpu::WebGPUDevice,
queue: &GPUQueue,
label: String,
lost_promise: Rc<Promise>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure exactly what you meant here, but this promise is created in new, that calls new_inherited.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, ok.

Comment thread components/webgpu/script_messages.rs Resolved
Comment thread components/webgpu/script_messages.rs Resolved
pub fn lose(&self, reason: GPUDeviceLostReason, msg: String) {
let ref lost_promise = *self.lost_promise.borrow();
let global = &self.global();
let lost = GPUDeviceLostInfo::new(global, msg.into(), reason);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we necessarily should propagate the message here, see the note in https://gpuweb.github.io/gpuweb/#lose-the-device

In our case we don't even know what is in the message, so we cannot guarantee that it does not leak system info.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the experimental nature of servo (and even more experimental WebGPU support) I chose more (servo/wgpu) developer friendly approach by propagate wgpu error messages.

Comment thread components/script/dom/globalscope.rs Resolved
@sagudev

sagudev commented Jun 14, 2024 •

Copy link
Copy Markdown
Member Author

Lifetime of GPUDevice still bugs me, global scope has hashmap of Dom<GPUDevice> that keeps GPUDevice alive unless GPUDevice is manually destroyed, so we should probably use weakref in hashmap: https://doc.servo.org/script/dom/bindings/weakref/index.html, but this can be done as a follow up (this problem also exist on main).

EDIT There is also draft of better GPUDevice cleanup in webgpu project board: WebGPU (view)

@sagudev
sagudev requested a review from gterzian June 14, 2024 14:43

@gterzian gterzian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

we should probably use weakref in hashmap

Add a note before merging?

@sagudev

sagudev commented Jun 17, 2024

Copy link
Copy Markdown
Member Author

we should probably use weakref in hashmap

Add a note before merging?

I opened #32519 and assigned myself as I already have WIP.

@sagudev
sagudev added this pull request to the merge queue Jun 17, 2024
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 17, 2024
@sagudev
sagudev added this pull request to the merge queue Jun 17, 2024
Merged via the queue into servo:main with commit cbc9304 Jun 17, 2024
@sagudev
sagudev deleted the device-lost branch June 17, 2024 13:43
sagudev added a commit to sagudev/servo that referenced this pull request Jun 17, 2024
{"fail_fast": false, "matrix": [{"name": "WebGPU CTS", "workflow": "linux", "wpt_layout": "2020", "profile": "production", "unit_tests": false, "wpt_tests_to_run": "_webgpu"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-content/webgpu The WebGPU implementation.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants