Skip to content

Commit

Permalink
Simplify bind group allocation call by passing pool collection object. (
Browse files Browse the repository at this point in the history
#1459)

Got tired of all these parameters and since `BindGroupPool::alloc` recently became non-mut, this can be easily simplified.
  • Loading branch information
Wumpf authored Mar 1, 2023
1 parent cb1783b commit 8dc3e46
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 44 deletions.
5 changes: 1 addition & 4 deletions crates/re_renderer/src/global_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl GlobalBindings {
) -> GpuBindGroup {
pools.bind_groups.alloc(
device,
pools,
// Needs to be kept in sync with `global_bindings.wgsl` / `self.layout`
&BindGroupDesc {
label: "global bind group".into(),
Expand All @@ -141,10 +142,6 @@ impl GlobalBindings {
],
layout: self.layout,
},
&pools.bind_group_layouts,
&pools.textures,
&pools.buffers,
&pools.samplers,
)
}
}
5 changes: 1 addition & 4 deletions crates/re_renderer/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl GpuMesh {
let texture = ctx.texture_manager_2d.get(&material.albedo)?;
let bind_group = pools.bind_groups.alloc(
device,
pools,
&BindGroupDesc {
label: material.label.clone(),
entries: smallvec![
Expand All @@ -240,10 +241,6 @@ impl GpuMesh {
],
layout: mesh_bind_group_layout,
},
&pools.bind_group_layouts,
&pools.textures,
&pools.buffers,
&pools.samplers,
);

materials.push(GpuMaterial {
Expand Down
10 changes: 3 additions & 7 deletions crates/re_renderer/src/renderer/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,22 @@ impl DrawData for CompositorDrawData {

impl CompositorDrawData {
pub fn new(ctx: &mut RenderContext, target: &GpuTexture) -> Self {
let pools = &mut ctx.gpu_resources;
let mut renderers = ctx.renderers.write();
let compositor = renderers.get_or_create::<_, Compositor>(
&ctx.shared_renderer_data,
pools,
&mut ctx.gpu_resources,
&ctx.device,
&mut ctx.resolver,
);
CompositorDrawData {
bind_group: pools.bind_groups.alloc(
bind_group: ctx.gpu_resources.bind_groups.alloc(
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: "compositor".into(),
entries: smallvec![BindGroupEntry::DefaultTextureView(target.handle)],
layout: compositor.bind_group_layout,
},
&pools.bind_group_layouts,
&pools.textures,
&pools.buffers,
&pools.samplers,
),
}
}
Expand Down
10 changes: 2 additions & 8 deletions crates/re_renderer/src/renderer/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ impl LineDrawData {

let bind_group_all_lines = ctx.gpu_resources.bind_groups.alloc(
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: "line draw data".into(),
entries: smallvec![
Expand All @@ -488,10 +489,6 @@ impl LineDrawData {
],
layout: line_renderer.bind_group_layout_all_lines,
},
&ctx.gpu_resources.bind_group_layouts,
&ctx.gpu_resources.textures,
&ctx.gpu_resources.buffers,
&ctx.gpu_resources.samplers,
);

// Process batches
Expand All @@ -517,15 +514,12 @@ impl LineDrawData {
.min(Self::MAX_NUM_VERTICES as u32);
let bind_group = ctx.gpu_resources.bind_groups.alloc(
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: batch_info.label.clone(),
entries: smallvec![uniform_buffer_binding],
layout: line_renderer.bind_group_layout_batch,
},
&ctx.gpu_resources.bind_group_layouts,
&ctx.gpu_resources.textures,
&ctx.gpu_resources.buffers,
&ctx.gpu_resources.samplers,
);

batches_internal.push(LineStripBatch {
Expand Down
10 changes: 2 additions & 8 deletions crates/re_renderer/src/renderer/point_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ impl PointCloudDrawData {

let bind_group_all_points = ctx.gpu_resources.bind_groups.alloc(
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: "line drawdata".into(),
entries: smallvec![
Expand All @@ -306,10 +307,6 @@ impl PointCloudDrawData {
],
layout: point_renderer.bind_group_layout_all_points,
},
&ctx.gpu_resources.bind_group_layouts,
&ctx.gpu_resources.textures,
&ctx.gpu_resources.buffers,
&ctx.gpu_resources.samplers,
);

// Process batches
Expand All @@ -333,15 +330,12 @@ impl PointCloudDrawData {
{
let bind_group = ctx.gpu_resources.bind_groups.alloc(
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: batch_info.label.clone(),
entries: smallvec![uniform_buffer_binding],
layout: point_renderer.bind_group_layout_batch,
},
&ctx.gpu_resources.bind_group_layouts,
&ctx.gpu_resources.textures,
&ctx.gpu_resources.buffers,
&ctx.gpu_resources.samplers,
);

let point_vertex_range_end = (start_point_for_next_batch + batch_info.point_count)
Expand Down
5 changes: 1 addition & 4 deletions crates/re_renderer/src/renderer/rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl RectangleDrawData {

bind_groups.push(ctx.gpu_resources.bind_groups.alloc(
&ctx.device,
&ctx.gpu_resources,
&BindGroupDesc {
label: "rectangle".into(),
entries: smallvec![
Expand All @@ -183,10 +184,6 @@ impl RectangleDrawData {
],
layout: rectangle_renderer.bind_group_layout,
},
&ctx.gpu_resources.bind_group_layouts,
&ctx.gpu_resources.textures,
&ctx.gpu_resources.buffers,
&ctx.gpu_resources.samplers,
));
}

Expand Down
19 changes: 10 additions & 9 deletions crates/re_renderer/src/wgpu_resources/bind_group_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use smallvec::SmallVec;
use crate::debug_label::DebugLabel;

use super::{
bind_group_layout_pool::{GpuBindGroupLayoutHandle, GpuBindGroupLayoutPool},
bind_group_layout_pool::GpuBindGroupLayoutHandle,
buffer_pool::{GpuBuffer, GpuBufferHandle, GpuBufferPool},
dynamic_resource_pool::{DynamicResource, DynamicResourcePool, DynamicResourcesDesc},
sampler_pool::{GpuSamplerHandle, GpuSamplerPool},
texture_pool::{GpuTexture, GpuTextureHandle, GpuTexturePool},
WgpuResourcePools,
};

slotmap::new_key_type! { pub struct GpuBindGroupHandle; }
Expand Down Expand Up @@ -104,11 +105,8 @@ impl GpuBindGroupPool {
pub fn alloc(
&self,
device: &wgpu::Device,
pools: &WgpuResourcePools,
desc: &BindGroupDesc,
bind_group_layouts: &GpuBindGroupLayoutPool,
textures: &GpuTexturePool,
buffers: &GpuBufferPool,
samplers: &GpuSamplerPool,
) -> GpuBindGroup {
// Retrieve strong handles to buffers and textures.
// This way, an owner of a bind group handle keeps buffers & textures alive!.
Expand All @@ -118,7 +116,8 @@ impl GpuBindGroupPool {
.filter_map(|e| {
if let BindGroupEntry::Buffer { handle, .. } = e {
Some(
buffers
pools
.buffers
.get_from_handle(*handle)
.expect("BindGroupDesc had an invalid buffer handle"),
)
Expand All @@ -134,7 +133,8 @@ impl GpuBindGroupPool {
.filter_map(|e| {
if let BindGroupEntry::DefaultTextureView(handle) = e {
Some(
textures
pools
.textures
.get_from_handle(*handle)
.expect("BindGroupDesc had an invalid texture handle"),
)
Expand Down Expand Up @@ -178,14 +178,15 @@ impl GpuBindGroupPool {
res
}
BindGroupEntry::Sampler(handle) => wgpu::BindingResource::Sampler(
samplers
pools
.samplers
.get_resource(*handle)
.expect("BindGroupDesc had an sampler handle"),
),
},
})
.collect::<Vec<_>>(),
layout: bind_group_layouts.get_resource(desc.layout).unwrap(),
layout: pools.bind_group_layouts.get_resource(desc.layout).unwrap(),
})
});

Expand Down

1 comment on commit 8dc3e46

@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: 8dc3e46 Previous: cb1783b Ratio
datastore/insert/batch/rects/insert 546884 ns/iter (± 1797) 537220 ns/iter (± 19353) 1.02
datastore/latest_at/batch/rects/query 1831 ns/iter (± 7) 1743 ns/iter (± 25) 1.05
datastore/latest_at/missing_components/primary 356 ns/iter (± 1) 344 ns/iter (± 4) 1.03
datastore/latest_at/missing_components/secondaries 426 ns/iter (± 0) 408 ns/iter (± 6) 1.04
datastore/range/batch/rects/query 155012 ns/iter (± 593) 146707 ns/iter (± 1732) 1.06
mono_points_arrow/generate_message_bundles 47762281 ns/iter (± 1312329) 44698006 ns/iter (± 1165970) 1.07
mono_points_arrow/generate_messages 138430517 ns/iter (± 1344508) 132761896 ns/iter (± 1834953) 1.04
mono_points_arrow/encode_log_msg 165552042 ns/iter (± 559602) 164429504 ns/iter (± 1307931) 1.01
mono_points_arrow/encode_total 358603187 ns/iter (± 2325877) 344972798 ns/iter (± 2488450) 1.04
mono_points_arrow/decode_log_msg 187663885 ns/iter (± 1101542) 180321929 ns/iter (± 1854326) 1.04
mono_points_arrow/decode_message_bundles 74420508 ns/iter (± 1233925) 70036243 ns/iter (± 1475520) 1.06
mono_points_arrow/decode_total 256789361 ns/iter (± 1978684) 248830965 ns/iter (± 2955044) 1.03
batch_points_arrow/generate_message_bundles 332935 ns/iter (± 2638) 320945 ns/iter (± 4653) 1.04
batch_points_arrow/generate_messages 6274 ns/iter (± 27) 6012 ns/iter (± 88) 1.04
batch_points_arrow/encode_log_msg 359501 ns/iter (± 1134) 350148 ns/iter (± 2491) 1.03
batch_points_arrow/encode_total 709109 ns/iter (± 2453) 683589 ns/iter (± 5872) 1.04
batch_points_arrow/decode_log_msg 346502 ns/iter (± 871) 341917 ns/iter (± 3074) 1.01
batch_points_arrow/decode_message_bundles 2057 ns/iter (± 13) 2024 ns/iter (± 28) 1.02
batch_points_arrow/decode_total 359068 ns/iter (± 1272) 347441 ns/iter (± 3079) 1.03
arrow_mono_points/insert 7151725441 ns/iter (± 20536898) 6744343365 ns/iter (± 18982185) 1.06
arrow_mono_points/query 1709144 ns/iter (± 9761) 1678376 ns/iter (± 19327) 1.02
arrow_batch_points/insert 2616679 ns/iter (± 9551) 2546167 ns/iter (± 23141) 1.03
arrow_batch_points/query 17644 ns/iter (± 67) 17169 ns/iter (± 395) 1.03
tuid/Tuid::random 34 ns/iter (± 0) 33 ns/iter (± 0) 1.03

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

Please sign in to comment.