Skip to content

Commit

Permalink
Readback depth from GPU picking (#1752)
Browse files Browse the repository at this point in the history
* gpu picking in the viewer picks up depth now
* WebGL workarounds
  • Loading branch information
Wumpf authored Apr 4, 2023
1 parent d94ca3d commit bf27c8e
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 91 deletions.
18 changes: 9 additions & 9 deletions crates/re_renderer/examples/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ impl framework::Example for Picking {
PickingLayerProcessor::next_readback_result::<()>(re_ctx, READBACK_IDENTIFIER)
{
// Grab the middle pixel. usually we'd want to do something clever that snaps the the closest object of interest.
let picked_pixel = picking_result.picking_data[(picking_result.rect.extent.x / 2
+ (picking_result.rect.extent.y / 2) * picking_result.rect.extent.x)
as usize];
let picked_id = picking_result.picked_id(picking_result.rect.extent / 2);
//let picked_position =
// picking_result.picked_world_position(picking_result.rect.extent / 2);
//dbg!(picked_position, picked_id);

self.mesh_is_hovered = false;
if picked_pixel == MESH_ID {
if picked_id == MESH_ID {
self.mesh_is_hovered = true;
} else if picked_pixel.object.0 != 0
&& picked_pixel.object.0 <= self.point_sets.len() as u64
} else if picked_id.object.0 != 0 && picked_id.object.0 <= self.point_sets.len() as u64
{
let point_set = &mut self.point_sets[picked_pixel.object.0 as usize - 1];
point_set.radii[picked_pixel.instance.0 as usize] = Size::new_scene(0.1);
point_set.colors[picked_pixel.instance.0 as usize] = Color32::DEBUG_COLOR;
let point_set = &mut self.point_sets[picked_id.object.0 as usize - 1];
point_set.radii[picked_id.instance.0 as usize] = Size::new_scene(0.1);
point_set.colors[picked_id.instance.0 as usize] = Color32::DEBUG_COLOR;
}
}

Expand Down
15 changes: 15 additions & 0 deletions crates/re_renderer/shader/copy_texture.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Reads the content of a texture and writes it out as is.
//
// This is needed e.g. on WebGL to convert from a depth format to a regular color format that can be read back to the CPU.

#import <./types.wgsl>
#import <./global_bindings.wgsl>
#import <./screen_triangle_vertex.wgsl>

@group(1) @binding(0)
var tex: texture_2d<f32>;

@fragment
fn main(in: FragmentInput) -> @location(0) Vec4 {
return textureSample(tex, nearest_sampler, in.texcoord);
}
3 changes: 2 additions & 1 deletion crates/re_renderer/src/allocator/gpu_readback_belt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ impl GpuReadbackBuffer {
},
);

self.range_in_chunk = start_offset..self.range_in_chunk.end;
self.range_in_chunk =
(start_offset + buffer_info.buffer_size_padded)..self.range_in_chunk.end;
}
}

