mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
webgpu: Implement onSubmittedWorkDone (#31772)
* Implement onSubmittedWorkDone * Use rust closures for callback & actually remove entries from hashmap. * Remove hashmap * Fix warnings * Update expectations * clean flaky crashes * re * Update components/script/dom/gpuqueue.rs Co-authored-by: Martin Robinson <mrobinson@igalia.com> --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
08ef158d4e
commit
62a916ce5c
6 changed files with 1442 additions and 3109 deletions
|
@ -2,19 +2,22 @@
|
|||
* 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 std::rc::Rc;
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use ipc_channel::ipc::IpcSharedMemory;
|
||||
use webgpu::identity::WebGPUOpResult;
|
||||
use webgpu::{wgt, WebGPU, WebGPUQueue, WebGPURequest};
|
||||
use webgpu::{wgt, WebGPU, WebGPUQueue, WebGPURequest, WebGPUResponse};
|
||||
|
||||
use super::bindings::codegen::Bindings::WebGPUBinding::{GPUImageCopyTexture, GPUImageDataLayout};
|
||||
use super::gpu::{response_async, AsyncWGPUListener};
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||
GPUExtent3D, GPUQueueMethods, GPUSize64,
|
||||
};
|
||||
use crate::dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer as BufferSource;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
@ -25,6 +28,7 @@ use crate::dom::gpuconvert::{
|
|||
convert_texture_size_to_wgt,
|
||||
};
|
||||
use crate::dom::gpudevice::GPUDevice;
|
||||
use crate::dom::promise::Promise;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct GPUQueue {
|
||||
|
@ -191,4 +195,39 @@ impl GPUQueueMethods for GPUQueue {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpuqueue-onsubmittedworkdone>
|
||||
fn OnSubmittedWorkDone(&self) -> Rc<Promise> {
|
||||
let global = self.global();
|
||||
let promise = Promise::new(&global);
|
||||
let sender = response_async(&promise, self);
|
||||
if let Err(e) = self.channel.0.send((
|
||||
self.device.borrow().as_ref().unwrap().use_current_scope(),
|
||||
WebGPURequest::QueueOnSubmittedWorkDone {
|
||||
sender,
|
||||
queue_id: self.queue.0,
|
||||
},
|
||||
)) {
|
||||
warn!("QueueOnSubmittedWorkDone failed with {e}")
|
||||
}
|
||||
promise
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncWGPUListener for GPUQueue {
|
||||
fn handle_response(
|
||||
&self,
|
||||
response: Option<Result<webgpu::WebGPUResponse, String>>,
|
||||
promise: &Rc<Promise>,
|
||||
) {
|
||||
match response {
|
||||
Some(Ok(WebGPUResponse::SubmittedWorkDone)) => {
|
||||
promise.resolve_native(&());
|
||||
},
|
||||
_ => {
|
||||
warn!("GPUQueue received wrong WebGPUResponse");
|
||||
promise.reject_error(Error::Operation);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue