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) ...@@ -120,6 +120,20 @@ bool IsTransformFeedbackOnly(const gl::State &glState)
return glState.isTransformFeedbackActiveUnpaused() && glState.isRasterizerDiscardEnabled(); 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 } // namespace
ContextMtl::ContextMtl(const gl::State &state, gl::ErrorSet *errorSet, DisplayMtl *display) ContextMtl::ContextMtl(const gl::State &state, gl::ErrorSet *errorSet, DisplayMtl *display)
...@@ -629,11 +643,13 @@ angle::Result ContextMtl::insertEventMarker(GLsizei length, const char *marker) ...@@ -629,11 +643,13 @@ angle::Result ContextMtl::insertEventMarker(GLsizei length, const char *marker)
angle::Result ContextMtl::pushGroupMarker(GLsizei length, const char *marker) angle::Result ContextMtl::pushGroupMarker(GLsizei length, const char *marker)
{ {
mCmdBuffer.pushDebugGroup(ConvertMarkerToString(length, marker));
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result ContextMtl::popGroupMarker() angle::Result ContextMtl::popGroupMarker()
{ {
mCmdBuffer.popDebugGroup();
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -115,6 +115,8 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N ...@@ -115,6 +115,8 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N
void queueEventSignal(const mtl::SharedEventRef &event, uint64_t value); void queueEventSignal(const mtl::SharedEventRef &event, uint64_t value);
void serverWaitEvent(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; } CommandQueue &cmdQueue() { return mCmdQueue; }
...@@ -134,6 +136,9 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N ...@@ -134,6 +136,9 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N
void setEventImpl(const mtl::SharedEventRef &event, uint64_t value); void setEventImpl(const mtl::SharedEventRef &event, uint64_t value);
void waitEventImpl(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>>; using ParentClass = WrappedObject<id<MTLCommandBuffer>>;
CommandQueue &mCmdQueue; CommandQueue &mCmdQueue;
...@@ -146,6 +151,8 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N ...@@ -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::pair<mtl::SharedEventRef, uint64_t>> mPendingSignalEvents;
std::vector<std::string> mDebugGroups;
bool mCommitted = false; bool mCommitted = false;
}; };
...@@ -169,6 +176,9 @@ class CommandEncoder : public WrappedObject<id<MTLCommandEncoder>>, angle::NonCo ...@@ -169,6 +176,9 @@ class CommandEncoder : public WrappedObject<id<MTLCommandEncoder>>, angle::NonCo
CommandEncoder &markResourceBeingWrittenByGPU(const BufferRef &buffer); CommandEncoder &markResourceBeingWrittenByGPU(const BufferRef &buffer);
CommandEncoder &markResourceBeingWrittenByGPU(const TextureRef &texture); CommandEncoder &markResourceBeingWrittenByGPU(const TextureRef &texture);
virtual void pushDebugGroup(NSString *label);
virtual void popDebugGroup();
protected: protected:
using ParentClass = WrappedObject<id<MTLCommandEncoder>>; using ParentClass = WrappedObject<id<MTLCommandEncoder>>;
...@@ -453,6 +463,9 @@ class RenderCommandEncoder final : public CommandEncoder ...@@ -453,6 +463,9 @@ class RenderCommandEncoder final : public CommandEncoder
void setLabel(NSString *label); void setLabel(NSString *label);
void pushDebugGroup(NSString *label) override;
void popDebugGroup() override;
const RenderPassDesc &renderPassDesc() const { return mRenderPassDesc; } const RenderPassDesc &renderPassDesc() const { return mRenderPassDesc; }
bool hasDrawCalls() const { return mHasDrawCalls; } bool hasDrawCalls() const { return mHasDrawCalls; }
......
...@@ -63,7 +63,9 @@ namespace ...@@ -63,7 +63,9 @@ namespace
PROC(DrawIndexedInstanced) \ PROC(DrawIndexedInstanced) \
PROC(DrawIndexedInstancedBaseVertex) \ PROC(DrawIndexedInstancedBaseVertex) \
PROC(SetVisibilityResultMode) \ PROC(SetVisibilityResultMode) \
PROC(UseResource) PROC(UseResource) \
PROC(PushDebugGroup) \
PROC(PopDebugGroup)
#define ANGLE_MTL_TYPE_DECL(CMD) CMD, #define ANGLE_MTL_TYPE_DECL(CMD) CMD,
...@@ -345,12 +347,35 @@ void UseResourceCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStre ...@@ -345,12 +347,35 @@ void UseResourceCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStre
[resource ANGLE_MTL_RELEASE]; [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 // Command encoder mapping
#define ANGLE_MTL_CMD_MAP(CMD) CMD##Cmd, #define ANGLE_MTL_CMD_MAP(CMD) CMD##Cmd,
using CommandEncoderFunc = void (*)(id<MTLRenderCommandEncoder>, IntermediateCommandStream *); using CommandEncoderFunc = void (*)(id<MTLRenderCommandEncoder>, IntermediateCommandStream *);
constexpr CommandEncoderFunc gCommandEncoders[] = {ANGLE_MTL_CMD_X(ANGLE_MTL_CMD_MAP)}; 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 // CommandQueue implementation
...@@ -593,6 +618,11 @@ void CommandBuffer::restart() ...@@ -593,6 +618,11 @@ void CommandBuffer::restart()
mQueueSerial = serial; mQueueSerial = serial;
mCommitted = false; mCommitted = false;
for (std::string &marker : mDebugGroups)
{
pushDebugGroupImpl(marker);
}
ASSERT(metalCmdBuffer); ASSERT(metalCmdBuffer);
} }
...@@ -622,6 +652,33 @@ void CommandBuffer::serverWaitEvent(const mtl::SharedEventRef &event, uint64_t v ...@@ -622,6 +652,33 @@ void CommandBuffer::serverWaitEvent(const mtl::SharedEventRef &event, uint64_t v
waitEventImpl(event, value); 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 */ /** private use only */
void CommandBuffer::set(id<MTLCommandBuffer> metalBuffer) void CommandBuffer::set(id<MTLCommandBuffer> metalBuffer)
{ {
...@@ -733,6 +790,29 @@ void CommandBuffer::waitEventImpl(const mtl::SharedEventRef &event, uint64_t val ...@@ -733,6 +790,29 @@ void CommandBuffer::waitEventImpl(const mtl::SharedEventRef &event, uint64_t val
#endif // #if ANGLE_MTL_EVENT_AVAILABLE #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 implementation
CommandEncoder::CommandEncoder(CommandBuffer *cmdBuffer, Type type) CommandEncoder::CommandEncoder(CommandBuffer *cmdBuffer, Type type)
: mType(type), mCmdBuffer(*cmdBuffer) : mType(type), mCmdBuffer(*cmdBuffer)
...@@ -776,6 +856,18 @@ CommandEncoder &CommandEncoder::markResourceBeingWrittenByGPU(const TextureRef & ...@@ -776,6 +856,18 @@ CommandEncoder &CommandEncoder::markResourceBeingWrittenByGPU(const TextureRef &
return *this; return *this;
} }
void CommandEncoder::pushDebugGroup(NSString *label)
{
// Default implementation
[get() pushDebugGroup:label];
}
void CommandEncoder::popDebugGroup()
{
// Default implementation
[get() popDebugGroup];
}
// RenderCommandEncoderShaderStates implementation // RenderCommandEncoderShaderStates implementation
RenderCommandEncoderShaderStates::RenderCommandEncoderShaderStates() RenderCommandEncoderShaderStates::RenderCommandEncoderShaderStates()
{ {
...@@ -1541,6 +1633,16 @@ RenderCommandEncoder &RenderCommandEncoder::useResource(const BufferRef &resourc ...@@ -1541,6 +1633,16 @@ RenderCommandEncoder &RenderCommandEncoder::useResource(const BufferRef &resourc
return *this; 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, RenderCommandEncoder &RenderCommandEncoder::setColorStoreAction(MTLStoreAction action,
uint32_t colorAttachmentIndex) 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