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 anyhow::Result;
use crawl::wgpu; use crawl::{wgpu, wgpu_profiler::GpuProfiler};
use crate::camera::CameraController; use crate::camera::CameraController;
@ -106,29 +106,41 @@ impl VoxelRenderer {
} }
impl crawl::Pass for 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 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_pipeline(&self.raygen_pipeline);
compute_pass.set_bind_group(0, &self.raygen_bind_group, &[]); compute_pass.set_bind_group(0, &self.raygen_bind_group, &[]);
compute_pass.dispatch_workgroups(size.width / 8, size.height / 8, 1); compute_pass.dispatch_workgroups(size.width / 8, size.height / 8, 1);
drop(compute_pass); 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_pipeline(&self.raycast_pipeline);
compute_pass.set_bind_group(0, &self.raygen_bind_group, &[]); compute_pass.set_bind_group(0, &self.raygen_bind_group, &[]);
compute_pass.dispatch_workgroups(size.width / 8, size.height / 8, 1); compute_pass.dispatch_workgroups(size.width / 8, size.height / 8, 1);
drop(compute_pass); drop(compute_pass);
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut render_pass = scope.scoped_render_pass(
label: Some("Render Pass"), "Quad render",
color_attachments: &[Some(wgpu::RenderPassColorAttachment { device,
view, wgpu::RenderPassDescriptor {
resolve_target: None, label: Some("Render Pass"),
ops: wgpu::Operations::default(), color_attachments: &[Some(wgpu::RenderPassColorAttachment {
})], view,
..Default::default() resolve_target: None,
}); ops: wgpu::Operations::default(),
})],
..Default::default()
},
);
render_pass.set_pipeline(&self.render_pipeline); render_pass.set_pipeline(&self.render_pipeline);
render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]); render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]);
render_pass.draw(0..6, 0..1); render_pass.draw(0..6, 0..1);