This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] use sync fence for image uploads. #56609
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
491e166
[Impeller] use sync fence for image uploads.
639fe30
Merge branch 'main' of github.com:flutter/engine into implement-wait-…
75e37d6
++
c67779a
fix importss.
6b199ea
remove one more include.
6232416
add unit test.
b6bf09e
fix texture format.
1d29ad2
clang tidy.
e0d15ad
jason review.
7ef2efd
rename to GLStorage, make private.
377a926
Merge branch 'main' into implement-wait-sync
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,51 +13,57 @@ | |
|
|
||
| namespace impeller { | ||
|
|
||
| static std::optional<GLuint> CreateGLHandle(const ProcTableGLES& gl, | ||
| HandleType type) { | ||
| GLuint handle = GL_NONE; | ||
| static std::optional<GLHandle> CreateGLHandle(const ProcTableGLES& gl, | ||
| HandleType type) { | ||
| GLHandle handle = GLHandle{.handle = GL_NONE}; | ||
| switch (type) { | ||
| case HandleType::kUnknown: | ||
| return std::nullopt; | ||
| case HandleType::kTexture: | ||
| gl.GenTextures(1u, &handle); | ||
| gl.GenTextures(1u, &handle.handle); | ||
| return handle; | ||
| case HandleType::kBuffer: | ||
| gl.GenBuffers(1u, &handle); | ||
| gl.GenBuffers(1u, &handle.handle); | ||
| return handle; | ||
| case HandleType::kProgram: | ||
| return gl.CreateProgram(); | ||
| return GLHandle{.handle = gl.CreateProgram()}; | ||
| case HandleType::kRenderBuffer: | ||
| gl.GenRenderbuffers(1u, &handle); | ||
| gl.GenRenderbuffers(1u, &handle.handle); | ||
| return handle; | ||
| case HandleType::kFrameBuffer: | ||
| gl.GenFramebuffers(1u, &handle); | ||
| gl.GenFramebuffers(1u, &handle.handle); | ||
| return handle; | ||
| case HandleType::kFence: | ||
| return GLHandle{.sync = gl.FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0)}; | ||
| break; | ||
|
||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| static bool CollectGLHandle(const ProcTableGLES& gl, | ||
| HandleType type, | ||
| GLuint handle) { | ||
| GLHandle handle) { | ||
| switch (type) { | ||
| case HandleType::kUnknown: | ||
| return false; | ||
| case HandleType::kTexture: | ||
| gl.DeleteTextures(1u, &handle); | ||
| gl.DeleteTextures(1u, &handle.handle); | ||
| return true; | ||
| case HandleType::kBuffer: | ||
| gl.DeleteBuffers(1u, &handle); | ||
| gl.DeleteBuffers(1u, &handle.handle); | ||
| return true; | ||
| case HandleType::kProgram: | ||
| gl.DeleteProgram(handle); | ||
| gl.DeleteProgram(handle.handle); | ||
| return true; | ||
| case HandleType::kRenderBuffer: | ||
| gl.DeleteRenderbuffers(1u, &handle); | ||
| gl.DeleteRenderbuffers(1u, &handle.handle); | ||
| return true; | ||
| case HandleType::kFrameBuffer: | ||
| gl.DeleteFramebuffers(1u, &handle); | ||
| gl.DeleteFramebuffers(1u, &handle.handle); | ||
| return true; | ||
| case HandleType::kFence: | ||
| gl.DeleteSync(handle.sync); | ||
| break; | ||
| } | ||
| return false; | ||
| } | ||
|
|
@@ -117,18 +123,44 @@ const ProcTableGLES& ReactorGLES::GetProcTable() const { | |
| } | ||
|
|
||
| std::optional<GLuint> ReactorGLES::GetGLHandle(const HandleGLES& handle) const { | ||
| if (handle.type == HandleType::kFence) { | ||
|
||
| return std::nullopt; | ||
| } | ||
| ReaderLock handles_lock(handles_mutex_); | ||
| if (auto found = handles_.find(handle); found != handles_.end()) { | ||
| if (found->second.pending_collection) { | ||
| VALIDATION_LOG | ||
| << "Attempted to acquire a handle that was pending collection."; | ||
| return std::nullopt; | ||
| } | ||
| std::optional<GLHandle> name = found->second.name; | ||
| if (!name.has_value()) { | ||
| VALIDATION_LOG << "Attempt to acquire a handle outside of an operation."; | ||
| return std::nullopt; | ||
| } | ||
| return name->handle; | ||
| } | ||
| VALIDATION_LOG << "Attempted to acquire an invalid GL handle."; | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::optional<GLsync> ReactorGLES::GetGLFence(const HandleGLES& handle) const { | ||
| if (handle.type != HandleType::kFence) { | ||
| return std::nullopt; | ||
| } | ||
| ReaderLock handles_lock(handles_mutex_); | ||
| if (auto found = handles_.find(handle); found != handles_.end()) { | ||
| if (found->second.pending_collection) { | ||
| VALIDATION_LOG | ||
| << "Attempted to acquire a handle that was pending collection."; | ||
| return std::nullopt; | ||
| } | ||
| if (!found->second.name.has_value()) { | ||
| std::optional<GLHandle> name = found->second.name; | ||
| if (!name.has_value()) { | ||
| VALIDATION_LOG << "Attempt to acquire a handle outside of an operation."; | ||
| return std::nullopt; | ||
| } | ||
| return found->second.name; | ||
| return name->sync; | ||
| } | ||
| VALIDATION_LOG << "Attempted to acquire an invalid GL handle."; | ||
| return std::nullopt; | ||
|
|
@@ -171,9 +203,9 @@ HandleGLES ReactorGLES::CreateHandle(HandleType type, GLuint external_handle) { | |
| } | ||
| WriterLock handles_lock(handles_mutex_); | ||
|
|
||
| std::optional<GLuint> gl_handle; | ||
| std::optional<GLHandle> gl_handle; | ||
| if (external_handle != GL_NONE) { | ||
| gl_handle = external_handle; | ||
| gl_handle = GLHandle{.handle = external_handle}; | ||
| } else if (CanReactOnCurrentThread()) { | ||
| gl_handle = CreateGLHandle(GetProcTable(), type); | ||
| } | ||
|
|
@@ -215,6 +247,8 @@ static DebugResourceType ToDebugResourceType(HandleType type) { | |
| return DebugResourceType::kRenderBuffer; | ||
| case HandleType::kFrameBuffer: | ||
| return DebugResourceType::kFrameBuffer; | ||
| case HandleType::kFence: | ||
| return DebugResourceType::kFence; | ||
| } | ||
| FML_UNREACHABLE(); | ||
| } | ||
|
|
@@ -253,9 +287,10 @@ bool ReactorGLES::ConsolidateHandles() { | |
| handle.second.name = gl_handle; | ||
| } | ||
| // Set pending debug labels. | ||
| if (handle.second.pending_debug_label.has_value()) { | ||
| if (handle.second.pending_debug_label.has_value() && | ||
| handle.first.type != HandleType::kFence) { | ||
| if (gl.SetDebugLabel(ToDebugResourceType(handle.first.type), | ||
| handle.second.name.value(), | ||
| handle.second.name.value().handle, | ||
| handle.second.pending_debug_label.value())) { | ||
| handle.second.pending_debug_label = std::nullopt; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
impeller/renderer/backend/gles/test/texture_gles_unittests.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/impeller/playground/playground_test.h" | ||
| #include "flutter/impeller/renderer/backend/gles/context_gles.h" | ||
| #include "flutter/impeller/renderer/backend/gles/texture_gles.h" | ||
| #include "flutter/testing/testing.h" | ||
| #include "gtest/gtest.h" | ||
| #include "impeller/core/formats.h" | ||
| #include "impeller/core/texture_descriptor.h" | ||
| #include "impeller/renderer/backend/gles/handle_gles.h" | ||
| #include "impeller/renderer/backend/gles/proc_table_gles.h" | ||
|
|
||
| namespace impeller::testing { | ||
|
|
||
| using TextureGLESTest = PlaygroundTest; | ||
| INSTANTIATE_OPENGLES_PLAYGROUND_SUITE(TextureGLESTest); | ||
|
|
||
| TEST_P(TextureGLESTest, CanSetSyncFence) { | ||
| ContextGLES& context_gles = ContextGLES::Cast(*GetContext()); | ||
| if (!context_gles.GetReactor() | ||
| ->GetProcTable() | ||
| .GetDescription() | ||
| ->GetGlVersion() | ||
| .IsAtLeast(Version{3, 0, 0})) { | ||
| GTEST_SKIP() << "GL Version too low to test sync fence."; | ||
| } | ||
|
|
||
| TextureDescriptor desc; | ||
| desc.storage_mode = StorageMode::kDevicePrivate; | ||
| desc.size = {100, 100}; | ||
| desc.format = PixelFormat::kR8G8B8A8UNormInt; | ||
|
|
||
| auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc); | ||
| ASSERT_TRUE(!!texture); | ||
|
|
||
| EXPECT_TRUE(GetContext()->AddTrackingFence(texture)); | ||
| EXPECT_TRUE(context_gles.GetReactor()->React()); | ||
|
|
||
| std::optional<HandleGLES> sync_fence = | ||
| TextureGLES::Cast(*texture).GetSyncFence(); | ||
| ASSERT_TRUE(sync_fence.has_value()); | ||
| if (!sync_fence.has_value()) { | ||
| return; | ||
| } | ||
| EXPECT_EQ(sync_fence.value().type, HandleType::kFence); | ||
|
|
||
| std::optional<GLsync> sync = | ||
| context_gles.GetReactor()->GetGLFence(sync_fence.value()); | ||
| ASSERT_TRUE(sync.has_value()); | ||
| if (!sync.has_value()) { | ||
| return; | ||
| } | ||
|
|
||
| // Now queue up operation that binds texture to verify that sync fence is | ||
| // waited and removed. | ||
|
|
||
| EXPECT_TRUE( | ||
| context_gles.GetReactor()->AddOperation([&](const ReactorGLES& reactor) { | ||
| return TextureGLES::Cast(*texture).Bind(); | ||
| })); | ||
|
|
||
| sync_fence = TextureGLES::Cast(*texture).GetSyncFence(); | ||
| ASSERT_FALSE(sync_fence.has_value()); | ||
| } | ||
|
|
||
| } // namespace impeller::testing |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
GLES3 has a
glIsSyncAPI that can be used hereThere 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.
This is only used for debug labeling which I don't believe can be done to the sync fence APIs