forked from GPUOpen-Tools/gpu_performance_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdx11_utils.cc
134 lines (109 loc) · 4.43 KB
/
dx11_utils.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//==============================================================================
// Copyright (c) 2015-2020 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools Team
/// \file
/// \brief DX11 utility function implementation
//==============================================================================
#include "dx11_utils.h"
#include "dxx_ext_utils.h"
#include "gpa_common_defs.h"
bool DX11Utils::GetD3D11Device(IUnknown* pInterfacePointer, ID3D11Device** ppD3D11Device)
{
*ppD3D11Device = nullptr;
bool success = false;
// Check to see if it's an ID3D11Device
HRESULT hr = pInterfacePointer->QueryInterface(__uuidof(ID3D11Device), reinterpret_cast<void**>(ppD3D11Device));
if (hr == E_NOINTERFACE)
{
// It's not an ID3D11device, so see if it is an ID3D11DeviceChild-derived interface
ID3D11DeviceChild* pDeviceChild = nullptr;
hr = pInterfacePointer->QueryInterface(__uuidof(ID3D11DeviceChild), reinterpret_cast<void**>(&pDeviceChild));
if (SUCCEEDED(hr))
{
// Note: GetDevice increments a ref on out parameter
pDeviceChild->GetDevice(ppD3D11Device);
(*ppD3D11Device)->Release();
pDeviceChild->Release();
}
}
if (SUCCEEDED(hr))
{
success = true;
(*ppD3D11Device)->Release();
}
return success;
}
bool DX11Utils::IsFeatureLevelSupported(ID3D11Device* pD3D11Device)
{
bool isSupported = true;
// Get the current feature level in use by the application
D3D_FEATURE_LEVEL level = pD3D11Device->GetFeatureLevel();
// DX9 feature level is not supported
if (level == D3D_FEATURE_LEVEL_9_1 || level == D3D_FEATURE_LEVEL_9_2 || level == D3D_FEATURE_LEVEL_9_3)
{
GPA_LogError("GPUPerfAPI does not support D3D_FEATURE_LEVEL_9_1, _9_2, and _9_3.");
isSupported = false;
}
return isSupported;
}
bool DX11Utils::GetTimestampFrequency(ID3D11Device* pD3D11Device, UINT64& timestampFrequency)
{
bool success = false;
if (nullptr != pD3D11Device)
{
ID3D11Query* timeStampDisjointQuery = nullptr;
D3D11_QUERY_DESC timeStampDesc;
timeStampDesc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
timeStampDesc.MiscFlags = 0;
HRESULT hr = E_FAIL;
hr = pD3D11Device->CreateQuery(&timeStampDesc, &timeStampDisjointQuery);
#ifdef _DEBUG
D3D_SET_OBJECT_NAME_A(timeStampDisjointQuery, "GPA_TimestampFrequencyQuery");
#endif
if (SUCCEEDED(hr))
{
// get immediate context
ID3D11DeviceContext* pD3DContext = nullptr;
pD3D11Device->GetImmediateContext(&pD3DContext);
if (nullptr != pD3DContext)
{
//Submit the query
pD3DContext->Begin(timeStampDisjointQuery);
pD3DContext->End(timeStampDisjointQuery);
// need to loop on checking the values, it may not be immediately available.
HRESULT dataReady = S_OK;
do
{
dataReady = pD3DContext->GetData(timeStampDisjointQuery, nullptr, 0, 0);
if (FAILED(dataReady))
{
GPA_LogError("Call to ID3D11DeviceContext::GetData failed.");
return false;
}
} while (S_FALSE == dataReady); // S_OK == data ready; S_FALSE == data not ready
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timeStampDisjoint;
assert(timeStampDisjointQuery->GetDataSize() == sizeof(D3D11_QUERY_DATA_TIMESTAMP_DISJOINT));
hr = pD3DContext->GetData(timeStampDisjointQuery, &timeStampDisjoint, sizeof(D3D11_QUERY_DATA_TIMESTAMP_DISJOINT), 0);
timestampFrequency = timeStampDisjoint.Frequency;
assert(SUCCEEDED(hr));
success = true;
pD3DContext->Release();
timeStampDisjointQuery->Release();
timeStampDisjointQuery = nullptr;
}
else
{
GPA_LogError("GetTimestampFrequency Immediate Context is NULL.");
}
}
else
{
GPA_LogError("GetTimestampFrequency Call to ID3D11Device::CreateQuery failed.");
}
}
else
{
GPA_LogError("GetTimestampFrequency DX11 Device is NULL.");
}
return success;
}