Share a single render pass

This commit is contained in:
Hanno Braun 2024-11-25 21:10:10 +01:00
parent b32b232a06
commit 8d38eb0005
2 changed files with 30 additions and 66 deletions

View File

@ -108,36 +108,9 @@ impl<V> Pipeline<V> {
pub fn draw( pub fn draw(
&self, &self,
encoder: &mut wgpu::CommandEncoder, render_pass: &mut wgpu::RenderPass,
color_view: &wgpu::TextureView,
depth_view: &wgpu::TextureView,
geometry: &Geometry<V>, geometry: &Geometry<V>,
) { ) {
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: color_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: Some(
wgpu::RenderPassDepthStencilAttachment {
view: depth_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Load,
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
},
),
timestamp_writes: None,
occlusion_query_set: None,
});
if geometry.num_indices > 0 { if geometry.num_indices > 0 {
render_pass.set_index_buffer( render_pass.set_index_buffer(
geometry.indices.slice(..), geometry.indices.slice(..),

View File

@ -89,45 +89,36 @@ impl Renderer {
.create_view(&wgpu::TextureViewDescriptor::default()); .create_view(&wgpu::TextureViewDescriptor::default());
{ {
// No need to do anything else with the render pass. Creating and let mut render_pass =
// then dropping it is enough to clear the background. encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None,
label: None, color_attachments: &[Some(
color_attachments: &[Some(wgpu::RenderPassColorAttachment { wgpu::RenderPassColorAttachment {
view: &color_view, view: &color_view,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::WHITE), load: wgpu::LoadOp::Clear(wgpu::Color::WHITE),
store: wgpu::StoreOp::Store, store: wgpu::StoreOp::Store,
}, },
})], },
depth_stencil_attachment: Some( )],
wgpu::RenderPassDepthStencilAttachment { depth_stencil_attachment: Some(
view: &self.depth_view, wgpu::RenderPassDepthStencilAttachment {
depth_ops: Some(wgpu::Operations { view: &self.depth_view,
load: wgpu::LoadOp::Clear(1.0), depth_ops: Some(wgpu::Operations {
store: wgpu::StoreOp::Store, load: wgpu::LoadOp::Clear(1.0),
}), store: wgpu::StoreOp::Store,
stencil_ops: None, }),
}, stencil_ops: None,
), },
timestamp_writes: None, ),
occlusion_query_set: None, timestamp_writes: None,
}); occlusion_query_set: None,
} });
self.pipelines.vertices.draw( self.pipelines.vertices.draw(&mut render_pass, &vertices);
&mut encoder, self.pipelines.triangles.draw(&mut render_pass, &triangles);
&color_view, }
&self.depth_view,
&vertices,
);
self.pipelines.triangles.draw(
&mut encoder,
&color_view,
&self.depth_view,
&triangles,
);
self.queue.submit(Some(encoder.finish())); self.queue.submit(Some(encoder.finish()));
frame.present(); frame.present();