Skip to content

Commit

Permalink
Workaround for alpha to coverage state leaking on (Web)GL renderer (#…
Browse files Browse the repository at this point in the history
…1596)

* Workaround for alpha to coverage state leaking on (Web)GL renderer
Plus, use `Web` hardware tier when rendering with GLES.

* Rename HardwareTier::Web to Basic

* match bool -> if

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
  • Loading branch information
Wumpf and emilk authored Mar 17, 2023
1 parent 217e783 commit 1790f0d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
38 changes: 28 additions & 10 deletions crates/re_renderer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,41 @@
/// but instead support set of features, each a superset of the next.
#[derive(Clone, Copy, Debug)]
pub enum HardwareTier {
/// Maintains strict WebGL capability.
Web,
// Run natively with Vulkan/Metal but don't demand anything that isn't widely available.
/// For WebGL and native OpenGL. Maintains strict WebGL capability.
Basic,

/// Run natively with Vulkan/Metal but don't demand anything that isn't widely available.
Native,
// Run natively with Vulkan/Metal and require additional features.
//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::Basic => 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::Basic => 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 "Basic" tier for actual web but also if someone forces the GL backend!
if supported_backends() == wgpu::Backends::GL {
HardwareTier::Basic
} 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
7 changes: 4 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,12 @@ 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,
if tier.support_sampling_msaa_texture() {
// The MSAA shader variant deals with *exactly* 4 samples.
// See `jumpflooding_step_msaa.wgsl`.
HardwareTier::Native => 4,
4
} else {
1
}
}

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

1 comment on commit 1790f0d

@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: 1790f0d Previous: 217e783 Ratio
datastore/insert/batch/rects/insert 556299 ns/iter (± 37639) 571442 ns/iter (± 2301) 0.97
datastore/latest_at/batch/rects/query 1843 ns/iter (± 66) 1897 ns/iter (± 4) 0.97
datastore/latest_at/missing_components/primary 288 ns/iter (± 0) 285 ns/iter (± 0) 1.01
datastore/latest_at/missing_components/secondaries 438 ns/iter (± 0) 439 ns/iter (± 0) 1.00
datastore/range/batch/rects/query 152372 ns/iter (± 509) 152576 ns/iter (± 344) 1.00
mono_points_arrow/generate_message_bundles 48332381 ns/iter (± 2057438) 47323466 ns/iter (± 717830) 1.02
mono_points_arrow/generate_messages 127384757 ns/iter (± 928225) 126745758 ns/iter (± 1029971) 1.01
mono_points_arrow/encode_log_msg 158947927 ns/iter (± 1138186) 157765071 ns/iter (± 1340455) 1.01
mono_points_arrow/encode_total 332645976 ns/iter (± 1642748) 331379061 ns/iter (± 1235405) 1.00
mono_points_arrow/decode_log_msg 179026182 ns/iter (± 871195) 180097694 ns/iter (± 789305) 0.99
mono_points_arrow/decode_message_bundles 64449650 ns/iter (± 740401) 64690497 ns/iter (± 863620) 1.00
mono_points_arrow/decode_total 239313697 ns/iter (± 4476831) 243367611 ns/iter (± 1314650) 0.98
batch_points_arrow/generate_message_bundles 322075 ns/iter (± 2815) 323148 ns/iter (± 606) 1.00
batch_points_arrow/generate_messages 6404 ns/iter (± 33) 6372 ns/iter (± 12) 1.01
batch_points_arrow/encode_log_msg 357316 ns/iter (± 2697) 354200 ns/iter (± 1232) 1.01
batch_points_arrow/encode_total 707810 ns/iter (± 5889) 714454 ns/iter (± 1876) 0.99
batch_points_arrow/decode_log_msg 347742 ns/iter (± 948) 350486 ns/iter (± 2502) 0.99
batch_points_arrow/decode_message_bundles 2032 ns/iter (± 13) 2082 ns/iter (± 9) 0.98
batch_points_arrow/decode_total 356138 ns/iter (± 5112) 357303 ns/iter (± 989) 1.00
arrow_mono_points/insert 6138659933 ns/iter (± 15981279) 6091936932 ns/iter (± 18853298) 1.01
arrow_mono_points/query 1796190 ns/iter (± 31350) 1804911 ns/iter (± 9463) 1.00
arrow_batch_points/insert 2701820 ns/iter (± 22486) 2696428 ns/iter (± 10857) 1.00
arrow_batch_points/query 16821 ns/iter (± 184) 16966 ns/iter (± 63) 0.99
arrow_batch_vecs/insert 42844 ns/iter (± 155) 42871 ns/iter (± 99) 1.00
arrow_batch_vecs/query 505267 ns/iter (± 2974) 506667 ns/iter (± 857) 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.