Repository navigation
Conversation
Flutter GPU calls PipelineLibrary::HasPipeline and GetPipeline on the UI thread (flutter::gpu::RenderPass::GetOrCreatePipeline) while Impeller requests pipeline variants on the raster thread. PipelineLibraryGLES locked programs_ but not pipelines_, and GetPipeline does its map lookup and insert on the calling thread (only program creation is deferred to the reactor), so a lookup could race an insertion or rehash. Guard pipelines_ with a mutex. The lock covers only the map accesses, not pipeline creation, and try_emplace makes concurrent requests for the same descriptor share one future. RemovePipelinesWithEntryPoint takes the pipelines lock before the programs lock; no other path holds both. Add PipelineLibraryGLESTest.CanLookUpPipelinesWhileCreatingPipelines, which looks up an existing pipeline on one thread while the reactor thread creates new variants.
There was a problem hiding this comment.
Code Review
This pull request introduces thread safety to the PipelineLibraryGLES class by guarding the pipelines_ map with a new pipelines_mutex_ mutex. Lock acquisitions have been added to GetPipeline, HasPipeline, and RemovePipelinesWithEntryPoint to prevent concurrent access issues. Additionally, a new concurrent unit test CanLookUpPipelinesWhileCreatingPipelines has been added to verify these changes. There are no review comments, and I have no feedback to provide.
|
I think this will likely be unnecessary after #194022 lands. Can you please give that a look and see if it addresses your problem. |
|
Thanks for the pointer. I checked #194022 and it doesn't cover this one. The race in #193745 is between callers of the library (Flutter GPU on the UI thread and the raster thread), so it's independent of where compilation runs. Happy to rebase this on top of #194022 once it lands, or land first if you prefer. |
|
Okay, yea just looked into this a bit more and noticed you are talking about the flutter-gpu usage. Let's try to land that other fix first since it's a pretty intensive change. I'll ping you on this PR when that lands. I don't like that fluttergpu is using the library differently. I would prefer that fluttergpu keeps a handle to a shader that gets resolved on the raster thread. (cc @bdero ) |
|
fyi #194022 has landed. I reached out to bdero asking about reworking this so that the threading model of flutter-gpu matches flutter. I'm not sure how fast that will progress though. |
…ine-library-lock # Conflicts: # engine/src/flutter/impeller/renderer/backend/gles/pipeline_library_gles.cc # engine/src/flutter/impeller/renderer/backend/gles/test/pipeline_library_gles_unittests.cc
|
Lemme take a quick look at this. I think this may be good to land in the meantime. |
@bdero if that's anywhere close to being completed I'd prefer to land that. If not, let's file an issue for the removal of this mutex and put some TODO's in the code. |
|
Closing this in lieu of #194882 |
PipelineLibraryGLESlocksprograms_but notpipelines_.GetPipelinelooks up and inserts intopipelines_on the calling thread; only program compilation and linking run on the reactor. Flutter GPU callsHasPipelineandGetPipelineon the UI thread (RenderPass::GetOrCreatePipeline), andRemovePipelinesWithEntryPointwhen a shader is reloaded, while Impeller inserts pipeline variants on the raster thread. A lookup can race an insert or a rehash.This PR guards
pipelines_with its own mutex. The lock covers only the map accesses, not pipeline creation, andtry_emplacemakes concurrent requests for the same descriptor share one future.RemovePipelinesWithEntryPointtakes the pipelines lock and then the programs lock; no other path holds both, so the order cannot invert.The new test,
PipelineLibraryGLESTest.CanLookUpPipelinesWhileCreatingPipelines, looks up an existing pipeline on one thread while the test thread, which is the GLES reactor thread, creates 128 variants.Verified on master d03768e, Linux x64, OpenGL ES on Mesa under Xvfb, as in CI:
pipelines_race in 10/10pipelines_raceThe full Linux
impeller_unittestsrun passes with the lock (run with an earlier version of the test inrenderer_unittests.cc), and the format and clang-tidy checks are clean.Related: the same race in
PipelineLibraryMTL(#193721 / #193722) and in the sampler libraries (#193737 / #193738). This PR touches only GLES files, so it does not depend on either.Fixes #193745
Pre-launch Checklist
///).