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

ViewerContext test harness 0.1 #6432

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 9 additions & 5 deletions crates/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ pub fn tensor_ui(
None
};

let Some(render_ctx) = ctx.render_ctx else {
return;
};

let texture_result = gpu_bridge::tensor_to_gpu(
ctx.render_ctx,
render_ctx,
&debug_name,
tensor_data_row_id,
tensor,
Expand All @@ -147,7 +151,7 @@ pub fn tensor_ui(
ui.set_min_size(preview_size);

show_image_preview(
ctx.render_ctx,
render_ctx,
ctx.re_ui,
ui,
texture.clone(),
Expand All @@ -158,7 +162,7 @@ pub fn tensor_ui(
// Show larger image on hover.
let preview_size = Vec2::splat(400.0);
show_image_preview(
ctx.render_ctx,
render_ctx,
ctx.re_ui,
ui,
texture.clone(),
Expand Down Expand Up @@ -216,7 +220,7 @@ pub fn tensor_ui(
.min(texture_size(texture))
.min(egui::vec2(150.0, 300.0));
let response = show_image_preview(
ctx.render_ctx,
render_ctx,
ctx.re_ui,
ui,
texture.clone(),
Expand All @@ -227,7 +231,7 @@ pub fn tensor_ui(
if let Some(pointer_pos) = ui.ctx().pointer_latest_pos() {
let image_rect = response.rect;
show_zoomed_image_region_tooltip(
ctx.render_ctx,
render_ctx,
ui,
response,
tensor_data_row_id,
Expand Down
30 changes: 30 additions & 0 deletions crates/re_selection_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,33 @@ mod space_view_entity_picker;
mod space_view_space_origin_ui;

pub use selection_panel::SelectionPanel;

#[cfg(test)]
mod test {
use super::*;
use re_data_store::LatestAtQuery;
use re_viewer_context::{blueprint_timeline, Item, SpaceViewId};
use re_viewport_blueprint::ViewportBlueprint;

#[test]
fn test_selection_panel() {
abey79 marked this conversation as resolved.
Show resolved Hide resolved
re_log::setup_logging();

let mut test_ctx = re_viewer_context::test_context::TestContext::default();
test_ctx.edit_selection(|selection_state| {
selection_state.set_selection(Item::SpaceView(SpaceViewId::random()));
});

test_ctx.run(|ctx, ui| {
let (sender, _) = std::sync::mpsc::channel();
let blueprint = ViewportBlueprint::try_from_db(
ctx.store_context.blueprint,
&LatestAtQuery::latest(blueprint_timeline()),
sender,
);

let mut selection_panel = SelectionPanel::default();
selection_panel.show_panel(ctx, &blueprint, &mut Default::default(), ui, true);
});
}
}
7 changes: 4 additions & 3 deletions crates/re_space_view_spatial/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod ui_2d;
mod ui_3d;
mod visualizers;

use re_renderer::RenderContext;
use re_types::blueprint::components::BackgroundKind;
use re_types::components::{Resolution, TensorData};

Expand Down Expand Up @@ -78,7 +79,7 @@ fn query_pinhole(
}

pub(crate) fn configure_background(
ctx: &re_viewer_context::ViewerContext<'_>,
render_ctx: &RenderContext,
kind: BackgroundKind,
color: re_types::components::Color,
) -> (Option<re_renderer::QueueableDrawData>, re_renderer::Rgba) {
Expand All @@ -88,7 +89,7 @@ pub(crate) fn configure_background(
BackgroundKind::GradientDark => (
Some(
renderer::GenericSkyboxDrawData::new(
ctx.render_ctx,
render_ctx,
renderer::GenericSkyboxType::GradientDark,
)
.into(),
Expand All @@ -99,7 +100,7 @@ pub(crate) fn configure_background(
BackgroundKind::GradientBright => (
Some(
renderer::GenericSkyboxDrawData::new(
ctx.render_ctx,
render_ctx,
renderer::GenericSkyboxType::GradientBright,
)
.into(),
Expand Down
14 changes: 11 additions & 3 deletions crates/re_space_view_spatial/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ pub fn picking(
return Ok(response);
};

let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};

let picking_context = PickingContext::new(
pointer_pos_ui,
space_from_ui,
Expand All @@ -453,7 +457,7 @@ pub fn picking(
.at_most(128.0) as u32;

let _ = view_builder.schedule_picking_rect(
ctx.render_ctx,
render_ctx,
re_renderer::RectInt::from_middle_and_extent(
picking_context.pointer_in_pixel.as_ivec2(),
glam::uvec2(picking_rect_size, picking_rect_size),
Expand All @@ -467,7 +471,7 @@ pub fn picking(
let images = visualizers.get::<ImageVisualizer>()?;

let picking_result = picking_context.pick(
ctx.render_ctx,
render_ctx,
query.space_view_id.gpu_readback_id(),
&state.previous_picking_result,
&images.images,
Expand Down Expand Up @@ -699,6 +703,10 @@ fn image_hover_ui(
);
}

let Some(render_ctx) = ctx.render_ctx else {
return;
};
abey79 marked this conversation as resolved.
Show resolved Hide resolved

if let Some([h, w, ..]) = tensor.image_height_width_channels() {
ui.separator();
ui.horizontal(|ui| {
Expand Down Expand Up @@ -726,7 +734,7 @@ fn image_hover_ui(
c.entry(tensor_data_row_id, &decoded_tensor)
});
show_zoomed_image_region(
ctx.render_ctx,
render_ctx,
ui,
tensor_data_row_id,
&decoded_tensor,
Expand Down
10 changes: 7 additions & 3 deletions crates/re_space_view_spatial/src/ui_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ pub fn view_2d(
return Ok(());
}

let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};
abey79 marked this conversation as resolved.
Show resolved Hide resolved

// TODO(emilk): some way to visualize the resolution rectangle of the pinhole camera (in case there is no image logged).

// Note that we can't rely on the camera being part of scene.space_cameras since that requires
Expand Down Expand Up @@ -246,7 +250,7 @@ pub fn view_2d(
return Ok(());
};

let mut view_builder = ViewBuilder::new(ctx.render_ctx, target_config);
let mut view_builder = ViewBuilder::new(render_ctx, target_config);

// Create labels now since their shapes participate are added to scene.ui for picking.
let (label_shapes, ui_rects) = create_labels(
Expand Down Expand Up @@ -283,7 +287,7 @@ pub fn view_2d(
let background = re_viewport_blueprint::view_property::<Background>(ctx, query.space_view_id)
.unwrap_or(Background::DEFAULT_2D);
let (background_drawable, clear_color) = crate::configure_background(
ctx,
render_ctx,
background.kind,
background.color.unwrap_or(Background::DEFAULT_COLOR_2D),
);
Expand All @@ -295,7 +299,7 @@ pub fn view_2d(

if let Some(mode) = screenshot_context_menu(ctx, &response) {
view_builder
.schedule_screenshot(ctx.render_ctx, query.space_view_id.gpu_readback_id(), mode)
.schedule_screenshot(render_ctx, query.space_view_id.gpu_readback_id(), mode)
.ok();
}

Expand Down
12 changes: 8 additions & 4 deletions crates/re_space_view_spatial/src/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ pub fn view_3d(
draw_data,
} = system_output;

let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};
abey79 marked this conversation as resolved.
Show resolved Hide resolved

let highlights = &query.highlights;
let space_cameras = &parts.get::<CamerasVisualizer>()?.space_cameras;
// TODO(#5607): what should happen if the promise is still pending?
Expand All @@ -467,7 +471,7 @@ pub fn view_3d(
let eye = view_eye.to_eye();

// Various ui interactions draw additional lines.
let mut line_builder = LineDrawableBuilder::new(ctx.render_ctx);
let mut line_builder = LineDrawableBuilder::new(render_ctx);
line_builder.radius_boost_in_ui_points_for_outlines(SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES);
// We don't know ahead of time how many lines we need, but it's not gonna be a huge amount!
line_builder.reserve_strips(32)?;
Expand Down Expand Up @@ -519,7 +523,7 @@ pub fn view_3d(
.then(|| outline_config(ui.ctx())),
};

let mut view_builder = ViewBuilder::new(ctx.render_ctx, target_config);
let mut view_builder = ViewBuilder::new(render_ctx, target_config);

// Create labels now since their shapes participate are added to scene.ui for picking.
let (label_shapes, ui_rects) = create_labels(
Expand Down Expand Up @@ -610,7 +614,7 @@ pub fn view_3d(
// Screenshot context menu.
if let Some(mode) = screenshot_context_menu(ctx, &response) {
view_builder
.schedule_screenshot(ctx.render_ctx, query.space_view_id.gpu_readback_id(), mode)
.schedule_screenshot(render_ctx, query.space_view_id.gpu_readback_id(), mode)
.ok();
}

Expand Down Expand Up @@ -668,7 +672,7 @@ pub fn view_3d(
let background = re_viewport_blueprint::view_property::<Background>(ctx, query.space_view_id)
.unwrap_or(Background::DEFAULT_3D);
let (background_drawable, clear_color) = crate::configure_background(
ctx,
render_ctx,
background.kind,
background.color.unwrap_or(Background::DEFAULT_COLOR_3D),
);
Expand Down
6 changes: 5 additions & 1 deletion crates/re_space_view_spatial/src/visualizers/arrows2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ impl VisualizerSystem for Arrows2DVisualizer {
view_query: &ViewQuery<'_>,
view_ctx: &ViewContextCollection,
) -> Result<Vec<re_renderer::QueueableDrawData>, SpaceViewSystemExecutionError> {
let mut line_builder = LineDrawableBuilder::new(ctx.render_ctx);
let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};
Comment on lines +215 to +217
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a better way that's not super tricky to implement right now, but this kind of early out here makes this approach a lot less viable for benchmarks. It would be great if we could still some logic of the visualizers, at least including the queries

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. In this case though, literally the next line needs a render_ctx, and it can't be moved further down... 🤷


let mut line_builder = LineDrawableBuilder::new(render_ctx);
line_builder.radius_boost_in_ui_points_for_outlines(SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES);

super::entity_iterator::process_archetype::<Self, Arrows2D, _>(
Expand Down
6 changes: 5 additions & 1 deletion crates/re_space_view_spatial/src/visualizers/arrows3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ impl VisualizerSystem for Arrows3DVisualizer {
view_query: &ViewQuery<'_>,
view_ctx: &ViewContextCollection,
) -> Result<Vec<re_renderer::QueueableDrawData>, SpaceViewSystemExecutionError> {
let mut line_builder = LineDrawableBuilder::new(ctx.render_ctx);
let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};

let mut line_builder = LineDrawableBuilder::new(render_ctx);
line_builder.radius_boost_in_ui_points_for_outlines(SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES);

super::entity_iterator::process_archetype::<Self, Arrows3D, _>(
Expand Down
19 changes: 16 additions & 3 deletions crates/re_space_view_spatial/src/visualizers/assets3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use re_entity_db::EntityPath;
use re_log_types::{Instance, RowId, TimeInt};
use re_query::range_zip_1x2;
use re_renderer::renderer::MeshInstance;
use re_renderer::RenderContext;
use re_types::{
archetypes::Asset3D,
components::{Blob, MediaType, OutOfTreeTransform3D},
Expand Down Expand Up @@ -44,6 +45,7 @@ impl Asset3DVisualizer {
fn process_data<'a>(
&mut self,
ctx: &ViewerContext<'_>,
render_ctx: &RenderContext,
instances: &mut Vec<MeshInstance>,
entity_path: &EntityPath,
ent_context: &SpatialSceneEntityContext<'_>,
Expand Down Expand Up @@ -73,7 +75,7 @@ impl Asset3DVisualizer {
media_type: data.media_type.cloned(),
},
AnyMesh::Asset(&mesh),
ctx.render_ctx,
render_ctx,
)
});

Expand Down Expand Up @@ -133,6 +135,10 @@ impl VisualizerSystem for Asset3DVisualizer {
view_query: &ViewQuery<'_>,
view_ctx: &ViewContextCollection,
) -> Result<Vec<re_renderer::QueueableDrawData>, SpaceViewSystemExecutionError> {
let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};

let mut instances = Vec::new();

super::entity_iterator::process_archetype::<Self, Asset3D, _>(
Expand Down Expand Up @@ -169,12 +175,19 @@ impl VisualizerSystem for Asset3DVisualizer {
})
});

self.process_data(ctx, &mut instances, entity_path, spatial_ctx, data);
self.process_data(
ctx,
render_ctx,
&mut instances,
entity_path,
spatial_ctx,
data,
);
Ok(())
},
)?;

match re_renderer::renderer::MeshDrawData::new(ctx.render_ctx, &instances) {
match re_renderer::renderer::MeshDrawData::new(render_ctx, &instances) {
Ok(draw_data) => Ok(vec![draw_data.into()]),
Err(err) => {
re_log::error_once!("Failed to create mesh draw data from mesh instances: {err}");
Expand Down
6 changes: 5 additions & 1 deletion crates/re_space_view_spatial/src/visualizers/boxes2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ impl VisualizerSystem for Boxes2DVisualizer {
view_query: &ViewQuery<'_>,
view_ctx: &ViewContextCollection,
) -> Result<Vec<re_renderer::QueueableDrawData>, SpaceViewSystemExecutionError> {
let mut line_builder = LineDrawableBuilder::new(ctx.render_ctx);
let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};

let mut line_builder = LineDrawableBuilder::new(render_ctx);
line_builder.radius_boost_in_ui_points_for_outlines(SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES);

super::entity_iterator::process_archetype::<Self, Boxes2D, _>(
Expand Down
6 changes: 5 additions & 1 deletion crates/re_space_view_spatial/src/visualizers/boxes3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ impl VisualizerSystem for Boxes3DVisualizer {
view_query: &ViewQuery<'_>,
view_ctx: &ViewContextCollection,
) -> Result<Vec<re_renderer::QueueableDrawData>, SpaceViewSystemExecutionError> {
let mut line_builder = LineDrawableBuilder::new(ctx.render_ctx);
let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};

let mut line_builder = LineDrawableBuilder::new(render_ctx);
line_builder.radius_boost_in_ui_points_for_outlines(SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES);

super::entity_iterator::process_archetype::<Self, Boxes3D, _>(
Expand Down
6 changes: 5 additions & 1 deletion crates/re_space_view_spatial/src/visualizers/cameras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,15 @@ impl VisualizerSystem for CamerasVisualizer {
query: &ViewQuery<'_>,
view_ctx: &ViewContextCollection,
) -> Result<Vec<re_renderer::QueueableDrawData>, SpaceViewSystemExecutionError> {
let Some(render_ctx) = ctx.render_ctx else {
return Err(SpaceViewSystemExecutionError::NoRenderContextError);
};

let transforms = view_ctx.get::<TransformContext>()?;

// Counting all cameras ahead of time is a bit wasteful, but we also don't expect a huge amount,
// so let re_renderer's allocator internally decide what buffer sizes to pick & grow them as we go.
let mut line_builder = re_renderer::LineDrawableBuilder::new(ctx.render_ctx);
let mut line_builder = re_renderer::LineDrawableBuilder::new(render_ctx);
line_builder.radius_boost_in_ui_points_for_outlines(SIZE_BOOST_IN_POINTS_FOR_LINE_OUTLINES);

for data_result in query.iter_visible_data_results(ctx, Self::identifier()) {
Expand Down
Loading
Loading