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 GPUShaderModule
Added WebIDL bindings for `GPUShaderModule`. Implemented the `createShaderModule` function of `GPUDevice`.
- Loading branch information
| @@ -13,16 +13,20 @@ use crate::dom::bindings::codegen::Bindings::GPUBindGroupLayoutBinding::{ | ||
| use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::GPUBufferDescriptor; | ||
| 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; | ||
| use crate::dom::bindings::codegen::UnionTypes::Uint32ArrayOrString::{String, Uint32Array}; | ||
| use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; | ||
| use crate::dom::bindings::root::{Dom, DomRoot}; | ||
| use crate::dom::bindings::str::DOMString; | ||
| use crate::dom::bindings::trace::RootedTraceableBox; | ||
| use crate::dom::eventtarget::EventTarget; | ||
| use crate::dom::globalscope::GlobalScope; | ||
| use crate::dom::gpuadapter::GPUAdapter; | ||
| use crate::dom::gpubindgroup::GPUBindGroup; | ||
| use crate::dom::gpubindgrouplayout::GPUBindGroupLayout; | ||
| use crate::dom::gpubuffer::{GPUBuffer, GPUBufferState}; | ||
| use crate::dom::gpupipelinelayout::GPUPipelineLayout; | ||
| use crate::dom::gpushadermodule::GPUShaderModule; | ||
| use crate::script_runtime::JSContext as SafeJSContext; | ||
| use dom_struct::dom_struct; | ||
| use ipc_channel::ipc; | ||
| @@ -523,9 +527,36 @@ impl GPUDeviceMethods for GPUDevice { | ||
| descriptor.layout.id(), | ||
| bindings, | ||
| )) | ||
| .expect("Failed to create WebGPU PipelineLayout"); | ||
| .expect("Failed to create WebGPU BindGroup"); | ||
|
|
||
| let bind_group = receiver.recv().unwrap(); | ||
| GPUBindGroup::new(&self.global(), bind_group, valid) | ||
| } | ||
|
|
||
| /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createshadermodule | ||
| fn CreateShaderModule( | ||
| &self, | ||
| descriptor: RootedTraceableBox<GPUShaderModuleDescriptor>, | ||
| ) -> DomRoot<GPUShaderModule> { | ||
| let (sender, receiver) = ipc::channel().unwrap(); | ||
| let program: Vec<u32> = match &descriptor.code { | ||
| Uint32Array(program) => program.to_vec(), | ||
| String(program) => program.chars().map(|c| c as u32).collect::<Vec<u32>>(), | ||
| }; | ||
| let id = self | ||
| .global() | ||
| .wgpu_create_shader_module_id(self.device.0.backend()); | ||
| self.channel | ||
| .0 | ||
| .send(WebGPURequest::CreateShaderModule( | ||
| sender, | ||
| self.device, | ||
| id, | ||
| program, | ||
| )) | ||
| .expect("Failed to create WebGPU ShaderModule"); | ||
|
|
||
| let shader_module = receiver.recv().unwrap(); | ||
kvark
Member
|
||
| GPUShaderModule::new(&self.global(), shader_module) | ||
| } | ||
| } | ||
| @@ -0,0 +1,54 @@ | ||
| /* 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::GPUShaderModuleBinding::{ | ||
| self, GPUShaderModuleMethods, | ||
| }; | ||
| 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::WebGPUShaderModule; | ||
|
|
||
| #[dom_struct] | ||
| pub struct GPUShaderModule { | ||
| reflector_: Reflector, | ||
| label: DomRefCell<Option<DOMString>>, | ||
| shader_module: WebGPUShaderModule, | ||
| } | ||
|
|
||
| impl GPUShaderModule { | ||
| fn new_inherited(shader_module: WebGPUShaderModule) -> GPUShaderModule { | ||
| Self { | ||
| reflector_: Reflector::new(), | ||
| label: DomRefCell::new(None), | ||
| shader_module, | ||
| } | ||
| } | ||
|
|
||
| pub fn new( | ||
| global: &GlobalScope, | ||
| shader_module: WebGPUShaderModule, | ||
| ) -> DomRoot<GPUShaderModule> { | ||
| reflect_dom_object( | ||
| Box::new(GPUShaderModule::new_inherited(shader_module)), | ||
| global, | ||
| GPUShaderModuleBinding::Wrap, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl GPUShaderModuleMethods for GPUShaderModule { | ||
| /// 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,15 @@ | ||
| /* 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/#gpushadermodule | ||
| [Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"] | ||
| interface GPUShaderModule { | ||
| }; | ||
| GPUShaderModule includes GPUObjectBase; | ||
|
|
||
| typedef (Uint32Array or DOMString) GPUShaderCode; | ||
|
|
||
| dictionary GPUShaderModuleDescriptor : GPUObjectDescriptorBase { | ||
| required GPUShaderCode code; | ||
| }; |
nit: perhaps it would be simpler to just have a function returning
&mut GpuIdHuband let the users call the methods appropriately?