-
Notifications
You must be signed in to change notification settings - Fork 6k
Added the ability to make untracked opengles handles (migrated textures) #56927
Conversation
| type_(GetTextureTypeFromDescriptor(GetTextureDescriptor())), | ||
| handle_(external_handle.has_value() | ||
| ? external_handle.value() | ||
| : reactor_->CreateHandle(ToHandleType(type_))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe textures can be created on any thread. To make the texture object manage its own handle, you'd lazily initialize it in the InitializeContentsIfNecessary function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what's happening here. CreateUntrackedHandle creates the texture synchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it creates it synchronously, then we have to be careful not to create texture objects on threads other than raster/IO. but if you defer construction then the existing lifecycle mechanisms manage that for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what the assertion that the thread reacts is maintaining. I don't think we have a use case where we have to create textures on a thread other than the io/raster thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReactorGLES::CreateHandle is already creating these synchronously too, so there is no change in the behavior here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only creates it immediately if CanReactOnCurrentThread is true:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only creates it immediately if CanReactOnCurrentThread is true:
Right, but we assert CanReactOnCurrentThread so it's the same. I ran wonderous with this patch ( #56927 (comment) ) and the assert was never hit. It seems like a feature we may not even be using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be getting used by flutter gpu, but if we're not hitting the assert anywhere that is good enough for me
|
@jonahwilliams I'm putting this into review now. It does a portion of what we were talking about. I think this moves us in the right direction to get there. Check out the description for some idea about where we go after this PR. |
|
I checked wonderous with the following additions: diff --git a/impeller/renderer/backend/gles/device_buffer_gles.cc b/impeller/renderer/backend/gles/device_buffer_gles.cc
index f4caaf5af8..aaed494cab 100644
--- a/impeller/renderer/backend/gles/device_buffer_gles.cc
+++ b/impeller/renderer/backend/gles/device_buffer_gles.cc
@@ -17,7 +17,7 @@ DeviceBufferGLES::DeviceBufferGLES(DeviceBufferDescriptor desc,
std::shared_ptr<Allocation> backing_store)
: DeviceBuffer(desc),
reactor_(std::move(reactor)),
- handle_(reactor_ ? reactor_->CreateHandle(HandleType::kBuffer)
+ handle_(reactor_ ? reactor_->CreateUntrackedHandle(HandleType::kBuffer)
: HandleGLES::DeadHandle()),
backing_store_(std::move(backing_store)) {}
diff --git a/impeller/renderer/backend/gles/unique_handle_gles.cc b/impeller/renderer/backend/gles/unique_handle_gles.cc
index ddf4081791..07b4bf00ef 100644
--- a/impeller/renderer/backend/gles/unique_handle_gles.cc
+++ b/impeller/renderer/backend/gles/unique_handle_gles.cc
@@ -11,7 +11,7 @@ namespace impeller {
UniqueHandleGLES::UniqueHandleGLES(ReactorGLES::Ref reactor, HandleType type)
: reactor_(std::move(reactor)) {
if (reactor_) {
- handle_ = reactor_->CreateHandle(type);
+ handle_ = reactor_->CreateUntrackedHandle(type);
}
}Things are looking good to use this everywhere and all the overhead of reactor was eliminated from the profile. |
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Chatted with @jonahwilliams offline. This approach is looking good but I need to make sure I didn't break debug naming. We can punt on synchronous deletion the profiles after pipelines, buffers and textures are moved over is looking good. |
|
Does this put additional burden on the caller to ensure that texture handles in the OpenGL ES backend are created or destroyed on a specific thread? |
It has the burden that a call to create must happen on a thread that reacts. For deletion it goes through the same flow (so can happen on any thread). The major costs were GetHandle(), not the creation and deletion. |
…159808) flutter/engine@1f7f37e...9e8fcad 2024-12-04 skia-flutter-autoroll@skia.org Manual roll Dart SDK from 470117150f34 to a2a9428e761f (1 revision) (flutter/engine#56939) 2024-12-04 30870216+gaaclarke@users.noreply.github.com Added the ability to make untracked opengles handles (migrated textures) (flutter/engine#56927) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC bdero@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
issue: flutter/flutter#159745 #56927 introduced untracked handles, but naming them didn't work. This adds a test to make sure they work. I kept naming thread-safe since it isn't happening often anyways. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
|
In that case, this will be an issue for the OpenGL Flutter GPU runtime. I'll file a bug to sort out the threading implications for Flutter GPU like usages. |
Here's a model on how to do it: a289daa You track the untracked handle only long enough to perform the operation. That makes things like naming a item require synchronization, but no hash table lookup. For creation we'd need a future so that we can make sure subsequent accesses to the name require no hash table lookup or synchronization. |
|
@chinmaygarde also note I haven't closed any existing code paths yet. the slow fully tracked way is still available. We'll probably want to move everything to untracked at some point but have 2 entrypoints that are threadsafe vs not threadsafe, not tracked vs not tracked. |
…es) (flutter/engine#56927) issue: flutter#159745 This tweaks ReactorGLES so that one can easily opt out of it's mutex/hash map for cases where we can statically reason about the safety of doing so. The goal here was to make migration of existing code really easy to do. It may be in the future that everything is an untracked handle? We can move there in baby steps. Potential follow up PRs: - Move `Pipeline` to use untracked handles - Move `DeviceBufferGLES` to use untracked handles - Add a new method to synchronously delete untracked handles - Start storing handles to be deleted in its own vector, so handles_ doesn't need to be used for deleting untracked handles ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/engine/blob/main/docs/testing/Testing-the-engine.md [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
issue: flutter#159745 flutter/engine#56927 introduced untracked handles, but naming them didn't work. This adds a test to make sure they work. I kept naming thread-safe since it isn't happening often anyways. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
issue: flutter/flutter#159745
This tweaks ReactorGLES so that one can easily opt out of it's mutex/hash map for cases where we can statically reason about the safety of doing so. The goal here was to make migration of existing code really easy to do. It may be in the future that everything is an untracked handle? We can move there in baby steps.
Potential follow up PRs:
Pipelineto use untracked handlesDeviceBufferGLESto use untracked handlesPre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.