From 6c2137aa60187ce9bba6343288678828656a315a Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Tue, 5 Mar 2024 21:44:20 +0100 Subject: [PATCH] Cache MAX_SAMPLES on gles backend --- CHANGELOG.md | 1 + wgpu-hal/src/gles/adapter.rs | 9 +++------ wgpu-hal/src/gles/mod.rs | 5 +++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1c4be5f3..b36ad8dd70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,6 +120,7 @@ By @cwfitzgerald in [#5325](https://github.com/gfx-rs/wgpu/pull/5325). #### GLES - Log an error when GLES texture format heuristics fail. By @PolyMeilex in [#5266](https://github.com/gfx-rs/wgpu/issues/5266) +- Cache the sample count to keep `get_texture_format_features` cheap. By @Dinnerbone in [#5346](https://github.com/gfx-rs/wgpu/pull/5346) ### Bug Fixes diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 1576530451..60ef72cc41 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -801,6 +801,7 @@ impl super::Adapter { } let downlevel_defaults = wgt::DownlevelLimits {}; + let max_samples = unsafe { gl.get_parameter_i32(glow::MAX_SAMPLES) }; // Drop the GL guard so we can move the context into AdapterShared // ( on Wasm the gl handle is just a ref so we tell clippy to allow @@ -819,6 +820,7 @@ impl super::Adapter { next_shader_id: Default::default(), program_cache: Default::default(), es: es_ver.is_some(), + max_msaa_samples: max_samples, }), }, info: Self::make_info(vendor, renderer), @@ -974,12 +976,7 @@ impl crate::Adapter for super::Adapter { use wgt::TextureFormat as Tf; let sample_count = { - let max_samples = unsafe { - self.shared - .context - .lock() - .get_parameter_i32(glow::MAX_SAMPLES) - }; + let max_samples = self.shared.max_msaa_samples; if max_samples >= 16 { Tfc::MULTISAMPLE_X2 | Tfc::MULTISAMPLE_X4 diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 70c487acf0..bcb3db5099 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -251,6 +251,11 @@ struct AdapterShared { next_shader_id: AtomicU32, program_cache: Mutex, es: bool, + + /// Result of `gl.get_parameter_i32(glow::MAX_SAMPLES)`. + /// Cached here so it doesn't need to be queried every time texture format capabilities are requested. + /// (this has been shown to be a significant enough overhead) + max_msaa_samples: i32, } pub struct Adapter {