mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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:
parent
2a6cfbaaf9
commit
8843a0e400
3 changed files with 38 additions and 25 deletions
|
@ -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");
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
|||
/// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-createrenderpipeline>
|
||||
pub fn create(
|
||||
device: &GPUDevice,
|
||||
implicit_ids: Option<(PipelineLayoutId, Vec<BindGroupLayoutId>)>,
|
||||
pipeline_layout: PipelineLayout,
|
||||
descriptor: RenderPipelineDescriptor<'static>,
|
||||
async_sender: Option<IpcSender<WebGPUResponse>>,
|
||||
) -> Fallible<WebGPURenderPipeline> {
|
||||
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue