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 GPUQueue #25744
Merged
+181
−16
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
| @@ -16,6 +16,7 @@ use crate::dom::gpucommandbuffer::GPUCommandBuffer; | ||
| use crate::dom::gpucomputepassencoder::GPUComputePassEncoder; | ||
| use dom_struct::dom_struct; | ||
| use ipc_channel::ipc; | ||
| use std::collections::HashSet; | ||
| use webgpu::{wgpu::command::RawPass, WebGPU, WebGPUCommandEncoder, WebGPURequest}; | ||
|
|
||
| #[dom_struct] | ||
| @@ -25,6 +26,7 @@ pub struct GPUCommandEncoder { | ||
| channel: WebGPU, | ||
| label: DomRefCell<Option<DOMString>>, | ||
| encoder: WebGPUCommandEncoder, | ||
| buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>, | ||
| } | ||
|
|
||
| impl GPUCommandEncoder { | ||
| @@ -34,6 +36,7 @@ impl GPUCommandEncoder { | ||
| reflector_: Reflector::new(), | ||
| label: DomRefCell::new(None), | ||
| encoder, | ||
| buffers: DomRefCell::new(HashSet::new()), | ||
| } | ||
| } | ||
|
|
||
| @@ -82,6 +85,10 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { | ||
| destination_offset: u64, | ||
| size: u64, | ||
| ) { | ||
| self.buffers.borrow_mut().insert(DomRoot::from_ref(source)); | ||
| self.buffers | ||
| .borrow_mut() | ||
| .insert(DomRoot::from_ref(destination)); | ||
| self.channel | ||
| .0 | ||
| .send(WebGPURequest::CopyBufferToBuffer( | ||
| @@ -106,9 +113,14 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { | ||
| // 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"); | ||
| .expect("Failed to send Finish"); | ||
|
|
||
| let buffer = receiver.recv().unwrap(); | ||
| GPUCommandBuffer::new(&self.global(), self.channel.clone(), buffer) | ||
| GPUCommandBuffer::new( | ||
| &self.global(), | ||
| self.channel.clone(), | ||
| buffer, | ||
| self.buffers.borrow_mut().drain().collect(), | ||
imiklos
Author
Contributor
|
||
| ) | ||
| } | ||
| } | ||
| @@ -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(); | ||
| } | ||
| } |
| @@ -0,0 +1,18 @@ | ||
| /* 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/#gpuqueue | ||
| [Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"] | ||
| interface GPUQueue { | ||
| void submit(sequence<GPUCommandBuffer> commandBuffers); | ||
|
|
||
| // GPUFence createFence(optional GPUFenceDescriptor descriptor = {}); | ||
| // void signal(GPUFence fence, unsigned long long signalValue); | ||
|
|
||
| // void copyImageBitmapToTexture( | ||
| // GPUImageBitmapCopyView source, | ||
| // GPUTextureCopyView destination, | ||
| // GPUExtent3D copySize); | ||
| }; | ||
| GPUQueue includes GPUObjectBase; |
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.
Let's do this instead:
self.buffers.borrow_mut().drain().map(|b| DomRoot::from_ref(&**b)).collect()