Skip to content

Commit

Permalink
[gl] reorder program_cache & context lock acquisition
Browse files Browse the repository at this point in the history
We are using `program_cache.try_lock()` when creting pipelines which is covered by a guard gotten from `context.lock()`. For the `.try_lock()` to always succeed we need to make sure that the other lock acquisitions are also covered by a `context.lock()`.

The `wgpu_examples::hello_compute::tests::multithreaded_compute` test has been failing intermittently in CI due to this.
  • Loading branch information
teoxoy committed Jun 24, 2024
1 parent 7cf0711 commit 333ed78
Showing 1 changed file with 4 additions and 4 deletions.
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

0 comments on commit 333ed78

Please sign in to comment.