Skip to content

Commit

Permalink
improved renderer label handling (#1731)
Browse files Browse the repository at this point in the history
* use format! instead of push_str on DebugLabel

* change most DebugLabels to more principled naming approach by mirrored rust field

* introduce include_shader_module for automatic debug labels on shader modules

* doc warning fix

* strip path prefix from shader
  • Loading branch information
Wumpf authored Mar 29, 2023
1 parent d84d2d1 commit 6d219e6
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 159 deletions.
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

2 comments on commit 6d219e6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 6d219e6 Previous: d84d2d1 Ratio
datastore/insert/batch/rects/insert 604432 ns/iter (± 3491) 595656 ns/iter (± 5248) 1.01
datastore/latest_at/batch/rects/query 1875 ns/iter (± 2) 1827 ns/iter (± 64) 1.03
datastore/latest_at/missing_components/primary 280 ns/iter (± 2) 276 ns/iter (± 3) 1.01
datastore/latest_at/missing_components/secondaries 434 ns/iter (± 2) 425 ns/iter (± 5) 1.02
datastore/range/batch/rects/query 167577 ns/iter (± 477) 149051 ns/iter (± 2000) 1.12
mono_points_arrow/generate_message_bundles 48140756 ns/iter (± 553167) 42956054 ns/iter (± 846925) 1.12
mono_points_arrow/generate_messages 186798797 ns/iter (± 1628346) 181906241 ns/iter (± 1670214) 1.03
mono_points_arrow/encode_log_msg 230999657 ns/iter (± 3655728) 219005854 ns/iter (± 1655460) 1.05
mono_points_arrow/encode_total 462511998 ns/iter (± 4022138) 443594955 ns/iter (± 3756558) 1.04
mono_points_arrow/decode_log_msg 276288133 ns/iter (± 1820309) 266153192 ns/iter (± 2562157) 1.04
mono_points_arrow/decode_message_bundles 101352669 ns/iter (± 1355560) 94505495 ns/iter (± 1244586) 1.07
mono_points_arrow/decode_total 372735857 ns/iter (± 2649819) 359343268 ns/iter (± 14241870) 1.04
mono_points_arrow_batched/generate_message_bundles 45633505 ns/iter (± 826076) 31349750 ns/iter (± 1599319) 1.46
mono_points_arrow_batched/generate_messages 16223157 ns/iter (± 767037) 8889953 ns/iter (± 501904) 1.82
mono_points_arrow_batched/encode_log_msg 1855934 ns/iter (± 37424) 1770994 ns/iter (± 15125) 1.05
mono_points_arrow_batched/encode_total 61330388 ns/iter (± 1387494) 44236809 ns/iter (± 2346489) 1.39
mono_points_arrow_batched/decode_log_msg 1031892 ns/iter (± 38272) 987788 ns/iter (± 5247) 1.04
mono_points_arrow_batched/decode_message_bundles 24058907 ns/iter (± 355251) 16492553 ns/iter (± 1183928) 1.46
mono_points_arrow_batched/decode_total 25835228 ns/iter (± 488503) 18039322 ns/iter (± 881815) 1.43
batch_points_arrow/generate_message_bundles 291854 ns/iter (± 2182) 280540 ns/iter (± 3106) 1.04
batch_points_arrow/generate_messages 7839 ns/iter (± 24) 7621 ns/iter (± 122) 1.03
batch_points_arrow/encode_log_msg 400285 ns/iter (± 3045) 381834 ns/iter (± 3251) 1.05
batch_points_arrow/encode_total 723520 ns/iter (± 10485) 683418 ns/iter (± 8730) 1.06
batch_points_arrow/decode_log_msg 352255 ns/iter (± 6589) 335913 ns/iter (± 2797) 1.05
batch_points_arrow/decode_message_bundles 2941 ns/iter (± 10) 2836 ns/iter (± 36) 1.04
batch_points_arrow/decode_total 355726 ns/iter (± 3360) 347147 ns/iter (± 2060) 1.02
arrow_mono_points/insert 8198778068 ns/iter (± 96848496) 6801273546 ns/iter (± 16225597) 1.21
arrow_mono_points/query 2023940 ns/iter (± 250786) 1743930 ns/iter (± 21940) 1.16
arrow_batch_points/insert 3199163 ns/iter (± 275112) 2966999 ns/iter (± 25040) 1.08
arrow_batch_points/query 17113 ns/iter (± 26) 16890 ns/iter (± 200) 1.01
arrow_batch_vecs/insert 43284 ns/iter (± 461) 42739 ns/iter (± 335) 1.01
arrow_batch_vecs/query 507484 ns/iter (± 1052) 497910 ns/iter (± 6017) 1.02
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 6d219e6 Previous: d84d2d1 Ratio
mono_points_arrow_batched/generate_messages 16223157 ns/iter (± 767037) 8889953 ns/iter (± 501904) 1.82

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.