1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // DebugAnnotator11.cpp: D3D11 helpers for adding trace annotations.
7 //
8
9 #include "libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h"
10
11 #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
12
13 #include <versionhelpers.h>
14
15 namespace rx
16 {
17
DebugAnnotator11()18 DebugAnnotator11::DebugAnnotator11() {}
19
~DebugAnnotator11()20 DebugAnnotator11::~DebugAnnotator11() {}
21
beginEvent(const char * eventName,const char * eventMessage)22 void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessage)
23 {
24 angle::LoggingAnnotator::beginEvent(eventName, eventMessage);
25 if (loggingEnabledForThisThread())
26 {
27 std::mbstate_t state = std::mbstate_t();
28 std::mbsrtowcs(mWCharMessage, &eventMessage, kMaxMessageLength, &state);
29 mUserDefinedAnnotation->BeginEvent(mWCharMessage);
30 }
31 }
32
endEvent(const char * eventName)33 void DebugAnnotator11::endEvent(const char *eventName)
34 {
35 angle::LoggingAnnotator::endEvent(eventName);
36 if (loggingEnabledForThisThread())
37 {
38 mUserDefinedAnnotation->EndEvent();
39 }
40 }
41
setMarker(const char * markerName)42 void DebugAnnotator11::setMarker(const char *markerName)
43 {
44 angle::LoggingAnnotator::setMarker(markerName);
45 if (loggingEnabledForThisThread())
46 {
47 std::mbstate_t state = std::mbstate_t();
48 std::mbsrtowcs(mWCharMessage, &markerName, kMaxMessageLength, &state);
49 mUserDefinedAnnotation->SetMarker(mWCharMessage);
50 }
51 }
52
getStatus()53 bool DebugAnnotator11::getStatus()
54 {
55 if (loggingEnabledForThisThread())
56 {
57 return !!(mUserDefinedAnnotation->GetStatus());
58 }
59
60 return false;
61 }
62
loggingEnabledForThisThread() const63 bool DebugAnnotator11::loggingEnabledForThisThread() const
64 {
65 return mUserDefinedAnnotation != nullptr && std::this_thread::get_id() == mAnnotationThread;
66 }
67
initialize(ID3D11DeviceContext * context)68 void DebugAnnotator11::initialize(ID3D11DeviceContext *context)
69 {
70 #if !defined(ANGLE_ENABLE_WINDOWS_UWP)
71 // ID3DUserDefinedAnnotation.GetStatus only works on Windows10 or greater.
72 // Returning true unconditionally from DebugAnnotator11::getStatus() means
73 // writing out all compiled shaders to temporary files even if debugging
74 // tools are not attached. See rx::ShaderD3D::prepareSourceAndReturnOptions.
75 // If you want debug annotations, you must use Windows 10.
76 if (IsWindows10OrGreater())
77 #endif
78 {
79 mAnnotationThread = std::this_thread::get_id();
80 mUserDefinedAnnotation.Attach(
81 d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context));
82 }
83 }
84
release()85 void DebugAnnotator11::release()
86 {
87 mUserDefinedAnnotation.Reset();
88 }
89
90 } // namespace rx
91