Skip to content

Commit 875aa5b

Browse files
committed
chore: wgpu cleanup
1 parent 96155d3 commit 875aa5b

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

src/backend/wgpu.rs

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<T> WgpuBackend<T>
3737
where
3838
T: Copy + Clone + Default + bytemuck::Pod + bytemuck::Zeroable,
3939
{
40-
async fn get_device_and_queue() -> (wgpu::Device, wgpu::Queue) {
40+
async fn create_device_and_queue() -> (wgpu::Device, wgpu::Queue) {
4141
let instance = wgpu::Instance::default();
4242

4343
let adapter = instance
@@ -90,11 +90,46 @@ where
9090
})
9191
}
9292

93+
fn create_pipeline(
94+
device: &wgpu::Device,
95+
pipeline_layout: &wgpu::PipelineLayout,
96+
vertex_shader: &wgpu::ShaderModule,
97+
fragment_shader: &wgpu::ShaderModule,
98+
entry_point: Option<&str>,
99+
) -> wgpu::RenderPipeline {
100+
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
101+
label: None,
102+
layout: Some(&pipeline_layout),
103+
vertex: wgpu::VertexState {
104+
module: vertex_shader,
105+
entry_point: None,
106+
buffers: &[],
107+
compilation_options: wgpu::PipelineCompilationOptions::default(),
108+
},
109+
fragment: Some(wgpu::FragmentState {
110+
module: fragment_shader,
111+
entry_point,
112+
compilation_options: wgpu::PipelineCompilationOptions::default(),
113+
targets: &[Some(wgpu::ColorTargetState {
114+
format: wgpu::TextureFormat::Rgba8Unorm,
115+
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
116+
write_mask: wgpu::ColorWrites::ALL,
117+
})],
118+
}),
119+
primitive: wgpu::PrimitiveState::default(),
120+
depth_stencil: None,
121+
multisample: wgpu::MultisampleState::default(),
122+
multiview: None,
123+
cache: None,
124+
});
125+
pipeline
126+
}
127+
93128
async fn new_inner<'a>(
94129
shader_desc: wgpu::ShaderModuleDescriptor<'a>,
95130
entry_point: Option<&str>,
96131
) -> Self {
97-
let (device, queue) = Self::get_device_and_queue().await;
132+
let (device, queue) = Self::create_device_and_queue().await;
98133

99134
let vertex_shader =
100135
device.create_shader_module(wgpu::include_wgsl!("../shaders/fullscreen_vertex.wgsl"));
@@ -171,31 +206,13 @@ where
171206
push_constant_ranges: &[],
172207
});
173208

174-
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
175-
label: None,
176-
layout: Some(&pipeline_layout),
177-
vertex: wgpu::VertexState {
178-
module: &vertex_shader,
179-
entry_point: Some("main"),
180-
buffers: &[],
181-
compilation_options: wgpu::PipelineCompilationOptions::default(),
182-
},
183-
fragment: Some(wgpu::FragmentState {
184-
module: &fragment_shader,
185-
entry_point,
186-
compilation_options: wgpu::PipelineCompilationOptions::default(),
187-
targets: &[Some(wgpu::ColorTargetState {
188-
format: wgpu::TextureFormat::Rgba8Unorm,
189-
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
190-
write_mask: wgpu::ColorWrites::ALL,
191-
})],
192-
}),
193-
primitive: wgpu::PrimitiveState::default(),
194-
depth_stencil: None,
195-
multisample: wgpu::MultisampleState::default(),
196-
multiview: None,
197-
cache: None,
198-
});
209+
let pipeline = Self::create_pipeline(
210+
&device,
211+
&pipeline_layout,
212+
&vertex_shader,
213+
&fragment_shader,
214+
entry_point,
215+
);
199216

200217
WgpuBackend {
201218
device,

0 commit comments

Comments
 (0)