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

Commit 3705fc4

Browse files
ianelliottusCommit Bot
authored andcommitted
Vulkan:Add debug labels for OpenGL calls
Implement the DebugAnnotatorVk class, and plumb the EVENT macro in the GL entrypoints to save a string of call info in the vector of all GL calls in ContextVk. Then add a vkCmdBeginDebugUtilsLabelEXT() call that includes the OpenGL draw/dispatch call prior to any Vulkan Draw or Dispatch calls. Also embedded under that label add a second vkCmdBeginDebugUtilsLabelEXT() call labeled "OpenGL Commands" that includes all of the OpenGL calls leading up to the draw/dispatch. Each individual OpenGL call is then given its own vkCmdBegin/EndDebugUtilsLabelEXT() pair so that the complete sequence of GL calls leading up to a draw call is visible for each Draw. Enable the OGL->VK mapping feature by setting "angle_enable_trace = true" in GN args. Note: This will create an ANGLE APK on Android that generally won't work with games, unless launched by AGI (which provides the debug utils extension). A future version will disable these labels unless the debug utils extension is found. Bug: b/162068318 Bug: b/169243237 Change-Id: I09886f17fa9287528c12552698738ea1fe2a4b8c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2427557 Commit-Queue: Ian Elliott <[email protected]> Reviewed-by: Tim Van Patten <[email protected]> Reviewed-by: Jamie Madill <[email protected]> Reviewed-by: Courtney Goeltzenleuchter <[email protected]> Reviewed-by: Shahbaz Youssefi <[email protected]>
1 parent b156a75 commit 3705fc4

File tree

8 files changed

+195
-25
lines changed

8 files changed

+195
-25
lines changed

src/common/debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ std::ostream *gSwallowStream;
8181

8282
bool DebugAnnotationsActive()
8383
{
84-
#if defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS)
84+
#if defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) || defined(ANGLE_ENABLE_DEBUG_TRACE)
8585
return g_debugAnnotator != nullptr && g_debugAnnotator->getStatus();
8686
#else
8787
return false;

src/libANGLE/renderer/vulkan/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ _vulkan_backend_sources = [
2727
"CompilerVk.h",
2828
"ContextVk.cpp",
2929
"ContextVk.h",
30+
"DebugAnnotatorVk.cpp",
31+
"DebugAnnotatorVk.h",
3032
"DeviceVk.cpp",
3133
"DeviceVk.h",
3234
"DisplayVk.cpp",

src/libANGLE/renderer/vulkan/ContextVk.cpp

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ vk::ResourceAccess GetStencilAccess(const gl::DepthStencilState &dsState)
302302
// Simplify this check by returning write instead of checking the mask.
303303
return vk::ResourceAccess::Write;
304304
}
305+
306+
#if defined(ANGLE_ENABLE_DEBUG_TRACE)
307+
# define ANGLE_WRITE_EVENT_LOG(context, commandBuffer) writeEventLog(context, commandBuffer)
308+
# define ANGLE_END_EVENT_LOG(commandBuffer) commandBuffer->endDebugUtilsLabelEXT()
309+
#else
310+
# define ANGLE_WRITE_EVENT_LOG(context, commandBuffer)
311+
# define ANGLE_END_EVENT_LOG(commandBuffer)
312+
#endif
305313
} // anonymous namespace
306314

307315
ANGLE_INLINE void ContextVk::flushDescriptorSetUpdates()
@@ -1077,6 +1085,8 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
10771085
if (dirtyBits.none())
10781086
return angle::Result::Continue;
10791087

1088+
ANGLE_WRITE_EVENT_LOG(context, *commandBufferOut);
1089+
10801090
// Flush any relevant dirty bits.
10811091
for (size_t dirtyBit : dirtyBits)
10821092
{
@@ -1282,6 +1292,7 @@ angle::Result ContextVk::setupDispatch(const gl::Context *context,
12821292
// The following ensures prior commands are flushed before we start processing dirty bits.
12831293
ANGLE_TRY(flushCommandsAndEndRenderPass());
12841294
*commandBufferOut = &mOutsideRenderPassCommands->getCommandBuffer();
1295+
ANGLE_WRITE_EVENT_LOG(context, *commandBufferOut);
12851296

12861297
// Create a local object to ensure we flush the descriptor updates to device when we leave this
12871298
// function
@@ -2087,7 +2098,7 @@ angle::Result ContextVk::drawArrays(const gl::Context *context,
20872098
nullptr, mNonIndexedDirtyBitsMask, &commandBuffer));
20882099
commandBuffer->draw(clampedVertexCount, first);
20892100
}
2090-
2101+
ANGLE_END_EVENT_LOG(commandBuffer);
20912102
return angle::Result::Continue;
20922103
}
20932104

