Compare commits

...

2 Commits

Author SHA1 Message Date
Jarrod Doyle 8fd8731696
Implement gpu profiling to voxel rendering 2024-05-18 17:35:30 +01:00
Jarrod Doyle 443b18729e
Enable GPU timestamp queries 2024-05-18 17:35:03 +01:00
2 changed files with 30 additions and 14 deletions

View File

@ -4,7 +4,10 @@ mod renderer;
use std::time::Instant; use std::time::Instant;
use anyhow::Result; use anyhow::Result;
use crawl::winit::event::{Event, WindowEvent}; use crawl::{
wgpu,
winit::event::{Event, WindowEvent},
};
use renderer::VoxelRenderer; use renderer::VoxelRenderer;
fn main() -> Result<()> { fn main() -> Result<()> {
@ -13,6 +16,7 @@ fn main() -> Result<()> {
crawl::ContextBuilder::new() crawl::ContextBuilder::new()
.with_title("BEAVER") .with_title("BEAVER")
.with_vsync(false) .with_vsync(false)
.with_features(wgpu::Features::default() | wgpu::Features::TIMESTAMP_QUERY)
.build(), .build(),
)?; )?;

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);