Skip to content

Commit 40eadfa

Browse files
committed
docs
1 parent f4dc8e1 commit 40eadfa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

crates/bevy_render/src/picking.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,13 @@ fn map_and_send_buffer_async(query: Query<&ExtractedGpuPickingCamera, With<Extra
8080
Err(err) => bevy_log::error!("Failed to map entity buffer: {err}"),
8181
});
8282

83-
// Buffer is mapped and ready to be sent
83+
// This waits until the Buffer is mapped
8484
rx.recv().await.unwrap();
8585

8686
// Send the buffer to the main world
87-
let entity_buffer = &buffers.entity_buffer;
8887
let buffer_view = buffer_slice.get_mapped_range();
89-
// Immediately copy the data to CPU to avoid holding the mapped view for long
88+
// Copy the data to the CPU
9089
let entity_data = Vec::from(&*buffer_view);
91-
drop(buffer_view);
92-
entity_buffer.unmap();
9390

9491
// Because the channel is bounded to 1 entry, the channel will sometimes be full.
9592
// This isn't ideal but not blocking makes it faster which is preferred.
@@ -245,6 +242,7 @@ pub fn entity_as_uvec2(entity: Entity) -> UVec2 {
245242
UVec2::new(bits as u32, (bits >> 32) as u32)
246243
}
247244

245+
/// The textures used to draw the entity for each rendered mesh
248246
#[derive(Component, Clone)]
249247
pub struct EntityTextures {
250248
pub main: CachedTexture,
@@ -282,6 +280,7 @@ impl EntityTextures {
282280
}
283281
}
284282

283+
/// This creates the required buffers for each camera
285284
fn prepare_gpu_picking_buffers(
286285
render_device: Res<RenderDevice>,
287286
mut cameras: Query<
@@ -294,6 +293,9 @@ fn prepare_gpu_picking_buffers(
294293

295294
let buffer_dimensions =
296295
BufferDimensions::new(size.x as usize, size.y as usize, ENTITY_TEXTURE_FORMAT);
296+
// TODO We currently create one buffer per frame. This isn't ideal.
297+
// We should have a way to only create a buffer when required. Unfortunately, the async nature of
298+
// the buffer map api makes it hard to know how many buffer we'll need since we need at least one per frame.
297299
let entity_buffer = render_device.create_buffer(&BufferDescriptor {
298300
label: Some("Entity Buffer"),
299301
size: (buffer_dimensions.padded_bytes_per_row * buffer_dimensions.height) as u64,

0 commit comments

Comments
 (0)