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(gl::Context * context,angle::EntryPoint entryPoint,const char * eventName,const char * eventMessage)22 void DebugAnnotator11::beginEvent(gl::Context *context,
23 angle::EntryPoint entryPoint,
24 const char *eventName,
25 const char *eventMessage)
26 {
27 angle::LoggingAnnotator::beginEvent(context, entryPoint, eventName, eventMessage);
28 if (loggingEnabledForThisThread())
29 {
30 std::mbstate_t state = std::mbstate_t();
31 std::mbsrtowcs(mWCharMessage, &eventMessage, kMaxMessageLength, &state);
32 mUserDefinedAnnotation->BeginEvent(mWCharMessage);
33 }
34 }
35
endEvent(gl::Context * context,const char * eventName,angle::EntryPoint entryPoint)36 void DebugAnnotator11::endEvent(gl::Context *context,
37 const char *eventName,
38 angle::EntryPoint entryPoint)
39 {
40 angle::LoggingAnnotator::endEvent(context, eventName, entryPoint);
41 if (loggingEnabledForThisThread())
42 {
43 mUserDefinedAnnotation->EndEvent();
44 }
45 }
46
setMarker(const char * markerName)47 void DebugAnnotator11::setMarker(const char *markerName)
48 {
49 angle::LoggingAnnotator::setMarker(markerName);
50 if (loggingEnabledForThisThread())
51 {
52 std::mbstate_t state = std::mbstate_t();
53 std::mbsrtowcs(mWCharMessage, &markerName, kMaxMessageLength, &state);
54 mUserDefinedAnnotation->SetMarker(mWCharMessage);
55 }
56 }
57
getStatus()58 bool DebugAnnotator11::getStatus()
59 {
60 if (loggingEnabledForThisThread())
61 {
62 return !!(mUserDefinedAnnotation->GetStatus());
63 }
64
65 return false;
66 }
67
loggingEnabledForThisThread() const68 bool DebugAnnotator11::loggingEnabledForThisThread() const
69 {
70 return mUserDefinedAnnotation != nullptr && std::this_thread::get_id() == mAnnotationThread;
71 }
72
initialize(ID3D11DeviceContext * context)73 void DebugAnnotator11::initialize(ID3D11DeviceContext *context)
74 {
75 #if !defined(ANGLE_ENABLE_WINDOWS_UWP)
76 // ID3DUserDefinedAnnotation.GetStatus only works on Windows10 or greater.
77 // Returning true unconditionally from DebugAnnotator11::getStatus() means
78 // writing out all compiled shaders to temporary files even if debugging
79 // tools are not attached. See rx::ShaderD3D::prepareSourceAndReturnOptions.
80 // If you want debug annotations, you must use Windows 10.
81 if (IsWindows10OrGreater())
82 #endif
83 {
84 mAnnotationThread = std::this_thread::get_id();
85 mUserDefinedAnnotation.Attach(
86 d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context));
87 }
88 }
89
release()90 void DebugAnnotator11::release()
91 {
92 mUserDefinedAnnotation.Reset();
93 }
94
95 } // namespace rx
96