@@ -2107,12 +2118,15 @@ angle::Result ContextVk::drawArraysInstanced(const gl::Context *context,
21072118
gl::DrawElementsType::InvalidEnum, nullptr, &commandBuffer,
21082119
&numIndices));
21092120
commandBuffer->drawIndexedInstanced(numIndices, instances);
2110-
return angle::Result::Continue;
21112121
}
2112-
2113-
ANGLE_TRY(setupDraw(context, mode, first, count, instances, gl::DrawElementsType::InvalidEnum,
2114-
nullptr, mNonIndexedDirtyBitsMask, &commandBuffer));
2115-
commandBuffer->drawInstanced(gl::GetClampedVertexCount<uint32_t>(count), instances, first);
2122+
else
2123+
{
2124+
ANGLE_TRY(setupDraw(context, mode, first, count, instances,
2125+
gl::DrawElementsType::InvalidEnum, nullptr, mNonIndexedDirtyBitsMask,
2126+
&commandBuffer));
2127+
commandBuffer->drawInstanced(gl::GetClampedVertexCount<uint32_t>(count), instances, first);
2128+
}
2129+
ANGLE_END_EVENT_LOG(commandBuffer);
21162130
return angle::Result::Continue;
21172131
}
21182132

@@ -2134,13 +2148,16 @@ angle::Result ContextVk::drawArraysInstancedBaseInstance(const gl::Context *cont
21342148
&numIndices));
21352149
commandBuffer->drawIndexedInstancedBaseVertexBaseInstance(numIndices, instances, 0, 0,
21362150
baseInstance);
2137-
return angle::Result::Continue;
21382151
}
2139-
2140-
ANGLE_TRY(setupDraw(context, mode, first, count, instances, gl::DrawElementsType::InvalidEnum,
2141-
nullptr, mNonIndexedDirtyBitsMask, &commandBuffer));
2142-
commandBuffer->drawInstancedBaseInstance(gl::GetClampedVertexCount<uint32_t>(count), instances,
2143-
first, baseInstance);
2152+
else
2153+
{
2154+
ANGLE_TRY(setupDraw(context, mode, first, count, instances,
2155+
gl::DrawElementsType::InvalidEnum, nullptr, mNonIndexedDirtyBitsMask,
2156+
&commandBuffer));
2157+
commandBuffer->drawInstancedBaseInstance(gl::GetClampedVertexCount<uint32_t>(count),
2158+
instances, first, baseInstance);
2159+
}
2160+
ANGLE_END_EVENT_LOG(commandBuffer);
21442161
return angle::Result::Continue;
21452162
}
21462163

@@ -2163,7 +2180,7 @@ angle::Result ContextVk::drawElements(const gl::Context *context,
21632180
ANGLE_TRY(setupIndexedDraw(context, mode, count, 1, type, indices, &commandBuffer));
21642181
commandBuffer->drawIndexed(count);
21652182
}
2166-
2183+
ANGLE_END_EVENT_LOG(commandBuffer);
21672184
return angle::Result::Continue;
21682185
}
21692186

@@ -2187,7 +2204,7 @@ angle::Result ContextVk::drawElementsBaseVertex(const gl::Context *context,
21872204
ANGLE_TRY(setupIndexedDraw(context, mode, count, 1, type, indices, &commandBuffer));
21882205
commandBuffer->drawIndexedBaseVertex(count, baseVertex);
21892206
}
2190-
2207+
ANGLE_END_EVENT_LOG(commandBuffer);
21912208
return angle::Result::Continue;
21922209
}
21932210

@@ -2213,6 +2230,7 @@ angle::Result ContextVk::drawElementsInstanced(const gl::Context *context,
22132230
}
22142231

22152232
commandBuffer->drawIndexedInstanced(count, instances);
2233+
ANGLE_END_EVENT_LOG(commandBuffer);
22162234
return angle::Result::Continue;
22172235
}
22182236

@@ -2239,6 +2257,7 @@ angle::Result ContextVk::drawElementsInstancedBaseVertex(const gl::Context *cont
22392257
}
22402258

