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

Cache MAX_SAMPLES on gles backend #5346

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 3 additions & 6 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -974,12 +976,7 @@ impl crate::Adapter<super::Api> 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
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ struct AdapterShared {
next_shader_id: AtomicU32,
program_cache: Mutex<ProgramCache>,
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 {
Expand Down
Loading