webgpu: Move actual Create* implementations from GPUDevice to Self (#33320)

* Move actual Create* implementations from `GPUDevice` to Self

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* move Create*Pipeline to Self::create

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* `parse_render_pipeline` outside`GPURenderPipeline::create`

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson 2024-09-05 21:48:16 +02:00 committed by GitHub
parent 312cf0df08
commit ebed9218f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 594 additions and 486 deletions

View file

@ -3,7 +3,10 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use webgpu::{WebGPU, WebGPUBindGroupLayout, WebGPURenderPipeline, WebGPURequest};
use ipc_channel::ipc::IpcSender;
use webgpu::wgc::id::{BindGroupLayoutId, PipelineLayoutId};
use webgpu::wgc::pipeline::RenderPipelineDescriptor;
use webgpu::{WebGPU, WebGPUBindGroupLayout, WebGPURenderPipeline, WebGPURequest, WebGPUResponse};
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPURenderPipelineMethods;
@ -63,6 +66,33 @@ impl GPURenderPipeline {
pub fn id(&self) -> WebGPURenderPipeline {
self.render_pipeline
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-createrenderpipeline>
pub fn create(
device: &GPUDevice,
implicit_ids: Option<(PipelineLayoutId, Vec<BindGroupLayoutId>)>,
descriptor: RenderPipelineDescriptor<'static>,
async_sender: Option<IpcSender<WebGPUResponse>>,
) -> Fallible<WebGPURenderPipeline> {
let render_pipeline_id = device
.global()
.wgpu_id_hub()
.create_render_pipeline_id(device.id().0.backend());
device
.channel()
.0
.send(WebGPURequest::CreateRenderPipeline {
device_id: device.id().0,
render_pipeline_id,
descriptor,
implicit_ids,
async_sender,
})
.expect("Failed to create WebGPU render pipeline");
Ok(WebGPURenderPipeline(render_pipeline_id))
}
}
impl GPURenderPipelineMethods for GPURenderPipeline {