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

CpuWriteGpuReadBelt for fast frame by frame memory transfers #1382

Merged
merged 23 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
137deba
Allow mapped_on_creation for wgpu buffer
Wumpf Feb 20, 2023
ef93d72
Add CpuWriteGpuReadBelt and use it for frameuniform buffer as poc
Wumpf Feb 20, 2023
a1c439e
Reduce amount of unsafe code in CpuWriteGpuReadBuffer. Better handlin…
Wumpf Feb 20, 2023
847e3af
debug fmt for CpuWriteGpuReadBelt for easier debugging
Wumpf Feb 20, 2023
ceb2695
add missing profiler scopes & call to before_submit
Wumpf Feb 20, 2023
10c4a9f
require point cloud builder for creating point cloud data
Wumpf Feb 20, 2023
0226fb2
Make `CpuWriteGpuReadBuffer` more like a Vec. POC usage in PointCloud…
Wumpf Feb 20, 2023
1bf15f7
add note on pitfalls of write combined memory
Wumpf Feb 20, 2023
09a1f20
Introduce minimum alignment to CpuWriteGpuReadBelt, fix padding mista…
Wumpf Feb 21, 2023
628162f
Merge remote-tracking branch 'origin/main' into andreas/re_renderer/s…
Wumpf Feb 22, 2023
5728005
cleanup, fixup alignment padding a bit
Wumpf Feb 22, 2023
7d544a7
Limit number of in-flight queue submissions
Wumpf Feb 22, 2023
cf57460
different memory budget for web and native on staging belt
Wumpf Feb 22, 2023
9db6f70
nicer poll_device implementation
Wumpf Feb 22, 2023
1d30e9a
move per_frame_data_helper into ActiveFrame
Wumpf Feb 22, 2023
b7078c3
iterating on some doc and api aspects. Add resource ownership check a…
Wumpf Feb 22, 2023
4e00a03
commenting out DynamicResourcePool drop check
Wumpf Feb 22, 2023
053e100
fix missing extend_defaults as well as fix a bug in it
Wumpf Feb 22, 2023
8b37ffc
Merge remote-tracking branch 'origin/main' into andreas/re_renderer/s…
Wumpf Feb 22, 2023
93f320c
doc string link fixes
Wumpf Feb 23, 2023
eee79a2
drop a todo
Wumpf Feb 23, 2023
b059255
fix writing to frame uniform buffer twice
Wumpf Feb 23, 2023
f193edb
comment fix & improvements
Wumpf Feb 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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