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

re_renderer: Arrow buffers as (optional) first-class citizen #1482

Merged
merged 30 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
db87ebf
implement depth cloud renderer
teh-cmc Feb 27, 2023
ea87f88
proper rp config
teh-cmc Feb 27, 2023
931b468
self-review
teh-cmc Feb 27, 2023
0ee30e1
handle breaking changes from main
teh-cmc Feb 28, 2023
66729fe
upload depth textures through staging belt
teh-cmc Feb 28, 2023
981ddfc
addressing PR comments part 1 of N
teh-cmc Feb 28, 2023
90ecd3d
work around wgpu d16 web issue
teh-cmc Feb 28, 2023
f8bd1fc
addressing PR comments part 2 of N
teh-cmc Feb 28, 2023
ad9b19e
big refactoring of the whole quad spanning story
teh-cmc Feb 28, 2023
3d79fd6
accomodating breaking changes
teh-cmc Mar 1, 2023
85f40ca
bring back coverage
teh-cmc Mar 1, 2023
5e84d89
todos
teh-cmc Mar 1, 2023
6dd8819
procedural example
teh-cmc Mar 1, 2023
e564ce3
clean
teh-cmc Mar 1, 2023
2114e22
fix wasm cranky
teh-cmc Mar 2, 2023
d12a5b9
set up entity props & selection panel for backprojection
teh-cmc Feb 27, 2023
0335097
integrate depth clouds into rerun
teh-cmc Feb 27, 2023
2356b33
last merge conflicts
teh-cmc Mar 1, 2023
e157911
huh, nasty
teh-cmc Mar 2, 2023
cb9d705
everything working as i want
teh-cmc Mar 2, 2023
7cf4fd0
cleanin up
teh-cmc Mar 2, 2023
6581a98
self review
teh-cmc Mar 2, 2023
e0ea750
arrow as a first-class citizen
teh-cmc Mar 2, 2023
007c81b
Merge branch 'main' into cmc/depth_clouds_integration
teh-cmc Mar 2, 2023
3588352
Merge branch 'main' into cmc/depth_clouds_integration
teh-cmc Mar 3, 2023
4c0ad58
compute auto heuristics properly
teh-cmc Mar 3, 2023
a9c1fb1
gentle radius scale
teh-cmc Mar 3, 2023
cb63756
Merge branch 'cmc/depth_clouds_integration' into cmc/re_renderer_arrow
teh-cmc Mar 3, 2023
bb38d2a
transparent arrow integration
teh-cmc Mar 3, 2023
ec110ce
explicitly enable arrow for re_viewer
teh-cmc Mar 3, 2023
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.

30 changes: 30 additions & 0 deletions crates/re_data_store/src/entity_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl EntityPropertyMap {

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

// TODO(#1423): We need to properly split entity properties that only apply to specific
// views/primitives.
#[cfg(feature = "serde")]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
Expand All @@ -50,6 +52,20 @@ pub struct EntityProperties {
/// Only applies to pinhole cameras when in a spatial view, using 3D navigation.
///
pub pinhole_image_plane_distance: EditableAutoValue<f32>,

/// Should the depth texture be backprojected into a point cloud?
///
/// Only applies to tensors with meaning=depth that are affected by a pinhole transform when
/// in a spatial view, using 3D navigation.
pub backproject_depth: bool,
/// Entity path of the pinhole transform used for the backprojection.
///
/// `None` means backprojection is disabled.
pub backproject_pinhole_ent_path: Option<EntityPath>,
/// Used to scale the resulting point cloud.
pub backproject_scale: EditableAutoValue<f32>,
/// Used to scale the radii of the points in the resulting point cloud.
pub backproject_radius_scale: EditableAutoValue<f32>,
}

#[cfg(feature = "serde")]
Expand All @@ -64,6 +80,16 @@ impl EntityProperties {
.pinhole_image_plane_distance
.or(&child.pinhole_image_plane_distance)
.clone(),
backproject_depth: self.backproject_depth || child.backproject_depth,
backproject_pinhole_ent_path: child
.backproject_pinhole_ent_path
.clone()
.or(self.backproject_pinhole_ent_path.clone()),
backproject_scale: child.backproject_scale.or(&self.backproject_scale).clone(),
backproject_radius_scale: child
.backproject_radius_scale
.or(&self.backproject_radius_scale)
.clone(),
}
}
}
Expand All @@ -76,6 +102,10 @@ impl Default for EntityProperties {
visible_history: ExtraQueryHistory::default(),
interactive: true,
pinhole_image_plane_distance: EditableAutoValue::default(),
backproject_depth: false,
backproject_pinhole_ent_path: None,
backproject_scale: EditableAutoValue::default(),
backproject_radius_scale: EditableAutoValue::default(),
}
}
}
Expand Down
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"]
teh-cmc marked this conversation as resolved.
Show resolved Hide resolved

## 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
21 changes: 7 additions & 14 deletions crates/re_renderer/examples/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,14 @@ impl RenderDepthClouds {
} = self;

