Implements the naming of untracked gles handles (flutter/engine#56948)

issue: https://github.com/flutter/flutter/issues/159745

https://github.com/flutter/engine/pull/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
This commit is contained in:
gaaclarke 2024-12-04 18:06:44 -08:00 committed by GitHub
parent 9e25a25686
commit 8c736f4144
5 changed files with 48 additions and 7 deletions

View File

@ -360,7 +360,7 @@ static bool ResourceIsLive(const ProcTableGLES& gl,
bool ProcTableGLES::SetDebugLabel(DebugResourceType type, bool ProcTableGLES::SetDebugLabel(DebugResourceType type,
GLint name, GLint name,
const std::string& label) const { std::string_view label) const {
if (debug_label_max_length_ <= 0) { if (debug_label_max_length_ <= 0) {
return true; return true;
} }

View File

@ -311,7 +311,7 @@ class ProcTableGLES {
bool SetDebugLabel(DebugResourceType type, bool SetDebugLabel(DebugResourceType type,
GLint name, GLint name,
const std::string& label) const; std::string_view label) const;
void PushDebugGroup(const std::string& string) const; void PushDebugGroup(const std::string& string) const;

View File

@ -386,15 +386,23 @@ void ReactorGLES::SetupDebugGroups() {
void ReactorGLES::SetDebugLabel(const HandleGLES& handle, void ReactorGLES::SetDebugLabel(const HandleGLES& handle,
std::string_view label) { std::string_view label) {
FML_DCHECK(handle.GetType() != HandleType::kFence);
if (!can_set_debug_labels_) { if (!can_set_debug_labels_) {
return; return;
} }
if (handle.IsDead()) { if (handle.IsDead()) {
return; return;
} }
WriterLock handles_lock(handles_mutex_); if (handle.untracked_id_.has_value()) {
if (auto found = handles_.find(handle); found != handles_.end()) { FML_DCHECK(CanReactOnCurrentThread());
found->second.pending_debug_label = label; const auto& gl = GetProcTable();
gl.SetDebugLabel(ToDebugResourceType(handle.GetType()),
handle.untracked_id_.value(), label);
} else {
WriterLock handles_lock(handles_mutex_);
if (auto found = handles_.find(handle); found != handles_.end()) {
found->second.pending_debug_label = label;
}
} }
} }

View File

@ -83,6 +83,9 @@ void mockGetIntegerv(GLenum name, int* value) {
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
*value = 8; *value = 8;
break; break;
case GL_MAX_LABEL_LENGTH_KHR:
*value = 64;
break;
default: default:
*value = 0; *value = 0;
break; break;
@ -170,6 +173,8 @@ static_assert(CheckSameSignature<decltype(mockDeleteQueriesEXT), //
void mockUniform1fv(GLint location, GLsizei count, const GLfloat* value) { void mockUniform1fv(GLint location, GLsizei count, const GLfloat* value) {
RecordGLCall("glUniform1fv"); RecordGLCall("glUniform1fv");
} }
static_assert(CheckSameSignature<decltype(mockUniform1fv), //
decltype(glUniform1fv)>::value);
void mockGenTextures(GLsizei n, GLuint* textures) { void mockGenTextures(GLsizei n, GLuint* textures) {
RecordGLCall("glGenTextures"); RecordGLCall("glGenTextures");
@ -182,8 +187,17 @@ void mockGenTextures(GLsizei n, GLuint* textures) {
} }
} }
static_assert(CheckSameSignature<decltype(mockUniform1fv), // static_assert(CheckSameSignature<decltype(mockGenTextures), //
decltype(glUniform1fv)>::value); decltype(glGenTextures)>::value);
void mockObjectLabelKHR(GLenum identifier,
GLuint name,
GLsizei length,
const GLchar* label) {
RecordGLCall("glObjectLabelKHR");
}
static_assert(CheckSameSignature<decltype(mockObjectLabelKHR), //
decltype(glObjectLabelKHR)>::value);
std::shared_ptr<MockGLES> MockGLES::Init( std::shared_ptr<MockGLES> MockGLES::Init(
const std::optional<std::vector<const unsigned char*>>& extensions, const std::optional<std::vector<const unsigned char*>>& extensions,
@ -230,6 +244,8 @@ const ProcTableGLES::Resolver kMockResolverGLES = [](const char* name) {
return reinterpret_cast<void*>(mockUniform1fv); return reinterpret_cast<void*>(mockUniform1fv);
} else if (strcmp(name, "glGenTextures") == 0) { } else if (strcmp(name, "glGenTextures") == 0) {
return reinterpret_cast<void*>(mockGenTextures); return reinterpret_cast<void*>(mockGenTextures);
} else if (strcmp(name, "glObjectLabelKHR") == 0) {
return reinterpret_cast<void*>(mockObjectLabelKHR);
} else { } else {
return reinterpret_cast<void*>(&doNothing); return reinterpret_cast<void*>(&doNothing);
} }

View File

@ -91,6 +91,23 @@ TEST(ReactorGLES, UntrackedHandle) {
calls.end()); calls.end());
} }
TEST(ReactorGLES, NameUntrackedHandle) {
std::shared_ptr<MockGLES> mock_gles = MockGLES::Init();
ProcTableGLES::Resolver resolver = kMockResolverGLES;
auto proc_table = std::make_unique<ProcTableGLES>(resolver);
auto worker = std::make_shared<TestWorker>();
auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
reactor->AddWorker(worker);
mock_gles->SetNextTexture(1234u);
HandleGLES handle = reactor->CreateUntrackedHandle(HandleType::kTexture);
mock_gles->GetCapturedCalls();
reactor->SetDebugLabel(handle, "hello, joe!");
std::vector<std::string> calls = mock_gles->GetCapturedCalls();
EXPECT_TRUE(std::find(calls.begin(), calls.end(), "glObjectLabelKHR") !=
calls.end());
}
TEST(ReactorGLES, PerThreadOperationQueues) { TEST(ReactorGLES, PerThreadOperationQueues) {
auto mock_gles = MockGLES::Init(); auto mock_gles = MockGLES::Init();
ProcTableGLES::Resolver resolver = kMockResolverGLES; ProcTableGLES::Resolver resolver = kMockResolverGLES;