Update wgpu-profiler

This commit is contained in:
Imbris 2021-03-20 01:13:24 -04:00 committed by Avi Weinstock
parent e7e9c16af4
commit 2084e07ab4
5 changed files with 25 additions and 189 deletions

4
Cargo.lock generated
View File

@ -6584,9 +6584,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-profiler" name = "wgpu-profiler"
version = "0.2.1" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98580e756637420f660385d6ec86e97080b588325daa3326d0229b39307d5aa3" checksum = "b96b9e4e035cf917ec6172118dbee8c130b1d8a0ac02f1ca0d3898ee90395407"
dependencies = [ dependencies = [
"futures", "futures",
"wgpu", "wgpu",

View File

@ -43,7 +43,7 @@ anim = {package = "veloren-voxygen-anim", path = "anim"}
# Graphics # Graphics
winit = {version = "0.24.0", features = ["serde"]} winit = {version = "0.24.0", features = ["serde"]}
wgpu = "0.7.0" wgpu = "0.7.0"
wgpu-profiler = "0.2.1" wgpu-profiler = "0.3.1"
bytemuck = { version="1.4", features=["derive"] } bytemuck = { version="1.4", features=["derive"] }
shaderc = "0.6.2" shaderc = "0.6.2"

View File

@ -8,7 +8,6 @@ pub mod mesh;
pub mod model; pub mod model;
pub mod pipelines; pub mod pipelines;
pub mod renderer; pub mod renderer;
mod scope;
pub mod texture; pub mod texture;
// Reexports // Reexports

View File

@ -8,13 +8,13 @@ use super::{
clouds, figure, fluid, lod_terrain, particle, postprocess, shadow, skybox, sprite, clouds, figure, fluid, lod_terrain, particle, postprocess, shadow, skybox, sprite,
terrain, ui, ColLights, GlobalsBindGroup, Light, Shadow, terrain, ui, ColLights, GlobalsBindGroup, Light, Shadow,
}, },
scope::{ManualOwningScope, OwningScope, Scope},
}, },
Renderer, ShadowMap, ShadowMapRenderer, Renderer, ShadowMap, ShadowMapRenderer,
}; };
use core::{num::NonZeroU32, ops::Range}; use core::{num::NonZeroU32, ops::Range};
use std::sync::Arc; use std::sync::Arc;
use vek::Aabr; use vek::Aabr;
use wgpu_profiler::scope::{ManualOwningScope, OwningScope, Scope};
// Borrow the fields we need from the renderer so that the GpuProfiler can be // Borrow the fields we need from the renderer so that the GpuProfiler can be
// dijointly borrowed mutably // dijointly borrowed mutably
@ -57,7 +57,7 @@ impl<'frame> Drawer<'frame> {
}; };
let mut encoder = let mut encoder =
ManualOwningScope::start(&mut renderer.profiler, encoder, borrow.device, "frame"); ManualOwningScope::start("frame", &mut renderer.profiler, encoder, borrow.device);
Self { Self {
encoder: Some(encoder), encoder: Some(encoder),
@ -75,7 +75,7 @@ impl<'frame> Drawer<'frame> {
let encoder = self.encoder.as_mut().unwrap(); let encoder = self.encoder.as_mut().unwrap();
let device = self.borrow.device; let device = self.borrow.device;
let mut render_pass = let mut render_pass =
encoder.scoped_render_pass(device, "shadow_pass", &wgpu::RenderPassDescriptor { encoder.scoped_render_pass("shadow_pass", device, &wgpu::RenderPassDescriptor {
label: Some("shadow pass"), label: Some("shadow pass"),
color_attachments: &[], color_attachments: &[],
depth_stencil_attachment: Some( depth_stencil_attachment: Some(
@ -106,7 +106,7 @@ impl<'frame> Drawer<'frame> {
let encoder = self.encoder.as_mut().unwrap(); let encoder = self.encoder.as_mut().unwrap();
let device = self.borrow.device; let device = self.borrow.device;
let mut render_pass = let mut render_pass =
encoder.scoped_render_pass(device, "first_pass", &wgpu::RenderPassDescriptor { encoder.scoped_render_pass("first_pass", device, &wgpu::RenderPassDescriptor {
label: Some("first pass"), label: Some("first pass"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &self.borrow.views.tgt_color, attachment: &self.borrow.views.tgt_color,
@ -140,7 +140,7 @@ impl<'frame> Drawer<'frame> {
let encoder = self.encoder.as_mut().unwrap(); let encoder = self.encoder.as_mut().unwrap();
let device = self.borrow.device; let device = self.borrow.device;
let mut render_pass = let mut render_pass =
encoder.scoped_render_pass(device, "second_pass", &wgpu::RenderPassDescriptor { encoder.scoped_render_pass("second_pass", device, &wgpu::RenderPassDescriptor {
label: Some("second pass (clouds)"), label: Some("second pass (clouds)"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &self.borrow.views.tgt_color_pp, attachment: &self.borrow.views.tgt_color_pp,
@ -166,7 +166,7 @@ impl<'frame> Drawer<'frame> {
let encoder = self.encoder.as_mut().unwrap(); let encoder = self.encoder.as_mut().unwrap();
let device = self.borrow.device; let device = self.borrow.device;
let mut render_pass = let mut render_pass =
encoder.scoped_render_pass(device, "third_pass", &wgpu::RenderPassDescriptor { encoder.scoped_render_pass("third_pass", device, &wgpu::RenderPassDescriptor {
label: Some("third pass (postprocess + ui)"), label: Some("third pass (postprocess + ui)"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &self.swap_tex.view, attachment: &self.swap_tex.view,
@ -199,7 +199,7 @@ impl<'frame> Drawer<'frame> {
.encoder .encoder
.as_mut() .as_mut()
.unwrap() .unwrap()
.scope(device, "point shadows"); .scope("point shadows", device);
const STRIDE: usize = std::mem::size_of::<shadow::PointLightMatrix>(); const STRIDE: usize = std::mem::size_of::<shadow::PointLightMatrix>();
let data = bytemuck::cast_slice(matrices); let data = bytemuck::cast_slice(matrices);
@ -222,7 +222,7 @@ impl<'frame> Drawer<'frame> {
let label = format!("point shadow face-{} pass", face); let label = format!("point shadow face-{} pass", face);
let mut render_pass = let mut render_pass =
encoder.scoped_render_pass(device, &label, &wgpu::RenderPassDescriptor { encoder.scoped_render_pass(&label, device, &wgpu::RenderPassDescriptor {
label: Some(&label), label: Some(&label),
color_attachments: &[], color_attachments: &[],
depth_stencil_attachment: Some( depth_stencil_attachment: Some(
@ -269,9 +269,9 @@ impl<'frame> Drawer<'frame> {
if let ShadowMap::Enabled(ref shadow_renderer) = self.borrow.shadow.map { if let ShadowMap::Enabled(ref shadow_renderer) = self.borrow.shadow.map {
let device = self.borrow.device; let device = self.borrow.device;
let encoder = self.encoder.as_mut().unwrap(); let encoder = self.encoder.as_mut().unwrap();
encoder.scoped_render_pass( let _ = encoder.scoped_render_pass(
device,
"clear_directed_shadow", "clear_directed_shadow",
device,
&wgpu::RenderPassDescriptor { &wgpu::RenderPassDescriptor {
label: Some("clear directed shadow pass"), label: Some("clear directed shadow pass"),
color_attachments: &[], color_attachments: &[],
@ -306,7 +306,7 @@ impl<'frame> Drawer<'frame> {
}); });
let label = format!("clear point shadow face-{} pass", face); let label = format!("clear point shadow face-{} pass", face);
encoder.scoped_render_pass(device, &label, &wgpu::RenderPassDescriptor { let _ = encoder.scoped_render_pass(&label, device, &wgpu::RenderPassDescriptor {
label: Some(&label), label: Some(&label),
color_attachments: &[], color_attachments: &[],
depth_stencil_attachment: Some( depth_stencil_attachment: Some(
@ -349,7 +349,7 @@ impl<'pass> ShadowPassDrawer<'pass> {
pub fn draw_figure_shadows(&mut self) -> FigureShadowDrawer<'_, 'pass> { pub fn draw_figure_shadows(&mut self) -> FigureShadowDrawer<'_, 'pass> {
let mut render_pass = self let mut render_pass = self
.render_pass .render_pass
.scope(self.borrow.device, "direcred_figure_shadows"); .scope("direcred_figure_shadows", self.borrow.device);
render_pass.set_pipeline(&self.shadow_renderer.figure_directed_pipeline.pipeline); render_pass.set_pipeline(&self.shadow_renderer.figure_directed_pipeline.pipeline);
set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow);
@ -360,7 +360,7 @@ impl<'pass> ShadowPassDrawer<'pass> {
pub fn draw_terrain_shadows(&mut self) -> TerrainShadowDrawer<'_, 'pass> { pub fn draw_terrain_shadows(&mut self) -> TerrainShadowDrawer<'_, 'pass> {
let mut render_pass = self let mut render_pass = self
.render_pass .render_pass
.scope(self.borrow.device, "direcred_terrain_shadows"); .scope("direcred_terrain_shadows", self.borrow.device);
render_pass.set_pipeline(&self.shadow_renderer.terrain_directed_pipeline.pipeline); render_pass.set_pipeline(&self.shadow_renderer.terrain_directed_pipeline.pipeline);
set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow);
@ -412,7 +412,7 @@ pub struct FirstPassDrawer<'pass> {
impl<'pass> FirstPassDrawer<'pass> { impl<'pass> FirstPassDrawer<'pass> {
pub fn draw_skybox<'data: 'pass>(&mut self, model: &'data Model<skybox::Vertex>) { pub fn draw_skybox<'data: 'pass>(&mut self, model: &'data Model<skybox::Vertex>) {
let mut render_pass = self.render_pass.scope(self.borrow.device, "skybox"); let mut render_pass = self.render_pass.scope("skybox", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.skybox.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.skybox.pipeline);
set_quad_index_buffer::<skybox::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<skybox::Vertex>(&mut render_pass, &self.borrow);
@ -421,7 +421,7 @@ impl<'pass> FirstPassDrawer<'pass> {
} }
pub fn draw_lod_terrain<'data: 'pass>(&mut self, model: &'data Model<lod_terrain::Vertex>) { pub fn draw_lod_terrain<'data: 'pass>(&mut self, model: &'data Model<lod_terrain::Vertex>) {
let mut render_pass = self.render_pass.scope(self.borrow.device, "lod_terrain"); let mut render_pass = self.render_pass.scope("lod_terrain", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.lod_terrain.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.lod_terrain.pipeline);
set_quad_index_buffer::<lod_terrain::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<lod_terrain::Vertex>(&mut render_pass, &self.borrow);
@ -430,7 +430,7 @@ impl<'pass> FirstPassDrawer<'pass> {
} }
pub fn draw_figures(&mut self) -> FigureDrawer<'_, 'pass> { pub fn draw_figures(&mut self) -> FigureDrawer<'_, 'pass> {
let mut render_pass = self.render_pass.scope(self.borrow.device, "figures"); let mut render_pass = self.render_pass.scope("figures", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.figure.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.figure.pipeline);
set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow);
@ -439,7 +439,7 @@ impl<'pass> FirstPassDrawer<'pass> {
} }
pub fn draw_terrain<'data: 'pass>(&mut self) -> TerrainDrawer<'_, 'pass> { pub fn draw_terrain<'data: 'pass>(&mut self) -> TerrainDrawer<'_, 'pass> {
let mut render_pass = self.render_pass.scope(self.borrow.device, "terrain"); let mut render_pass = self.render_pass.scope("terrain", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.terrain.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.terrain.pipeline);
set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow);
@ -451,7 +451,7 @@ impl<'pass> FirstPassDrawer<'pass> {
} }
pub fn draw_particles(&mut self) -> ParticleDrawer<'_, 'pass> { pub fn draw_particles(&mut self) -> ParticleDrawer<'_, 'pass> {
let mut render_pass = self.render_pass.scope(self.borrow.device, "particles"); let mut render_pass = self.render_pass.scope("particles", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.particle.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.particle.pipeline);
set_quad_index_buffer::<particle::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<particle::Vertex>(&mut render_pass, &self.borrow);
@ -464,7 +464,7 @@ impl<'pass> FirstPassDrawer<'pass> {
globals: &'data sprite::SpriteGlobalsBindGroup, globals: &'data sprite::SpriteGlobalsBindGroup,
col_lights: &'data ColLights<sprite::Locals>, col_lights: &'data ColLights<sprite::Locals>,
) -> SpriteDrawer<'_, 'pass> { ) -> SpriteDrawer<'_, 'pass> {
let mut render_pass = self.render_pass.scope(self.borrow.device, "sprites"); let mut render_pass = self.render_pass.scope("sprites", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.sprite.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.sprite.pipeline);
set_quad_index_buffer::<particle::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<particle::Vertex>(&mut render_pass, &self.borrow);
@ -481,7 +481,7 @@ impl<'pass> FirstPassDrawer<'pass> {
&mut self, &mut self,
waves: &'data fluid::BindGroup, waves: &'data fluid::BindGroup,
) -> FluidDrawer<'_, 'pass> { ) -> FluidDrawer<'_, 'pass> {
let mut render_pass = self.render_pass.scope(self.borrow.device, "fluid"); let mut render_pass = self.render_pass.scope("fluid", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.fluid.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.fluid.pipeline);
set_quad_index_buffer::<fluid::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<fluid::Vertex>(&mut render_pass, &self.borrow);
@ -643,14 +643,14 @@ pub struct ThirdPassDrawer<'pass> {
impl<'pass> ThirdPassDrawer<'pass> { impl<'pass> ThirdPassDrawer<'pass> {
pub fn draw_post_process(&mut self) { pub fn draw_post_process(&mut self) {
let mut render_pass = self.render_pass.scope(self.borrow.device, "postprocess"); let mut render_pass = self.render_pass.scope("postprocess", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.postprocess.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.postprocess.pipeline);
render_pass.set_bind_group(1, &self.borrow.locals.postprocess_bind.bind_group, &[]); render_pass.set_bind_group(1, &self.borrow.locals.postprocess_bind.bind_group, &[]);
render_pass.draw(0..3, 0..1); render_pass.draw(0..3, 0..1);
} }
pub fn draw_ui(&mut self) -> UiDrawer<'_, 'pass> { pub fn draw_ui(&mut self) -> UiDrawer<'_, 'pass> {
let mut render_pass = self.render_pass.scope(self.borrow.device, "ui"); let mut render_pass = self.render_pass.scope("ui", self.borrow.device);
render_pass.set_pipeline(&self.borrow.pipelines.ui.pipeline); render_pass.set_pipeline(&self.borrow.pipelines.ui.pipeline);
set_quad_index_buffer::<ui::Vertex>(&mut render_pass, &self.borrow); set_quad_index_buffer::<ui::Vertex>(&mut render_pass, &self.borrow);

View File

@ -1,163 +0,0 @@
use wgpu_profiler::{GpuProfiler, ProfilerCommandRecorder};
pub struct Scope<'a, W: ProfilerCommandRecorder> {
profiler: &'a mut GpuProfiler,
wgpu_thing: &'a mut W,
}
pub struct OwningScope<'a, W: ProfilerCommandRecorder> {
profiler: &'a mut GpuProfiler,
wgpu_thing: W,
}
// Separate type since we can't destructure types that impl Drop :/
pub struct ManualOwningScope<'a, W: ProfilerCommandRecorder> {
profiler: &'a mut GpuProfiler,
wgpu_thing: W,
}
impl<'a, W: ProfilerCommandRecorder> Scope<'a, W> {
pub fn start(
profiler: &'a mut GpuProfiler,
wgpu_thing: &'a mut W,
device: &wgpu::Device,
label: &str,
) -> Self {
profiler.begin_scope(label, wgpu_thing, device);
Self {
profiler,
wgpu_thing,
}
}
/// Starts a scope nested within this one
pub fn scope(&mut self, device: &wgpu::Device, label: &str) -> Scope<'_, W> {
Scope::start(self.profiler, self.wgpu_thing, device, label)
}
}
impl<'a, W: ProfilerCommandRecorder> OwningScope<'a, W> {
pub fn start(
profiler: &'a mut GpuProfiler,
mut wgpu_thing: W,
device: &wgpu::Device,
label: &str,
) -> Self {
profiler.begin_scope(label, &mut wgpu_thing, device);
Self {
profiler,
wgpu_thing,
}
}
/// Starts a scope nested within this one
pub fn scope(&mut self, device: &wgpu::Device, label: &str) -> Scope<'_, W> {
Scope::start(self.profiler, &mut self.wgpu_thing, device, label)
}
}
impl<'a, W: ProfilerCommandRecorder> ManualOwningScope<'a, W> {
pub fn start(
profiler: &'a mut GpuProfiler,
mut wgpu_thing: W,
device: &wgpu::Device,
label: &str,
) -> Self {
profiler.begin_scope(label, &mut wgpu_thing, device);
Self {
profiler,
wgpu_thing,
}
}
/// Starts a scope nested within this one
pub fn scope(&mut self, device: &wgpu::Device, label: &str) -> Scope<'_, W> {
Scope::start(self.profiler, &mut self.wgpu_thing, device, label)
}
/// Ends the scope allowing the extraction of owned the wgpu thing
/// and the mutable reference to the GpuProfiler
pub fn end_scope(mut self) -> (W, &'a mut GpuProfiler) {
self.profiler.end_scope(&mut self.wgpu_thing);
(self.wgpu_thing, self.profiler)
}
}
impl<'a> Scope<'a, wgpu::CommandEncoder> {
/// Start a render pass wrapped in an OwnedScope
pub fn scoped_render_pass<'b>(
&'b mut self,
device: &wgpu::Device,
label: &str,
pass_descriptor: &wgpu::RenderPassDescriptor<'b, '_>,
) -> OwningScope<'b, wgpu::RenderPass> {
let render_pass = self.wgpu_thing.begin_render_pass(pass_descriptor);
OwningScope::start(self.profiler, render_pass, device, label)
}
}
impl<'a> OwningScope<'a, wgpu::CommandEncoder> {
/// Start a render pass wrapped in an OwnedScope
pub fn scoped_render_pass<'b>(
&'b mut self,
device: &wgpu::Device,
label: &str,
pass_descriptor: &wgpu::RenderPassDescriptor<'b, '_>,
) -> OwningScope<'b, wgpu::RenderPass> {
let render_pass = self.wgpu_thing.begin_render_pass(pass_descriptor);
OwningScope::start(self.profiler, render_pass, device, label)
}
}
impl<'a> ManualOwningScope<'a, wgpu::CommandEncoder> {
/// Start a render pass wrapped in an OwnedScope
pub fn scoped_render_pass<'b>(
&'b mut self,
device: &wgpu::Device,
label: &str,
pass_descriptor: &wgpu::RenderPassDescriptor<'b, '_>,
) -> OwningScope<'b, wgpu::RenderPass> {
let render_pass = self.wgpu_thing.begin_render_pass(pass_descriptor);
OwningScope::start(self.profiler, render_pass, device, label)
}
}
// Scope
impl<'a, W: ProfilerCommandRecorder> std::ops::Deref for Scope<'a, W> {
type Target = W;
fn deref(&self) -> &Self::Target { self.wgpu_thing }
}
impl<'a, W: ProfilerCommandRecorder> std::ops::DerefMut for Scope<'a, W> {
fn deref_mut(&mut self) -> &mut Self::Target { self.wgpu_thing }
}
impl<'a, W: ProfilerCommandRecorder> Drop for Scope<'a, W> {
fn drop(&mut self) { self.profiler.end_scope(self.wgpu_thing); }
}
// OwningScope
impl<'a, W: ProfilerCommandRecorder> std::ops::Deref for OwningScope<'a, W> {
type Target = W;
fn deref(&self) -> &Self::Target { &self.wgpu_thing }
}
impl<'a, W: ProfilerCommandRecorder> std::ops::DerefMut for OwningScope<'a, W> {
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.wgpu_thing }
}
impl<'a, W: ProfilerCommandRecorder> Drop for OwningScope<'a, W> {
fn drop(&mut self) { self.profiler.end_scope(&mut self.wgpu_thing); }
}
// ManualOwningScope
impl<'a, W: ProfilerCommandRecorder> std::ops::Deref for ManualOwningScope<'a, W> {
type Target = W;
fn deref(&self) -> &Self::Target { &self.wgpu_thing }
}
impl<'a, W: ProfilerCommandRecorder> std::ops::DerefMut for ManualOwningScope<'a, W> {
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.wgpu_thing }
}