-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add polylines and spheres for handling large worlds #152
Open
arjo129
wants to merge
44
commits into
main
Choose a base branch
from
arjo/feat/offscreen_rendering
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 41 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
b67b072
Preliminary spawning of polylines for lanes
luca-della-vedova c3ae7fb
Adds support for offscreen rendering.
arjo129 2f5b6dc
Able to retrieve and debug a color selection buffer.
arjo129 a78996c
Get selection camera to follow main camera.
arjo129 983feac
Fix various resizing related issues.
arjo129 d91eb55
Adds a simple color picking shader.
arjo129 e48b0bb
Comments
arjo129 efa32f2
Clean ups
arjo129 6e35e8d
Minor fixes.
arjo129 96472de
Playing with bevy_points
arjo129 14418f5
Got fixed sized anchors working
arjo129 4929e7f
Make anchors pickable in screen space as well
arjo129 87f2994
Lane selecting works
arjo129 e9b1ccb
Rename
arjo129 6e00b78
Style
arjo129 5430079
Merge branch 'main' of github.com:open-rmf/rmf_site into arjo/feat/of…
arjo129 77198bd
Clean ups
arjo129 4c0b3ce
Get arrows to scale as well
arjo129 4596c76
style
arjo129 e53ea42
Refactoring out the scale factor
arjo129 cd75fc9
Refactoring out the scale factor
arjo129 4efd873
Refactoring the selection system out
arjo129 c0cbe57
Renaming files to make things more readable
arjo129 df93732
More refactors
arjo129 0c6179a
style
arjo129 4ec4d20
Yet another rename
arjo129 ae4b634
Remove expensive re-spawning that was being done.
arjo129 366adce
More refactoring
arjo129 795ca6e
Merge branch 'main' into arjo/feat/offscreen_rendering
arjo129 54e421e
Disable color picking
arjo129 23cfeae
Merge remote-tracking branch 'origin' into arjo/feat/offscreen_rendering
arjo129 6466fa0
Broke stuff
arjo129 425889d
Discovered why selection was not working.
arjo129 d5dbd97
ctually commit the sign flip code.
arjo129 a4083bf
Second attempt at integrating into the system
arjo129 33d2015
GPU picking seems to work for anchors
arjo129 dac8788
Style
arjo129 22ab07c
Style
arjo129 efaef70
Lane picking should work now
arjo129 667522e
Merge branch 'main' into arjo/feat/offscreen_rendering
arjo129 ef4d256
Clean ups
arjo129 0f1c1fc
Double perf with smaller texture
arjo129 c8dc723
Slight perf improvement
arjo129 3487b85
cargo fmt
arjo129 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
rmf_site_editor/src/interaction/color_based_picker/camera_capture.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// Taken from https://github.com/bevyengine/bevy/pull/5550/files | ||
// Might be useful to move this to a utils folder. | ||
use std::sync::Arc; | ||
|
||
use bevy::prelude::*; | ||
use bevy::render::render_asset::RenderAssets; | ||
use bevy::render::render_graph::{self, NodeRunError, RenderGraph, RenderGraphContext}; | ||
use bevy::render::renderer::{RenderContext, RenderDevice, RenderQueue}; | ||
use bevy::render::{Extract, RenderApp, RenderStage}; | ||
|
||
use bevy::render::render_resource::{ | ||
Buffer, BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, ImageCopyBuffer, | ||
ImageDataLayout, | ||
}; | ||
use pollster::FutureExt; | ||
|
||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
pub fn receive_images( | ||
image_copiers: Query<&ImageCopier>, | ||
mut images: ResMut<Assets<Image>>, | ||
render_device: Res<RenderDevice>, | ||
) { | ||
for image_copier in image_copiers.iter() { | ||
if !image_copier.enabled() { | ||
continue; | ||
} | ||
// Derived from: https://sotrh.github.io/learn-wgpu/showcase/windowless/#a-triangle-without-a-window | ||
// We need to scope the mapping variables so that we can | ||
// unmap the buffer | ||
async { | ||
let buffer_slice = image_copier.buffer.slice(..); | ||
|
||
// NOTE: We have to create the mapping THEN device.poll() before await | ||
// the future. Otherwise the application will freeze. | ||
let (tx, rx) = futures_intrusive::channel::shared::oneshot_channel(); | ||
buffer_slice.map_async(wgpu::MapMode::Read, move |result| { | ||
tx.send(result).unwrap(); | ||
}); | ||
render_device.poll(wgpu::Maintain::Wait); | ||
rx.receive().await.unwrap().unwrap(); | ||
if let Some(mut image) = images.get_mut(&image_copier.dst_image) { | ||
image.data = buffer_slice.get_mapped_range().to_vec(); | ||
} | ||
|
||
image_copier.buffer.unmap(); | ||
} | ||
.block_on(); | ||
} | ||
} | ||
|
||
pub const IMAGE_COPY: &str = "image_copy"; | ||
|
||
pub struct ImageCopyPlugin; | ||
impl Plugin for ImageCopyPlugin { | ||
fn build(&self, app: &mut App) { | ||
let render_app = app.add_system(receive_images).sub_app_mut(RenderApp); | ||
|
||
render_app.add_system_to_stage(RenderStage::Extract, image_copy_extract); | ||
|
||
let mut graph = render_app.world.get_resource_mut::<RenderGraph>().unwrap(); | ||
|
||
graph.add_node(IMAGE_COPY, ImageCopyDriver::default()); | ||
|
||
graph | ||
.add_node_edge(IMAGE_COPY, bevy::render::main_graph::node::CAMERA_DRIVER) | ||
.unwrap(); | ||
} | ||
} | ||
|
||
#[derive(Clone, Default, Resource, Deref, DerefMut)] | ||
pub struct ImageCopiers(pub Vec<ImageCopier>); | ||
|
||
#[derive(Clone, Component)] | ||
pub struct ImageCopier { | ||
buffer: Buffer, | ||
enabled: Arc<AtomicBool>, | ||
src_image: Handle<Image>, | ||
dst_image: Handle<Image>, | ||
} | ||
|
||
impl ImageCopier { | ||
pub fn new( | ||
src_image: Handle<Image>, | ||
dst_image: Handle<Image>, | ||
size: Extent3d, | ||
render_device: &RenderDevice, | ||
) -> ImageCopier { | ||
let padded_bytes_per_row = | ||
RenderDevice::align_copy_bytes_per_row((size.width) as usize) * 4; | ||
|
||
let cpu_buffer = render_device.create_buffer(&BufferDescriptor { | ||
label: None, | ||
size: padded_bytes_per_row as u64 * size.height as u64, | ||
usage: BufferUsages::MAP_READ | BufferUsages::COPY_DST, | ||
mapped_at_creation: false, | ||
}); | ||
|
||
ImageCopier { | ||
buffer: cpu_buffer, | ||
src_image, | ||
dst_image, | ||
enabled: Arc::new(AtomicBool::new(true)), | ||
} | ||
} | ||
|
||
pub fn enable(&self) { | ||
self.enabled.store(true, Ordering::Relaxed); | ||
} | ||
|
||
pub fn disable(&self) { | ||
self.enabled.store(false, Ordering::Relaxed); | ||
} | ||
|
||
pub fn enabled(&self) -> bool { | ||
self.enabled.load(Ordering::Relaxed) | ||
} | ||
} | ||
|
||
pub fn image_copy_extract(mut commands: Commands, image_copiers: Extract<Query<&ImageCopier>>) { | ||
commands.insert_resource(ImageCopiers( | ||
image_copiers.iter().cloned().collect::<Vec<ImageCopier>>(), | ||
)); | ||
Comment on lines
+121
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll admit not knowing much about the rendering systems, why do we need to do this? Is it because render graph nodes can't actually get data from the world but only from resources? |
||
} | ||
|
||
#[derive(Default)] | ||
pub struct ImageCopyDriver; | ||
|
||
impl render_graph::Node for ImageCopyDriver { | ||
fn run( | ||
&self, | ||
_graph: &mut RenderGraphContext, | ||
render_context: &mut RenderContext, | ||
world: &World, | ||
) -> Result<(), NodeRunError> { | ||
let image_copiers = world.get_resource::<ImageCopiers>().unwrap(); | ||
let gpu_images = world.get_resource::<RenderAssets<Image>>().unwrap(); | ||
|
||
for image_copier in image_copiers.iter() { | ||
if !image_copier.enabled() { | ||
continue; | ||
} | ||
|
||
let src_image = gpu_images.get(&image_copier.src_image).unwrap(); | ||
|
||
let mut encoder = render_context | ||
.render_device | ||
.create_command_encoder(&CommandEncoderDescriptor::default()); | ||
|
||
let format = src_image.texture_format.describe(); | ||
|
||
let padded_bytes_per_row = RenderDevice::align_copy_bytes_per_row( | ||
(src_image.size.x as usize / format.block_dimensions.0 as usize) | ||
* format.block_size as usize, | ||
); | ||
|
||
let texture_extent = Extent3d { | ||
width: src_image.size.x as u32, | ||
height: src_image.size.y as u32, | ||
depth_or_array_layers: 1, | ||
}; | ||
|
||
encoder.copy_texture_to_buffer( | ||
src_image.texture.as_image_copy(), | ||
ImageCopyBuffer { | ||
buffer: &image_copier.buffer, | ||
layout: ImageDataLayout { | ||
offset: 0, | ||
bytes_per_row: Some( | ||
std::num::NonZeroU32::new(padded_bytes_per_row as u32).unwrap(), | ||
), | ||
rows_per_image: None, | ||
}, | ||
}, | ||
texture_extent, | ||
); | ||
|
||
let render_queue = world.get_resource::<RenderQueue>().unwrap(); | ||
render_queue.submit(std::iter::once(encoder.finish())); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly concerned about this but, to be fair, I'm not sure the alternative I'll propose is worth the additional effort, or even whether this is a big bottleneck at all!
From what I understand, this system will poll the gpu for the buffer, copy it to the CPU, then copy it into an image, so at least 1 GPU - CPU copy (usually quite expensive) and 2 CPU copies (expensive but not as much).
The
block_on()
call would make this system only return when all of this has happened. My proposal was to remove the blocking and either: