mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #27570 - kunalmohan:gpu-uncaptured-error, r=kvark
Implement GPUUncapturedErrorEvent <!-- Please describe your changes on the following line: --> A new `uncapturederror` variant is added to atoms/static-atoms.txt. `GPUUncapturedErrorEvent` is fired when an error is not captured by any `ErrorScope`. All tests for error scopes `PASS` now. r?@kvark --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
72c9b1c380
7 changed files with 136 additions and 16 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -6955,7 +6955,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wgpu-core"
|
name = "wgpu-core"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "git+https://github.com/gfx-rs/wgpu#8057acf120f9944056a6b5de6cf326f18ae7671d"
|
source = "git+https://github.com/gfx-rs/wgpu#430b29d781200009ef02839e41136718ff62456a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.5.1",
|
"arrayvec 0.5.1",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
@ -6982,7 +6982,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wgpu-types"
|
name = "wgpu-types"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "git+https://github.com/gfx-rs/wgpu#8057acf120f9944056a6b5de6cf326f18ae7671d"
|
source = "git+https://github.com/gfx-rs/wgpu#430b29d781200009ef02839e41136718ff62456a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -137,6 +137,7 @@ transitioncancel
|
||||||
transitionend
|
transitionend
|
||||||
transitionrun
|
transitionrun
|
||||||
transitionstart
|
transitionstart
|
||||||
|
uncapturederror
|
||||||
unhandledrejection
|
unhandledrejection
|
||||||
unload
|
unload
|
||||||
url
|
url
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#![allow(unsafe_code)]
|
#![allow(unsafe_code)]
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::EventBinding::EventInit;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUBindGroupBinding::{
|
use crate::dom::bindings::codegen::Bindings::GPUBindGroupBinding::{
|
||||||
GPUBindGroupDescriptor, GPUBindingResource,
|
GPUBindGroupDescriptor, GPUBindingResource,
|
||||||
};
|
};
|
||||||
|
@ -32,6 +34,7 @@ use crate::dom::bindings::codegen::Bindings::GPUTextureBinding::{
|
||||||
GPUTextureDimension, GPUTextureFormat,
|
GPUTextureDimension, GPUTextureFormat,
|
||||||
};
|
};
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUTextureViewBinding::GPUTextureViewDimension;
|
use crate::dom::bindings::codegen::Bindings::GPUTextureViewBinding::GPUTextureViewDimension;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::GPUUncapturedErrorEventBinding::GPUUncapturedErrorEventInit;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUValidationErrorBinding::{
|
use crate::dom::bindings::codegen::Bindings::GPUValidationErrorBinding::{
|
||||||
GPUError, GPUErrorFilter,
|
GPUError, GPUErrorFilter,
|
||||||
};
|
};
|
||||||
|
@ -57,6 +60,7 @@ use crate::dom::gpurenderpipeline::GPURenderPipeline;
|
||||||
use crate::dom::gpusampler::GPUSampler;
|
use crate::dom::gpusampler::GPUSampler;
|
||||||
use crate::dom::gpushadermodule::GPUShaderModule;
|
use crate::dom::gpushadermodule::GPUShaderModule;
|
||||||
use crate::dom::gputexture::GPUTexture;
|
use crate::dom::gputexture::GPUTexture;
|
||||||
|
use crate::dom::gpuuncapturederrorevent::GPUUncapturedErrorEvent;
|
||||||
use crate::dom::gpuvalidationerror::GPUValidationError;
|
use crate::dom::gpuvalidationerror::GPUValidationError;
|
||||||
use crate::dom::promise::Promise;
|
use crate::dom::promise::Promise;
|
||||||
use crate::realms::InRealm;
|
use crate::realms::InRealm;
|
||||||
|
@ -76,7 +80,7 @@ use webgpu::{self, identity::WebGPUOpResult, wgt, ErrorScopeId, WebGPU, WebGPURe
|
||||||
#[derive(JSTraceable, MallocSizeOf)]
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
struct ErrorScopeInfo {
|
struct ErrorScopeInfo {
|
||||||
op_count: u64,
|
op_count: u64,
|
||||||
#[ignore_malloc_size_of = "defined in webgpu"]
|
#[ignore_malloc_size_of = "Because it is non-owning"]
|
||||||
error: Option<GPUError>,
|
error: Option<GPUError>,
|
||||||
#[ignore_malloc_size_of = "promises are hard"]
|
#[ignore_malloc_size_of = "promises are hard"]
|
||||||
promise: Option<Rc<Promise>>,
|
promise: Option<Rc<Promise>>,
|
||||||
|
@ -201,12 +205,14 @@ impl GPUDevice {
|
||||||
if let Some(s) = scop {
|
if let Some(s) = scop {
|
||||||
self.handle_error(s, err);
|
self.handle_error(s, err);
|
||||||
} else {
|
} else {
|
||||||
// Fire UncapturedErrorEvent.
|
self.fire_uncaptured_error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.try_remove_scope(s_id);
|
self.try_remove_scope(s_id);
|
||||||
} else {
|
} else {
|
||||||
// Fire UncapturedErrorEvent if result is Error
|
if let Err((err, _)) = result {
|
||||||
|
self.fire_uncaptured_error(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,10 +234,7 @@ impl GPUDevice {
|
||||||
if let Some(ref promise) = err_scope.promise {
|
if let Some(ref promise) = err_scope.promise {
|
||||||
if !promise.is_fulfilled() {
|
if !promise.is_fulfilled() {
|
||||||
if let Some(ref e) = err_scope.error {
|
if let Some(ref e) = err_scope.error {
|
||||||
match e {
|
promise.resolve_native(e);
|
||||||
GPUError::GPUValidationError(v) => promise.resolve_native(&v),
|
|
||||||
GPUError::GPUOutOfMemoryError(w) => promise.resolve_native(&w),
|
|
||||||
}
|
|
||||||
} else if err_scope.op_count == 0 {
|
} else if err_scope.op_count == 0 {
|
||||||
promise.resolve_native(&None::<GPUError>);
|
promise.resolve_native(&None::<GPUError>);
|
||||||
}
|
}
|
||||||
|
@ -248,6 +251,18 @@ impl GPUDevice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fire_uncaptured_error(&self, err: GPUError) {
|
||||||
|
let ev = GPUUncapturedErrorEvent::new(
|
||||||
|
&self.global(),
|
||||||
|
DOMString::from("uncapturederror"),
|
||||||
|
&GPUUncapturedErrorEventInit {
|
||||||
|
error: err,
|
||||||
|
parent: EventInit::empty(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let _ = self.eventtarget.DispatchEvent(ev.event());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn use_current_scope(&self) -> Option<ErrorScopeId> {
|
pub fn use_current_scope(&self) -> Option<ErrorScopeId> {
|
||||||
let mut context = self.scope_context.borrow_mut();
|
let mut context = self.scope_context.borrow_mut();
|
||||||
let scope_id = context
|
let scope_id = context
|
||||||
|
@ -1051,10 +1066,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
};
|
};
|
||||||
let remove = if let Some(mut err_scope) = context.error_scopes.get_mut(&scope_id) {
|
let remove = if let Some(mut err_scope) = context.error_scopes.get_mut(&scope_id) {
|
||||||
if let Some(ref e) = err_scope.error {
|
if let Some(ref e) = err_scope.error {
|
||||||
match e {
|
promise.resolve_native(e);
|
||||||
GPUError::GPUValidationError(ref v) => promise.resolve_native(&v),
|
|
||||||
GPUError::GPUOutOfMemoryError(ref w) => promise.resolve_native(&w),
|
|
||||||
}
|
|
||||||
} else if err_scope.op_count == 0 {
|
} else if err_scope.op_count == 0 {
|
||||||
promise.resolve_native(&None::<GPUError>);
|
promise.resolve_native(&None::<GPUError>);
|
||||||
}
|
}
|
||||||
|
@ -1070,6 +1082,9 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
}
|
}
|
||||||
promise
|
promise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-onuncapturederror
|
||||||
|
event_handler!(uncapturederror, GetOnuncapturederror, SetOnuncapturederror);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_address_mode(address_mode: GPUAddressMode) -> wgt::AddressMode {
|
fn convert_address_mode(address_mode: GPUAddressMode) -> wgt::AddressMode {
|
||||||
|
|
84
components/script/dom/gpuuncapturederrorevent.rs
Normal file
84
components/script/dom/gpuuncapturederrorevent.rs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use crate::dom::bindings::codegen::Bindings::EventBinding::EventBinding::EventMethods;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::GPUUncapturedErrorEventBinding::{
|
||||||
|
GPUUncapturedErrorEventInit, GPUUncapturedErrorEventMethods,
|
||||||
|
};
|
||||||
|
use crate::dom::bindings::codegen::Bindings::GPUValidationErrorBinding::GPUError;
|
||||||
|
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||||
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
use crate::dom::bindings::str::DOMString;
|
||||||
|
use crate::dom::event::Event;
|
||||||
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
use dom_struct::dom_struct;
|
||||||
|
use servo_atoms::Atom;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct GPUUncapturedErrorEvent {
|
||||||
|
event: Event,
|
||||||
|
#[ignore_malloc_size_of = "Because it is non-owning"]
|
||||||
|
gpu_error: GPUError,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GPUUncapturedErrorEvent {
|
||||||
|
fn new_inherited(init: &GPUUncapturedErrorEventInit) -> Self {
|
||||||
|
Self {
|
||||||
|
gpu_error: clone_gpu_error(&init.error),
|
||||||
|
event: Event::new_inherited(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(
|
||||||
|
global: &GlobalScope,
|
||||||
|
type_: DOMString,
|
||||||
|
init: &GPUUncapturedErrorEventInit,
|
||||||
|
) -> DomRoot<Self> {
|
||||||
|
let ev = reflect_dom_object(
|
||||||
|
Box::new(GPUUncapturedErrorEvent::new_inherited(init)),
|
||||||
|
global,
|
||||||
|
);
|
||||||
|
ev.event.init_event(
|
||||||
|
Atom::from(type_),
|
||||||
|
init.parent.bubbles,
|
||||||
|
init.parent.cancelable,
|
||||||
|
);
|
||||||
|
ev
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://gpuweb.github.io/gpuweb/#dom-gpuuncapturederrorevent-gpuuncapturederrorevent
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub fn Constructor(
|
||||||
|
global: &GlobalScope,
|
||||||
|
type_: DOMString,
|
||||||
|
init: &GPUUncapturedErrorEventInit,
|
||||||
|
) -> DomRoot<Self> {
|
||||||
|
GPUUncapturedErrorEvent::new(global, type_, init)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GPUUncapturedErrorEvent {
|
||||||
|
pub fn event(&self) -> &Event {
|
||||||
|
&self.event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GPUUncapturedErrorEventMethods for GPUUncapturedErrorEvent {
|
||||||
|
/// https://gpuweb.github.io/gpuweb/#dom-gpuuncapturederrorevent-error
|
||||||
|
fn Error(&self) -> GPUError {
|
||||||
|
clone_gpu_error(&self.gpu_error)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://dom.spec.whatwg.org/#dom-event-istrusted
|
||||||
|
fn IsTrusted(&self) -> bool {
|
||||||
|
self.event.IsTrusted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_gpu_error(error: &GPUError) -> GPUError {
|
||||||
|
match *error {
|
||||||
|
GPUError::GPUValidationError(ref v) => GPUError::GPUValidationError(v.clone()),
|
||||||
|
GPUError::GPUOutOfMemoryError(ref w) => GPUError::GPUOutOfMemoryError(w.clone()),
|
||||||
|
}
|
||||||
|
}
|
|
@ -349,6 +349,7 @@ pub mod gpuswapchain;
|
||||||
pub mod gputexture;
|
pub mod gputexture;
|
||||||
pub mod gputextureusage;
|
pub mod gputextureusage;
|
||||||
pub mod gputextureview;
|
pub mod gputextureview;
|
||||||
|
pub mod gpuuncapturederrorevent;
|
||||||
pub mod gpuvalidationerror;
|
pub mod gpuvalidationerror;
|
||||||
pub mod hashchangeevent;
|
pub mod hashchangeevent;
|
||||||
pub mod headers;
|
pub mod headers;
|
||||||
|
|
22
components/script/dom/webidls/GPUUncapturedErrorEvent.webidl
Normal file
22
components/script/dom/webidls/GPUUncapturedErrorEvent.webidl
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
// https://gpuweb.github.io/gpuweb/#gpuuncapturederrorevent
|
||||||
|
[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
|
||||||
|
interface GPUUncapturedErrorEvent : Event {
|
||||||
|
constructor(
|
||||||
|
DOMString type,
|
||||||
|
GPUUncapturedErrorEventInit gpuUncapturedErrorEventInitDict
|
||||||
|
);
|
||||||
|
/*[SameObject]*/ readonly attribute GPUError error;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary GPUUncapturedErrorEventInit : EventInit {
|
||||||
|
required GPUError error;
|
||||||
|
};
|
||||||
|
|
||||||
|
partial interface GPUDevice {
|
||||||
|
[Exposed=(Window, DedicatedWorker)]
|
||||||
|
attribute EventHandler onuncapturederror;
|
||||||
|
};
|
|
@ -137,9 +137,6 @@
|
||||||
|
|
||||||
|
|
||||||
[cts.html?q=webgpu:api,validation,error_scope:*]
|
[cts.html?q=webgpu:api,validation,error_scope:*]
|
||||||
[webgpu:api,validation,error_scope:if_no_error_scope_handles_an_error_it_fires_an_uncapturederror_event:]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[cts.html?q=webgpu:api,validation,resource_usages,textureUsageInRender:*]
|
[cts.html?q=webgpu:api,validation,resource_usages,textureUsageInRender:*]
|
||||||
expected: CRASH
|
expected: CRASH
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue