Cache MAX_SAMPLES on gles backend (#5346)

This commit is contained in:
Nathan Adams 2024-03-09 10:16:31 +01:00 committed by GitHub
parent f86898ffeb
commit 2234fd681d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View File

@ -120,6 +120,7 @@ By @cwfitzgerald in [#5325](https://github.com/gfx-rs/wgpu/pull/5325).
#### GLES #### GLES
- Log an error when GLES texture format heuristics fail. By @PolyMeilex in [#5266](https://github.com/gfx-rs/wgpu/issues/5266) - 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 ### Bug Fixes

View File

@ -802,6 +802,7 @@ impl super::Adapter {
} }
let downlevel_defaults = wgt::DownlevelLimits {}; 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 // 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 // ( on Wasm the gl handle is just a ref so we tell clippy to allow
@ -820,6 +821,7 @@ impl super::Adapter {
next_shader_id: Default::default(), next_shader_id: Default::default(),
program_cache: Default::default(), program_cache: Default::default(),
es: es_ver.is_some(), es: es_ver.is_some(),
max_msaa_samples: max_samples,
}), }),
}, },
info: Self::make_info(vendor, renderer), info: Self::make_info(vendor, renderer),
@ -986,12 +988,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
use wgt::TextureFormat as Tf; use wgt::TextureFormat as Tf;
let sample_count = { let sample_count = {
let max_samples = unsafe { let max_samples = self.shared.max_msaa_samples;
self.shared
.context
.lock()
.get_parameter_i32(glow::MAX_SAMPLES)
};
if max_samples >= 16 { if max_samples >= 16 {
Tfc::MULTISAMPLE_X2 Tfc::MULTISAMPLE_X2
| Tfc::MULTISAMPLE_X4 | Tfc::MULTISAMPLE_X4

View File

@ -251,6 +251,11 @@ struct AdapterShared {
next_shader_id: AtomicU32, next_shader_id: AtomicU32,
program_cache: Mutex<ProgramCache>, program_cache: Mutex<ProgramCache>,
es: bool, 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 { pub struct Adapter {