Commit 37e84651 by Le Hoang Quyen Committed by Commit Bot

Metal: Partially implement EXT_debug_marker

Partially implemented to make it easier to debug. Only debug group is supported for now. Bug: angleproject:2634 Change-Id: I029dd4283790fb57a6964aad89c37d092e3378e5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2433331 Commit-Queue: Le Hoang Quyen <le.hoang.q@gmail.com> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 1c881dad
......@@ -120,6 +120,20 @@ bool IsTransformFeedbackOnly(const gl::State &glState)
return glState.isTransformFeedbackActiveUnpaused() && glState.isRasterizerDiscardEnabled();
}
std::string ConvertMarkerToString(GLsizei length, const char *marker)
{
std::string cppString;
if (length == 0)
{
cppString = marker;
}
else
{
cppString.assign(marker, length);
}
return cppString;
}
} // namespace
ContextMtl::ContextMtl(const gl::State &state, gl::ErrorSet *errorSet, DisplayMtl *display)
......@@ -629,11 +643,13 @@ angle::Result ContextMtl::insertEventMarker(GLsizei length, const char *marker)
angle::Result ContextMtl::pushGroupMarker(GLsizei length, const char *marker)
{
mCmdBuffer.pushDebugGroup(ConvertMarkerToString(length, marker));
return angle::Result::Continue;
}
angle::Result ContextMtl::popGroupMarker()
{
mCmdBuffer.popDebugGroup();
return angle::Result::Continue;
}
......
......@@ -115,6 +115,8 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N
void queueEventSignal(const mtl::SharedEventRef &event, uint64_t value);
void serverWaitEvent(const mtl::SharedEventRef &event, uint64_t value);
void pushDebugGroup(const std::string &marker);
void popDebugGroup();
CommandQueue &cmdQueue() { return mCmdQueue; }
......@@ -134,6 +136,9 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N
void setEventImpl(const mtl::SharedEventRef &event, uint64_t value);
void waitEventImpl(const mtl::SharedEventRef &event, uint64_t value);
void pushDebugGroupImpl(const std::string &marker);
void popDebugGroupImpl();
using ParentClass = WrappedObject<id<MTLCommandBuffer>>;
CommandQueue &mCmdQueue;
......@@ -146,6 +151,8 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N
std::vector<std::pair<mtl::SharedEventRef, uint64_t>> mPendingSignalEvents;
std::vector<std::string> mDebugGroups;
bool mCommitted = false;
};
......@@ -169,6 +176,9 @@ class CommandEncoder : public WrappedObject<id<MTLCommandEncoder>>, angle::NonCo
CommandEncoder &markResourceBeingWrittenByGPU(const BufferRef &buffer);
CommandEncoder &markResourceBeingWrittenByGPU(const TextureRef &texture);
virtual void pushDebugGroup(NSString *label);
virtual void popDebugGroup();
protected:
using ParentClass = WrappedObject<id<MTLCommandEncoder>>;
......@@ -453,6 +463,9 @@ class RenderCommandEncoder final : public CommandEncoder
void setLabel(NSString *label);
void pushDebugGroup(NSString *label) override;
void popDebugGroup() override;
const RenderPassDesc &renderPassDesc() const { return mRenderPassDesc; }
bool hasDrawCalls() const { return mHasDrawCalls; }
......
......@@ -63,7 +63,9 @@ namespace
PROC(DrawIndexedInstanced) \
PROC(DrawIndexedInstancedBaseVertex) \
PROC(SetVisibilityResultMode) \
PROC(UseResource)
PROC(UseResource) \
PROC(PushDebugGroup) \
PROC(PopDebugGroup)
#define ANGLE_MTL_TYPE_DECL(CMD) CMD,
......@@ -345,12 +347,35 @@ void UseResourceCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStre
[resource ANGLE_MTL_RELEASE];
}
void PushDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream)
{
NSString *label = stream->fetch<NSString *>();
[encoder pushDebugGroup:label];
[label ANGLE_MTL_RELEASE];
}
void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream)
{
[encoder popDebugGroup];
}
// Command encoder mapping
#define ANGLE_MTL_CMD_MAP(CMD) CMD##Cmd,
using CommandEncoderFunc = void (*)(id<MTLRenderCommandEncoder>, IntermediateCommandStream *);
constexpr CommandEncoderFunc gCommandEncoders[] = {ANGLE_MTL_CMD_X(ANGLE_MTL_CMD_MAP)};
NSString *cppLabelToObjC(const std::string &marker)
{
NSString *label = [NSString stringWithUTF8String:marker.c_str()];
if (!label)
{
// This can happen if the string is not a valid ascii string.
label = @"Invalid ASCII string";
}
return label;
}
}
// CommandQueue implementation
......@@ -593,6 +618,11 @@ void CommandBuffer::restart()
mQueueSerial = serial;
mCommitted = false;
for (std::string &marker : mDebugGroups)
{
pushDebugGroupImpl(marker);
}
ASSERT(metalCmdBuffer);
}
......@@ -622,6 +652,33 @@ void CommandBuffer::serverWaitEvent(const mtl::SharedEventRef &event, uint64_t v
waitEventImpl(event, value);
}
void CommandBuffer::pushDebugGroup(const std::string &marker)
{
mDebugGroups.push_back(marker);
std::lock_guard<std::mutex> lg(mLock);
if (readyImpl())
{
pushDebugGroupImpl(marker);
}
}
void CommandBuffer::popDebugGroup()
{
if (!mDebugGroups.empty())
{
mDebugGroups.pop_back();
}
std::lock_guard<std::mutex> lg(mLock);
if (readyImpl())
{
return;
}
}
/** private use only */
void CommandBuffer::set(id<MTLCommandBuffer> metalBuffer)
{
......@@ -733,6 +790,29 @@ void CommandBuffer::waitEventImpl(const mtl::SharedEventRef &event, uint64_t val
#endif // #if ANGLE_MTL_EVENT_AVAILABLE
}
void CommandBuffer::pushDebugGroupImpl(const std::string &marker)
{
ANGLE_MTL_OBJC_SCOPE
{
NSString *label = cppLabelToObjC(marker);
[get() pushDebugGroup:label];
if (mActiveCommandEncoder)
{
mActiveCommandEncoder->pushDebugGroup(label);
}
}
}
void CommandBuffer::popDebugGroupImpl()
{
if (mActiveCommandEncoder)
{
mActiveCommandEncoder->popDebugGroup();
}
[get() popDebugGroup];
}
// CommandEncoder implementation
CommandEncoder::CommandEncoder(CommandBuffer *cmdBuffer, Type type)
: mType(type), mCmdBuffer(*cmdBuffer)
......@@ -776,6 +856,18 @@ CommandEncoder &CommandEncoder::markResourceBeingWrittenByGPU(const TextureRef &
return *this;
}
void CommandEncoder::pushDebugGroup(NSString *label)
{
// Default implementation
[get() pushDebugGroup:label];
}
void CommandEncoder::popDebugGroup()
{
// Default implementation
[get() popDebugGroup];
}
// RenderCommandEncoderShaderStates implementation
RenderCommandEncoderShaderStates::RenderCommandEncoderShaderStates()
{
......@@ -1541,6 +1633,16 @@ RenderCommandEncoder &RenderCommandEncoder::useResource(const BufferRef &resourc
return *this;
}
void RenderCommandEncoder::pushDebugGroup(NSString *label)
{
// Defer the insertion until endEncoding()
mCommands.push(CmdType::PushDebugGroup).push([label ANGLE_MTL_RETAIN]);
}
void RenderCommandEncoder::popDebugGroup()
{
mCommands.push(CmdType::PopDebugGroup);
}
RenderCommandEncoder &RenderCommandEncoder::setColorStoreAction(MTLStoreAction action,
uint32_t colorAttachmentIndex)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment