New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of GPUCommandEncoder #25702
Merged
+766
−25
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
| @@ -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<Option<DOMString>>, | ||
| 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<GPUCommandBuffer> { | ||
| 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<DOMString> { | ||
| self.label.borrow().clone() | ||
| } | ||
|
|
||
| /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label | ||
| fn SetLabel(&self, value: Option<DOMString>) { | ||
| *self.label.borrow_mut() = value; | ||
| } | ||
| } |
| @@ -0,0 +1,114 @@ | ||
| /* 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::GPUCommandEncoderBinding::{ | ||
| self, GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor, | ||
| }; | ||
| use crate::dom::bindings::reflector::DomObject; | ||
| 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::GPUBuffer; | ||
| use crate::dom::gpucommandbuffer::GPUCommandBuffer; | ||
| use crate::dom::gpucomputepassencoder::GPUComputePassEncoder; | ||
| use dom_struct::dom_struct; | ||
| use ipc_channel::ipc; | ||
| use webgpu::{wgpu::command::RawPass, WebGPU, WebGPUCommandEncoder, WebGPURequest}; | ||
|
|
||
| #[dom_struct] | ||
| pub struct GPUCommandEncoder { | ||
| reflector_: Reflector, | ||
| #[ignore_malloc_size_of = "defined in webgpu"] | ||
| channel: WebGPU, | ||
| label: DomRefCell<Option<DOMString>>, | ||
| encoder: WebGPUCommandEncoder, | ||
| } | ||
|
|
||
| impl GPUCommandEncoder { | ||
| pub fn new_inherited(channel: WebGPU, encoder: WebGPUCommandEncoder) -> GPUCommandEncoder { | ||
| GPUCommandEncoder { | ||
| channel, | ||
| reflector_: Reflector::new(), | ||
| label: DomRefCell::new(None), | ||
| encoder, | ||
| } | ||
| } | ||
|
|
||
| pub fn new( | ||
| global: &GlobalScope, | ||
| channel: WebGPU, | ||
| encoder: WebGPUCommandEncoder, | ||
| ) -> DomRoot<GPUCommandEncoder> { | ||
| reflect_dom_object( | ||
| Box::new(GPUCommandEncoder::new_inherited(channel, encoder)), | ||
| global, | ||
| GPUCommandEncoderBinding::Wrap, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl GPUCommandEncoderMethods for GPUCommandEncoder { | ||
| /// 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-gpucommandencoder-begincomputepass | ||
| fn BeginComputePass( | ||
| &self, | ||
| _descriptor: &GPUComputePassDescriptor, | ||
| ) -> DomRoot<GPUComputePassEncoder> { | ||
| GPUComputePassEncoder::new( | ||
| &self.global(), | ||
| self.channel.clone(), | ||
| RawPass::new_compute(self.encoder.0), | ||
| ) | ||
| } | ||
|
|
||
| /// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertobuffer | ||
| fn CopyBufferToBuffer( | ||
| &self, | ||
| source: &GPUBuffer, | ||
| source_offset: u64, | ||
| destination: &GPUBuffer, | ||
| destination_offset: u64, | ||
| size: u64, | ||
| ) { | ||
| self.channel | ||
| .0 | ||
| .send(WebGPURequest::CopyBufferToBuffer( | ||
| self.encoder.0, | ||
| source.id().0, | ||
| source_offset, | ||
| destination.id().0, | ||
| destination_offset, | ||
| size, | ||
| )) | ||
| .expect("Failed to send CopyBufferToBuffer"); | ||
| } | ||
|
|
||
| /// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-finish | ||
| fn Finish(&self, _descriptor: &GPUCommandBufferDescriptor) -> DomRoot<GPUCommandBuffer> { | ||
| let (sender, receiver) = ipc::channel().unwrap(); | ||
| self.channel | ||
| .0 | ||
| .send(WebGPURequest::CommandEncoderFinish( | ||
| sender, | ||
| self.encoder.0, | ||
| // TODO(zakorgy): We should use `_descriptor` here after it's not empty | ||
| // and the underlying wgpu-core struct is serializable | ||
| )) | ||
| .expect("Failed to send CopyBufferToBuffer"); | ||
|
|
||
| let buffer = receiver.recv().unwrap(); | ||
|
||
| GPUCommandBuffer::new(&self.global(), self.channel.clone(), buffer) | ||
| } | ||
| } | ||
| @@ -0,0 +1,59 @@ | ||
| /* 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::GPUComputePassEncoderBinding::{ | ||
| self, GPUComputePassEncoderMethods, | ||
| }; | ||
| 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::{wgpu::command::RawPass, WebGPU}; | ||
|
|
||
| #[dom_struct] | ||
| pub struct GPUComputePassEncoder { | ||
| reflector_: Reflector, | ||
| #[ignore_malloc_size_of = "defined in webgpu"] | ||
| channel: WebGPU, | ||
| label: DomRefCell<Option<DOMString>>, | ||
| #[ignore_malloc_size_of = "defined in wgpu-core"] | ||
| pass: RawPass, | ||
| } | ||
|
|
||
| impl GPUComputePassEncoder { | ||
| pub fn new_inherited(channel: WebGPU, pass: RawPass) -> GPUComputePassEncoder { | ||
| GPUComputePassEncoder { | ||
| channel, | ||
| reflector_: Reflector::new(), | ||
| label: DomRefCell::new(None), | ||
| pass, | ||
| } | ||
| } | ||
|
|
||
| pub fn new( | ||
| global: &GlobalScope, | ||
| channel: WebGPU, | ||
| pass: RawPass, | ||
| ) -> DomRoot<GPUComputePassEncoder> { | ||
| reflect_dom_object( | ||
| Box::new(GPUComputePassEncoder::new_inherited(channel, pass)), | ||
| global, | ||
| GPUComputePassEncoderBinding::Wrap, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl GPUComputePassEncoderMethods for GPUComputePassEncoder { | ||
| /// 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; | ||
| } | ||
| } |
| @@ -0,0 +1,55 @@ | ||
| /* 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::GPUComputePipelineBinding::{ | ||
| GPUComputePipelineBinding, GPUComputePipelineMethods, | ||
| }; | ||
| use crate::dom::bindings::reflector::reflect_dom_object; | ||
| use crate::dom::bindings::reflector::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::WebGPUComputePipeline; | ||
|
|
||
| #[dom_struct] | ||
| pub struct GPUComputePipeline { | ||
| reflector_: Reflector, | ||
| label: DomRefCell<Option<DOMString>>, | ||
| compute_pipeline: WebGPUComputePipeline, | ||
| } | ||
|
|
||
| impl GPUComputePipeline { | ||
| fn new_inherited(compute_pipeline: WebGPUComputePipeline) -> GPUComputePipeline { | ||
| Self { | ||
| reflector_: Reflector::new(), | ||
| label: DomRefCell::new(None), | ||
| compute_pipeline, | ||
| } | ||
| } | ||
|
|
||
| pub fn new( | ||
| global: &GlobalScope, | ||
| compute_pipeline: WebGPUComputePipeline, | ||
| ) -> DomRoot<GPUComputePipeline> { | ||
| reflect_dom_object( | ||
| Box::new(GPUComputePipeline::new_inherited(compute_pipeline)), | ||
| global, | ||
| GPUComputePipelineBinding::Wrap, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl GPUComputePipelineMethods for GPUComputePipeline { | ||
| /// 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; | ||
| } | ||
| } |
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
similarly to object creation, this shouldn't be blocking