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

Commit d7eaf82

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

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

impeller/renderer/backend/gles/reactor_gles.cc

Lines changed: 12 additions & 11 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) {
@@ -317,15 +318,6 @@ bool ReactorGLES::ConsolidateHandles() {
317318
}
318319
handle.second.name = gl_handle;
319320
}
320-
// Set pending debug labels.
321-
if (handle.second.pending_debug_label.has_value() &&
322-
handle.first.GetType() != HandleType::kFence) {
323-
handles_to_name.emplace_back(std::make_tuple(
324-
ToDebugResourceType(handle.first.GetType()),
325-
handle.second.name.value().handle,
326-
std::move(handle.second.pending_debug_label.value())));
327-
handle.second.pending_debug_label = std::nullopt;
328-
}
329321
}
330322
for (const auto& handle_to_delete : handles_to_delete) {
331323
handles_.erase(std::get<0>(handle_to_delete));
@@ -386,15 +378,24 @@ void ReactorGLES::SetupDebugGroups() {
386378

387379
void ReactorGLES::SetDebugLabel(const HandleGLES& handle,
388380
std::string_view label) {
381+
FML_DCHECK(handle.GetType() != HandleType::kFence);
389382
if (!can_set_debug_labels_) {
390383
return;
391384
}
392385
if (handle.IsDead()) {
393386
return;
394387
}
395388
WriterLock handles_lock(handles_mutex_);
396-
if (auto found = handles_.find(handle); found != handles_.end()) {
397-
found->second.pending_debug_label = label;
389+
if (handle.untracked_id_.has_value()) {
390+
handles_to_name_.emplace_back(
391+
std::make_tuple(ToDebugResourceType(handle.GetType()),
392+
handle.untracked_id_.value(), std::string(label)));
393+
} else {
394+
if (auto found = handles_.find(handle); found != handles_.end()) {
395+
handles_to_name_.emplace_back(std::make_tuple(
396+
ToDebugResourceType(handle.GetType()),
397+
found->second.name.value().handle, std::string(label)));
398+
}
398399
}
399400
}
400401

impeller/renderer/backend/gles/reactor_gles.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ class ReactorGLES {
272272

273273
struct LiveHandle {
274274
std::optional<GLStorage> name;
275-
std::optional<std::string> pending_debug_label;
276275
bool pending_collection = false;
277276
fml::ScopedCleanupClosure callback = {};
278277

@@ -296,6 +295,9 @@ class ReactorGLES {
296295
mutable RWMutex handles_mutex_;
297296
LiveHandles handles_ IPLR_GUARDED_BY(handles_mutex_);
298297
int32_t handles_to_collect_count_ IPLR_GUARDED_BY(handles_mutex_) = 0;
298+
std::vector<
299+
std::tuple<DebugResourceType, GLint, std::string>> handles_to_name_
300+
IPLR_GUARDED_BY(handles_mutex_);
299301

300302
mutable Mutex workers_mutex_;
301303
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)