22412259
commandBuffer->drawIndexedInstancedBaseVertex(count, instances, baseVertex);
2260+
ANGLE_END_EVENT_LOG(commandBuffer);
22422261
return angle::Result::Continue;
22432262
}
22442263

@@ -2260,12 +2279,14 @@ angle::Result ContextVk::drawElementsInstancedBaseVertexBaseInstance(const gl::C
22602279
setupLineLoopDraw(context, mode, 0, count, type, indices, &commandBuffer, &indexCount));
22612280
commandBuffer->drawIndexedInstancedBaseVertexBaseInstance(indexCount, instances, 0,
22622281
baseVertex, baseInstance);
2263-
return angle::Result::Continue;
22642282
}
2265-
2266-
ANGLE_TRY(setupIndexedDraw(context, mode, count, instances, type, indices, &commandBuffer));
2267-
commandBuffer->drawIndexedInstancedBaseVertexBaseInstance(count, instances, 0, baseVertex,
2268-
baseInstance);
2283+
else
2284+
{
2285+
ANGLE_TRY(setupIndexedDraw(context, mode, count, instances, type, indices, &commandBuffer));
2286+
commandBuffer->drawIndexedInstancedBaseVertexBaseInstance(count, instances, 0, baseVertex,
2287+
baseInstance);
2288+
}
2289+
ANGLE_END_EVENT_LOG(commandBuffer);
22692290
return angle::Result::Continue;
22702291
}
22712292

@@ -2339,13 +2360,16 @@ angle::Result ContextVk::drawArraysIndirect(const gl::Context *context,
23392360
&dstIndirectBuf, &dstIndirectBufOffset));
23402361

23412362
commandBuffer->drawIndexedIndirect(dstIndirectBuf->getBuffer(), dstIndirectBufOffset, 1, 0);
2342-
return angle::Result::Continue;
23432363
}
2364+
else
2365+
{
2366+
ANGLE_TRY(setupIndirectDraw(context, mode, mNonIndexedDirtyBitsMask, currentIndirectBuf,
2367+
currentIndirectBufOffset, &commandBuffer));
23442368

2345-
ANGLE_TRY(setupIndirectDraw(context, mode, mNonIndexedDirtyBitsMask, currentIndirectBuf,
2346-
currentIndirectBufOffset, &commandBuffer));
2347-
2348-
commandBuffer->drawIndirect(currentIndirectBuf->getBuffer(), currentIndirectBufOffset, 1, 0);
2369+
commandBuffer->drawIndirect(currentIndirectBuf->getBuffer(), currentIndirectBufOffset, 1,
2370+
0);
2371+
}
2372+
ANGLE_END_EVENT_LOG(commandBuffer);
23492373
return angle::Result::Continue;
23502374
}
23512375

@@ -2420,6 +2444,7 @@ angle::Result ContextVk::drawElementsIndirect(const gl::Context *context,
24202444

24212445
commandBuffer->drawIndexedIndirect(currentIndirectBuf->getBuffer(), currentIndirectBufOffset, 1,
24222446
0);
2447+
ANGLE_END_EVENT_LOG(commandBuffer);
24232448
return angle::Result::Continue;
24242449
}
24252450

@@ -2617,6 +2642,56 @@ angle::Result ContextVk::popDebugGroup(const gl::Context *context)
26172642
return angle::Result::Continue;
26182643
}
26192644

