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

Simplify bind group allocation call by passing pool collection object. #1459

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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