wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

feat: add `wgpu_types::error::{ErrorType, WebGpuError}`, use them to classify errors in `wgpu` and `deno_webgpu`

Open ErichDonGubler opened this issue 1 year ago • 3 comments

Recommended review experience:

  • This is a rebase-friendly history, so you should be able to review commit-by-commit.
  • For your first pass, you might be tempted to focus on whether the classification of errors (i.e., the bodies of WebGpuError implementations) is correct or not. This is the vast majority of the review, but also the easiest to fix if we get something wrong; I recommend looking at the plumbing first, and then reviewing the myriad implementations of WebGpuError afterward.

Connections

Description

Manually classify each and every error type that wgpu and deno_webgpu report their classification as WebGPU errors (ErrorTypes) using a new WebGpuError trait. These are defined as:

pub enum ErrorType {
    Internal {
        device_lost: bool,
    },
    OutOfMemory,
    Validation,
}

pub trait WebGpuError: core::error::Error + 'static {
    fn webgpu_error_type(&self) -> ErrorType;
}

ErrorType and core::error::Error should now be the only APIs necessary to construct the correspondent errors in an implementation of WebGPU; this is now what happens in wgpu and deno_webgpu.

Testing

CI mostly passes, modulo some bugs that have been exposed and worked around in this PR. They have been reported separately for follow-up, with comments in code making them clear follow-up work.

Checklist

  • [x] Add change to CHANGELOG.md. See simple instructions inside file.

ErichDonGubler avatar Nov 14 '24 22:11 ErichDonGubler

I noticed we have a bunch of variants that are unused; I opened https://github.com/gfx-rs/wgpu/pull/6550 rather than commenting here about all of them.

teoxoy avatar Nov 15 '24 10:11 teoxoy

This will simplify error handling in servo too, currently we hack it: https://github.com/servo/servo/blob/ee63174d6ff0b3b7d9b255fc47c72a82ae63bc09/components/webgpu/gpu_error.rs#L76

That reminds me this should also be used for classification in wgpu: https://github.com/gfx-rs/wgpu/blob/c110bf22d811ac1a65d79375e4cfa2313787e3bc/wgpu/src/backend/wgpu_core.rs#L267-L300

sagudev avatar Nov 16 '24 06:11 sagudev

This will simplify error handling in servo too, currently we hack it: servo/servo@ee63174/components/webgpu/gpu_error.rs#L76

That reminds me this should also be used for classification in wgpu:

https://github.com/gfx-rs/wgpu/blob/c110bf22d811ac1a65d79375e4cfa2313787e3bc/wgpu/src/backend/wgpu_core.rs#L267-L300

@sagudev: I've now implemented this, and it exposes a couple of issues I'll be filing. Nice!

ErichDonGubler avatar Jun 13 '25 02:06 ErichDonGubler

@teoxoy: Just rebased, and that had some compile errors. These have been resolved with 30da56de, 66825c9, and 2b918447.

ErichDonGubler avatar Jun 27 '25 15:06 ErichDonGubler