Skip to content

Commit

Permalink
Reland "Vulkan: Implement debug markers"
Browse files Browse the repository at this point in the history
This reverts commit 0c01e36.

Reason for revert: Its dependency that was reverted has now relanded:

    https://chromium-review.googlesource.com/c/angle/angle/+/1489153

Original change's description:
> Revert "Vulkan: Implement debug markers"
>
> This reverts commit 983e446.
>
> Reason for revert: Depends on a CL that's reverted: https://chromium-review.googlesource.com/c/angle/angle/+/1470605
>
> Original change's description:
> > Vulkan: Implement debug markers
> >
> > Covers both GL_KHR_debug and GL_EXT_debug_marker.
> >
> > Debug markers are used to specify events or hierarchically categorize a
> > set of commands within the command buffer.  When debugging, this allows
> > for quicker navigation to the draw calls of interest, and otherwise
> > provides context to debug output.
> >
> > Bug: angleproject:2853
> > Change-Id: Id65e11fc877d9e70b6fd0fae7f0bbbcb1164bf10
> > Reviewed-on: https://chromium-review.googlesource.com/c/1403956
> > Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
> > Reviewed-by: Jamie Madill <jmadill@chromium.org>
> > Reviewed-by: Geoff Lang <geofflang@chromium.org>
>
> TBR=geofflang@chromium.org,jmadill@chromium.org,syoussefi@chromium.org
>
> Change-Id: I7fcfc8683195d396aec61848719f52c0fa049ece
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: angleproject:2853
> Reviewed-on: https://chromium-review.googlesource.com/c/1470606
> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>

TBR=geofflang@chromium.org,jmadill@google.com,syoussefi@chromium.org

Bug: angleproject:2853
Change-Id: Ie19ae103244d54dcf7108d5f61c24e318fc44057
Reviewed-on: https://chromium-review.googlesource.com/c/1489154
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Jamie Madill <jmadill@google.com>
  • Loading branch information
ShabbyX authored and Commit Bot committed Mar 2, 2019
1 parent 6f1a852 commit 4d15338
Show file tree
Hide file tree
Showing 22 changed files with 215 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/common/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template <typename T>
struct Color
{
Color();
Color(T r, T g, T b, T a);
constexpr Color(T r, T g, T b, T a);

const T *data() const { return &red; }
T *ptr() { return &red; }
Expand Down
2 changes: 1 addition & 1 deletion src/common/Color.inl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Color<T>::Color() : Color(0, 0, 0, 0)
}

template <typename T>
Color<T>::Color(T r, T g, T b, T a) : red(r), green(g), blue(b), alpha(a)
constexpr Color<T>::Color(T r, T g, T b, T a) : red(r), green(g), blue(b), alpha(a)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5008,8 +5008,8 @@ GLuint Context::getDebugMessageLog(GLuint count,
void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
{
std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
mImplementation->pushDebugGroup(source, id, msg);
mState.getDebug().pushGroup(source, id, std::move(msg));
mImplementation->pushDebugGroup(source, id, length, message);
}

void Context::popDebugGroup()
Expand Down
4 changes: 2 additions & 2 deletions src/libANGLE/renderer/ContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class ContextImpl : public GLImplFactory
virtual void popGroupMarker() = 0;

// KHR_debug
virtual void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) = 0;
virtual void popDebugGroup() = 0;
virtual void pushDebugGroup(GLenum source, GLuint id, const std::string &message) = 0;
virtual void popDebugGroup() = 0;

// State sync with dirty bits.
virtual angle::Result syncState(const gl::Context *context,
Expand Down
4 changes: 2 additions & 2 deletions src/libANGLE/renderer/d3d/d3d11/Context11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ void Context11::popGroupMarker()
}
}

void Context11::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
void Context11::pushDebugGroup(GLenum source, GLuint id, const std::string &message)
{
// Fall through to the EXT_debug_marker functions
pushGroupMarker(length, message);
pushGroupMarker(message.size(), message.c_str());
}

void Context11::popDebugGroup()
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/d3d/d3d11/Context11.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Context11 : public ContextD3D, public MultisampleTextureInitializer
void popGroupMarker() override;

