Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved renderer label handling #1731

Merged
merged 5 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl CpuWriteGpuReadBelt {
let buffer = buffer_pool.alloc(
device,
&BufferDesc {
label: "CpuWriteGpuReadBelt buffer".into(),
label: "CpuWriteGpuReadBelt chunk buffer".into(),
size: buffer_size,
usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC,
mapped_at_creation: true,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/src/allocator/gpu_readback_belt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl GpuReadbackBelt {
let buffer = buffer_pool.alloc(
device,
&BufferDesc {
label: "GpuReadbackBelt buffer".into(),
label: "GpuReadbackBelt chunk buffer".into(),
size: buffer_size,
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
Expand Down
13 changes: 6 additions & 7 deletions crates/re_renderer/src/debug_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ pub struct DebugLabel {
label: String,
}

impl DebugLabel {
impl std::fmt::Debug for DebugLabel {
#[cfg(debug_assertions)]
pub fn push_str(mut self, append_this: &str) -> DebugLabel {
self.label.push_str(append_this);
self
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.label.fmt(f)
}

#[cfg(not(debug_assertions))]
pub fn push_str(&mut self, _append_this: &str) -> DebugLabel {
DebugLabel {}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DebugLabel").finish_non_exhaustive()
}
}

impl std::fmt::Debug for DebugLabel {
impl std::fmt::Display for DebugLabel {
#[cfg(debug_assertions)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.label.fmt(f)
Expand Down
47 changes: 18 additions & 29 deletions crates/re_renderer/src/draw_phases/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
use crate::{
allocator::create_and_fill_uniform_buffer_batch,
config::HardwareTier,
include_file,
include_shader_module,
renderer::screen_triangle_vertex_shader,
view_builder::ViewBuilder,
wgpu_resources::{
BindGroupDesc, BindGroupEntry, BindGroupLayoutDesc, GpuBindGroup, GpuBindGroupLayoutHandle,
GpuRenderPipelineHandle, GpuTexture, PipelineLayoutDesc, PoolError, RenderPipelineDesc,
SamplerDesc, ShaderModuleDesc, WgpuResourcePools,
SamplerDesc, WgpuResourcePools,
},
DebugLabel, RenderContext,
};
Expand Down Expand Up @@ -203,15 +203,15 @@ impl OutlineMaskProcessor {
resolution_in_pixel: [u32; 2],
) -> Self {
crate::profile_function!();
let instance_label = view_name.clone().push_str(" - OutlineMaskProcessor");
let instance_label: DebugLabel = format!("{view_name} - OutlineMaskProcessor").into();

// ------------- Textures -------------
let texture_pool = &ctx.gpu_resources.textures;

let mask_sample_count =
Self::mask_sample_count(ctx.shared_renderer_data.config.hardware_tier);
let mask_texture_desc = crate::wgpu_resources::TextureDesc {
label: instance_label.clone().push_str("::mask_texture"),
label: format!("{instance_label}::mask_texture").into(),
size: wgpu::Extent3d {
width: resolution_in_pixel[0],
height: resolution_in_pixel[1],
Expand All @@ -232,15 +232,15 @@ impl OutlineMaskProcessor {
let mask_depth = texture_pool.alloc(
&ctx.device,
&crate::wgpu_resources::TextureDesc {
label: instance_label.clone().push_str("::mask_depth"),
label: format!("{instance_label}::mask_depth").into(),
format: Self::MASK_DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
..mask_texture_desc
},
);

let voronoi_texture_desc = crate::wgpu_resources::TextureDesc {
label: instance_label.clone().push_str("::distance_texture"),
label: format!("{instance_label}::distance_texture").into(),
sample_count: 1,
format: Self::VORONOI_FORMAT,
..mask_texture_desc
Expand All @@ -266,6 +266,11 @@ impl OutlineMaskProcessor {

let screen_triangle_vertex_shader =
screen_triangle_vertex_shader(&mut ctx.gpu_resources, &ctx.device, &mut ctx.resolver);
let jumpflooding_init_shader_module = if mask_sample_count == 1 {
include_shader_module!("../../shader/outlines/jumpflooding_init.wgsl")
} else {
include_shader_module!("../../shader/outlines/jumpflooding_init_msaa.wgsl")
};
let jumpflooding_init_desc = RenderPipelineDesc {
label: "OutlineMaskProcessor::jumpflooding_init".into(),
pipeline_layout: ctx.gpu_resources.pipeline_layouts.get_or_create(
Expand All @@ -282,14 +287,7 @@ impl OutlineMaskProcessor {
fragment_handle: ctx.gpu_resources.shader_modules.get_or_create(
&ctx.device,
&mut ctx.resolver,
&ShaderModuleDesc {
label: "jumpflooding_init".into(),
source: if mask_sample_count == 1 {
include_file!("../../shader/outlines/jumpflooding_init.wgsl")
} else {
include_file!("../../shader/outlines/jumpflooding_init_msaa.wgsl")
},
},
&jumpflooding_init_shader_module,
),
vertex_buffers: smallvec![],
render_targets: smallvec![Some(Self::VORONOI_FORMAT.into())],
Expand Down Expand Up @@ -318,10 +316,7 @@ impl OutlineMaskProcessor {
fragment_handle: ctx.gpu_resources.shader_modules.get_or_create(
&ctx.device,
&mut ctx.resolver,
&ShaderModuleDesc {
label: "jumpflooding_step".into(),
source: include_file!("../../shader/outlines/jumpflooding_step.wgsl"),
},
&include_shader_module!("../../shader/outlines/jumpflooding_step.wgsl"),
),
..jumpflooding_init_desc
},
Expand Down Expand Up @@ -353,7 +348,7 @@ impl OutlineMaskProcessor {
encoder: &'a mut wgpu::CommandEncoder,
) -> wgpu::RenderPass<'a> {
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: self.label.clone().push_str(" - mask pass").get(),
label: DebugLabel::from(format!("{} - mask pass", self.label)).get(),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &self.mask_texture.default_view,
resolve_target: None, // We're going to do a manual resolve.
Expand Down Expand Up @@ -388,7 +383,7 @@ impl OutlineMaskProcessor {
// Initialize the jump flooding into voronoi texture 0 by looking at the mask texture.
{
let mut jumpflooding_init = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: self.label.clone().push_str(" - jumpflooding_init").get(),
label: DebugLabel::from(format!("{} - jumpflooding_init", self.label)).get(),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &self.voronoi_textures[0].default_view,
resolve_target: None,
Expand All @@ -409,11 +404,7 @@ impl OutlineMaskProcessor {
pipelines.get_resource(self.render_pipeline_jumpflooding_step)?;
for (i, bind_group) in self.bind_group_jumpflooding_steps.into_iter().enumerate() {
let mut jumpflooding_step = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: self
.label
.clone()
.push_str(&format!(" - jumpflooding_step {i}"))
.get(),
label: DebugLabel::from(format!("{} - jumpflooding_step {i}", self.label)).get(),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
// Start with texture 1 since the init step wrote to texture 0
view: &self.voronoi_textures[(i + 1) % 2].default_view,
Expand Down Expand Up @@ -458,7 +449,7 @@ impl OutlineMaskProcessor {
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: instance_label.clone().push_str("::jumpflooding_init"),
label: format!("{instance_label}::jumpflooding_init").into(),
entries: smallvec![BindGroupEntry::DefaultTextureView(mask_texture.handle)],
layout: bind_group_layout_jumpflooding_init,
},
Expand Down Expand Up @@ -545,9 +536,7 @@ impl OutlineMaskProcessor {
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: instance_label
.clone()
.push_str(&format!("::jumpflooding_steps[{i}]")),
label: format!("{instance_label}::jumpflooding_steps[{i}]").into(),
entries: smallvec![
BindGroupEntry::DefaultTextureView(voronoi_textures[i % 2].handle),
BindGroupEntry::Sampler(sampler),
Expand Down
10 changes: 4 additions & 6 deletions crates/re_renderer/src/draw_phases/picking_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl PickingLayerProcessor {
let picking_target = ctx.gpu_resources.textures.alloc(
&ctx.device,
&TextureDesc {
label: view_name.clone().push_str(" - PickingLayerProcessor"),
label: format!("{view_name} - PickingLayerProcessor").into(),
size: picking_rect.wgpu_extent(),
mip_level_count: 1,
sample_count: 1,
Expand All @@ -126,7 +126,7 @@ impl PickingLayerProcessor {
let picking_depth = ctx.gpu_resources.textures.alloc(
&ctx.device,
&TextureDesc {
label: view_name.clone().push_str(" - picking_layer depth"),
label: format!("{view_name} - picking_layer depth").into(),
format: Self::PICKING_LAYER_DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
..picking_target.creation_desc
Expand Down Expand Up @@ -166,9 +166,7 @@ impl PickingLayerProcessor {

let frame_uniform_buffer = create_and_fill_uniform_buffer(
ctx,
view_name
.clone()
.push_str(" - picking_layer frame uniform buffer"),
format!("{view_name} - picking_layer frame uniform buffer").into(),
frame_uniform_buffer_content,
);

Expand Down Expand Up @@ -203,7 +201,7 @@ impl PickingLayerProcessor {
crate::profile_function!();

let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: view_name.clone().push_str(" - picking_layer pass").get(),
label: DebugLabel::from(format!("{view_name} - picking_layer pass")).get(),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &self.picking_target.default_view,
resolve_target: None,
Expand Down
8 changes: 4 additions & 4 deletions crates/re_renderer/src/global_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl GlobalBindings {
layout: pools.bind_group_layouts.get_or_create(
device,
&BindGroupLayoutDesc {
label: "global bind group layout".into(),
label: "GlobalBindings::layout".into(),

// Needs to be kept in sync with `global_bindings.wgsl` / `create_bind_group`
entries: vec![
Expand Down Expand Up @@ -99,7 +99,7 @@ impl GlobalBindings {
nearest_neighbor_sampler: pools.samplers.get_or_create(
device,
&SamplerDesc {
label: "nearest".into(),
label: "GlobalBindings::nearest_neighbor_sampler".into(),
address_mode_u: wgpu::AddressMode::Repeat,
address_mode_v: wgpu::AddressMode::Repeat,
address_mode_w: wgpu::AddressMode::Repeat,
Expand All @@ -109,7 +109,7 @@ impl GlobalBindings {
trilinear_sampler: pools.samplers.get_or_create(
device,
&SamplerDesc {
label: "linear".into(),
label: "GlobalBindings::trilinear_sampler".into(),
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Linear,
Expand All @@ -134,7 +134,7 @@ impl GlobalBindings {
pools,
// Needs to be kept in sync with `global_bindings.wgsl` / `self.layout`
&BindGroupDesc {
label: "global bind group".into(),
label: "GlobalBindings::create_bind_group".into(),
entries: smallvec![
frame_uniform_buffer_binding,
BindGroupEntry::Sampler(self.nearest_neighbor_sampler),
Expand Down
6 changes: 3 additions & 3 deletions crates/re_renderer/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl GpuMesh {
let vertex_buffer_combined = pools.buffers.alloc(
device,
&BufferDesc {
label: data.label.clone().push_str(" - vertices"),
label: format!("{} - vertices", data.label).into(),
size: vb_combined_size,
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
Expand Down Expand Up @@ -247,7 +247,7 @@ impl GpuMesh {
let index_buffer = pools.buffers.alloc(
device,
&BufferDesc {
label: data.label.clone().push_str(" - indices"),
label: format!("{} - indices", data.label).into(),
size: index_buffer_size,
usage: wgpu::BufferUsages::INDEX | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
Expand All @@ -271,7 +271,7 @@ impl GpuMesh {
let materials = {
let uniform_buffer_bindings = create_and_fill_uniform_buffer_batch(
ctx,
data.label.clone().push_str(" - material uniforms"),
format!("{} - material uniforms", data.label).into(),
data.materials
.iter()
.map(|material| gpu_data::MaterialUniformBuffer {
Expand Down
11 changes: 4 additions & 7 deletions crates/re_renderer/src/renderer/compositor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::{
allocator::create_and_fill_uniform_buffer,
context::SharedRendererData,
include_file,
include_shader_module,
renderer::{screen_triangle_vertex_shader, DrawData, Renderer},
view_builder::ViewBuilder,
wgpu_resources::{
BindGroupDesc, BindGroupEntry, BindGroupLayoutDesc, GpuBindGroup, GpuBindGroupLayoutHandle,
GpuRenderPipelineHandle, GpuTexture, PipelineLayoutDesc, RenderPipelineDesc,
ShaderModuleDesc, WgpuResourcePools,
WgpuResourcePools,
},
OutlineConfig, Rgba,
};
Expand Down Expand Up @@ -89,7 +89,7 @@ impl CompositorDrawData {
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: "compositor".into(),
label: "CompositorDrawData::bind_group".into(),
entries: smallvec![
uniform_buffer_binding,
BindGroupEntry::DefaultTextureView(color_texture.handle),
Expand Down Expand Up @@ -172,10 +172,7 @@ impl Renderer for Compositor {
fragment_handle: pools.shader_modules.get_or_create(
device,
resolver,
&ShaderModuleDesc {
label: "tonemap (fragment)".into(),
source: include_file!("../../shader/composite.wgsl"),
},
&include_shader_module!("../../shader/composite.wgsl"),
),
vertex_buffers: smallvec![],
render_targets: smallvec![Some(shared_data.config.output_format_color.into())],
Expand Down
9 changes: 3 additions & 6 deletions crates/re_renderer/src/renderer/debug_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::{
allocator::create_and_fill_uniform_buffer,
context::SharedRendererData,
draw_phases::DrawPhase,
include_file,
include_shader_module,
wgpu_resources::{
BindGroupDesc, BindGroupEntry, BindGroupLayoutDesc, GpuBindGroup, GpuBindGroupLayoutHandle,
GpuRenderPipelineHandle, GpuTexture, PipelineLayoutDesc, RenderPipelineDesc,
ShaderModuleDesc, WgpuResourcePools,
WgpuResourcePools,
},
IntRect,
};
Expand Down Expand Up @@ -185,10 +185,7 @@ impl Renderer for DebugOverlayRenderer {
let shader_module = pools.shader_modules.get_or_create(
device,
resolver,
&ShaderModuleDesc {
label: "DebugOverlay".into(),
source: include_file!("../../shader/debug_overlay.wgsl"),
},
&include_shader_module!("../../shader/debug_overlay.wgsl"),
);
let render_pipeline = pools.render_pipelines.get_or_create(
device,
Expand Down
11 changes: 4 additions & 7 deletions crates/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use smallvec::smallvec;
use crate::{
allocator::create_and_fill_uniform_buffer_batch,
draw_phases::{DrawPhase, OutlineMaskProcessor},
include_file,
include_shader_module,
resource_managers::ResourceManagerError,
view_builder::ViewBuilder,
wgpu_resources::{
BindGroupDesc, BindGroupEntry, BindGroupLayoutDesc, GpuBindGroup, GpuBindGroupLayoutHandle,
GpuRenderPipelineHandle, GpuTexture, PipelineLayoutDesc, RenderPipelineDesc,
ShaderModuleDesc, TextureDesc, TextureRowDataInfo,
GpuRenderPipelineHandle, GpuTexture, PipelineLayoutDesc, RenderPipelineDesc, TextureDesc,
TextureRowDataInfo,
},
ColorMap, OutlineMaskPreference,
};
Expand Down Expand Up @@ -450,10 +450,7 @@ impl Renderer for DepthCloudRenderer {
let shader_module = pools.shader_modules.get_or_create(
device,
resolver,
&ShaderModuleDesc {
label: "depth_cloud".into(),
source: include_file!("../../shader/depth_cloud.wgsl"),
},
&include_shader_module!("../../shader/depth_cloud.wgsl"),
);

let render_pipeline_desc_color = RenderPipelineDesc {
Expand Down
Loading