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

[gl] reorder program_cache & context lock acquisition #5870

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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
8 changes: 4 additions & 4 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,17 +1409,17 @@ impl crate::Device for super::Device {
}

unsafe fn destroy_render_pipeline(&self, pipeline: super::RenderPipeline) {
let mut program_cache = self.shared.program_cache.lock();
// If the pipeline only has 2 strong references remaining, they're `pipeline` and `program_cache`
// This is safe to assume as long as:
// - `RenderPipeline` can't be cloned
// - The only place that we can get a new reference is during `program_cache.lock()`
if Arc::strong_count(&pipeline.inner) == 2 {
let gl = &self.shared.context.lock();
let mut program_cache = self.shared.program_cache.lock();
program_cache.retain(|_, v| match *v {
Ok(ref p) => p.program != pipeline.inner.program,
Err(_) => false,
});
let gl = &self.shared.context.lock();
unsafe { gl.delete_program(pipeline.inner.program) };
}

Expand All @@ -1441,17 +1441,17 @@ impl crate::Device for super::Device {
}

unsafe fn destroy_compute_pipeline(&self, pipeline: super::ComputePipeline) {
let mut program_cache = self.shared.program_cache.lock();
// If the pipeline only has 2 strong references remaining, they're `pipeline` and `program_cache``
// This is safe to assume as long as:
// - `ComputePipeline` can't be cloned
// - The only place that we can get a new reference is during `program_cache.lock()`
if Arc::strong_count(&pipeline.inner) == 2 {
let gl = &self.shared.context.lock();
let mut program_cache = self.shared.program_cache.lock();
program_cache.retain(|_, v| match *v {
Ok(ref p) => p.program != pipeline.inner.program,
Err(_) => false,
});
let gl = &self.shared.context.lock();
unsafe { gl.delete_program(pipeline.inner.program) };
}

Expand Down
Loading