Skip to content

Commit

Permalink
re_renderer: Arrow buffers as (optional) first-class citizen (#1482)
Browse files Browse the repository at this point in the history
* implement depth cloud renderer

* proper rp config

* self-review

* handle breaking changes from main

* upload depth textures through staging belt

* addressing PR comments part 1 of N

* work around wgpu d16 web issue

* addressing PR comments part 2 of N

* big refactoring of the whole quad spanning story

* accomodating breaking changes

* bring back coverage

* todos

* procedural example

* clean

* fix wasm cranky

* set up entity props & selection panel for backprojection

* integrate depth clouds into rerun

* last merge conflicts

* huh, nasty

* everything working as i want

* cleanin up

* self review

* arrow as a first-class citizen

* compute auto heuristics properly

* gentle radius scale

* explicitly enable arrow for re_viewer
  • Loading branch information
teh-cmc committed Mar 3, 2023
1 parent cb48497 commit 042240e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
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: 5 additions & 1 deletion crates/re_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]


[features]
default = ["import-obj", "import-gltf"]
default = ["arrow", "import-obj", "import-gltf"]

## Support for Arrow datatypes for end-to-end zero-copy.
arrow = ["dep:arrow2"]

## Support importing .obj files
import-obj = ["dep:tobj"]
Expand Down Expand Up @@ -61,6 +64,7 @@ thiserror.workspace = true
type-map = "0.5"

