Commit 0aa11026 by Geoff Lang Committed by Commit Bot

Only log D3D11 annotations from the thread used to initialize the annotator.

Chrome makes some ANGLE calls from multiple threads for initializing WebXR buffers which breaks the assumption that DebugAnnotator11 is only called from a single thread. Work around this by only allowing DebugAnnotator11 to log annotations from the thread used to initialize it. BUG=995888 BUG=972914 Change-Id: I2241e078031633cafea470f85b7b1ecf1fba8466 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1769057Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent d7d42540
......@@ -22,11 +22,10 @@ DebugAnnotator11::~DebugAnnotator11() {}
void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessage)
{
angle::LoggingAnnotator::beginEvent(eventName, eventMessage);
if (mUserDefinedAnnotation != nullptr)
if (loggingEnabledForThisThread())
{
std::mbstate_t state = std::mbstate_t();
std::mbsrtowcs(mWCharMessage, &eventMessage, kMaxMessageLength, &state);
std::lock_guard<std::mutex> lock(mAnnotationMutex);
mUserDefinedAnnotation->BeginEvent(mWCharMessage);
}
}
......@@ -34,9 +33,8 @@ void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessag
void DebugAnnotator11::endEvent(const char *eventName)
{
angle::LoggingAnnotator::endEvent(eventName);
if (mUserDefinedAnnotation != nullptr)
if (loggingEnabledForThisThread())
{
std::lock_guard<std::mutex> lock(mAnnotationMutex);
mUserDefinedAnnotation->EndEvent();
}
}
......@@ -44,26 +42,29 @@ void DebugAnnotator11::endEvent(const char *eventName)
void DebugAnnotator11::setMarker(const char *markerName)
{
angle::LoggingAnnotator::setMarker(markerName);
if (mUserDefinedAnnotation != nullptr)
if (loggingEnabledForThisThread())
{
std::mbstate_t state = std::mbstate_t();
std::mbsrtowcs(mWCharMessage, &markerName, kMaxMessageLength, &state);
std::lock_guard<std::mutex> lock(mAnnotationMutex);
mUserDefinedAnnotation->SetMarker(mWCharMessage);
}
}
bool DebugAnnotator11::getStatus()
{
if (mUserDefinedAnnotation != nullptr)
if (loggingEnabledForThisThread())
{
std::lock_guard<std::mutex> lock(mAnnotationMutex);
return !!(mUserDefinedAnnotation->GetStatus());
}
return false;
}
bool DebugAnnotator11::loggingEnabledForThisThread() const
{
return mUserDefinedAnnotation != nullptr && std::this_thread::get_id() == mAnnotationThread;
}
void DebugAnnotator11::initialize(ID3D11DeviceContext *context)
{
// ID3DUserDefinedAnnotation.GetStatus only works on Windows10 or greater.
......@@ -73,6 +74,7 @@ void DebugAnnotator11::initialize(ID3D11DeviceContext *context)
// If you want debug annotations, you must use Windows 10.
if (IsWindows10OrGreater())
{
mAnnotationThread = std::this_thread::get_id();
mUserDefinedAnnotation.Attach(
d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context));
}
......
......@@ -11,7 +11,7 @@
#include "libANGLE/LoggingAnnotator.h"
#include <mutex>
#include <thread>
namespace rx
{
......@@ -29,10 +29,14 @@ class DebugAnnotator11 : public angle::LoggingAnnotator
bool getStatus() override;
private:
bool loggingEnabledForThisThread() const;
angle::ComPtr<ID3DUserDefinedAnnotation> mUserDefinedAnnotation;
static constexpr size_t kMaxMessageLength = 256;
wchar_t mWCharMessage[kMaxMessageLength];
std::mutex mAnnotationMutex;
// Only log annotations from the thread used to initialize the debug annotator
std::thread::id mAnnotationThread;
};
} // namespace rx
......
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