// KHR_debug
void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) override;
void pushDebugGroup(GLenum source, GLuint id, const std::string &message) override;
void popDebugGroup() override;

// State sync with dirty bits.
Expand Down
4 changes: 2 additions & 2 deletions src/libANGLE/renderer/d3d/d3d9/Context9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ void Context9::popGroupMarker()
}
}

void Context9::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
void Context9::pushDebugGroup(GLenum source, GLuint id, const std::string &message)
{
// Fall through to the EXT_debug_marker functions
pushGroupMarker(length, message);
pushGroupMarker(message.size(), message.c_str());
}

void Context9::popDebugGroup()
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/d3d/d3d9/Context9.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Context9 : public ContextD3D
void popGroupMarker() override;

// KHR_debug
void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) override;
void pushDebugGroup(GLenum source, GLuint id, const std::string &message) override;
void popDebugGroup() override;

// State sync with dirty bits.
Expand Down
4 changes: 2 additions & 2 deletions src/libANGLE/renderer/gl/ContextGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ void ContextGL::popGroupMarker()
mRenderer->popGroupMarker();
}

void ContextGL::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
void ContextGL::pushDebugGroup(GLenum source, GLuint id, const std::string &message)
{
mRenderer->pushDebugGroup(source, id, length, message);
mRenderer->pushDebugGroup(source, id, message);
}

void ContextGL::popDebugGroup()
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/gl/ContextGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class ContextGL : public ContextImpl
void popGroupMarker() override;

// KHR_debug
void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) override;
void pushDebugGroup(GLenum source, GLuint id, const std::string &message) override;
void popDebugGroup() override;

// State sync with dirty bits.
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/gl/RendererGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void RendererGL::pushGroupMarker(GLsizei length, const char *marker) {}

void RendererGL::popGroupMarker() {}

void RendererGL::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) {}
void RendererGL::pushDebugGroup(GLenum source, GLuint id, const std::string &message) {}

void RendererGL::popDebugGroup() {}

Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/gl/RendererGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class RendererGL : angle::NonCopyable
void popGroupMarker();

// KHR_debug
void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message);
void pushDebugGroup(GLenum source, GLuint id, const std::string &message);
void popDebugGroup();

std::string getVendorString() const;
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/null/ContextNULL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void ContextNULL::pushGroupMarker(GLsizei length, const char *marker) {}

void ContextNULL::popGroupMarker() {}

void ContextNULL::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) {}
void ContextNULL::pushDebugGroup(GLenum source, GLuint id, const std::string &message) {}

void ContextNULL::popDebugGroup() {}

Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/null/ContextNULL.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ContextNULL : public ContextImpl
void popGroupMarker() override;

// KHR_debug
void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) override;
void pushDebugGroup(GLenum source, GLuint id, const std::string &message) override;
void popDebugGroup() override;

// State sync with dirty bits.
Expand Down
158 changes: 134 additions & 24 deletions src/libANGLE/renderer/vulkan/CommandGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,45 @@ const char *GetResourceTypeName(CommandGraphResourceType resourceType,
UNREACHABLE();
return "FenceSync";
}
case CommandGraphResourceType::DebugMarker:
switch (function)
{
case CommandGraphNodeFunction::InsertDebugMarker:
return "InsertDebugMarker";
case CommandGraphNodeFunction::PushDebugMarker:
return "PushDebugMarker";
case CommandGraphNodeFunction::PopDebugMarker:
return "PopDebugMarker";
default:
UNREACHABLE();
return "DebugMarker";
}
default:
UNREACHABLE();
return "";
}
}