# optional
arrow2 = { workspace = true, optional = true }
gltf = { workspace = true, optional = true }
serde = { version = "1", features = ["derive"], optional = true }
tobj = { version = "3.2", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/examples/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl DepthTexture {
spiral(dimensions).for_each(|(texcoords, d)| {
data[(texcoords.x + texcoords.y * dimensions.x) as usize] = d;
});
let data = DepthCloudDepthData::F32(data);
let data = DepthCloudDepthData::F32(data.into());

Self { dimensions, data }
}
Expand Down
10 changes: 10 additions & 0 deletions crates/re_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ pub use ecolor::{Color32, Rgba};

// ---------------------------------------------------------------------------

// Make Arrow integration as transparent as possible.

#[cfg(feature = "arrow")]
pub type Buffer<T> = arrow2::buffer::Buffer<T>;

#[cfg(not(feature = "arrow"))]
pub type Buffer<T> = Vec<T>;

// ---------------------------------------------------------------------------

/// Profiling macro for puffin
#[doc(hidden)]
#[macro_export]
Expand Down
12 changes: 9 additions & 3 deletions crates/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ mod gpu_data {
// TODO(cmc): expose knobs to linearize/normalize/flip/cam-to-plane depth.
#[derive(Debug, Clone)]
pub enum DepthCloudDepthData {
U16(Vec<u16>),
F32(Vec<f32>),
U16(crate::Buffer<u16>),
F32(crate::Buffer<f32>),
}

impl Default for DepthCloudDepthData {
fn default() -> Self {
Self::F32(Default::default())
}
}

pub struct DepthCloud {
Expand Down Expand Up @@ -92,7 +98,7 @@ impl Default for DepthCloud {
depth_camera_intrinsics: glam::Mat3::IDENTITY,
radius_scale: 1.0,
depth_dimensions: glam::UVec2::ZERO,
depth_data: DepthCloudDepthData::F32(Vec::new()),
depth_data: DepthCloudDepthData::default(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ re_log_types = { workspace = true, features = [
] }
re_memory.workspace = true
re_query.workspace = true
re_renderer = { workspace = true, features = ["serde"] }
re_renderer = { workspace = true, features = ["arrow", "serde"] }
re_smart_channel.workspace = true
re_string_interner.workspace = true
re_tensor_ops.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,9 @@ impl ImagesPart {

// TODO(cmc): automagically convert as needed for non-natively supported datatypes?
let data = match &tensor.data {
// TODO(cmc): re_renderer needs native interop with Arrow, we shouldn't need to
// allocate this massive buffer and do a memcpy when we could just carry arround the
// original `arrow::Buffer`.
TensorData::U16(data) => DepthCloudDepthData::U16(data.to_vec()),
TensorData::F32(data) => DepthCloudDepthData::F32(data.to_vec()),
// NOTE: Shallow clone if feature `arrow` is enabled, full alloc + memcpy otherwise.
TensorData::U16(data) => DepthCloudDepthData::U16(data.clone()),
TensorData::F32(data) => DepthCloudDepthData::F32(data.clone()),
_ => {
let discriminant = std::mem::discriminant(&tensor.data);
re_log::warn_once!(
Expand Down

1 comment on commit 042240e

@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: 042240e Previous: cb48497 Ratio
datastore/insert/batch/rects/insert 535325 ns/iter (± 8175) 551075 ns/iter (± 4665) 0.97
datastore/latest_at/batch/rects/query 1798 ns/iter (± 19) 1808 ns/iter (± 5) 0.99
datastore/latest_at/missing_components/primary 346 ns/iter (± 6) 356 ns/iter (± 2) 0.97
datastore/latest_at/missing_components/secondaries 425 ns/iter (± 6) 422 ns/iter (± 3) 1.01
datastore/range/batch/rects/query 146994 ns/iter (± 2146) 150240 ns/iter (± 2085) 0.98
mono_points_arrow/generate_message_bundles 44338774 ns/iter (± 1578010) 49053814 ns/iter (± 2443665) 0.90
mono_points_arrow/generate_messages 132149687 ns/iter (± 1917376) 136929232 ns/iter (± 1351940) 0.97
mono_points_arrow/encode_log_msg 168587948 ns/iter (± 2309499) 167189745 ns/iter (± 997675) 1.01
mono_points_arrow/encode_total 354260027 ns/iter (± 3645159) 355925554 ns/iter (± 5163442) 1.00
mono_points_arrow/decode_log_msg 183555336 ns/iter (± 2600001) 187054410 ns/iter (± 1137135) 0.98
mono_points_arrow/decode_message_bundles 70359425 ns/iter (± 1293964) 71930702 ns/iter (± 1607760) 0.98
mono_points_arrow/decode_total 249807350 ns/iter (± 3363403) 266507009 ns/iter (± 3993786) 0.94
batch_points_arrow/generate_message_bundles 319531 ns/iter (± 4260) 334203 ns/iter (± 587) 0.96
batch_points_arrow/generate_messages 5944 ns/iter (± 82) 6249 ns/iter (± 17) 0.95
batch_points_arrow/encode_log_msg 348286 ns/iter (± 3586) 369439 ns/iter (± 1707) 0.94
batch_points_arrow/encode_total 681749 ns/iter (± 6844) 724084 ns/iter (± 12310) 0.94
batch_points_arrow/decode_log_msg 345234 ns/iter (± 3423) 357228 ns/iter (± 1481) 0.97
batch_points_arrow/decode_message_bundles 1985 ns/iter (± 32) 2107 ns/iter (± 5) 0.94
batch_points_arrow/decode_total 350955 ns/iter (± 3029) 351783 ns/iter (± 2166) 1.00
arrow_mono_points/insert 7019332677 ns/iter (± 20357376) 7256577931 ns/iter (± 40153605) 0.97
arrow_mono_points/query 1652387 ns/iter (± 31493) 1777555 ns/iter (± 19146) 0.93
arrow_batch_points/insert 2555820 ns/iter (± 25746) 2625185 ns/iter (± 12291) 0.97
arrow_batch_points/query 15423 ns/iter (± 182) 16024 ns/iter (± 157) 0.96
arrow_batch_vecs/insert 40901 ns/iter (± 434) 41636 ns/iter (± 305) 0.98
arrow_batch_vecs/query 485801 ns/iter (± 8610) 505694 ns/iter (± 828) 0.96
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

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

Please sign in to comment.