forked from GPUOpen-Tools/gpu_performance_api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGLGPAImplementor.cpp
325 lines (261 loc) · 10.2 KB
/
GLGPAImplementor.cpp
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//==============================================================================
// Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools Team
/// \file
/// \brief GL GPA Implementation
//==============================================================================
#include <assert.h>
#include <DeviceInfoUtils.h>
#include "GLInclude.h"
#include "ASICInfo.h"
#include "GLGPAImplementor.h"
#include "GLGPAContext.h"
IGPAImplementor* s_pGpaImp = GLGPAImplementor::Instance();
GPA_API_Type GLGPAImplementor::GetAPIType() const
{
return GPA_API_OPENGL;
}
bool GLGPAImplementor::GetHwInfoFromAPI(const GPAContextInfoPtr pContextInfo,
GPA_HWInfo& hwInfo) const
{
UNREFERENCED_PARAMETER(pContextInfo);
// get the entry points
m_isGlEntryPointsInitialized = oglUtils::InitializeGLFunctions();
if (!m_isGlEntryPointsInitialized)
{
GPA_LogError("Unable to initialize essential GL functions.");
return m_isGlEntryPointsInitialized;
}
const GLubyte* pRenderer = oglUtils::_oglGetString(GL_RENDERER);
if (nullptr != pRenderer)
{
hwInfo.SetDeviceName(reinterpret_cast<const char*>(pRenderer));
}
// Handle non-AMD GPU vendors
const GLubyte* pVendor = oglUtils::_oglGetString(GL_VENDOR);
bool isAmdVendor = false;
if (nullptr != strstr(reinterpret_cast<const char*>(pVendor), oglUtils::s_pATIRenderer) ||
nullptr != strstr(reinterpret_cast<const char*>(pVendor), oglUtils::s_pAMDRenderer))
{
isAmdVendor = true;
}
else if (nullptr != strstr(reinterpret_cast<const char*>(pVendor), oglUtils::s_pNVIDIARenderer))
{
//TODO: investigate supporting GPUTime for these vendors
return false;
}
else if (nullptr != strstr(reinterpret_cast<const char*>(pVendor), oglUtils::s_pIntelRenderer))
{
//TODO: investigate supporting GPUTime for these vendors
return false;
}
// in addition to checking the vendor string to make sure it is ATI / AMD,
// also check the Renderer string - sometimes the GL driver needs to override
// the vendor string to make apps behave differently, so using the renderer
// offers a fallback ssolution.
if (isAmdVendor ||
nullptr != strstr(reinterpret_cast<const char*>(pRenderer), oglUtils::s_pATIRenderer) ||
nullptr != strstr(reinterpret_cast<const char*>(pRenderer), oglUtils::s_pAMDRenderer) ||
nullptr != strstr(reinterpret_cast<const char*>(pRenderer), oglUtils::s_pRadeonRenderer))
{
hwInfo.SetVendorID(AMD_VENDOR_ID);
bool isDeviceIdKnown = false;
if (nullptr != oglUtils::_oglXQueryCurrentRendererIntegerMESA)
{
// first try to get the device id from the glXQueryCurrentRendererIntegerMESA extension
unsigned int driverDeviceId;
oglUtils::_oglXQueryCurrentRendererIntegerMESA(GLX_RENDERER_DEVICE_ID_MESA, &driverDeviceId);
// check to make sure the device id returned is found in the device info table
GDT_HW_GENERATION hwGeneration;
isDeviceIdKnown = AMDTDeviceInfoUtils::Instance()->GetHardwareGeneration(driverDeviceId, hwGeneration);
if (isDeviceIdKnown)
{
hwInfo.SetDeviceID(driverDeviceId);
if (!hwInfo.UpdateRevisionIdBasedOnDeviceIDAndName())
{
// We didn't find a revision Id, set it to REVISION_ID_ANY
hwInfo.SetRevisionID(REVISION_ID_ANY);
}
}
}
// if we were unable to use the glXQueryCurrentRendererIntegerMESA extension,
// then fall back to the GPIN counters exposed by the driver
if (!isDeviceIdKnown)
{
ASICInfo asicInfo;
if (!GetASICInfo(asicInfo))
{
GPA_LogError("Unable to obtain asic information.");
return false;
}
GDT_HW_ASIC_TYPE asicType = GDT_ASIC_TYPE_NONE;
// switch between values in ASICInfo.h and GPAHWInfo.cpp
switch (asicInfo.eAsicRev)
{
case ATIASIC_ID_TAHITI_P:
hwInfo.SetDeviceID(0x679A);
asicType = GDT_TAHITI_PRO;
break;
case ATIASIC_ID_PITCAIRN_PM:
hwInfo.SetDeviceID(0x6819);
asicType = GDT_PITCAIRN_PRO;
break;
case ATIASIC_ID_CAPEVERDE_M:
hwInfo.SetDeviceID(0x6822);
asicType = GDT_CAPEVERDE_PRO;
break;
case ATIASIC_ID_OLAND_M:
hwInfo.SetDeviceID(0x6610);
asicType = GDT_OLAND;
break;
case ATIASIC_ID_HAINAN_M:
hwInfo.SetDeviceID(0x6660);
asicType = GDT_HAINAN;
break;
case ATIASIC_ID_BONAIRE_M:
hwInfo.SetDeviceID(0x665C);
asicType = GDT_BONAIRE;
break;
case ATIASIC_ID_SPECTRE:
hwInfo.SetDeviceID(0x130C);
asicType = GDT_SPECTRE;
break;
case ATIASIC_ID_SPOOKY:
hwInfo.SetDeviceID(0x130B);
asicType = GDT_SPOOKY;
break;
case ATIASIC_ID_KALINDI:
hwInfo.SetDeviceID(0x9830);
asicType = GDT_KALINDI;
break;
case ATIASIC_ID_HAWAII_P:
hwInfo.SetDeviceID(0x67B0);
asicType = GDT_HAWAII;
break;
case ATIASIC_ID_ICELAND_M:
hwInfo.SetDeviceID(0x6900);
asicType = GDT_ICELAND;
break;
case ATIASIC_ID_TONGA_P:
hwInfo.SetDeviceID(0x6920);
asicType = GDT_TONGA;
break;
case ATIASIC_ID_GODAVARI:
hwInfo.SetDeviceID(0x9855);
asicType = GDT_KALINDI;
break;
case ATIASIC_ID_CARRIZO:
hwInfo.SetDeviceID(0x9874);
asicType = GDT_CARRIZO;
break;
case ATIASIC_ID_STONEY:
hwInfo.SetDeviceID(0x98E4);
asicType = GDT_STONEY;
break;
case ATIASIC_ID_FIJI_P:
hwInfo.SetDeviceID(0x7300);
asicType = GDT_FIJI;
break;
case ATIASIC_ID_ELLESMERE:
hwInfo.SetDeviceID(0x67DF);
asicType = GDT_ELLESMERE;
break;
case ATIASIC_ID_BAFFIN:
hwInfo.SetDeviceID(0x67FF);
asicType = GDT_BAFFIN;
break;
case ATIASIC_ID_VEGAM:
hwInfo.SetDeviceID(0x694C);
asicType = GDT_VEGAM1;
break;
case ATIASIC_ID_LEXA:
hwInfo.SetDeviceID(0x699F);
asicType = GDT_GFX8_0_4;
break;
case ATIASIC_ID_VEGA:
hwInfo.SetDeviceID(0x687F);
asicType = GDT_GFX9_0_0;
break;
case ATIASIC_ID_VEGA_APU:
hwInfo.SetDeviceID(0x15DD);
asicType = GDT_GFX9_0_2;
break;
default:
GPA_LogError("Unsupported asic ID.");
return false;
}
if (!hwInfo.UpdateDeviceInfoBasedOnASICTypeAndName(asicType))
{
// We didn't find a revision Id, set it to REVISION_ID_ANY
hwInfo.SetRevisionID(REVISION_ID_ANY);
}
}
// GPUTime information is returned in nanoseconds, so set the frequency to convert it into seconds
hwInfo.SetTimeStampFrequency(1000000000);
return true;
}
GPA_LogError("A non-AMD graphics card was identified.");
return false;
}
// TODO: this implementation doesn't do much -- is it needed?
bool GLGPAImplementor::VerifyAPIHwSupport(const GPAContextInfoPtr pContextInfo,
const GPA_HWInfo& hwInfo) const
{
UNREFERENCED_PARAMETER(pContextInfo);
bool isSupported = false;
GDT_HW_GENERATION generation = GDT_HW_GENERATION_NONE;
if (!hwInfo.GetHWGeneration(generation))
{
GPA_LogError("Unable to get hardware generation.");
}
else
{
isSupported = true;
}
return isSupported;
}
GLGPAImplementor::GLGPAImplementor():
m_isGlEntryPointsInitialized(false)
{
}
IGPAContext* GLGPAImplementor::OpenAPIContext(GPAContextInfoPtr pContextInfo,
GPA_HWInfo& hwInfo,
GPA_OpenContextFlags flags)
{
UNREFERENCED_PARAMETER(pContextInfo);
GLGPAContext* pRetGpaContext = nullptr;
GLContextPtr glContext = static_cast<GLContextPtr>(pContextInfo);
GLGPAContext* pGLGpaContext = new(std::nothrow) GLGPAContext(glContext, hwInfo, flags);
if (nullptr == pGLGpaContext)
{
GPA_LogError("Unable to allocate memory for the context.");
}
else
{
if (pGLGpaContext->Initialize())
{
pRetGpaContext = pGLGpaContext;
}
else
{
delete pGLGpaContext;
GPA_LogError("Unable to open a context.");
}
}
return pRetGpaContext;
}
bool GLGPAImplementor::CloseAPIContext(GPADeviceIdentifier pDeviceIdentifier, IGPAContext* pContext)
{
assert(nullptr != pDeviceIdentifier);
assert(nullptr != pContext);
UNREFERENCED_PARAMETER(pDeviceIdentifier);
if (nullptr != pContext)
{
delete reinterpret_cast<GLGPAContext*>(pContext);
}
return (nullptr != pContext) && (nullptr != pDeviceIdentifier);
}
GPADeviceIdentifier GLGPAImplementor::GetDeviceIdentifierFromContextInfo(GPAContextInfoPtr pContextInfo) const
{
return pContextInfo;
}