Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d98c37e

Browse files
committed
Implements the naming of untracked gles handles
1 parent 8093eb3 commit d98c37e

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

impeller/renderer/backend/gles/reactor_gles.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ bool ReactorGLES::ConsolidateHandles() {
301301
WriterLock handles_lock(handles_mutex_);
302302
handles_to_delete.reserve(handles_to_collect_count_);
303303
handles_to_collect_count_ = 0;
304+
std::swap(handles_to_name, handles_to_name_);
304305
for (auto& handle : handles_) {
305306
// Collect dead handles.
306307
if (handle.second.pending_collection) {
@@ -386,15 +387,22 @@ void ReactorGLES::SetupDebugGroups() {
386387

387388
void ReactorGLES::SetDebugLabel(const HandleGLES& handle,
388389
std::string_view label) {
390+
FML_DCHECK(handle.GetType() != HandleType::kFence);
389391
if (!can_set_debug_labels_) {
390392
return;
391393
}
392394
if (handle.IsDead()) {
393395
return;
394396
}
395397
WriterLock handles_lock(handles_mutex_);
396-
if (auto found = handles_.find(handle); found != handles_.end()) {
397-
found->second.pending_debug_label = label;
398+
if (handle.untracked_id_.has_value()) {
399+
handles_to_name_.emplace_back(
400+
std::make_tuple(ToDebugResourceType(handle.GetType()),
401+
handle.untracked_id_.value(), std::string(label)));
402+
} else {
403+
if (auto found = handles_.find(handle); found != handles_.end()) {
404+
found->second.pending_debug_label = label;
405+
}
398406
}
399407
}
400408

impeller/renderer/backend/gles/reactor_gles.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ class ReactorGLES {
296296
mutable RWMutex handles_mutex_;
297297
LiveHandles handles_ IPLR_GUARDED_BY(handles_mutex_);
298298
int32_t handles_to_collect_count_ IPLR_GUARDED_BY(handles_mutex_) = 0;
299+
std::vector<
300+
std::tuple<DebugResourceType, GLint, std::string>> handles_to_name_
301+
IPLR_GUARDED_BY(handles_mutex_);
299302

300303
mutable Mutex workers_mutex_;
301304
mutable std::map<WorkerID, std::weak_ptr<Worker>> workers_ IPLR_GUARDED_BY(

impeller/renderer/backend/gles/test/mock_gles.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ void mockGetIntegerv(GLenum name, int* value) {
8383
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
8484
*value = 8;
8585
break;
86+
case GL_MAX_LABEL_LENGTH_KHR:
87+
*value = 64;
88+
break;
8689
default:
8790
*value = 0;
8891
break;
@@ -170,6 +173,8 @@ static_assert(CheckSameSignature<decltype(mockDeleteQueriesEXT), //
170173
void mockUniform1fv(GLint location, GLsizei count, const GLfloat* value) {
171174
RecordGLCall("glUniform1fv");
172175
}
176+
static_assert(CheckSameSignature<decltype(mockUniform1fv), //
177+
decltype(glUniform1fv)>::value);
173178

174179
void mockGenTextures(GLsizei n, GLuint* textures) {
175180
RecordGLCall("glGenTextures");
@@ -182,8 +187,17 @@ void mockGenTextures(GLsizei n, GLuint* textures) {
182187
}
183188
}
184189

185-
static_assert(CheckSameSignature<decltype(mockUniform1fv), //
186-
decltype(glUniform1fv)>::value);
190+
static_assert(CheckSameSignature<decltype(mockGenTextures), //
191+
decltype(glGenTextures)>::value);
192+
193+
void mockObjectLabelKHR(GLenum identifier,
194+
GLuint name,
195+
GLsizei length,
196+
const GLchar* label) {
197+
RecordGLCall("glObjectLabelKHR");
198+
}
199+
static_assert(CheckSameSignature<decltype(mockObjectLabelKHR), //
200+
decltype(glObjectLabelKHR)>::value);
187201

188202
std::shared_ptr<MockGLES> MockGLES::Init(
189203
const std::optional<std::vector<const unsigned char*>>& extensions,
@@ -230,6 +244,8 @@ const ProcTableGLES::Resolver kMockResolverGLES = [](const char* name) {
230244
return reinterpret_cast<void*>(mockUniform1fv);
231245
} else if (strcmp(name, "glGenTextures") == 0) {
232246
return reinterpret_cast<void*>(mockGenTextures);
247+
} else if (strcmp(name, "glObjectLabelKHR") == 0) {
248+
return reinterpret_cast<void*>(mockObjectLabelKHR);
233249
} else {
234250
return reinterpret_cast<void*>(&doNothing);
235251
}

impeller/renderer/backend/gles/test/reactor_unittests.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ TEST(ReactorGLES, UntrackedHandle) {
9191
calls.end());
9292
}
9393

94+
TEST(ReactorGLES, NameUntrackedHandle) {
95+
std::shared_ptr<MockGLES> mock_gles = MockGLES::Init();
96+
ProcTableGLES::Resolver resolver = kMockResolverGLES;
97+
auto proc_table = std::make_unique<ProcTableGLES>(resolver);
98+
auto worker = std::make_shared<TestWorker>();
99+
auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
100+
reactor->AddWorker(worker);
101+
102+
mock_gles->SetNextTexture(1234u);
103+
HandleGLES handle = reactor->CreateUntrackedHandle(HandleType::kTexture);
104+
mock_gles->GetCapturedCalls();
105+
reactor->SetDebugLabel(handle, "hello, joe!");
106+
// Without an operation nothing is cleaned up.
107+
EXPECT_TRUE(reactor->AddOperation([&](const ReactorGLES&) {}));
108+
EXPECT_TRUE(reactor->React());
109+
std::vector<std::string> calls = mock_gles->GetCapturedCalls();
110+
EXPECT_TRUE(std::find(calls.begin(), calls.end(), "glObjectLabelKHR") !=
111+
calls.end());
112+
}
113+
94114
TEST(ReactorGLES, PerThreadOperationQueues) {
95115
auto mock_gles = MockGLES::Init();
96116
ProcTableGLES::Resolver resolver = kMockResolverGLES;

0 commit comments

Comments
 (0)