wgpu: Add some more debug labels

This commit is contained in:
Nathan Adams 2022-12-23 21:06:09 +01:00
parent af9b1f1dec
commit 1863c93be1
3 changed files with 44 additions and 7 deletions

View File

@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex, Weak};
type PoolInner<T> = Mutex<Vec<T>>;
type Constructor<T> = Box<dyn Fn(&Descriptors) -> T>;
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct TexturePool {
pools: FnvHashMap<TextureKey, BufferPool<wgpu::Texture>>,
globals_cache: FnvHashMap<GlobalsKey, Weak<Globals>>,
@ -16,7 +16,10 @@ pub struct TexturePool {
impl TexturePool {
pub fn new() -> Self {
Default::default()
Self {
pools: FnvHashMap::default(),
globals_cache: FnvHashMap::default(),
}
}
pub fn get_texture(
@ -34,9 +37,17 @@ impl TexturePool {
sample_count,
};
let pool = self.pools.entry(key).or_insert_with(|| {
let label = if cfg!(feature = "render_debug_labels") {
use std::sync::atomic::{AtomicU32, Ordering};
static ID_COUNT: AtomicU32 = AtomicU32::new(0);
let id = ID_COUNT.fetch_add(1, Ordering::Relaxed);
create_debug_label!("Pooled texture {}", id)
} else {
None
};
BufferPool::new(Box::new(move |descriptors| {
descriptors.device.create_texture(&wgpu::TextureDescriptor {
label: None,
label: label.as_deref(),
size,
mip_level_count: 1,
sample_count,

View File

@ -306,7 +306,15 @@ impl<'pass, 'frame: 'pass, 'global: 'frame> CommandRenderer<'pass, 'frame, 'glob
Chunk::Draw(chunk, needs_depth) => {
let mut render_pass =
draw_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
label: create_debug_label!(
"Chunked draw calls {}",
if needs_depth {
"(with depth)"
} else {
"(Depthless)"
}
)
.as_deref(),
color_attachments: &[target.color_attachments(clear_color.take())],
depth_stencil_attachment: if needs_depth {
target.depth_attachment(&descriptors, texture_pool, first)
@ -394,7 +402,16 @@ impl<'pass, 'frame: 'pass, 'global: 'frame> CommandRenderer<'pass, 'frame, 'glob
descriptors
.device
.create_bind_group(&wgpu::BindGroupDescriptor {
label: None,
label: create_debug_label!(
"Complex blend binds {:?} {}",
blend_mode,
if needs_depth {
"(with depth)"
} else {
"(Depthless)"
}
)
.as_deref(),
layout: &descriptors.bind_layouts.blend,
entries: &[
wgpu::BindGroupEntry {
@ -424,7 +441,16 @@ impl<'pass, 'frame: 'pass, 'global: 'frame> CommandRenderer<'pass, 'frame, 'glob
let mut render_pass =
draw_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
label: create_debug_label!(
"Complex blend {:?} {}",
blend_mode,
if needs_depth {
"(with depth)"
} else {
"(Depthless)"
}
)
.as_deref(),
color_attachments: &[target.color_attachments(clear_color.take())],
depth_stencil_attachment: if needs_depth {
target.depth_attachment(descriptors, texture_pool, first)

View File

@ -275,7 +275,7 @@ impl Surface {
resolve_target: None,
})],
depth_stencil_attachment: None,
label: None,
label: create_debug_label!("Copy back to render target").as_deref(),
});
render_pass.set_pipeline(&pipeline);