clippy: Fix type_complexity warnings in components/script/dom (#33790)

* clippy: Fix type_complexity warnings in components/script/dom

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Use explicit & implicit method calls where needed

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Remove unwrap & pass pipeline_layout

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Remove unused variable - bgls

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

---------

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
tanishka 2024-10-11 20:27:41 +05:30 committed by GitHub
parent 2a6cfbaaf9
commit 8843a0e400
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 25 deletions

View file

@ -86,6 +86,29 @@ pub struct GPUDevice {
valid: Cell<bool>,
}
pub enum PipelineLayout {
Implicit(PipelineLayoutId, Vec<BindGroupLayoutId>),
Explicit(PipelineLayoutId),
}
impl PipelineLayout {
pub fn explicit(&self) -> Option<PipelineLayoutId> {
match self {
PipelineLayout::Explicit(layout_id) => Some(*layout_id),
_ => None,
}
}
pub fn implicit(self) -> Option<(PipelineLayoutId, Vec<BindGroupLayoutId>)> {
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<PipelineLayoutId>,
Option<(PipelineLayoutId, Vec<BindGroupLayoutId>)>,
Vec<webgpu::WebGPUBindGroupLayout>,
) {
) -> 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<BindGroupLayoutId>)>,
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))
}
/// <https://gpuweb.github.io/gpuweb/#lose-the-device>
@ -477,8 +491,8 @@ impl GPUDeviceMethods for GPUDevice {
&self,
descriptor: &GPURenderPipelineDescriptor,
) -> Fallible<DomRoot<GPURenderPipeline>> {
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,