diff options
author | Zakor <gyula.zakor@h-lab.eu> | 2020-02-03 17:25:01 +0100 |
---|---|---|
committer | Istvan Miklos <istvan.miklos@h-lab.eu> | 2020-02-13 14:37:25 +0100 |
commit | a3c6810b1850d5b8ce29af2f745058b94a39bb80 (patch) | |
tree | 0daf3fc9302386ef29d9066200faf381b61444b0 /components/script/dom/gpuqueue.rs | |
parent | 0790c856d5c376a0839347a3f0d4e4f7b07779c6 (diff) | |
download | servo-a3c6810b1850d5b8ce29af2f745058b94a39bb80.tar.gz servo-a3c6810b1850d5b8ce29af2f745058b94a39bb80.zip |
Initial implementation of GPUQueue
Added WebIDL bindings for `GPUQueue`.
Implemented the `submit` function of `GPUQueue` and `defaultQueue` function of `GPUDevice`.
Diffstat (limited to 'components/script/dom/gpuqueue.rs')
-rw-r--r-- | components/script/dom/gpuqueue.rs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/components/script/dom/gpuqueue.rs b/components/script/dom/gpuqueue.rs new file mode 100644 index 00000000000..dfa97402253 --- /dev/null +++ b/components/script/dom/gpuqueue.rs @@ -0,0 +1,73 @@ +/* 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::cell::DomRefCell; +use crate::dom::bindings::codegen::Bindings::GPUQueueBinding::{self, GPUQueueMethods}; +use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; +use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::str::DOMString; +use crate::dom::globalscope::GlobalScope; +use crate::dom::gpubuffer::GPUBufferState; +use crate::dom::gpucommandbuffer::GPUCommandBuffer; +use dom_struct::dom_struct; +use webgpu::{WebGPU, WebGPUQueue, WebGPURequest}; + +#[dom_struct] +pub struct GPUQueue { + reflector_: Reflector, + #[ignore_malloc_size_of = "defined in webgpu"] + channel: WebGPU, + label: DomRefCell<Option<DOMString>>, + queue: WebGPUQueue, +} + +impl GPUQueue { + fn new_inherited(channel: WebGPU, queue: WebGPUQueue) -> GPUQueue { + GPUQueue { + channel, + reflector_: Reflector::new(), + label: DomRefCell::new(None), + queue, + } + } + + pub fn new(global: &GlobalScope, channel: WebGPU, queue: WebGPUQueue) -> DomRoot<GPUQueue> { + reflect_dom_object( + Box::new(GPUQueue::new_inherited(channel, queue)), + global, + GPUQueueBinding::Wrap, + ) + } +} + +impl GPUQueueMethods for GPUQueue { + /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label + fn GetLabel(&self) -> Option<DOMString> { + self.label.borrow().clone() + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label + fn SetLabel(&self, value: Option<DOMString>) { + *self.label.borrow_mut() = value; + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpuqueue-submit + fn Submit(&self, command_buffers: Vec<DomRoot<GPUCommandBuffer>>) { + let valid = command_buffers.iter().all(|cb| { + cb.buffers().iter().all(|b| match *b.state() { + GPUBufferState::Unmapped => true, + _ => false, + }) + }); + if !valid { + // TODO: Generate error to the ErrorScope + return; + } + let buffer_ids = command_buffers.iter().map(|cb| cb.id().0).collect(); + self.channel + .0 + .send(WebGPURequest::Submit(self.queue.0, buffer_ids)) + .unwrap(); + } +} |