2645+
void ContextVk::writeEventLog(const gl::Context *context, vk::CommandBuffer *commandBuffer)
2646+
{
2647+
if (mEventLog.empty())
2648+
{
2649+
return;
2650+
}
2651+
2652+
// Insert OpenGL ES commands into debug label. We create a 3-level cascade here for
2653+
// OpenGL-ES-first debugging in AGI. Here's the general outline of commands:
2654+
// -glDrawCommand
2655+
// --vkCmdBeginDebugUtilsLabelEXT() #1 for "glDrawCommand"
2656+
// --OpenGL ES Commands
2657+
// ---vkCmdBeginDebugUtilsLabelEXT() #2 for "OpenGL ES Commands"
2658+
// ---Individual OpenGL ES Commands leading up to glDrawCommand
2659+
// ----vkCmdBeginDebugUtilsLabelEXT() #3 for each individual OpenGL ES Command
2660+
// ----vkCmdEndDebugUtilsLabelEXT() #3 for each individual OpenGL ES Command
2661+
// ----...More Individual OGL Commands...
2662+
// ----Final Individual OGL command will be the same glDrawCommand shown in #1 above
2663+
// ---vkCmdEndDebugUtilsLabelEXT() #2 for "OpenGL ES Commands"
2664+
// --VK SetupDraw & Draw-related commands will be embedded here under glDraw #1
2665+
// --vkCmdEndDebugUtilsLabelEXT() #1 is called after each vkDraw* or vkDispatch* call
2666+
VkDebugUtilsLabelEXT label = {VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
2667+
nullptr,
2668+
mEventLog.back().c_str(),
2669+
{0.0f, 0.0f, 0.0f, 0.0f}};
2670+
// This is #1 from comment above
2671+
commandBuffer->beginDebugUtilsLabelEXT(label);
2672+
std::string oglCmds = "OpenGL ES Commands";
2673+
label.pLabelName = oglCmds.c_str();
2674+
// This is #2 from comment above
2675+
commandBuffer->beginDebugUtilsLabelEXT(label);
2676+
for (uint32_t i = 0; i < mEventLog.size(); ++i)
2677+
{
2678+
label.pLabelName = mEventLog[i].c_str();
2679+
// NOTE: We have to use a begin/end pair here because AGI does not promote the
2680+
// pLabelName from an insertDebugUtilsLabelEXT() call to the Commands panel.
2681+
// Internal bug b/169243237 is tracking this and once the insert* call shows the
2682+
// pLabelName similar to begin* call, we can switch these to insert* calls instead.
2683+
// This is #3 from comment above.
2684+
// TODO(ianelliott): Transfer the bug to a publicly-visible bug.
2685+
commandBuffer->beginDebugUtilsLabelEXT(label);
2686+
commandBuffer->endDebugUtilsLabelEXT();
2687+
}
2688+
commandBuffer->endDebugUtilsLabelEXT();
2689+
// The final end* call for #1 above is made in the ContextVk::draw* or
2690+
// ContextVk::dispatch* function calls.
2691+
2692+
mEventLog.clear();
2693+
}
2694+
26202695
bool ContextVk::isViewportFlipEnabledForDrawFBO() const
26212696
{
26222697
return mFlipViewportForDrawFramebuffer && mFlipYForCurrentSurface;
@@ -3578,6 +3653,8 @@ angle::Result ContextVk::dispatchCompute(const gl::Context *context,
35783653

35793654
commandBuffer->dispatch(numGroupsX, numGroupsY, numGroupsZ);
35803655

3656+
ANGLE_END_EVENT_LOG(commandBuffer);
3657+
35813658
return angle::Result::Continue;
35823659
}
35833660

@@ -3593,6 +3670,8 @@ angle::Result ContextVk::dispatchComputeIndirect(const gl::Context *context, GLi
35933670

35943671
commandBuffer->dispatchIndirect(buffer.getBuffer(), indirect);
35953672

3673+
ANGLE_END_EVENT_LOG(commandBuffer);
3674+
35963675
return angle::Result::Continue;
35973676
}
35983677

src/libANGLE/renderer/vulkan/ContextVk.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ class ContextVk : public ContextImpl, public vk::Context
261261
const std::string &message) override;
262262
angle::Result popDebugGroup(const gl::Context *context) override;
263263

264+
// Record GL API calls for debuggers
265+
void logEvent(const char *eventString) { mEventLog.push_back(eventString); }
266+
264267
bool isViewportFlipEnabledForDrawFBO() const;
265268
bool isViewportFlipEnabledForReadFBO() const;
266269
// When the device/surface is rotated such that the surface's aspect ratio is different than
@@ -952,6 +955,9 @@ class ContextVk : public ContextImpl, public vk::Context
952955
bool shouldSwitchToReadOnlyDepthFeedbackLoopMode(const gl::Context *context,
953956
gl::Texture *texture) const;
954957

958+
// Record GL API calls for debuggers
959+
void writeEventLog(const gl::Context *context, vk::CommandBuffer *commandBuffer);
960+
955961
std::array<DirtyBitHandler, DIRTY_BIT_MAX> mGraphicsDirtyBitHandlers;
956962
std::array<DirtyBitHandler, DIRTY_BIT_MAX> mComputeDirtyBitHandlers;
957963

@@ -1149,6 +1155,9 @@ class ContextVk : public ContextImpl, public vk::Context
11491155
vk::DynamicBuffer mStagingBuffer;
11501156

