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 GPUComputePipeline #25700
Changes from 1 commit
File filter...
Jump to…
Initial implementation of GPUComputePipeline
Added WebIDL bindings for `GPUComputePipeline`. Implemented the `createComputePipeline` function of `GPUDevice`.
- Loading branch information
| @@ -99,8 +99,8 @@ use time::{get_time, Timespec}; | ||
| use uuid::Uuid; | ||
| use webgpu::wgpu::{ | ||
| id::{ | ||
| AdapterId, BindGroupId, BindGroupLayoutId, BufferId, DeviceId, PipelineLayoutId, | ||
| ShaderModuleId, | ||
| AdapterId, BindGroupId, BindGroupLayoutId, BufferId, ComputePipelineId, DeviceId, | ||
| PipelineLayoutId, ShaderModuleId, | ||
| }, | ||
| Backend, | ||
| }; | ||
| @@ -2137,6 +2137,11 @@ impl GlobalScope { | ||
| .borrow_mut() | ||
| .create_shader_module_id(backend) | ||
| } | ||
| pub fn wgpu_create_compute_pipeline_id(&self, backend: Backend) -> ComputePipelineId { | ||
| self.gpu_id_hub | ||
jdm
Member
|
||
| .borrow_mut() | ||
| .create_compute_pipeline_id(backend) | ||
| } | ||
| } | ||
|
|
||
| fn timestamp_in_ms(time: Timespec) -> u64 { | ||
| @@ -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; | ||
| } | ||
| } |
| @@ -11,6 +11,7 @@ use crate::dom::bindings::codegen::Bindings::GPUBindGroupLayoutBinding::{ | ||
| GPUBindGroupLayoutBindings, GPUBindGroupLayoutDescriptor, GPUBindingType, | ||
| }; | ||
| use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::GPUBufferDescriptor; | ||
| use crate::dom::bindings::codegen::Bindings::GPUComputePipelineBinding::GPUComputePipelineDescriptor; | ||
| use crate::dom::bindings::codegen::Bindings::GPUDeviceBinding::{self, GPUDeviceMethods}; | ||
| use crate::dom::bindings::codegen::Bindings::GPUPipelineLayoutBinding::GPUPipelineLayoutDescriptor; | ||
| use crate::dom::bindings::codegen::Bindings::GPUShaderModuleBinding::GPUShaderModuleDescriptor; | ||
| @@ -25,6 +26,7 @@ use crate::dom::gpuadapter::GPUAdapter; | ||
| use crate::dom::gpubindgroup::GPUBindGroup; | ||
| use crate::dom::gpubindgrouplayout::GPUBindGroupLayout; | ||
| use crate::dom::gpubuffer::{GPUBuffer, GPUBufferState}; | ||
| use crate::dom::gpucomputepipeline::GPUComputePipeline; | ||
| use crate::dom::gpupipelinelayout::GPUPipelineLayout; | ||
| use crate::dom::gpushadermodule::GPUShaderModule; | ||
| use crate::script_runtime::JSContext as SafeJSContext; | ||
| @@ -559,4 +561,32 @@ impl GPUDeviceMethods for GPUDevice { | ||
| let shader_module = receiver.recv().unwrap(); | ||
kvark
Member
|
||
| GPUShaderModule::new(&self.global(), shader_module) | ||
| } | ||
|
|
||
| /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createcomputepipeline | ||
| fn CreateComputePipeline( | ||
| &self, | ||
| descriptor: &GPUComputePipelineDescriptor, | ||
| ) -> DomRoot<GPUComputePipeline> { | ||
| let pipeline = descriptor.parent.layout.id(); | ||
| let program = descriptor.computeStage.module.id(); | ||
| let entry_point = descriptor.computeStage.entryPoint.to_string(); | ||
| let id = self | ||
| .global() | ||
| .wgpu_create_compute_pipeline_id(self.device.0.backend()); | ||
| let (sender, receiver) = ipc::channel().unwrap(); | ||
| self.channel | ||
| .0 | ||
| .send(WebGPURequest::CreateComputePipeline( | ||
| sender, | ||
| self.device, | ||
| id, | ||
| pipeline.0, | ||
| program.0, | ||
| entry_point, | ||
| )) | ||
| .expect("Failed to create WebGPU ComputePipeline"); | ||
|
|
||
| let compute_pipeline = receiver.recv().unwrap(); | ||
| GPUComputePipeline::new(&self.global(), compute_pipeline) | ||
| } | ||
| } | ||
| @@ -0,0 +1,22 @@ | ||
| /* 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/#gpucomputepipeline | ||
| [Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"] | ||
| interface GPUComputePipeline { | ||
| }; | ||
| GPUComputePipeline includes GPUObjectBase; | ||
|
|
||
| dictionary GPUPipelineDescriptorBase : GPUObjectDescriptorBase { | ||
| required GPUPipelineLayout layout; | ||
| }; | ||
|
|
||
| dictionary GPUProgrammableStageDescriptor { | ||
| required GPUShaderModule module; | ||
| required DOMString entryPoint; | ||
| }; | ||
|
|
||
| dictionary GPUComputePipelineDescriptor : GPUPipelineDescriptorBase { | ||
| required GPUProgrammableStageDescriptor computeStage; | ||
| }; |
A bit surprised you are able to use the
RefCellhere. In Gecko implementation, multiple threads in the same content process may want to create their own resource IDs.