From 4facd3d4d21d131a222d3f44d5e8d077612f30e7 Mon Sep 17 00:00:00 2001 From: Zakor Gyula Date: Tue, 14 Jan 2020 08:54:08 +0100 Subject: Initial implementation of GPUCommandEncoder Added WebIDL bindings for `GPUCommandEncoder`, `GPUCommandBuffer`, `GPUComputePassEncoder`, `GPUProgrammablePassEncoder`. Implemented the `beginComputePass`, `copyBufferToBuffer` and `finish` functions of `GPUCommandEncoder`. Implemented the `createCommandEncoder` function of `GPUDevice`. --- components/script/dom/gpucommandbuffer.rs | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 components/script/dom/gpucommandbuffer.rs (limited to 'components/script/dom/gpucommandbuffer.rs') diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs new file mode 100644 index 00000000000..5cc4c926547 --- /dev/null +++ b/components/script/dom/gpucommandbuffer.rs @@ -0,0 +1,58 @@ +/* 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::GPUCommandBufferBinding::{ + self, GPUCommandBufferMethods, +}; +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 dom_struct::dom_struct; +use webgpu::{WebGPU, WebGPUCommandBuffer}; + +#[dom_struct] +pub struct GPUCommandBuffer { + reflector_: Reflector, + #[ignore_malloc_size_of = "defined in webgpu"] + channel: WebGPU, + label: DomRefCell>, + command_buffer: WebGPUCommandBuffer, +} + +impl GPUCommandBuffer { + pub fn new_inherited(channel: WebGPU, command_buffer: WebGPUCommandBuffer) -> GPUCommandBuffer { + GPUCommandBuffer { + channel, + reflector_: Reflector::new(), + label: DomRefCell::new(None), + command_buffer, + } + } + + pub fn new( + global: &GlobalScope, + channel: WebGPU, + command_buffer: WebGPUCommandBuffer, + ) -> DomRoot { + reflect_dom_object( + Box::new(GPUCommandBuffer::new_inherited(channel, command_buffer)), + global, + GPUCommandBufferBinding::Wrap, + ) + } +} + +impl GPUCommandBufferMethods for GPUCommandBuffer { + /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label + fn GetLabel(&self) -> Option { + self.label.borrow().clone() + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label + fn SetLabel(&self, value: Option) { + *self.label.borrow_mut() = value; + } +} -- cgit v1.2.3 From a3c6810b1850d5b8ce29af2f745058b94a39bb80 Mon Sep 17 00:00:00 2001 From: Zakor Date: Mon, 3 Feb 2020 17:25:01 +0100 Subject: Initial implementation of GPUQueue Added WebIDL bindings for `GPUQueue`. Implemented the `submit` function of `GPUQueue` and `defaultQueue` function of `GPUDevice`. --- components/script/dom/gpucommandbuffer.rs | 38 ++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'components/script/dom/gpucommandbuffer.rs') diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs index 5cc4c926547..24cd781c092 100644 --- a/components/script/dom/gpucommandbuffer.rs +++ b/components/script/dom/gpucommandbuffer.rs @@ -2,17 +2,28 @@ * 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::cell::{DomRefCell, Ref}; use crate::dom::bindings::codegen::Bindings::GPUCommandBufferBinding::{ self, GPUCommandBufferMethods, }; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; +use crate::dom::bindings::root::Dom; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::DOMString; use crate::dom::globalscope::GlobalScope; +use crate::dom::gpubuffer::GPUBuffer; use dom_struct::dom_struct; +use std::collections::HashSet; +use std::hash::{Hash, Hasher}; use webgpu::{WebGPU, WebGPUCommandBuffer}; +impl Eq for DomRoot {} +impl Hash for DomRoot { + fn hash(&self, state: &mut H) { + self.id().hash(state); + } +} + #[dom_struct] pub struct GPUCommandBuffer { reflector_: Reflector, @@ -20,15 +31,21 @@ pub struct GPUCommandBuffer { channel: WebGPU, label: DomRefCell>, command_buffer: WebGPUCommandBuffer, + buffers: DomRefCell>>, } impl GPUCommandBuffer { - pub fn new_inherited(channel: WebGPU, command_buffer: WebGPUCommandBuffer) -> GPUCommandBuffer { + fn new_inherited( + channel: WebGPU, + command_buffer: WebGPUCommandBuffer, + buffers: HashSet>, + ) -> GPUCommandBuffer { GPUCommandBuffer { channel, reflector_: Reflector::new(), label: DomRefCell::new(None), command_buffer, + buffers: DomRefCell::new(buffers.into_iter().map(|b| Dom::from_ref(&*b)).collect()), } } @@ -36,15 +53,30 @@ impl GPUCommandBuffer { global: &GlobalScope, channel: WebGPU, command_buffer: WebGPUCommandBuffer, + buffers: HashSet>, ) -> DomRoot { reflect_dom_object( - Box::new(GPUCommandBuffer::new_inherited(channel, command_buffer)), + Box::new(GPUCommandBuffer::new_inherited( + channel, + command_buffer, + buffers, + )), global, GPUCommandBufferBinding::Wrap, ) } } +impl GPUCommandBuffer { + pub fn id(&self) -> WebGPUCommandBuffer { + self.command_buffer + } + + pub fn buffers(&self) -> Ref>> { + self.buffers.borrow() + } +} + impl GPUCommandBufferMethods for GPUCommandBuffer { /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label fn GetLabel(&self) -> Option { -- cgit v1.2.3 From 3ea6d87bcc37167464e856949a4b9b77d0e9318a Mon Sep 17 00:00:00 2001 From: YUAN LYU Date: Fri, 20 Mar 2020 22:14:18 -0400 Subject: Add trait DomObjectWrap to provide WRAP function --- components/script/dom/gpucommandbuffer.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'components/script/dom/gpucommandbuffer.rs') diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs index 24cd781c092..b1871051e52 100644 --- a/components/script/dom/gpucommandbuffer.rs +++ b/components/script/dom/gpucommandbuffer.rs @@ -3,9 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::dom::bindings::cell::{DomRefCell, Ref}; -use crate::dom::bindings::codegen::Bindings::GPUCommandBufferBinding::{ - self, GPUCommandBufferMethods, -}; +use crate::dom::bindings::codegen::Bindings::GPUCommandBufferBinding::GPUCommandBufferMethods; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::root::Dom; use crate::dom::bindings::root::DomRoot; @@ -62,7 +60,6 @@ impl GPUCommandBuffer { buffers, )), global, - GPUCommandBufferBinding::Wrap, ) } } -- cgit v1.2.3 From 3b5ede153d61c2c033326b5df2417e3757dba17b Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Thu, 4 Jun 2020 01:19:13 +0530 Subject: Update wgpu-core and wgpu-types --- components/script/dom/gpucommandbuffer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/dom/gpucommandbuffer.rs') diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs index b1871051e52..4b23a622ca3 100644 --- a/components/script/dom/gpucommandbuffer.rs +++ b/components/script/dom/gpucommandbuffer.rs @@ -37,8 +37,8 @@ impl GPUCommandBuffer { channel: WebGPU, command_buffer: WebGPUCommandBuffer, buffers: HashSet>, - ) -> GPUCommandBuffer { - GPUCommandBuffer { + ) -> Self { + Self { channel, reflector_: Reflector::new(), label: DomRefCell::new(None), @@ -52,7 +52,7 @@ impl GPUCommandBuffer { channel: WebGPU, command_buffer: WebGPUCommandBuffer, buffers: HashSet>, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUCommandBuffer::new_inherited( channel, -- cgit v1.2.3 From cdc0a75fe43a962caaeed5fdb15dbc3a4dc18c56 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Mon, 20 Jul 2020 20:10:41 +0530 Subject: Update GPUObjectBase webidl and cleanup valid flags --- components/script/dom/gpucommandbuffer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'components/script/dom/gpucommandbuffer.rs') diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs index 4b23a622ca3..7c7f03629d9 100644 --- a/components/script/dom/gpucommandbuffer.rs +++ b/components/script/dom/gpucommandbuffer.rs @@ -7,7 +7,7 @@ use crate::dom::bindings::codegen::Bindings::GPUCommandBufferBinding::GPUCommand use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::root::Dom; use crate::dom::bindings::root::DomRoot; -use crate::dom::bindings::str::DOMString; +use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; use crate::dom::gpubuffer::GPUBuffer; use dom_struct::dom_struct; @@ -27,7 +27,7 @@ pub struct GPUCommandBuffer { reflector_: Reflector, #[ignore_malloc_size_of = "defined in webgpu"] channel: WebGPU, - label: DomRefCell>, + label: DomRefCell>, command_buffer: WebGPUCommandBuffer, buffers: DomRefCell>>, } @@ -76,12 +76,12 @@ impl GPUCommandBuffer { impl GPUCommandBufferMethods for GPUCommandBuffer { /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label - fn GetLabel(&self) -> Option { + fn GetLabel(&self) -> Option { self.label.borrow().clone() } /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label - fn SetLabel(&self, value: Option) { + fn SetLabel(&self, value: Option) { *self.label.borrow_mut() = value; } } -- cgit v1.2.3 From aff22db33ff237e0fd677671851e3919007f20ef Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Wed, 22 Jul 2020 17:52:49 +0530 Subject: Implement GPURenderBundleEncoder and GPURenderBundle --- components/script/dom/gpucommandbuffer.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'components/script/dom/gpucommandbuffer.rs') diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs index 7c7f03629d9..6e1eb8446f0 100644 --- a/components/script/dom/gpucommandbuffer.rs +++ b/components/script/dom/gpucommandbuffer.rs @@ -37,11 +37,12 @@ impl GPUCommandBuffer { channel: WebGPU, command_buffer: WebGPUCommandBuffer, buffers: HashSet>, + label: Option, ) -> Self { Self { channel, reflector_: Reflector::new(), - label: DomRefCell::new(None), + label: DomRefCell::new(label), command_buffer, buffers: DomRefCell::new(buffers.into_iter().map(|b| Dom::from_ref(&*b)).collect()), } @@ -52,12 +53,14 @@ impl GPUCommandBuffer { channel: WebGPU, command_buffer: WebGPUCommandBuffer, buffers: HashSet>, + label: Option, ) -> DomRoot { reflect_dom_object( Box::new(GPUCommandBuffer::new_inherited( channel, command_buffer, buffers, + label, )), global, ) -- cgit v1.2.3 From 8ff00f0e9c5c7eb232401407c4e5d455423a68d8 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Sat, 8 Aug 2020 20:20:07 +0530 Subject: Remove entries from error_command_buffers on drop --- components/script/dom/gpucommandbuffer.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'components/script/dom/gpucommandbuffer.rs') diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs index 6e1eb8446f0..eb6ede84c26 100644 --- a/components/script/dom/gpucommandbuffer.rs +++ b/components/script/dom/gpucommandbuffer.rs @@ -13,7 +13,7 @@ use crate::dom::gpubuffer::GPUBuffer; use dom_struct::dom_struct; use std::collections::HashSet; use std::hash::{Hash, Hasher}; -use webgpu::{WebGPU, WebGPUCommandBuffer}; +use webgpu::{WebGPU, WebGPUCommandBuffer, WebGPURequest}; impl Eq for DomRoot {} impl Hash for DomRoot { @@ -67,6 +67,20 @@ impl GPUCommandBuffer { } } +impl Drop for GPUCommandBuffer { + fn drop(&mut self) { + if let Err(e) = self.channel.0.send(( + None, + WebGPURequest::FreeCommandBuffer(self.command_buffer.0), + )) { + warn!( + "Failed to send FreeCommandBuffer({:?}) ({})", + self.command_buffer.0, e + ); + } + } +} + impl GPUCommandBuffer { pub fn id(&self) -> WebGPUCommandBuffer { self.command_buffer -- cgit v1.2.3