Commit e89c8f7c by Ian Elliott Committed by Commit Bot

Add run-time check in EVENT() to disable debug markers

To avoid a large performance impact from adding Vulkan debug-util markers for every GLES entrypoint, the EVENT() macro needs a run-time check that avoids constructing a ScopedPerfEventHelper object. Test: angle_perftests -v --local-output --gtest_filter="TracePerfTest.Run/*nba*" Bug: b/170249632 Change-Id: I422111cdf6f6f713800e7ac587e66582bd00359f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2491009 Commit-Queue: Ian Elliott <ianelliott@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent fbec291e
...@@ -120,19 +120,22 @@ std::mutex &GetDebugMutex() ...@@ -120,19 +120,22 @@ std::mutex &GetDebugMutex()
return *g_debugMutex; return *g_debugMutex;
} }
ScopedPerfEventHelper::ScopedPerfEventHelper(gl::Context *context, ScopedPerfEventHelper::ScopedPerfEventHelper(gl::Context *context, gl::EntryPoint entryPoint)
gl::EntryPoint entryPoint, : mContext(context), mEntryPoint(entryPoint), mFunctionName(nullptr)
const char *format, {}
...)
: mContext(context), mEntryPoint(entryPoint), mFunctionName(GetEntryPointName(entryPoint)) ScopedPerfEventHelper::~ScopedPerfEventHelper()
{ {
bool dbgTrace = DebugAnnotationsActive(); // EGL_Terminate() can set g_debugAnnotator to nullptr; must call DebugAnnotationsActive() here
#if !defined(ANGLE_ENABLE_DEBUG_TRACE) if (mFunctionName && DebugAnnotationsActive())
if (!dbgTrace)
{ {
return; g_debugAnnotator->endEvent(mContext, mFunctionName, mEntryPoint);
} }
#endif // !ANGLE_ENABLE_DEBUG_TRACE }
void ScopedPerfEventHelper::begin(const char *format, ...)
{
mFunctionName = GetEntryPointName(mEntryPoint);
va_list vararg; va_list vararg;
va_start(vararg, format); va_start(vararg, format);
...@@ -142,18 +145,8 @@ ScopedPerfEventHelper::ScopedPerfEventHelper(gl::Context *context, ...@@ -142,18 +145,8 @@ ScopedPerfEventHelper::ScopedPerfEventHelper(gl::Context *context,
va_end(vararg); va_end(vararg);
ANGLE_LOG(EVENT) << std::string(&buffer[0], len); ANGLE_LOG(EVENT) << std::string(&buffer[0], len);
if (dbgTrace) // Do not need to call DebugAnnotationsActive() here, because it was called in EVENT()
{ g_debugAnnotator->beginEvent(mContext, mEntryPoint, mFunctionName, buffer.data());
g_debugAnnotator->beginEvent(context, entryPoint, mFunctionName, buffer.data());
}
}
ScopedPerfEventHelper::~ScopedPerfEventHelper()
{
if (DebugAnnotationsActive())
{
g_debugAnnotator->endEvent(mContext, mFunctionName, mEntryPoint);
}
} }
LogMessage::LogMessage(const char *file, const char *function, int line, LogSeverity severity) LogMessage::LogMessage(const char *file, const char *function, int line, LogSeverity severity)
......
...@@ -35,9 +35,10 @@ enum class EntryPoint; ...@@ -35,9 +35,10 @@ enum class EntryPoint;
class ScopedPerfEventHelper : angle::NonCopyable class ScopedPerfEventHelper : angle::NonCopyable
{ {
public: public:
ANGLE_FORMAT_PRINTF(4, 5) ScopedPerfEventHelper(gl::Context *context, gl::EntryPoint entryPoint);
ScopedPerfEventHelper(gl::Context *context, gl::EntryPoint entryPoint, const char *format, ...);
~ScopedPerfEventHelper(); ~ScopedPerfEventHelper();
ANGLE_FORMAT_PRINTF(2, 3)
void begin(const char *format, ...);
private: private:
gl::Context *mContext; gl::Context *mContext;
...@@ -254,13 +255,26 @@ std::ostream &FmtHex(std::ostream &os, T value) ...@@ -254,13 +255,26 @@ std::ostream &FmtHex(std::ostream &os, T value)
// A macro to log a performance event around a scope. // A macro to log a performance event around a scope.
#if defined(ANGLE_TRACE_ENABLED) #if defined(ANGLE_TRACE_ENABLED)
# if defined(_MSC_VER) # if defined(_MSC_VER)
# define EVENT(context, entryPoint, function, message, ...) \ # define EVENT(context, entryPoint, function, message, ...) \
gl::ScopedPerfEventHelper scopedPerfEventHelper##__LINE__( \ gl::ScopedPerfEventHelper scopedPerfEventHelper##__LINE__(context, entryPoint); \
context, entryPoint, "%s(" message ")", function, __VA_ARGS__) do \
{ \
if (gl::DebugAnnotationsActive()) \
{ \
scopedPerfEventHelper##__LINE__.begin("%s(" message ")", function, \
__VA_ARGS__); \
} \
} while (0)
# else # else
# define EVENT(context, entryPoint, function, message, ...) \ # define EVENT(context, entryPoint, function, message, ...) \
gl::ScopedPerfEventHelper scopedPerfEventHelper( \ gl::ScopedPerfEventHelper scopedPerfEventHelper(context, entryPoint); \
context, entryPoint, "%s(" message ")", function, ##__VA_ARGS__) do \
{ \
if (gl::DebugAnnotationsActive()) \
{ \
scopedPerfEventHelper.begin("%s(" message ")", function, ##__VA_ARGS__); \
} \
} while (0)
# endif // _MSC_VER # endif // _MSC_VER
#else #else
# define EVENT(message, ...) (void(0)) # define EVENT(message, ...) (void(0))
......
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