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

Readback depth from GPU picking #1752

Merged
merged 6 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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