void MakeDebugUtilsLabel(GLenum source, const char *marker, VkDebugUtilsLabelEXT *label)
{
static constexpr angle::ColorF kLabelColors[6] = {
angle::ColorF(1.0f, 0.5f, 0.5f, 1.0f), // DEBUG_SOURCE_API
angle::ColorF(0.5f, 1.0f, 0.5f, 1.0f), // DEBUG_SOURCE_WINDOW_SYSTEM
angle::ColorF(0.5f, 0.5f, 1.0f, 1.0f), // DEBUG_SOURCE_SHADER_COMPILER
angle::ColorF(0.7f, 0.7f, 0.7f, 1.0f), // DEBUG_SOURCE_THIRD_PARTY
angle::ColorF(0.5f, 0.8f, 0.9f, 1.0f), // DEBUG_SOURCE_APPLICATION
angle::ColorF(0.9f, 0.8f, 0.5f, 1.0f), // DEBUG_SOURCE_OTHER
};

int colorIndex = source - GL_DEBUG_SOURCE_API;
ASSERT(colorIndex >= 0 && static_cast<size_t>(colorIndex) < ArraySize(kLabelColors));

label->sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
label->pNext = nullptr;
label->pLabelName = marker;
kLabelColors[colorIndex].writeData(label->color);
}

} // anonymous namespace

// CommandGraphResource implementation.
Expand Down Expand Up @@ -356,6 +390,14 @@ void CommandGraphNode::setFenceSync(const vk::Event &event)
mFenceSyncEvent = event.getHandle();
}

void CommandGraphNode::setDebugMarker(GLenum source, std::string &&marker)
{
ASSERT(mFunction == CommandGraphNodeFunction::InsertDebugMarker ||
mFunction == CommandGraphNodeFunction::PushDebugMarker);
mDebugMarkerSource = source;
mDebugMarker = std::move(marker);
}

// Do not call this in anything but testing code, since it's slow.
bool CommandGraphNode::isChildOf(CommandGraphNode *parent)
{
Expand Down Expand Up @@ -499,6 +541,39 @@ angle::Result CommandGraphNode::visitAndExecute(vk::Context *context,

break;

case CommandGraphNodeFunction::InsertDebugMarker:
ASSERT(!mOutsideRenderPassCommands.valid() && !mInsideRenderPassCommands.valid());

if (vkCmdInsertDebugUtilsLabelEXT)
{
VkDebugUtilsLabelEXT label;
MakeDebugUtilsLabel(mDebugMarkerSource, mDebugMarker.c_str(), &label);

vkCmdInsertDebugUtilsLabelEXT(primaryCommandBuffer->getHandle(), &label);
}
break;

case CommandGraphNodeFunction::PushDebugMarker:
ASSERT(!mOutsideRenderPassCommands.valid() && !mInsideRenderPassCommands.valid());

if (vkCmdBeginDebugUtilsLabelEXT)
{
VkDebugUtilsLabelEXT label;
MakeDebugUtilsLabel(mDebugMarkerSource, mDebugMarker.c_str(), &label);

vkCmdBeginDebugUtilsLabelEXT(primaryCommandBuffer->getHandle(), &label);
}
break;

case CommandGraphNodeFunction::PopDebugMarker:
ASSERT(!mOutsideRenderPassCommands.valid() && !mInsideRenderPassCommands.valid());

if (vkCmdEndDebugUtilsLabelEXT)
{
vkCmdEndDebugUtilsLabelEXT(primaryCommandBuffer->getHandle());
}
break;

default:
UNREACHABLE();
}
Expand Down Expand Up @@ -712,6 +787,26 @@ void CommandGraph::waitFenceSync(const vk::Event &event)
newNode->setFenceSync(event);
}

void CommandGraph::insertDebugMarker(GLenum source, std::string &&marker)
{
CommandGraphNode *newNode = allocateBarrierNode(CommandGraphResourceType::DebugMarker,
CommandGraphNodeFunction::InsertDebugMarker);
newNode->setDebugMarker(source, std::move(marker));
}

void CommandGraph::pushDebugMarker(GLenum source, std::string &&marker)
{
CommandGraphNode *newNode = allocateBarrierNode(CommandGraphResourceType::DebugMarker,
CommandGraphNodeFunction::PushDebugMarker);
newNode->setDebugMarker(source, std::move(marker));
}

void CommandGraph::popDebugMarker()
{
allocateBarrierNode(CommandGraphResourceType::DebugMarker,
CommandGraphNodeFunction::PopDebugMarker);
}

