Skip to content

Commit

Permalink
WebGL workarounds.
Browse files Browse the repository at this point in the history
* can't read depth formats
* and all the other weird things, see gfx-rs/wgpu#3644
  • Loading branch information
Wumpf committed Apr 3, 2023
1 parent 2149b16 commit 5ad8c09
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 24 deletions.
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);
}
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

0 comments on commit 5ad8c09

Please sign in to comment.