let focal_length = glam::Vec2::new(intrinsics.x_axis.x, intrinsics.y_axis.y);
let offset = glam::Vec2::new(intrinsics.x_axis.z, intrinsics.y_axis.z);
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| {
let linear_depth = depth.get_linear(
depth.dimensions.x - texcoords.x - 1,
depth.dimensions.y - texcoords.y - 1,
);
let linear_depth = depth.get_linear(texcoords.x, texcoords.y);
let pos_in_world = ((texcoords.as_vec2() - offset) * linear_depth
/ focal_length)
.extend(linear_depth);
Expand Down Expand Up @@ -171,17 +168,12 @@ impl RenderDepthClouds {
..
} = self;

let world_from_obj = glam::Mat4::from_cols(
glam::Vec4::NEG_X * *scale,
glam::Vec4::NEG_Y * *scale,
glam::Vec4::Z * *scale,
glam::Vec4::W,
);
let world_from_obj = glam::Mat4::from_scale(glam::Vec3::splat(*scale));

let depth_cloud_draw_data = DepthCloudDrawData::new(
re_ctx,
&[DepthCloud {
world_from_obj,
depth_camera_extrinsics: world_from_obj,
depth_camera_intrinsics: *intrinsics,
radius_scale: *radius_scale,
depth_dimensions: depth.dimensions,
Expand Down Expand Up @@ -261,7 +253,8 @@ impl framework::Example for RenderDepthClouds {
Vec3::new(focal_length, 0.0, offset.x),
Vec3::new(0.0, focal_length, offset.y),
Vec3::new(0.0, 0.0, 1.0),
);
)
.transpose();

RenderDepthClouds {
depth,
Expand Down Expand Up @@ -447,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
7 changes: 4 additions & 3 deletions crates/re_renderer/shader/depth_cloud.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn compute_point_data(quad_idx: i32) -> PointData {
let color = Vec4(linear_from_srgb(Vec3(norm_linear_depth)), 1.0);

// TODO(cmc): This assumes a pinhole camera; need to support other kinds at some point.
let intrinsics = transpose(depth_cloud_info.depth_camera_intrinsics);
let intrinsics = depth_cloud_info.depth_camera_intrinsics;
let focal_length = Vec2(intrinsics[0][0], intrinsics[1][1]);
let offset = Vec2(intrinsics[2][0], intrinsics[2][1]);

Expand All @@ -39,7 +39,7 @@ fn compute_point_data(quad_idx: i32) -> PointData {
norm_linear_depth,
);

let pos_in_world = depth_cloud_info.world_from_obj * Vec4(pos_in_obj, 1.0);
let pos_in_world = depth_cloud_info.extrinsincs * Vec4(pos_in_obj, 1.0);

var data: PointData;
data.pos_in_world = pos_in_world.xyz;
Expand All @@ -52,7 +52,8 @@ fn compute_point_data(quad_idx: i32) -> PointData {
// ---

struct DepthCloudInfo {
world_from_obj: Mat4,
/// The extrinsincs of the camera used for the projection.
extrinsincs: Mat4,

/// The intrinsics of the camera used for the projection.
///
Expand Down
46 changes: 30 additions & 16 deletions crates/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod gpu_data {
#[repr(C, align(256))]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub struct DepthCloudInfoUBO {
pub world_from_obj: crate::wgpu_buffer_types::Mat4,
pub depth_camera_extrinsics: crate::wgpu_buffer_types::Mat4,
pub depth_camera_intrinsics: crate::wgpu_buffer_types::Mat3,
pub radius_scale: crate::wgpu_buffer_types::F32RowPadded,

Expand All @@ -60,12 +60,26 @@ mod gpu_data {
// TODO(cmc): expose knobs to linearize/normalize/flip/cam-to-plane depth.
#[derive(Debug, Clone)]
pub enum DepthCloudDepthData {
#[cfg(not(feature = "arrow"))]
U16(Vec<u16>),
#[cfg(feature = "arrow")]
U16(arrow2::buffer::Buffer<u16>),
teh-cmc marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(not(feature = "arrow"))]
F32(Vec<f32>),
#[cfg(feature = "arrow")]
F32(arrow2::buffer::Buffer<f32>),
}

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

pub struct DepthCloud {
pub world_from_obj: glam::Mat4,
/// The extrinsics of the camera used for the projection.
pub depth_camera_extrinsics: glam::Mat4,

/// The intrinsics of the camera used for the projection.
///
Expand All @@ -87,11 +101,11 @@ pub struct DepthCloud {
impl Default for DepthCloud {
fn default() -> Self {
Self {
world_from_obj: glam::Mat4::IDENTITY,
depth_camera_extrinsics: glam::Mat4::IDENTITY,
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 All @@ -113,6 +127,17 @@ impl DepthCloudDrawData {
) -> Result<Self, ResourceManagerError> {
crate::profile_function!();

let bg_layout = ctx
.renderers
.write()
.get_or_create::<_, DepthCloudRenderer>(
&ctx.shared_renderer_data,
&mut ctx.gpu_resources,
&ctx.device,
&mut ctx.resolver,
)
.bind_group_layout;

if depth_clouds.is_empty() {
return Ok(DepthCloudDrawData {
bind_groups: Vec::new(),
Expand All @@ -123,24 +148,13 @@ impl DepthCloudDrawData {
ctx,
"depth_cloud_ubos".into(),
depth_clouds.iter().map(|info| gpu_data::DepthCloudInfoUBO {
world_from_obj: info.world_from_obj.into(),
depth_camera_extrinsics: info.depth_camera_extrinsics.into(),
depth_camera_intrinsics: info.depth_camera_intrinsics.into(),
radius_scale: info.radius_scale.into(),
end_padding: Default::default(),
}),
);

let bg_layout = ctx
.renderers
.write()
.get_or_create::<_, DepthCloudRenderer>(
&ctx.shared_renderer_data,
&mut ctx.gpu_resources,
&ctx.device,
&mut ctx.resolver,
)
.bind_group_layout;

let mut bind_groups = Vec::with_capacity(depth_clouds.len());
for (depth_cloud, ubo) in depth_clouds.iter().zip(depth_cloud_ubos.into_iter()) {
let depth_texture = match &depth_cloud.depth_data {
Expand Down
Loading