Expand Down
20 changes: 16 additions & 4 deletions crates/re_renderer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#[derive(Clone, Copy, Debug)]
pub enum HardwareTier {
/// For WebGL and native OpenGL. Maintains strict WebGL capability.
Basic,
Web,

/// Run natively with Vulkan/Metal but don't demand anything that isn't widely available.
Native,
Expand All @@ -17,7 +17,15 @@ impl HardwareTier {
/// Whether the current hardware tier supports sampling from textures with a sample count higher than 1.
pub fn support_sampling_msaa_texture(&self) -> bool {
match self {
HardwareTier::Basic => false,
HardwareTier::Web => false,
HardwareTier::Native => true,
}
}

/// Whether the current hardware tier supports sampling from textures with a sample count higher than 1.
pub fn support_depth_readback(&self) -> bool {
match self {
HardwareTier::Web => false,
HardwareTier::Native => true,
}
}
Expand All @@ -27,7 +35,7 @@ impl Default for HardwareTier {
fn default() -> Self {
// Use "Basic" tier for actual web but also if someone forces the GL backend!
if supported_backends() == wgpu::Backends::GL {
HardwareTier::Basic
HardwareTier::Web
} else {
HardwareTier::Native
}
Expand Down Expand Up @@ -63,7 +71,11 @@ impl HardwareTier {
/// Downlevel features required by the given tier.
pub fn required_downlevel_capabilities(self) -> wgpu::DownlevelCapabilities {
wgpu::DownlevelCapabilities {
flags: wgpu::DownlevelFlags::empty(),
flags: match self {
HardwareTier::Web => wgpu::DownlevelFlags::empty(),
// Require fully WebGPU compliance for the native tier.
HardwareTier::Native => wgpu::DownlevelFlags::all(),
},
limits: Default::default(), // unused so far both here and in wgpu
shader_model: wgpu::ShaderModel::Sm4,
}
Expand Down
Loading

1 comment on commit bf27c8e

@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: bf27c8e Previous: d94ca3d Ratio
arrow2/size_bytes/primitive/rows=10000/instances=100/array 151283 ns/iter (± 1110) 149363 ns/iter (± 918) 1.01
arrow2/size_bytes/primitive/rows=10000/instances=100/vec 3291 ns/iter (± 26) 3285 ns/iter (± 8) 1.00
arrow2/size_bytes/primitive/rows=10000/instances=100/vec/erased 17727 ns/iter (± 49) 17724 ns/iter (± 17) 1.00
arrow2/size_bytes/struct/rows=10000/instances=100/array 485165 ns/iter (± 3064) 491970 ns/iter (± 3490) 0.99
arrow2/size_bytes/struct/rows=10000/instances=100/vec 3285 ns/iter (± 11) 3288 ns/iter (± 9) 1.00
arrow2/size_bytes/struct/rows=10000/instances=100/vec/erased 17738 ns/iter (± 53) 17729 ns/iter (± 31) 1.00
arrow2/size_bytes/struct_large/rows=10000/instances=100/array 3729278 ns/iter (± 455125) 3796576 ns/iter (± 311267) 0.98
arrow2/size_bytes/struct_large/rows=10000/instances=100/vec 3974 ns/iter (± 15) 3978 ns/iter (± 13) 1.00
arrow2/size_bytes/struct_large/rows=10000/instances=100/vec/erased 17739 ns/iter (± 44) 17740 ns/iter (± 60) 1.00
arrow2/erased_clone/primitive/rows=10000/instances=100/cell/arc_erased 789253 ns/iter (± 1686) 783263 ns/iter (± 2196) 1.01
arrow2/erased_clone/primitive/rows=10000/instances=100/cell/wrapped_in_arc 195448 ns/iter (± 625) 198930 ns/iter (± 1569) 0.98
arrow2/erased_clone/primitive/rows=10000/instances=100/array 740940 ns/iter (± 2893) 750185 ns/iter (± 2279) 0.99
arrow2/erased_clone/primitive/rows=10000/instances=100/array/downcast_first 343781 ns/iter (± 1396) 345005 ns/iter (± 1144) 1.00
arrow2/erased_clone/primitive/rows=10000/instances=100/vec/full_copy 1011980 ns/iter (± 27228) 1027097 ns/iter (± 16175) 0.99
arrow2/erased_clone/primitive/rows=10000/instances=100/vec/wrapped_in_arc 128818 ns/iter (± 547) 128568 ns/iter (± 401) 1.00
arrow2/erased_clone/struct/rows=10000/instances=100/cell/arc_erased 4231047 ns/iter (± 79589) 4374814 ns/iter (± 127018) 0.97
arrow2/erased_clone/struct/rows=10000/instances=100/cell/wrapped_in_arc 287869 ns/iter (± 663) 287255 ns/iter (± 701) 1.00
arrow2/erased_clone/struct/rows=10000/instances=100/array 4234502 ns/iter (± 63681) 4258609 ns/iter (± 78409) 0.99
arrow2/erased_clone/struct/rows=10000/instances=100/array/downcast_first 3571220 ns/iter (± 44405) 3619118 ns/iter (± 58856) 0.99
arrow2/erased_clone/struct/rows=10000/instances=100/vec/full_copy 1287148 ns/iter (± 30665) 1293350 ns/iter (± 14984) 1.00
arrow2/erased_clone/struct/rows=10000/instances=100/vec/wrapped_in_arc 127479 ns/iter (± 182) 128546 ns/iter (± 292) 0.99
arrow2/erased_clone/struct_large/rows=10000/instances=100/cell/arc_erased 47856426 ns/iter (± 409354) 47406613 ns/iter (± 338387) 1.01
arrow2/erased_clone/struct_large/rows=10000/instances=100/cell/wrapped_in_arc 167118 ns/iter (± 426) 168731 ns/iter (± 837) 0.99
arrow2/erased_clone/struct_large/rows=10000/instances=100/array 46951163 ns/iter (± 422407) 46492032 ns/iter (± 382216) 1.01
arrow2/erased_clone/struct_large/rows=10000/instances=100/array/downcast_first 44645934 ns/iter (± 433245) 44560383 ns/iter (± 355142) 1.00
arrow2/erased_clone/struct_large/rows=10000/instances=100/vec/full_copy 4483235 ns/iter (± 132187) 4543857 ns/iter (± 142636) 0.99
arrow2/erased_clone/struct_large/rows=10000/instances=100/vec/wrapped_in_arc 127021 ns/iter (± 310) 127252 ns/iter (± 271) 1.00
arrow2_convert/serialize/primitive/instances=100000/arrow2_convert 416608 ns/iter (± 1008) 414447 ns/iter (± 1298) 1.01
arrow2_convert/serialize/primitive/instances=100000/arrow2/from_values 19735 ns/iter (± 108) 19581 ns/iter (± 93) 1.01
arrow2_convert/serialize/primitive/instances=100000/arrow2/from_vec 19666 ns/iter (± 110) 19498 ns/iter (± 103) 1.01
arrow2_convert/deserialize/primitive/instances=100000/arrow2_convert 96876 ns/iter (± 205) 96377 ns/iter (± 209) 1.01
arrow2_convert/deserialize/primitive/instances=100000/arrow2/validity_checks 159726 ns/iter (± 514) 163376 ns/iter (± 480) 0.98
arrow2_convert/deserialize/primitive/instances=100000/arrow2/validity_bypass 58632 ns/iter (± 241) 58188 ns/iter (± 148) 1.01
datastore/num_rows=1000/num_instances=1000/packed=false/insert/default 10763489 ns/iter (± 281148) 10815839 ns/iter (± 272848) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/insert/bucketsz=0 13018134 ns/iter (± 738578) 12957845 ns/iter (± 422964) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/insert/bucketsz=2 12651480 ns/iter (± 511062) 12514310 ns/iter (± 527432) 1.01
datastore/num_rows=1000/num_instances=1000/packed=false/insert/bucketsz=32 11134486 ns/iter (± 451515) 11179528 ns/iter (± 414170) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/insert/bucketsz=2048 10714231 ns/iter (± 402476) 10962498 ns/iter (± 422087) 0.98
datastore/num_rows=1000/num_instances=1000/packed=true/insert/default 10657953 ns/iter (± 394314) 10935737 ns/iter (± 506350) 0.97
datastore/num_rows=1000/num_instances=1000/packed=true/insert/bucketsz=0 13515670 ns/iter (± 708546) 12849798 ns/iter (± 622294) 1.05
datastore/num_rows=1000/num_instances=1000/packed=true/insert/bucketsz=2 13259593 ns/iter (± 481684) 12390150 ns/iter (± 596166) 1.07
datastore/num_rows=1000/num_instances=1000/packed=true/insert/bucketsz=32 10970687 ns/iter (± 348299) 10661511 ns/iter (± 411639) 1.03
datastore/num_rows=1000/num_instances=1000/packed=true/insert/bucketsz=2048 10855773 ns/iter (± 467414) 10266348 ns/iter (± 368447) 1.06
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/default 1823 ns/iter (± 18) 1812 ns/iter (± 30) 1.01
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/bucketsz=0 1834 ns/iter (± 5) 1816 ns/iter (± 3) 1.01
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/bucketsz=2 1806 ns/iter (± 10) 1821 ns/iter (± 5) 0.99
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/bucketsz=32 1798 ns/iter (± 6) 1822 ns/iter (± 4) 0.99
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/bucketsz=2048 1802 ns/iter (± 9) 1795 ns/iter (± 14) 1.00
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at/default 1837 ns/iter (± 18) 1856 ns/iter (± 20) 0.99
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at/bucketsz=0 1827 ns/iter (± 6) 1821 ns/iter (± 9) 1.00
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at/bucketsz=2 1829 ns/iter (± 13) 1834 ns/iter (± 9) 1.00
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at/bucketsz=32 1821 ns/iter (± 3) 1821 ns/iter (± 8) 1
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at/bucketsz=2048 1816 ns/iter (± 5) 1818 ns/iter (± 2) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/default 280 ns/iter (± 0) 280 ns/iter (± 0) 1
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/default 434 ns/iter (± 0) 447 ns/iter (± 3) 0.97
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/bucketsz=0 280 ns/iter (± 0) 279 ns/iter (± 1) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/bucketsz=0 443 ns/iter (± 1) 456 ns/iter (± 0) 0.97
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/bucketsz=2 281 ns/iter (± 1) 279 ns/iter (± 0) 1.01
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/bucketsz=2 444 ns/iter (± 4) 456 ns/iter (± 1) 0.97
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/bucketsz=32 281 ns/iter (± 0) 280 ns/iter (± 1) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/bucketsz=32 452 ns/iter (± 2) 453 ns/iter (± 2) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/bucketsz=2048 281 ns/iter (± 1) 280 ns/iter (± 1) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/bucketsz=2048 435 ns/iter (± 1) 448 ns/iter (± 0) 0.97
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/primary/default 280 ns/iter (± 1) 280 ns/iter (± 0) 1
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/secondaries/default 434 ns/iter (± 0) 448 ns/iter (± 1) 0.97
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/primary/bucketsz=0 281 ns/iter (± 0) 279 ns/iter (± 1) 1.01
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/secondaries/bucketsz=0 443 ns/iter (± 0) 457 ns/iter (± 1) 0.97
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/primary/bucketsz=2 280 ns/iter (± 0) 279 ns/iter (± 0) 1.00
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/secondaries/bucketsz=2 442 ns/iter (± 1) 456 ns/iter (± 0) 0.97
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/primary/bucketsz=32 281 ns/iter (± 1) 279 ns/iter (± 0) 1.01
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/secondaries/bucketsz=32 440 ns/iter (± 1) 453 ns/iter (± 1) 0.97
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/primary/bucketsz=2048 281 ns/iter (± 1) 280 ns/iter (± 0) 1.00
datastore/num_rows=1000/num_instances=1000/packed=true/latest_at_missing/secondaries/bucketsz=2048 439 ns/iter (± 1) 449 ns/iter (± 1) 0.98
datastore/num_rows=1000/num_instances=1000/packed=false/range/default 11457359 ns/iter (± 462659) 11778877 ns/iter (± 610053) 0.97
datastore/num_rows=1000/num_instances=1000/packed=false/range/bucketsz=0 2143869 ns/iter (± 15109) 2136426 ns/iter (± 48620) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/range/bucketsz=2 2112255 ns/iter (± 10677) 2170658 ns/iter (± 38729) 0.97
datastore/num_rows=1000/num_instances=1000/packed=false/range/bucketsz=32 1896031 ns/iter (± 9771) 1903331 ns/iter (± 16228) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/range/bucketsz=2048 1876213 ns/iter (± 8318) 1877590 ns/iter (± 12669) 1.00
datastore/num_rows=1000/num_instances=1000/packed=true/range/default 11001071 ns/iter (± 374155) 11004296 ns/iter (± 398845) 1.00
datastore/num_rows=1000/num_instances=1000/packed=true/range/bucketsz=0 2162103 ns/iter (± 10563) 2189262 ns/iter (± 11634) 0.99
datastore/num_rows=1000/num_instances=1000/packed=true/range/bucketsz=2 2159238 ns/iter (± 7589) 2144118 ns/iter (± 10726) 1.01
datastore/num_rows=1000/num_instances=1000/packed=true/range/bucketsz=32 1866201 ns/iter (± 6492) 1834324 ns/iter (± 6430) 1.02
datastore/num_rows=1000/num_instances=1000/packed=true/range/bucketsz=2048 1784572 ns/iter (± 8580) 1813853 ns/iter (± 9775) 0.98
vector_ops/sort/instances=10000/smallvec/n=4 12495 ns/iter (± 28) 12497 ns/iter (± 32) 1.00
vector_ops/sort/instances=10000/tinyvec/n=4 9657 ns/iter (± 25) 9650 ns/iter (± 34) 1.00
vector_ops/sort/instances=10000/vec 9646 ns/iter (± 15) 9635 ns/iter (± 27) 1.00
vector_ops/split_off/instances=10000/smallvec/n=4/manual 5540 ns/iter (± 14) 5565 ns/iter (± 63) 1.00
vector_ops/split_off/instances=10000/tinyvec/n=4 2725 ns/iter (± 29) 2732 ns/iter (± 24) 1.00
vector_ops/split_off/instances=10000/tinyvec/n=4/manual 2751 ns/iter (± 24) 2738 ns/iter (± 21) 1.00
vector_ops/split_off/instances=10000/vec 2725 ns/iter (± 28) 2724 ns/iter (± 26) 1.00
vector_ops/split_off/instances=10000/vec/manual 2729 ns/iter (± 18) 2722 ns/iter (± 22) 1.00
vector_ops/swap/instances=10000/smallvec/n=4 32799 ns/iter (± 109) 32785 ns/iter (± 40) 1.00
vector_ops/swap/instances=10000/tinyvec/n=4 18298 ns/iter (± 56) 18283 ns/iter (± 31) 1.00
vector_ops/swap/instances=10000/vec 12326 ns/iter (± 44) 12315 ns/iter (± 37) 1.00
vector_ops/swap_opt/instances=10000/smallvec/n=4 42721 ns/iter (± 128) 42732 ns/iter (± 84) 1.00
vector_ops/swap_opt/instances=10000/tinyvec/n=4 28740 ns/iter (± 71) 28857 ns/iter (± 86) 1.00
vector_ops/swap_opt/instances=10000/vec 20499 ns/iter (± 72) 19772 ns/iter (± 253) 1.04
mono_points_arrow/generate_message_bundles 42263835 ns/iter (± 565333) 42762926 ns/iter (± 508447) 0.99
mono_points_arrow/generate_messages 165330811 ns/iter (± 1195711) 164402629 ns/iter (± 1182345) 1.01
mono_points_arrow/encode_log_msg 208858509 ns/iter (± 728157) 206750164 ns/iter (± 684762) 1.01
mono_points_arrow/encode_total 412774486 ns/iter (± 1332459) 410846829 ns/iter (± 1447485) 1.00
mono_points_arrow/decode_log_msg 253238133 ns/iter (± 892875) 252734238 ns/iter (± 851442) 1.00
mono_points_arrow/decode_message_bundles 85034359 ns/iter (± 560002) 86121104 ns/iter (± 897095) 0.99
mono_points_arrow/decode_total 336980142 ns/iter (± 2768318) 336645405 ns/iter (± 1593705) 1.00
mono_points_arrow_batched/generate_message_bundles 35883327 ns/iter (± 1403287) 35683368 ns/iter (± 1150670) 1.01
mono_points_arrow_batched/generate_messages 9744786 ns/iter (± 579876) 9805754 ns/iter (± 554650) 0.99
mono_points_arrow_batched/encode_log_msg 1809577 ns/iter (± 4439) 1797258 ns/iter (± 7371) 1.01
mono_points_arrow_batched/encode_total 47117882 ns/iter (± 1687525) 48791444 ns/iter (± 1138909) 0.97
mono_points_arrow_batched/decode_log_msg 984344 ns/iter (± 2142) 980324 ns/iter (± 2531) 1.00
mono_points_arrow_batched/decode_message_bundles 18164779 ns/iter (± 842270) 18539368 ns/iter (± 701628) 0.98
mono_points_arrow_batched/decode_total 19901030 ns/iter (± 881916) 20079367 ns/iter (± 571829) 0.99
batch_points_arrow/generate_message_bundles 284872 ns/iter (± 1370) 283926 ns/iter (± 1107) 1.00
batch_points_arrow/generate_messages 7726 ns/iter (± 19) 7557 ns/iter (± 33) 1.02
batch_points_arrow/encode_log_msg 389145 ns/iter (± 1273) 383926 ns/iter (± 2129) 1.01
batch_points_arrow/encode_total 701660 ns/iter (± 3606) 695311 ns/iter (± 2021) 1.01
batch_points_arrow/decode_log_msg 339351 ns/iter (± 1047) 338564 ns/iter (± 1066) 1.00
batch_points_arrow/decode_message_bundles 3003 ns/iter (± 14) 2891 ns/iter (± 19) 1.04
batch_points_arrow/decode_total 347807 ns/iter (± 1059) 348887 ns/iter (± 1435) 1.00
arrow_mono_points/insert 6072989444 ns/iter (± 10257810) 6032616798 ns/iter (± 10393315) 1.01
arrow_mono_points/query 1821232 ns/iter (± 9323) 1807643 ns/iter (± 13133) 1.01
arrow_batch_points/insert 3059392 ns/iter (± 13171) 3033773 ns/iter (± 12081) 1.01
arrow_batch_points/query 16378 ns/iter (± 67) 16455 ns/iter (± 33) 1.00
arrow_batch_vecs/insert 43671 ns/iter (± 116) 42750 ns/iter (± 103) 1.02
arrow_batch_vecs/query 506597 ns/iter (± 3294) 506201 ns/iter (± 1478) 1.00
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

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

Please sign in to comment.