11511157
std::vector<std::string> mCommandBufferDiagnostics;
1158+
1159+
// Record GL API calls for debuggers
1160+
std::vector<std::string> mEventLog;
11521161
};
11531162

11541163
ANGLE_INLINE angle::Result ContextVk::endRenderPassIfTransformFeedbackBuffer(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
//
6+
// DebugAnnotatorVk.cpp: Vulkan helpers for adding trace annotations.
7+
//
8+
9+
#include "libANGLE/renderer/vulkan/DebugAnnotatorVk.h"
10+
#include "libANGLE/Context.h"
11+
#include "libANGLE/renderer/vulkan/ContextVk.h"
12+
13+
namespace rx
14+
{
15+
16+
DebugAnnotatorVk::DebugAnnotatorVk() {}
17+
18+
DebugAnnotatorVk::~DebugAnnotatorVk() {}
19+
20+
void DebugAnnotatorVk::beginEvent(gl::Context *context,
21+
const char *eventName,
22+
const char *eventMessage)
23+
{
24+
angle::LoggingAnnotator::beginEvent(context, eventName, eventMessage);
25+
if (context)
26+
{
27+
ContextVk *contextVk = vk::GetImpl(static_cast<gl::Context *>(context));
28+
contextVk->logEvent(eventMessage);
29+
}
30+
}
31+
32+
void DebugAnnotatorVk::endEvent(const char *eventName)
33+
{
34+
angle::LoggingAnnotator::endEvent(eventName);
35+
}
36+
37+
bool DebugAnnotatorVk::getStatus()
38+
{
39+
return true;
40+
}
41+
42+
} // namespace rx
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
//
6+
// DebugAnnotatorVk.h: Vulkan helpers for adding trace annotations.
7+
//
8+
9+
#ifndef LIBANGLE_RENDERER_VULKAN_DEBUGANNOTATORVK_H_
10+
#define LIBANGLE_RENDERER_VULKAN_DEBUGANNOTATORVK_H_
11+
12+
#include "libANGLE/LoggingAnnotator.h"
13+
14+
namespace rx
15+
{
16+
17+
class DebugAnnotatorVk : public angle::LoggingAnnotator
18+
{
19+
public:
20+
DebugAnnotatorVk();
21+
~DebugAnnotatorVk() override;
22+
void beginEvent(gl::Context *context, const char *eventName, const char *eventMessage) override;
23+
void endEvent(const char *eventName) override;
24+
bool getStatus() override;
25+
26+
// Note: To avoid any race conditions between threads, this class has no private data; all
27+
// events are stored in ContextVk.
28+
};
29+
30+
} // namespace rx
31+
32+
#endif // LIBANGLE_RENDERER_VULKAN_DEBUGANNOTATORVK_H_

src/libANGLE/renderer/vulkan/RendererVk.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,14 @@ angle::Result RendererVk::initialize(DisplayVk *displayVk,
902902
// Initialize the format table.
903903
mFormatTable.initialize(this, &mNativeTextureCaps, &mNativeCaps.compressedTextureFormats);
904904

905+
gl::InitializeDebugAnnotations(&mAnnotator);
906+
905907
if (getFeatures().enableCommandProcessingThread.enabled)
906908
{
907909
mCommandProcessorThread =
908910
std::thread(&CommandProcessor::processCommandProcessorTasks, &mCommandProcessor);
909911
}
912+
910913
return angle::Result::Continue;
911914
}
912915

src/libANGLE/renderer/vulkan/RendererVk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "libANGLE/BlobCache.h"
2828
#include "libANGLE/Caps.h"
2929
#include "libANGLE/renderer/vulkan/CommandProcessor.h"
30+
#include "libANGLE/renderer/vulkan/DebugAnnotatorVk.h"
3031
#include "libANGLE/renderer/vulkan/QueryVk.h"
3132
#include "libANGLE/renderer/vulkan/ResourceVk.h"
3233
#include "libANGLE/renderer/vulkan/UtilsVk.h"
@@ -369,6 +370,8 @@ class RendererVk : angle::NonCopyable
369370
std::string mLastValidationMessage;
370371
uint32_t mValidationMessageCount;
371372

373+
DebugAnnotatorVk mAnnotator;
374+
372375
// How close to VkPhysicalDeviceLimits::maxMemoryAllocationCount we allow ourselves to get
373376
static constexpr double kPercentMaxMemoryAllocationCount = 0.3;
374377
// How many objects to garbage collect before issuing a flush()

0 commit comments

Comments
 (0)