Skip to content

Commit

Permalink
CpuWriteGpuReadBelt for fast frame by frame memory transfers (#1382)
Browse files Browse the repository at this point in the history
* Add CpuWriteGpuReadBelt and use it for frameuniform buffer and colors as poc
* Limit number of in-flight queue submissions
  • Loading branch information
Wumpf authored Feb 23, 2023
1 parent c286db9 commit 53b2d92
Show file tree
Hide file tree
Showing 25 changed files with 869 additions and 209 deletions.
2 changes: 1 addition & 1 deletion crates/re_renderer/examples/2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl framework::Example for Render2D {
// Moving the windows to a high dpi screen makes the second one bigger.
// Also, it looks different under perspective projection.
// The third point is automatic thickness which is determined by the point renderer implementation.
let mut point_cloud_builder = PointCloudBuilder::<()>::default();
let mut point_cloud_builder = PointCloudBuilder::<()>::new(re_ctx);
point_cloud_builder
.batch("points")
.add_points_2d(
Expand Down
4 changes: 3 additions & 1 deletion crates/re_renderer/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ struct Application<E> {
window: Window,
surface: wgpu::Surface,
surface_config: wgpu::SurfaceConfiguration,
re_ctx: RenderContext,
time: Time,

example: E,

re_ctx: RenderContext,
}

impl<E: Example + 'static> Application<E> {
Expand Down Expand Up @@ -277,6 +278,7 @@ impl<E: Example + 'static> Application<E> {
}
};

self.re_ctx.before_submit();
self.re_ctx.queue.submit(
draw_results
.into_iter()
Expand Down
52 changes: 30 additions & 22 deletions crates/re_renderer/examples/multiview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ use rand::Rng;
use re_renderer::{
renderer::{
GenericSkyboxDrawData, LineDrawData, LineStripFlags, MeshDrawData, MeshInstance,
PointCloudBatchFlags, PointCloudBatchInfo, PointCloudDrawData, PointCloudVertex,
TestTriangleDrawData,
},
resource_managers::ResourceLifeTime,
view_builder::{OrthographicCameraMode, Projection, TargetConfiguration, ViewBuilder},
Color32, LineStripSeriesBuilder, RenderContext, Rgba, Size,
Color32, LineStripSeriesBuilder, PointCloudBuilder, RenderContext, Rgba, Size,
};
use winit::event::{ElementState, VirtualKeyCode};

Expand Down Expand Up @@ -163,7 +162,8 @@ struct Multiview {
mesh_instance_positions_and_colors: Vec<(glam::Vec3, Color32)>,

// Want to have a large cloud of random points, but doing rng for all of them every frame is too slow
random_points: Vec<PointCloudVertex>,
random_points_positions: Vec<glam::Vec3>,
random_points_radii: Vec<Size>,
random_points_colors: Vec<Color32>,
}

Expand All @@ -188,17 +188,23 @@ impl Example for Multiview {

let mut rnd = <rand::rngs::StdRng as rand::SeedableRng>::seed_from_u64(42);
let random_point_range = -5.0_f32..5.0_f32;
let random_points = (0..500000)
.map(|_| PointCloudVertex {
position: glam::vec3(

let point_count = 500000;
let random_points_positions = (0..point_count)
.map(|_| {
glam::vec3(
rnd.gen_range(random_point_range.clone()),
rnd.gen_range(random_point_range.clone()),
rnd.gen_range(random_point_range.clone()),
),
radius: Size::new_scene(rnd.gen_range(0.005..0.05)),
)
})
.collect_vec();
let random_points_colors = (0..500000).map(|_| random_color(&mut rnd)).collect_vec();
let random_points_radii = (0..point_count)
.map(|_| Size::new_scene(rnd.gen_range(0.005..0.05)))
.collect_vec();
let random_points_colors = (0..point_count)
.map(|_| random_color(&mut rnd))
.collect_vec();

let model_mesh_instances = {
let reader = std::io::Cursor::new(include_bytes!("rerun.obj.zip"));
Expand Down Expand Up @@ -232,7 +238,8 @@ impl Example for Multiview {

model_mesh_instances,
mesh_instance_positions_and_colors,
random_points,
random_points_positions,
random_points_radii,
random_points_colors,
}
}
Expand Down Expand Up @@ -260,18 +267,19 @@ impl Example for Multiview {
let triangle = TestTriangleDrawData::new(re_ctx);
let skybox = GenericSkyboxDrawData::new(re_ctx);
let lines = build_lines(re_ctx, seconds_since_startup);
let point_cloud = PointCloudDrawData::new(
re_ctx,
&self.random_points,
&self.random_points_colors,
&[PointCloudBatchInfo {
label: "Random points".into(),
world_from_obj: glam::Mat4::from_rotation_x(seconds_since_startup),
point_count: self.random_points.len() as _,
flags: PointCloudBatchFlags::ENABLE_SHADING,
}],
)
.unwrap();

let mut builder = PointCloudBuilder::<()>::new(re_ctx);
builder
.batch("Random Points")
.world_from_obj(glam::Mat4::from_rotation_x(seconds_since_startup))
.add_points(
self.random_points_positions.len(),
self.random_points_positions.iter().cloned(),
)
.radii(self.random_points_radii.iter().cloned())
.colors(self.random_points_colors.iter().cloned());

let point_cloud = builder.to_draw_data(re_ctx).unwrap();
let meshes = build_mesh_instances(
re_ctx,
&self.model_mesh_instances,
Expand Down
Loading

1 comment on commit 53b2d92

@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: 53b2d92 Previous: c286db9 Ratio
datastore/insert/batch/rects/insert 550705 ns/iter (± 2211) 528374 ns/iter (± 10581) 1.04
datastore/latest_at/batch/rects/query 1797 ns/iter (± 3) 1762 ns/iter (± 45) 1.02
datastore/latest_at/missing_components/primary 356 ns/iter (± 1) 350 ns/iter (± 5) 1.02
datastore/latest_at/missing_components/secondaries 424 ns/iter (± 16) 417 ns/iter (± 7) 1.02
datastore/range/batch/rects/query 149488 ns/iter (± 781) 147016 ns/iter (± 2315) 1.02
mono_points_arrow/generate_message_bundles 47120457 ns/iter (± 1768406) 45256734 ns/iter (± 1522907) 1.04
mono_points_arrow/generate_messages 135923920 ns/iter (± 1527071) 131896180 ns/iter (± 1536074) 1.03
mono_points_arrow/encode_log_msg 165605810 ns/iter (± 941345) 161906893 ns/iter (± 2378917) 1.02
mono_points_arrow/encode_total 349477526 ns/iter (± 2007288) 343187281 ns/iter (± 2464380) 1.02
mono_points_arrow/decode_log_msg 183996590 ns/iter (± 1213770) 178993491 ns/iter (± 1873413) 1.03
mono_points_arrow/decode_message_bundles 71569187 ns/iter (± 1230500) 69854975 ns/iter (± 983158) 1.02
mono_points_arrow/decode_total 251579389 ns/iter (± 1806132) 247048881 ns/iter (± 2899826) 1.02
batch_points_arrow/generate_message_bundles 329597 ns/iter (± 1678) 316812 ns/iter (± 4309) 1.04
batch_points_arrow/generate_messages 6363 ns/iter (± 350) 6114 ns/iter (± 110) 1.04
batch_points_arrow/encode_log_msg 356796 ns/iter (± 1777) 347164 ns/iter (± 3806) 1.03
batch_points_arrow/encode_total 706656 ns/iter (± 3255) 685956 ns/iter (± 9086) 1.03
batch_points_arrow/decode_log_msg 346833 ns/iter (± 1024) 340711 ns/iter (± 3895) 1.02
batch_points_arrow/decode_message_bundles 2046 ns/iter (± 10) 1971 ns/iter (± 33) 1.04
batch_points_arrow/decode_total 357442 ns/iter (± 872) 348207 ns/iter (± 2891) 1.03
arrow_mono_points/insert 6779573804 ns/iter (± 6871522) 6796019364 ns/iter (± 18325118) 1.00
arrow_mono_points/query 1729894 ns/iter (± 14918) 1677485 ns/iter (± 25864) 1.03
arrow_batch_points/insert 2704874 ns/iter (± 13007) 2639888 ns/iter (± 31739) 1.02
arrow_batch_points/query 16579 ns/iter (± 82) 15995 ns/iter (± 258) 1.04
tuid/Tuid::random 34 ns/iter (± 0) 33 ns/iter (± 0) 1.03

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

Please sign in to comment.