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

Optimize big point clouds by ~20% #3108

Merged
merged 11 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions crates/re_arrow_store/src/store_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ impl DataStore {
primary: ComponentName,
components: &[ComponentName; N],
) -> Option<(RowId, [Option<DataCell>; N])> {
re_tracing::profile_function!();

// TODO(cmc): kind & query_id need to somehow propagate through the span system.
self.query_id.fetch_add(1, Ordering::Relaxed);

Expand Down Expand Up @@ -461,8 +459,6 @@ impl IndexedTable {
primary: ComponentName,
components: &[ComponentName; N],
) -> Option<(RowId, [Option<DataCell>; N])> {
re_tracing::profile_function!();

// Early-exit if this entire table is unaware of this component.
if !self.all_components.contains(&primary) {
return None;
Expand Down Expand Up @@ -669,8 +665,6 @@ impl IndexedBucket {
primary: ComponentName,
components: &[ComponentName; N],
) -> Option<(RowId, [Option<DataCell>; N])> {
re_tracing::profile_function!();

self.sort_indices_if_needed();

let IndexedBucketInner {
Expand Down
4 changes: 4 additions & 0 deletions crates/re_query/src/archetype_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl ComponentWithInstances {
pub fn iter_instance_keys(
&self,
) -> impl Iterator<Item = re_types::components::InstanceKey> + '_ {
re_tracing::profile_function!();
self.instance_keys.to_native::<InstanceKey>()
}

Expand Down Expand Up @@ -268,6 +269,7 @@ impl<A: Archetype> ArchetypeView<A> {
/// Iterate over the [`InstanceKey`]s.
#[inline]
pub fn iter_instance_keys(&self) -> impl Iterator<Item = InstanceKey> + '_ {
re_tracing::profile_function!();
// TODO(https://github.com/rerun-io/rerun/issues/2750): Maybe make this an intersection instead
self.required_comp().iter_instance_keys()
}
Expand All @@ -284,6 +286,7 @@ impl<A: Archetype> ArchetypeView<A> {
pub fn iter_required_component<'a, C: Component + Default + 'a>(
&'a self,
) -> DeserializationResult<impl Iterator<Item = C> + '_> {
re_tracing::profile_function!();
debug_assert!(A::required_components()
.iter()
.any(|c| c.as_ref() == C::name()));
Expand Down Expand Up @@ -311,6 +314,7 @@ impl<A: Archetype> ArchetypeView<A> {
pub fn iter_optional_component<'a, C: Component + Clone + 'a>(
&'a self,
) -> DeserializationResult<impl Iterator<Item = Option<C>> + '_> {
re_tracing::profile_function!();
let component = self.components.get(&C::name());

if let Some(component) = component {
Expand Down
58 changes: 32 additions & 26 deletions crates/re_renderer/examples/2d.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use ecolor::Hsva;
use itertools::Itertools as _;

use re_renderer::{
renderer::{
ColormappedTexture, LineStripFlags, RectangleDrawData, RectangleOptions, TextureFilterMag,
Expand Down Expand Up @@ -169,23 +171,20 @@ impl framework::Example for Render2D {
// The third point is automatic thickness which is determined by the point renderer implementation.
let mut point_cloud_builder = PointCloudBuilder::new(re_ctx);
point_cloud_builder.batch("points").add_points_2d(
4,
[
glam::vec2(500.0, 120.0),
glam::vec2(520.0, 120.0),
glam::vec2(540.0, 120.0),
glam::vec2(560.0, 120.0),
]
.into_iter(),
[
&[
glam::vec3(500.0, 120.0, 0.0),
glam::vec3(520.0, 120.0, 0.0),
glam::vec3(540.0, 120.0, 0.0),
glam::vec3(560.0, 120.0, 0.0),
],
&[
Size::new_scene(4.0),
Size::new_points(4.0),
Size::AUTO,
Size::AUTO_LARGE,
]
.into_iter(),
std::iter::repeat(Color32::from_rgb(55, 180, 1)),
std::iter::repeat(re_renderer::PickingLayerInstanceId::default()),
],
&[Color32::from_rgb(55, 180, 1); 4],
&[re_renderer::PickingLayerInstanceId::default(); 4],
);

// Pile stuff to test for overlap handling.
Expand Down Expand Up @@ -214,22 +213,29 @@ impl framework::Example for Render2D {

let num_points = 8;
let size = Size::new_points(3.0);

let positions = (0..num_points)
.map(|i| {
glam::vec3(
30.0 * i as f32 + 20.0,
y_range.start
+ (y_range.end - y_range.start) / num_points as f32 * i as f32,
0.0,
)
})
.collect_vec();

let sizes = std::iter::repeat(size).collect_vec();

let colors = std::iter::repeat(Color32::WHITE).collect_vec();

let picking_ids =
std::iter::repeat(re_renderer::PickingLayerInstanceId::default()).collect_vec();

point_cloud_builder
.batch("points overlapping with lines")
.depth_offset(5)
.add_points_2d(
num_points,
(0..num_points).map(|i| {
glam::vec2(
30.0 * i as f32 + 20.0,
y_range.start
+ (y_range.end - y_range.start) / num_points as f32 * i as f32,
)
}),
std::iter::repeat(size),
std::iter::repeat(Color32::WHITE),
std::iter::repeat(re_renderer::PickingLayerInstanceId::default()),
);
.add_points_2d(&positions, &sizes, &colors, &picking_ids);
}

let line_strip_draw_data = line_strip_builder.into_draw_data(re_ctx).unwrap();
Expand Down
11 changes: 3 additions & 8 deletions crates/re_renderer/examples/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ impl RenderDepthClouds {
let offset = glam::Vec2::new(intrinsics.z_axis.x, intrinsics.z_axis.y);

let point_cloud_draw_data = {
let num_points = depth.dimensions.x * depth.dimensions.y;
let (points, colors, radii): (Vec<_>, Vec<_>, Vec<_>) = (0..depth.dimensions.y)
.flat_map(|y| (0..depth.dimensions.x).map(move |x| glam::UVec2::new(x, y)))
.map(|texcoords| {
Expand All @@ -98,13 +97,9 @@ impl RenderDepthClouds {
.multiunzip();

let mut builder = PointCloudBuilder::new(re_ctx);
builder.batch("backprojected point cloud").add_points(
num_points as _,
points.into_iter(),
radii.into_iter(),
colors.into_iter(),
std::iter::empty::<re_renderer::PickingLayerInstanceId>(),
);
builder
.batch("backprojected point cloud")
.add_points(&points, &radii, &colors, &[]);

builder.into_draw_data(re_ctx).unwrap()
};
Expand Down
9 changes: 4 additions & 5 deletions crates/re_renderer/examples/multiview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,10 @@ impl Example for Multiview {
.batch("Random Points")
.world_from_obj(glam::Affine3A::from_rotation_x(seconds_since_startup))
.add_points(
self.random_points_positions.len(),
self.random_points_positions.iter().cloned(),
self.random_points_radii.iter().cloned(),
self.random_points_colors.iter().cloned(),
std::iter::empty::<re_renderer::PickingLayerInstanceId>(),
&self.random_points_positions,
&self.random_points_radii,
&self.random_points_colors,
&[],
);

let point_cloud = builder.into_draw_data(re_ctx).unwrap();
Expand Down
9 changes: 4 additions & 5 deletions crates/re_renderer/examples/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ impl framework::Example for Picking {
.batch(format!("Random Points {i}"))
.picking_object_id(re_renderer::PickingLayerObjectId(i as u64 + 1)) // offset by one since 0=default=no hit
.add_points(
point_set.positions.len(),
point_set.positions.iter().cloned(),
point_set.radii.iter().cloned(),
point_set.colors.iter().cloned(),
point_set.picking_ids.iter().cloned(),
&point_set.positions,
&point_set.radii,
&point_set.colors,
&point_set.picking_ids,
);
}
view_builder.queue_draw(point_builder.into_draw_data(re_ctx).unwrap());
Expand Down
3 changes: 3 additions & 0 deletions crates/re_renderer/src/allocator/cpu_write_gpu_read_belt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ where
/// If the buffer is not big enough, only the first `self.remaining_capacity()` elements are pushed before returning an error.
#[inline]
pub fn extend_from_slice(&mut self, elements: &[T]) -> Result<(), CpuWriteGpuReadError> {
re_tracing::profile_function!();
let (result, elements) = if elements.len() > self.remaining_capacity() {
(
Err(CpuWriteGpuReadError::BufferFull {
Expand Down Expand Up @@ -106,6 +107,7 @@ where
&mut self,
elements: impl Iterator<Item = T>,
) -> Result<usize, CpuWriteGpuReadError> {
re_tracing::profile_function!();
let num_written_before = self.num_written();

for element in elements {
Expand All @@ -127,6 +129,7 @@ where
///
/// If the buffer is not big enough, only the first `self.remaining_capacity()` elements are pushed before returning an error.
pub fn fill_n(&mut self, element: T, num_elements: usize) -> Result<(), CpuWriteGpuReadError> {
re_tracing::profile_function!();
let (result, num_elements) = if num_elements > self.remaining_capacity() {
(
Err(CpuWriteGpuReadError::BufferFull {
Expand Down
2 changes: 2 additions & 0 deletions crates/re_renderer/src/allocator/uniform_buffer_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub fn create_and_fill_uniform_buffer_batch<T: bytemuck::Pod>(
label: DebugLabel,
content: impl ExactSizeIterator<Item = T>,
) -> Vec<BindGroupEntry> {
re_tracing::profile_function!(label.get().unwrap_or_default());

#[allow(clippy::let_unit_value)]
let _ = UniformBufferAlignmentCheck::<T>::CHECK;

Expand Down
Loading