// Dumps the command graph into a dot file that works with graphviz.
void CommandGraph::dumpGraphDotFile(std::ostream &out) const
{
Expand Down Expand Up @@ -739,38 +834,53 @@ void CommandGraph::dumpGraphDotFile(std::ostream &out) const

std::stringstream strstr;
strstr << GetResourceTypeName(node->getResourceTypeForDiagnostics(), node->getFunction());
strstr << " ";

auto it = objectIDMap.find(node->getResourceIDForDiagnostics());
if (it != objectIDMap.end())
if (node->getResourceTypeForDiagnostics() == CommandGraphResourceType::DebugMarker)
{
strstr << it->second;
// For debug markers, use the string from the debug marker itself.
if (node->getFunction() != CommandGraphNodeFunction::PopDebugMarker)
{
strstr << " " << node->getDebugMarker();
}
}
else
{
int id = 0;
strstr << " ";

switch (node->getResourceTypeForDiagnostics())
// Otherwise assign each object an ID, so all the nodes of the same object have the same
// label.
ASSERT(node->getResourceIDForDiagnostics() != 0);
auto it = objectIDMap.find(node->getResourceIDForDiagnostics());
if (it != objectIDMap.end())
{
case CommandGraphResourceType::Buffer:
id = bufferIDCounter++;
break;
case CommandGraphResourceType::Framebuffer:
id = framebufferIDCounter++;
break;
case CommandGraphResourceType::Image:
id = imageIDCounter++;
break;
case CommandGraphResourceType::Query:
id = queryIDCounter++;
break;
default:
UNREACHABLE();
break;
strstr << it->second;
}
else
{
int id = 0;

switch (node->getResourceTypeForDiagnostics())
{
case CommandGraphResourceType::Buffer:
id = bufferIDCounter++;
break;
case CommandGraphResourceType::Framebuffer:
id = framebufferIDCounter++;
break;
case CommandGraphResourceType::Image:
id = imageIDCounter++;
break;
case CommandGraphResourceType::Query:
id = queryIDCounter++;
break;
default:
UNREACHABLE();
break;
}

objectIDMap[node->getResourceIDForDiagnostics()] = id;
strstr << id;
}

objectIDMap[node->getResourceIDForDiagnostics()] = id;
strstr << id;
}

const std::string &label = strstr.str();
Expand Down
13 changes: 13 additions & 0 deletions src/libANGLE/renderer/vulkan/CommandGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class CommandGraphResourceType
Image,
Query,
FenceSync,
DebugMarker,
};

// Certain functionality cannot be put in secondary command buffers, so they are special-cased in
Expand All @@ -43,6 +44,9 @@ enum class CommandGraphNodeFunction
WriteTimestamp,
SetFenceSync,
WaitFenceSync,
InsertDebugMarker,
PushDebugMarker,
PopDebugMarker,
};

// Receives notifications when a command buffer is no longer able to record. Can be used with
Expand Down Expand Up @@ -131,6 +135,8 @@ class CommandGraphNode final : angle::NonCopyable

void setQueryPool(const QueryPool *queryPool, uint32_t queryIndex);
void setFenceSync(const vk::Event &event);
void setDebugMarker(GLenum source, std::string &&marker);
const std::string &getDebugMarker() const { return mDebugMarker; }

ANGLE_INLINE void addGlobalMemoryBarrier(VkFlags srcAccess, VkFlags dstAccess)
{
Expand Down Expand Up @@ -177,6 +183,9 @@ class CommandGraphNode final : angle::NonCopyable
uint32_t mQueryIndex;
// GLsync and EGLSync:
VkEvent mFenceSyncEvent;
// Debug markers:
GLenum mDebugMarkerSource;
std::string mDebugMarker;

// Parents are commands that must be submitted before 'this' CommandNode can be submitted.
std::vector<CommandGraphNode *> mParents;
Expand Down Expand Up @@ -369,6 +378,10 @@ class CommandGraph final : angle::NonCopyable
// GLsync and EGLSync:
void setFenceSync(const vk::Event &event);
void waitFenceSync(const vk::Event &event);
// Debug markers:
void insertDebugMarker(GLenum source, std::string &&marker);
void pushDebugMarker(GLenum source, std::string &&marker);
void popDebugMarker();

private:
CommandGraphNode *allocateBarrierNode(CommandGraphResourceType resourceType,
Expand Down
Loading

0 comments on commit 4d15338

Please sign in to comment.