GteDX11PerformanceCounter.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
9 #include <LowLevel/GteLogger.h>
11 using namespace gte;
12 
13 
15 {
19 }
20 
22  :
23  mFrequencyQuery(nullptr),
24  mStartTimeQuery(nullptr),
25  mFinalTimeQuery(nullptr),
26  mFrequency(0.0),
27  mInvFrequency(0.0),
28  mStartTime(0),
29  mFinalTime(0),
30  mTotalSeconds(0.0),
32 {
33  if (!device)
34  {
35  LogError("Input device is null.");
36  return;
37  }
38 
39  mTimeStamp.Frequency = 0;
40  mTimeStamp.Disjoint = FALSE;
41 
42  D3D11_QUERY_DESC desc;
43  desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
44  desc.MiscFlags = D3D11_QUERY_MISC_NONE;
45  HRESULT hr = device->CreateQuery(&desc, &mFrequencyQuery);
46  CHECK_HR_RETURN_VOID("Failed to create frequency query");
47 
48  mFrequency = static_cast<double>(mTimeStamp.Frequency);
50 
51  desc.Query = D3D11_QUERY_TIMESTAMP;
52  desc.MiscFlags = D3D11_QUERY_MISC_NONE;
53  hr = device->CreateQuery(&desc, &mStartTimeQuery);
54  if (FAILED(hr))
55  {
57  LogError("Failed to create start time query.");
58  return;
59  }
60 
61  hr = device->CreateQuery(&desc, &mFinalTimeQuery);
62  if (FAILED(hr))
63  {
66  LogError("Failed to create final time query.");
67  return;
68  }
69 }
70 
72 {
73  return (mFinalTime >= mStartTime ? mFinalTime - mStartTime : 0);
74 }
75 
77 {
78  if (FALSE == mTimeStamp.Disjoint)
79  {
80  double numer = static_cast<double>(GetTicks());
81  double denom = static_cast<double>(mTimeStamp.Frequency);
82  return numer/denom;
83  }
84  else
85  {
86  return 0.0;
87  }
88 }
89 
90 double DX11PerformanceCounter::GetSeconds(int64_t numTicks) const
91 {
92  return mInvFrequency*static_cast<double>(numTicks);
93 }
94 
96 {
97  return static_cast<int64_t>(seconds*mFrequency);
98 }
99 
101 {
102  mTotalSeconds = 0.0;
103  mNumMeasurements = 0;
104 }
105 
107 {
110 }
111 
113 {
114  if (mNumMeasurements > 0)
115  {
116  return mTotalSeconds/static_cast<double>(mNumMeasurements);
117  }
118  return 0.0;
119 }
120 
122 {
123  return mNumMeasurements;
124 }
125 
DX11PerformanceCounter(ID3D11Device *device)
ULONG FinalRelease(T *&object)
#define LogError(message)
Definition: GteLogger.h:92
GLfloat seconds
Definition: wglext.h:657
ULONG SafeRelease(T *&object)
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT mTimeStamp
#define CHECK_HR_RETURN_VOID(msg)
#define D3D11_QUERY_MISC_NONE


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59