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 and emilk committed Mar 2, 2023
1 parent cef46e5 commit 125ee72
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

0 comments on commit 125ee72

Please sign in to comment.