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

Workaround for alpha to coverage state leaking on (Web)GL renderer #1596

Merged
merged 4 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 24 additions & 7 deletions crates/re_renderer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,32 @@ pub enum HardwareTier {
//HighEnd
}

impl HardwareTier {
/// Temporary workaround until [this GL state leaking fix](https://github.com/gfx-rs/wgpu/pull/3589) is landed.
/// All our target platforms should support alpha to coverage.
pub fn support_alpha_to_coverage(&self) -> bool {
match self {
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_sampling_msaa_texture(&self) -> bool {
match self {
HardwareTier::Web => false,
HardwareTier::Native => true,
}
}
}

impl Default for HardwareTier {
fn default() -> Self {
#[cfg(target_arch = "wasm32")]
{
Self::Web
}
#[cfg(not(target_arch = "wasm32"))]
{
Self::Native
// Use "Web" tier for actual web but also if someone forces the GL backend!
if supported_backends() == wgpu::Backends::GL {
HardwareTier::Web
emilk marked this conversation as resolved.
Show resolved Hide resolved
} else {
HardwareTier::Native
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ impl Renderer for DepthCloudRenderer {
multisample: wgpu::MultisampleState {
// We discard pixels to do the round cutout, therefore we need to
// calculate our own sampling mask.
alpha_to_coverage_enabled: true,
alpha_to_coverage_enabled: shared_data
.config
.hardware_tier
.support_alpha_to_coverage(),
..ViewBuilder::MAIN_TARGET_DEFAULT_MSAA_STATE
},
};
Expand Down
5 changes: 4 additions & 1 deletion crates/re_renderer/src/renderer/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,10 @@ impl Renderer for LineRenderer {
depth_stencil: ViewBuilder::MAIN_TARGET_DEFAULT_DEPTH_STATE,
multisample: wgpu::MultisampleState {
// We discard pixels to do the round cutout, therefore we need to calculate our own sampling mask.
alpha_to_coverage_enabled: true,
alpha_to_coverage_enabled: shared_data
.config
.hardware_tier
.support_alpha_to_coverage(),
..ViewBuilder::MAIN_TARGET_DEFAULT_MSAA_STATE
},
},
Expand Down
6 changes: 3 additions & 3 deletions crates/re_renderer/src/renderer/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ impl OutlineMaskProcessor {

/// Number of MSAA samples used for the outline mask target.
pub fn mask_sample_count(tier: HardwareTier) -> u32 {
match tier {
HardwareTier::Web => 1,
match tier.support_sampling_msaa_texture() {
false => 1,
// The MSAA shader variant deals with *exactly* 4 samples.
// See `jumpflooding_step_msaa.wgsl`.
HardwareTier::Native => 4,
true => 4,
emilk marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
5 changes: 4 additions & 1 deletion crates/re_renderer/src/renderer/point_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ impl Renderer for PointCloudRenderer {
multisample: wgpu::MultisampleState {
// We discard pixels to do the round cutout, therefore we need to calculate
// our own sampling mask.
alpha_to_coverage_enabled: true,
alpha_to_coverage_enabled: shared_data
.config
.hardware_tier
.support_alpha_to_coverage(),
..ViewBuilder::MAIN_TARGET_DEFAULT_MSAA_STATE
},
};
Expand Down