diff --git a/components/script/dom/gpucomputepipeline.rs b/components/script/dom/gpucomputepipeline.rs index 6f64e59ab5d..cca5e414191 100644 --- a/components/script/dom/gpucomputepipeline.rs +++ b/components/script/dom/gpucomputepipeline.rs @@ -76,11 +76,11 @@ impl GPUComputePipeline { ) -> WebGPUComputePipeline { let compute_pipeline_id = device.global().wgpu_id_hub().create_compute_pipeline_id(); - let (layout, implicit_ids, _) = device.get_pipeline_layout_data(&descriptor.parent.layout); + let pipeline_layout = device.get_pipeline_layout_data(&descriptor.parent.layout); let desc = ComputePipelineDescriptor { label: (&descriptor.parent.parent).into(), - layout, + layout: pipeline_layout.explicit(), stage: (&descriptor.compute).into(), cache: None, }; @@ -92,7 +92,7 @@ impl GPUComputePipeline { device_id: device.id().0, compute_pipeline_id, descriptor: desc, - implicit_ids, + implicit_ids: pipeline_layout.implicit(), async_sender, }) .expect("Failed to create WebGPU ComputePipeline"); diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs index 97110b99af8..782e8605651 100644 --- a/components/script/dom/gpudevice.rs +++ b/components/script/dom/gpudevice.rs @@ -86,6 +86,29 @@ pub struct GPUDevice { valid: Cell, } +pub enum PipelineLayout { + Implicit(PipelineLayoutId, Vec), + Explicit(PipelineLayoutId), +} + +impl PipelineLayout { + pub fn explicit(&self) -> Option { + match self { + PipelineLayout::Explicit(layout_id) => Some(*layout_id), + _ => None, + } + } + + pub fn implicit(self) -> Option<(PipelineLayoutId, Vec)> { + match self { + PipelineLayout::Implicit(layout_id, bind_group_layout_ids) => { + Some((layout_id, bind_group_layout_ids)) + }, + _ => None, + } + } +} + impl GPUDevice { #[allow(clippy::too_many_arguments)] fn new_inherited( @@ -213,39 +236,30 @@ impl GPUDevice { pub fn get_pipeline_layout_data( &self, layout: &GPUPipelineLayoutOrGPUAutoLayoutMode, - ) -> ( - Option, - Option<(PipelineLayoutId, Vec)>, - Vec, - ) { + ) -> PipelineLayout { if let GPUPipelineLayoutOrGPUAutoLayoutMode::GPUPipelineLayout(ref layout) = layout { - (Some(layout.id().0), None, layout.bind_group_layouts()) + PipelineLayout::Explicit(layout.id().0) } else { let layout_id = self.global().wgpu_id_hub().create_pipeline_layout_id(); let max_bind_grps = self.limits.MaxBindGroups(); - let mut bgls = Vec::with_capacity(max_bind_grps as usize); let mut bgl_ids = Vec::with_capacity(max_bind_grps as usize); for _ in 0..max_bind_grps { let bgl = self.global().wgpu_id_hub().create_bind_group_layout_id(); - bgls.push(webgpu::WebGPUBindGroupLayout(bgl)); bgl_ids.push(bgl); } - (None, Some((layout_id, bgl_ids)), bgls) + PipelineLayout::Implicit(layout_id, bgl_ids) } } pub fn parse_render_pipeline<'a>( &self, descriptor: &GPURenderPipelineDescriptor, - ) -> Fallible<( - Option<(PipelineLayoutId, Vec)>, - RenderPipelineDescriptor<'a>, - )> { - let (layout, implicit_ids, _) = self.get_pipeline_layout_data(&descriptor.parent.layout); + ) -> Fallible<(PipelineLayout, RenderPipelineDescriptor<'a>)> { + let pipeline_layout = self.get_pipeline_layout_data(&descriptor.parent.layout); let desc = wgpu_pipe::RenderPipelineDescriptor { label: (&descriptor.parent.parent).into(), - layout, + layout: pipeline_layout.explicit(), cache: None, vertex: wgpu_pipe::VertexState { stage: (&descriptor.vertex.parent).into(), @@ -349,7 +363,7 @@ impl GPUDevice { }, multiview: None, }; - Ok((implicit_ids, desc)) + Ok((pipeline_layout, desc)) } /// @@ -477,8 +491,8 @@ impl GPUDeviceMethods for GPUDevice { &self, descriptor: &GPURenderPipelineDescriptor, ) -> Fallible> { - let (implicit_ids, desc) = self.parse_render_pipeline(descriptor)?; - let render_pipeline = GPURenderPipeline::create(self, implicit_ids, desc, None)?; + let (pipeline_layout, desc) = self.parse_render_pipeline(descriptor)?; + let render_pipeline = GPURenderPipeline::create(self, pipeline_layout, desc, None)?; Ok(GPURenderPipeline::new( &self.global(), render_pipeline, diff --git a/components/script/dom/gpurenderpipeline.rs b/components/script/dom/gpurenderpipeline.rs index dde7cc8ff38..96de0ffd925 100644 --- a/components/script/dom/gpurenderpipeline.rs +++ b/components/script/dom/gpurenderpipeline.rs @@ -4,7 +4,6 @@ use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; -use webgpu::wgc::id::{BindGroupLayoutId, PipelineLayoutId}; use webgpu::wgc::pipeline::RenderPipelineDescriptor; use webgpu::{WebGPU, WebGPUBindGroupLayout, WebGPURenderPipeline, WebGPURequest, WebGPUResponse}; @@ -16,7 +15,7 @@ use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; use crate::dom::gpubindgrouplayout::GPUBindGroupLayout; -use crate::dom::gpudevice::GPUDevice; +use crate::dom::gpudevice::{GPUDevice, PipelineLayout}; #[dom_struct] pub struct GPURenderPipeline { @@ -70,7 +69,7 @@ impl GPURenderPipeline { /// pub fn create( device: &GPUDevice, - implicit_ids: Option<(PipelineLayoutId, Vec)>, + pipeline_layout: PipelineLayout, descriptor: RenderPipelineDescriptor<'static>, async_sender: Option>, ) -> Fallible { @@ -83,7 +82,7 @@ impl GPURenderPipeline { device_id: device.id().0, render_pipeline_id, descriptor, - implicit_ids, + implicit_ids: pipeline_layout.implicit(), async_sender, }) .expect("Failed to create WebGPU render pipeline");