Implement gpu profiling to voxel rendering

This commit is contained in:
Jarrod Doyle 2024-05-18 17:35:30 +01:00
parent 443b18729e
commit 8fd8731696
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 25 additions and 13 deletions

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use crawl::wgpu;
use crawl::{wgpu, wgpu_profiler::GpuProfiler};
use crate::camera::CameraController;
@ -106,29 +106,41 @@ impl VoxelRenderer {
}
impl crawl::Pass for VoxelRenderer {
fn execute(&self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView) {
fn execute(
&self,
profiler: &GpuProfiler,
device: &wgpu::Device,
encoder: &mut wgpu::CommandEncoder,
view: &wgpu::TextureView,
) {
let mut scope = profiler.scope("Rendering", encoder, device);
let size = self.render_texture.attributes.size;
let mut compute_pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default());
let mut compute_pass = scope.scoped_compute_pass("Ray gen", device);
compute_pass.set_pipeline(&self.raygen_pipeline);
compute_pass.set_bind_group(0, &self.raygen_bind_group, &[]);
compute_pass.dispatch_workgroups(size.width / 8, size.height / 8, 1);
drop(compute_pass);
let mut compute_pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default());
let mut compute_pass = scope.scoped_compute_pass("Ray cast", device);
compute_pass.set_pipeline(&self.raycast_pipeline);
compute_pass.set_bind_group(0, &self.raygen_bind_group, &[]);
compute_pass.dispatch_workgroups(size.width / 8, size.height / 8, 1);
drop(compute_pass);
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
ops: wgpu::Operations::default(),
})],
..Default::default()
});
let mut render_pass = scope.scoped_render_pass(
"Quad render",
device,
wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
ops: wgpu::Operations::default(),
})],
..Default::default()
},
);
render_pass.set_pipeline(&self.render_pipeline);
render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]);
render_pass.draw(0..6, 0..1);