-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathGPUPerfAPIGL.cpp
More file actions
1158 lines (925 loc) · 39.4 KB
/
GPUPerfAPIGL.cpp
File metadata and controls
1158 lines (925 loc) · 39.4 KB
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//==============================================================================
// Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools Team
/// \file
/// \brief GL version of GPUPerfAPI
//==============================================================================
#include <string>
#include <vector>
#include <assert.h>
#include <sstream>
#ifdef _LINUX
#include <dlfcn.h>
#endif
#include "GPUPerfAPIImp.h"
#include "GPACustomHWValidationManager.h"
#include "GLCounterDataRequestManager.h"
#include "GPACounterGenerator.h"
#include "GPUPerfAPIGL.h"
#include "ASICInfo.h"
#include "ADLUtil.h"
#include "DeviceInfoUtils.h"
using std::string;
static const char* pAMDRenderer = "AMD"; ///< AMD Renderer string
static const char* pATIRenderer = "ATI"; ///< ATI Renderer string (legacy)
static const char* pNVIDIARenderer = "NVIDIA"; ///< NVIDIA Renderer string
static const char* pIntelRenderer = "Intel"; ///< Intel Renderer string
#ifdef DEBUG_GL_ERRORS
/// declared as extern in GPUPerfAPI.h
/// Helps the CheckForGLErrors macro get and use the error without having to
/// redefine it every time within the macro, also simplifies CheckForGLErrorsCond below.
GLenum g_glError = GL_NO_ERROR;
/// checks for OpenGL errors and logs the specified message if there is an error
/// \param pcsErrMsg the error message to put in the log
/// \return true if there is an error; false if there is no error
bool CheckForGLErrorsCond(const char* pcsErrMsg)
{
// Use the macro version for the asserts and error reporting.
// It will set g_glError which can then be used as the conditional.
CheckForGLErrors(pcsErrMsg);
return g_glError != GL_NO_ERROR;
}
//=============================================================================
/// DebugCallback
///
/// The call back function when there is debug message generated;
//=============================================================================
GLvoid __stdcall DebugCallback(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
GLvoid* userParam)
{
UNREFERENCED_PARAMETER(id);
UNREFERENCED_PARAMETER(length);
std::string string = "";
string += "'";
switch (source)
{
case GL_DEBUG_SOURCE_API_ARB:
string += "OpenGL API";
break;
case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB:
string += "Window System";
break;
case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB:
string += "Shader Compiler";
break;
case GL_DEBUG_SOURCE_THIRD_PARTY_ARB :
string += "Third Party";
break;
case GL_DEBUG_SOURCE_APPLICATION_ARB:
string += "Application";
break;
case GL_DEBUG_SOURCE_OTHER_ARB :
string += "Other";
break;
default:
string += "Unknown";
break;
}
string += "' output a(n)";
switch (type)
{
case GL_DEBUG_TYPE_ERROR_ARB:
string += " Error ";
break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB :
string += " Deprecated Behavior ";
break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB :
string += " Undefined Behavior ";
break;
case GL_DEBUG_TYPE_PORTABILITY_ARB :
string += " Portability ";
break;
case GL_DEBUG_TYPE_PERFORMANCE_ARB:
string += " Performance ";
break;
case GL_DEBUG_TYPE_OTHER_ARB :
string += " Other ";
break;
default:
string += " unknown ";
break;
}
string += "message with ";
switch (severity)
{
case GL_DEBUG_SEVERITY_HIGH_ARB:
string += "Severity - High ";
break;
case GL_DEBUG_SEVERITY_MEDIUM_ARB:
string += "Severity - Medium ";
break;
case GL_DEBUG_SEVERITY_LOW_ARB:
string += "Severity - Low ";
break;
default:
string += "Severity - unknown ";
break;
}
if (nullptr != message)
{
string += "and message '";
string += message;
string += "'";
}
string += ": ";
if (nullptr != userParam)
{
string += (GLchar*)userParam;
}
string += ".";
GPA_LogMessage(string.c_str());
}
////=============================================================================
///// Set up the callback function and control operation
///// This is currently commented out because the glDebugMessageControlARB function is always
///// nullptr, but the other entrypoint is available. Also, calling this function with a non-debug
///// runtime will cause a GL_INVALID_OPERATION to be generated. This needs some smarter handling
/////
///// The call back function when there is debug message generated;
////=============================================================================
//void SetupDebugCallback()
//{
// if (nullptr != _oglDebugMessageCallbackARB &&
// nullptr != _oglDebugMessageControlARB)
// {
// _oglDebugMessageCallbackARB(&DebugCallback, nullptr);
// _oglDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
// }
//}
#endif // DEBUG_GL_ERRORS
GPA_ContextStateGL* getCurrentContext()
{
return static_cast<GPA_ContextStateGL* >(g_pCurrentContext);
}
// Don't want to check results throughout the frame.
gpa_uint32 GPA_IMP_GetPreferredCheckResultFrequency()
{
return 50;
}
#ifndef GLES
#ifdef _WIN32
decltype(wglGetProcAddress)* _wglGetProcAddress = nullptr;
#endif
#ifdef _LINUX
decltype(glXGetProcAddressARB)* _GPAglXGetProcAddressARB = nullptr;
#endif
#else
decltype(eglGetProcAddress)* _GPAeglGetProcAddress = nullptr;
#endif
/// Checks the OpenGL extensions and initializes the various function pointers. The extensions queried are:
/// -- GL_AMD_performance_monitor
/// -- GL_ARB_timer_query (OpenGL)
/// -- GL_EXT_disjoint_timer_query (OpenGLES)
/// -- GL_AMD_debug_output
/// -- GLX_MESA_query_renderer
/// \return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED if the GL_AMD_performance_monitor or GL_ARB_timer_query extension entry points are not found
/// GPA_STATUS_OK otherwise
GPA_Status InitializeGLFunctions()
{
GPA_Status retVal = GPA_STATUS_OK;
bool bPerfMonExtFound = false;
bool bTimerQueryExtFound = false;
bool bDebugOutputExtFound = false;
bool bMesaQueryRendererExtFound = false;
#ifdef _WIN32
HMODULE module = LoadLibraryA("opengl32.dll");
#else
void* egl_module = dlopen("libEGL.so", RTLD_LAZY);
void* gl_module = dlopen("libGL.so", RTLD_LAZY);
#endif
if ((nullptr == egl_module) || (nullptr == gl_module))
{
return GPA_STATUS_ERROR_NULL_POINTER;
}
#ifndef GLES
#ifdef _WIN32
_wglGetCurrentContext = reinterpret_cast<decltype(wglGetCurrentContext)*>(GetProcAddress(module, "wglGetCurrentContext"));
_wglGetProcAddress = reinterpret_cast<decltype(wglGetProcAddress)*>(GetProcAddress(module, "wglGetProcAddress"));
if (nullptr == _wglGetProcAddress || nullptr == _wglGetCurrentContext)
{
return GPA_STATUS_ERROR_NULL_POINTER;
}
#endif
#ifdef _LINUX
_GPAglXGetProcAddressARB = reinterpret_cast<decltype(glXGetProcAddressARB)*>(dlsym(egl_module, "glXGetProcAddressARB"));
if (nullptr == _GPAglXGetProcAddressARB)
{
return GPA_STATUS_ERROR_NULL_POINTER;
}
#endif
#else // GLES
#ifdef _WIN32
_GPAeglGetProcAddress = reinterpret_cast<decltype(eglGetProcAddress)*>(GetProcAddress(module, "eglGetProcAddress"));
if (nullptr == _GPAeglGetProcAddress)
{
return GPA_STATUS_ERROR_NULL_POINTER;
}
#endif
#ifdef _LINUX
_GPAeglGetProcAddress = reinterpret_cast<decltype(eglGetProcAddress)*>(dlsym(egl_module, "eglGetProcAddress"));
if (nullptr == _GPAeglGetProcAddress)
{
return GPA_STATUS_ERROR_NULL_POINTER;
}
#endif
#endif // GLES
#ifdef _WIN32
_oglFlush = reinterpret_cast<decltype(glFlush)*>(GetProcAddress(module, "glFlush"));
_oglGetString = reinterpret_cast<decltype(glGetString)*>(GetProcAddress(module, "glGetString"));
_oglGetIntegerv = reinterpret_cast<decltype(glGetIntegerv)*>(GetProcAddress(module, "glGetIntegerv"));
#endif
#ifdef _LINUX
_oglFlush = reinterpret_cast<decltype(glFlush)*>(dlsym(gl_module, "glFlush"));
_oglGetString = reinterpret_cast<decltype(glGetString)*>(dlsym(gl_module, "glGetString"));
_oglGetIntegerv = reinterpret_cast<decltype(glGetIntegerv)*>(dlsym(gl_module, "glGetIntegerv"));
#endif
if (nullptr == _oglFlush || nullptr == _oglGetString || nullptr == _oglGetIntegerv)
{
return GPA_STATUS_ERROR_NULL_POINTER;
}
GET_PROC_ADDRESS(_oglGetStringi, PFNGLGETSTRINGIPROC, "glGetStringi");
// if OpenGL 3.x method of getting the extensions is available, use that, otherwise try the old method
if (nullptr != _oglGetStringi)
{
GPA_LogMessage("Using OpenGL 3.x method to query extensions.");
GLint numExtensions = 0;
_oglGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
for (GLint i = 0; i < numExtensions; i++)
{
const GLubyte* pExtension = _oglGetStringi(GL_EXTENSIONS, i);
if (nullptr != pExtension)
{
if (_strcmpi(reinterpret_cast<const char*>(pExtension), "GL_AMD_performance_monitor") == 0)
{
bPerfMonExtFound = true;
}
#ifndef GLES
if (_strcmpi(reinterpret_cast<const char*>(pExtension), "GL_ARB_timer_query") == 0)
{
bTimerQueryExtFound = true;
}
#else
if (_strcmpi(reinterpret_cast<const char*>(pExtension), "GL_EXT_disjoint_timer_query") == 0)
{
bTimerQueryExtFound = true;
}
#endif // GLES
if (_strcmpi(reinterpret_cast<const char*>(pExtension), "GL_AMD_debug_output") == 0)
{
bDebugOutputExtFound = true;
}
if (_strcmpi(reinterpret_cast<const char*>(pExtension), "GLX_MESA_query_renderer") == 0)
{
bMesaQueryRendererExtFound = true;
}
if (bPerfMonExtFound == true && bTimerQueryExtFound == true && bDebugOutputExtFound == true && bMesaQueryRendererExtFound == true)
{
break;
}
}
}
}
else
{
GPA_LogMessage("Using OpenGL 1.x method to query extensions.");
const GLubyte* pExtensions = _oglGetString(GL_EXTENSIONS);
if (nullptr != pExtensions)
{
if (nullptr != strstr(reinterpret_cast<const char*>(pExtensions), "GL_AMD_performance_monitor"))
{
bPerfMonExtFound = true;
}
#ifndef GLES
if (nullptr != strstr(reinterpret_cast<const char*>(pExtensions), "GL_ARB_timer_query"))
{
bTimerQueryExtFound = true;
}
#else
if (strstr(reinterpret_cast<const char*>(pExtensions), "GL_EXT_disjoint_timer_query") == 0)
{
bTimerQueryExtFound = true;
}
#endif // GLES
if (nullptr != strstr(reinterpret_cast<const char*>(pExtensions), "GL_AMD_debug_output"))
{
bDebugOutputExtFound = true;
}
if (nullptr != strstr(reinterpret_cast<const char*>(pExtensions), "GLX_MESA_query_renderer"))
{
bMesaQueryRendererExtFound = true;
}
}
}
// GLX_MESA_query_renderer extension
GET_PROC_ADDRESS(_oglXQueryCurrentRendererIntegerMESA, PFN_GLX_QUERYCURRENTRENDERERINTEGERMESA, "glXQueryCurrentRendererIntegerMESA");
if (nullptr == _oglXQueryCurrentRendererIntegerMESA)
{
if (bMesaQueryRendererExtFound)
{
GPA_LogMessage("The GLX_MESA_query_renderer extension is exposed by the driver, but not all entry points are available.");
}
else
{
GPA_LogMessage("The GLX_MESA_query_renderer extension is not exposed by the driver.");
}
}
#ifdef DEBUG_GL_ERRORS
// GL_AMD_debug_output extension
GET_PROC_ADDRESS(_oglDebugMessageControlARB, PFN_OGL_GLDEBUGMESSAGECONTROLARB, "glDebugMessageControlAMD");
GET_PROC_ADDRESS(_oglDebugMessageInsertARB, PFN_OGL_GLDEBUGMESSAGEINSERTARB, "glDebugMessageInsertAMD");
GET_PROC_ADDRESS(_oglDebugMessageCallbackARB, PFN_OGL_GLDEBUGMESSAGECALLBACKARB, "glDebugMessageCallbackAMD");
GET_PROC_ADDRESS(_oglGetDebugMessageLogARB, PFN_OGL_GLGETDEBUGMESSAGELOGARB, "glGetDebugMessageLogAMD");
if (
_oglDebugMessageControlARB == nullptr ||
_oglDebugMessageInsertARB == nullptr ||
_oglDebugMessageCallbackARB == nullptr ||
_oglGetDebugMessageLogARB == nullptr)
{
if (bDebugOutputExtFound)
{
GPA_LogMessage("The GL_AMD_debug_output extension is exposed by the driver, but not all entry points are available.");
}
else
{
// this interface is not required, but does help improve error logging, so allow the code
// to continue if this is not available.
GPA_LogMessage("The GL_AMD_debug_output extension is not exposed by the driver.");
}
}
#endif
// GL_AMD_performance_monitor extension
GET_PROC_ADDRESS(_oglGetPerfMonitorGroupsAMD, PFNGLGETPERFMONITORGROUPSAMDPROC, "glGetPerfMonitorGroupsAMD");
GET_PROC_ADDRESS(_oglGetPerfMonitorCountersAMD, PFNGLGETPERFMONITORCOUNTERSAMDPROC, "glGetPerfMonitorCountersAMD");
GET_PROC_ADDRESS(_oglGetPerfMonitorGroupStringAMD, PFNGLGETPERFMONITORGROUPSTRINGAMDPROC, "glGetPerfMonitorGroupStringAMD");
GET_PROC_ADDRESS(_oglGetPerfMonitorCounterStringAMD, PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC, "glGetPerfMonitorCounterStringAMD");
GET_PROC_ADDRESS(_oglGetPerfMonitorCounterInfoAMD, PFNGLGETPERFMONITORCOUNTERINFOAMDPROC, "glGetPerfMonitorCounterInfoAMD");
GET_PROC_ADDRESS(_oglGenPerfMonitorsAMD, PFNGLGENPERFMONITORSAMDPROC, "glGenPerfMonitorsAMD");
GET_PROC_ADDRESS(_oglDeletePerfMonitorsAMD, PFNGLDELETEPERFMONITORSAMDPROC, "glDeletePerfMonitorsAMD");
GET_PROC_ADDRESS(_oglSelectPerfMonitorCountersAMD, PFNGLSELECTPERFMONITORCOUNTERSAMDPROC, "glSelectPerfMonitorCountersAMD");
GET_PROC_ADDRESS(_oglBeginPerfMonitorAMD, PFNGLBEGINPERFMONITORAMDPROC, "glBeginPerfMonitorAMD");
GET_PROC_ADDRESS(_oglEndPerfMonitorAMD, PFNGLENDPERFMONITORAMDPROC, "glEndPerfMonitorAMD");
GET_PROC_ADDRESS(_oglGetPerfMonitorCounterDataAMD, PFNGLGETPERFMONITORCOUNTERDATAAMDPROC, "glGetPerfMonitorCounterDataAMD");
if (_oglGetPerfMonitorCountersAMD == nullptr ||
_oglGetPerfMonitorGroupStringAMD == nullptr ||
_oglGetPerfMonitorCounterInfoAMD == nullptr ||
_oglGetPerfMonitorCounterStringAMD == nullptr ||
_oglGenPerfMonitorsAMD == nullptr ||
_oglDeletePerfMonitorsAMD == nullptr ||
_oglSelectPerfMonitorCountersAMD == nullptr ||
_oglBeginPerfMonitorAMD == nullptr ||
_oglEndPerfMonitorAMD == nullptr ||
_oglGetPerfMonitorCounterDataAMD == nullptr)
{
if (bPerfMonExtFound)
{
GPA_LogError("The GL_AMD_performance_monitor extension is exposed by the driver, but not all entry points are available.");
}
else
{
GPA_LogError("The GL_AMD_performance_monitor extension is not exposed by the driver.");
}
if (nullptr != g_pCurrentContext && g_pCurrentContext->m_hwInfo.IsAMD())
{
retVal = GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED; // return error if AMD extension is missing on AMD hardware
}
}
#ifndef GLES
GET_PROC_ADDRESS(_oglBeginQuery, PFNGLBEGINQUERYPROC, "glBeginQuery"); //not used anymore
GET_PROC_ADDRESS(_oglEndQuery, PFNGLENDQUERYPROC, "glEndQuery"); //not used anymore
GET_PROC_ADDRESS(_oglGetQueryiv, PFNGLGETQUERYIVPROC, "glGetQueryiv"); //not used anymore
GET_PROC_ADDRESS(_oglGetQueryObjectui64vEXT, PFNGLGETQUERYOBJECTUI64VEXTPROC, "glGetQueryObjectui64vEXT");
GET_PROC_ADDRESS(_oglGetQueryObjectiv, PFNGLGETQUERYOBJECTIVPROC, "glGetQueryObjectiv");
GET_PROC_ADDRESS(_oglGenQueries, PFNGLGENQUERIESPROC, "glGenQueries");
GET_PROC_ADDRESS(_oglDeleteQueries, PFNGLDELETEQUERIESPROC, "glDeleteQueries");
GET_PROC_ADDRESS(_oglQueryCounter, PFNGLQUERYCOUNTERPROC, "glQueryCounter");
#else
GET_PROC_ADDRESS(_oglBeginQuery, PFNGLBEGINQUERYPROC, "glBeginQuery");
GET_PROC_ADDRESS(_oglEndQuery, PFNGLENDQUERYPROC, "glEndQuery");
GET_PROC_ADDRESS(_oglGetQueryiv, PFNGLGETQUERYIVPROC, "glGetQueryiv");
GET_PROC_ADDRESS(_oglGetQueryObjectui64vEXT, PFNGLGETQUERYOBJECTUI64VEXTPROC, "glGetQueryObjectui64vEXT");
GET_PROC_ADDRESS(_oglGetQueryObjectiv, PFNGLGETQUERYOBJECTIVPROC, "glGetQueryObjectiv");
GET_PROC_ADDRESS(_oglGenQueries, PFNGLGENQUERIESPROC, "glGenQueries");
GET_PROC_ADDRESS(_oglDeleteQueries, PFNGLDELETEQUERIESPROC, "glDeleteQueries");
GET_PROC_ADDRESS(_oglQueryCounter, PFNGLQUERYCOUNTERPROC, "glQueryCounter");
#ifndef GL_TIMESTAMP
#define GL_TIMESTAMP GL_TIMESTAMP_EXT
#endif // GL_TIMESTAMP
#endif // GLES
if (_oglBeginQuery == nullptr ||
_oglEndQuery == nullptr ||
_oglGetQueryObjectui64vEXT == nullptr ||
_oglGetQueryObjectiv == nullptr ||
_oglGenQueries == nullptr ||
_oglDeleteQueries == nullptr ||
_oglQueryCounter == nullptr)
{
if (bTimerQueryExtFound == false)
{
#ifndef GLES
GPA_LogError("The GL_ARB_timer_query extension is exposed by the driver, but the not all entry points are available.");
#else
GPA_LogError("The GL_EXT_disjoint_timer_query extension is exposed by the driver, but the entry points are not available.");
#endif
}
else
{
#ifndef GLES
GPA_LogError("The GL_ARB_timer_query extension is not exposed by the driver.");
#else
GPA_LogError("The GL_EXT_disjoint_timer_query extension is not exposed by the driver.");
#endif
}
retVal = GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
}
GET_PROC_ADDRESS(_oglGetQueryObjectui64v, PFNGLGETQUERYOBJECTUI64VPROC, "glGetQueryObjectui64v");
if (nullptr == _oglGetQueryObjectui64v)
{
GPA_LogMessage("glGetQueryObjectui64v entry point not exposed by the driver.");
}
return retVal;
}
//-----------------------------------------------------------------------------
GPA_Status GPA_IMP_GetHWInfo(void* pContext, GPA_HWInfo* pHwInfo)
{
UNREFERENCED_PARAMETER(pContext);
assert(nullptr != pHwInfo);
// get the entry points
GPA_Status status = InitializeGLFunctions();
if (status != GPA_STATUS_OK)
{
#ifndef GLES
GPA_LogError("Could not initialize required OpenGL functions.");
#else
GPA_LogError("Could not initialize required OpenGL ES functions.");
#endif // GLES
return status;
}
const GLubyte* pRenderer = _oglGetString(GL_RENDERER);
pHwInfo->SetDeviceName(reinterpret_cast<const char*>(pRenderer));
// Handle non-AMD GPU vendors
const GLubyte* pVendor = _oglGetString(GL_VENDOR);
//TODO: should at least support GPUTime for these vendors then
if (nullptr != strstr(reinterpret_cast<const char*>(pVendor), pNVIDIARenderer))
{
pHwInfo->SetVendorID(NVIDIA_VENDOR_ID);
pHwInfo->SetDeviceName(reinterpret_cast<const char*>(pRenderer));
pHwInfo->SetHWGeneration(GDT_HW_GENERATION_NVIDIA);
return GPA_STATUS_OK;
}
else if (nullptr != strstr(reinterpret_cast<const char*>(pVendor), pIntelRenderer))
{
pHwInfo->SetVendorID(INTEL_VENDOR_ID);
pHwInfo->SetDeviceName(reinterpret_cast<const char*>(pRenderer));
pHwInfo->SetHWGeneration(GDT_HW_GENERATION_INTEL);
return GPA_STATUS_OK;
}
// instead of checking the vendor string to make sure it is ATI / AMD,
// use the Renderer string - sometimes the GL driver team needs to override
// the vendor string to make apps and games behave differently, so using
// the renderer string is a better solution.
if (strstr(reinterpret_cast<const char*>(pRenderer), pATIRenderer) == 0 ||
strstr(reinterpret_cast<const char*>(pRenderer), pAMDRenderer) == 0)
{
pHwInfo->SetVendorID(AMD_VENDOR_ID);
bool isDeviceIdKnown = false;
if (nullptr != _oglXQueryCurrentRendererIntegerMESA)
{
// first try to get the device id from the glXQueryCurrentRendererIntegerMESA extension
unsigned int driverDeviceId;
_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)
{
pHwInfo->SetDeviceID(driverDeviceId);
}
}
// if we were unable to use the glCQueryCurrentRendererIntegerMESA extension,
// then fall back to the GPIN counters exposed by the driver
if (!isDeviceIdKnown)
{
ASICInfo asicInfo;
if (GetASICInfo(asicInfo) == false)
{
GPA_LogError("Unable to obtain asic information.");
return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
}
// switch between values in ASICInfo.h and GPAHWInfo.cpp
switch (asicInfo.eAsicRev)
{
case ATIASIC_ID_TAHITI_P:
pHwInfo->SetDeviceID(0x6779);
break;
case ATIASIC_ID_PITCAIRN_PM:
pHwInfo->SetDeviceID(0x6818);
break;
case ATIASIC_ID_CAPEVERDE_M:
pHwInfo->SetDeviceID(0x6838);
break;
case ATIASIC_ID_OLAND_M:
pHwInfo->SetDeviceID(0x6610);
break;
case ATIASIC_ID_HAINAN_M:
pHwInfo->SetDeviceID(0x6660);
break;
case ATIASIC_ID_BONAIRE_M:
pHwInfo->SetDeviceID(0x665C);
break;
case ATIASIC_ID_SPECTRE:
pHwInfo->SetDeviceID(0x1307);
break;
case ATIASIC_ID_SPOOKY:
pHwInfo->SetDeviceID(0x1312);
break;
case ATIASIC_ID_KALINDI:
pHwInfo->SetDeviceID(0x9830);
break;
case ATIASIC_ID_HAWAII_P:
pHwInfo->SetDeviceID(0x67A0);
break;
case ATIASIC_ID_ICELAND_M:
pHwInfo->SetDeviceID(0x6900);
break;
case ATIASIC_ID_TONGA_P:
pHwInfo->SetDeviceID(0x6920);
break;
case ATIASIC_ID_GODAVARI:
pHwInfo->SetDeviceID(0x9855);
break;
case ATIASIC_ID_CARRIZO:
pHwInfo->SetDeviceID(0x9870);
break;
case ATIASIC_ID_STONEY:
pHwInfo->SetDeviceID(0x98E4);
break;
case ATIASIC_ID_FIJI_P:
pHwInfo->SetDeviceID(0x7300);
break;
case ATIASIC_ID_ELLESMERE:
pHwInfo->SetDeviceID(0x67DF);
break;
case ATIASIC_ID_BAFFIN:
pHwInfo->SetDeviceID(0x67FF);
break;
case ATIASIC_ID_LEXA:
pHwInfo->SetDeviceID(0x699F);
break;
default:
GPA_LogError("Unsupported asic ID.");
return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
break;
}
}
pHwInfo->UpdateRevisionIdBasedOnDeviceIDAndName();
return GPA_STATUS_OK;
}
GPA_LogError("A non-AMD graphics card was identified.");
return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
}
//-----------------------------------------------------------------------------
GPA_Status GPA_IMP_CompareHWInfo(void* pContext, GPA_HWInfo* pHwInfo)
{
UNREFERENCED_PARAMETER(pContext);
assert(nullptr != pHwInfo);
// get the entry points
GPA_Status status = InitializeGLFunctions();
if (status != GPA_STATUS_OK)
{
#ifndef GLES
GPA_LogError("Could not initialize required OpenGL functions.");
#else
GPA_LogError("Could not initialize required OpenGL ES functions.");
#endif // GLES
return status;
}
const GLubyte* pRenderer = _oglGetString(GL_RENDERER);
const char* deviceName = nullptr;
pHwInfo->GetDeviceName(deviceName);
size_t deviceNameLen = strlen(deviceName);
// instead of checking the vendor string to make sure it is ATI / AMD,
// use the Renderer string - sometimes the GL driver team needs to override
// the vendor string to make apps and games behave differently, so using
// the renderer string is a better solution.
bool isAMDRenderer = strstr(reinterpret_cast<const char*>(pRenderer), pATIRenderer) == 0 ||
strstr(reinterpret_cast<const char*>(pRenderer), pAMDRenderer) == 0;
if (isAMDRenderer)
{
if (strncmp(deviceName, reinterpret_cast<const char*>(pRenderer), deviceNameLen) != 0)
{
// device names don't match, let the driver be the authority on the device name
pHwInfo->SetDeviceName(reinterpret_cast<const char*>(pRenderer));
}
return GPA_STATUS_OK;
}
const GLubyte* pVendor = _oglGetString(GL_VENDOR);
if (strstr(reinterpret_cast<const char*>(pVendor), pNVIDIARenderer))
{
if (pHwInfo->IsNVidia())
{
return GPA_STATUS_OK;
}
else
{
return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
}
}
if (strstr(reinterpret_cast<const char*>(pVendor), pIntelRenderer))
{
if (pHwInfo->IsIntel())
{
return GPA_STATUS_OK;
}
else
{
return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
}
}
GPA_LogError("A unknown graphics card was identified.");
return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
}
//-----------------------------------------------------------------------------
GPA_Status GPA_IMP_VerifyHWSupport(void* pContext, GPA_HWInfo* pHwInfo)
{
UNREFERENCED_PARAMETER(pContext);
if (nullptr == pHwInfo)
{
GPA_LogError("Parameter 'pHwInfo' is NULL.");
return GPA_STATUS_ERROR_NULL_POINTER;
}
// get the entry points
GPA_Status status = InitializeGLFunctions();
if (status != GPA_STATUS_OK)
{
#ifndef GLES
GPA_LogError("Could not initialize required OpenGL functions.");
#else
GPA_LogError("Could not initialize required OpenGL ES functions.");
#endif // GLES
return status;
}
// GPUTime information is returned in nanoseconds, so set the frequency to convert it into seconds
pHwInfo->SetTimeStampFrequency(1000000000);
status = GPACustomHwValidationManager::Instance()->ValidateHW(pContext, pHwInfo);
if (GPA_STATUS_OK != status)
{
return status;
}
// If GL has gotten this far, the hardware should be supported
return GPA_STATUS_OK;
}
//-----------------------------------------------------------------------------
GPA_Status GPA_IMP_CreateContext(GPA_ContextState** ppNewContext)
{
GPA_Status result = GPA_STATUS_OK;
if (nullptr == ppNewContext)
{
GPA_LogError("Unable to create context. Parameter 'ppNewContext' is NULL.");
result = GPA_STATUS_ERROR_NULL_POINTER;
}
GPA_ContextStateGL* pContext = new(std::nothrow) GPA_ContextStateGL;
if (nullptr == pContext)
{
GPA_LogError("Unable to create context.");
result = GPA_STATUS_ERROR_FAILED;
}
else
{
(*ppNewContext) = pContext;
}
return result;
}
//-----------------------------------------------------------------------------
GPA_Status GPA_IMP_Initialize()
{
return GPA_STATUS_OK;
}
//-----------------------------------------------------------------------------
GPA_Status GPA_IMP_Destroy()
{
return GPA_STATUS_OK;
}
//-----------------------------------------------------------------------------
// Startup / exit
GPA_Status GPA_IMP_OpenContext(void* pContext)
{
UNREFERENCED_PARAMETER(pContext);
//#ifdef DEBUG_GL_ERRORS
// SetupDebugCallback();
//#endif // DEBUG_GL_ERRORS
GPA_ContextStateGL* pGLContext = getCurrentContext();
GDT_HW_GENERATION generation = GDT_HW_GENERATION_NONE;
if (nullptr == pGLContext || pGLContext->m_hwInfo.GetHWGeneration(generation) == false)
{
GPA_LogError("Unable to get hardware generation.");
return GPA_STATUS_ERROR_FAILED;
}
gpa_uint32 vendorId = 0;
if (pGLContext->m_hwInfo.GetVendorID(vendorId) == false)
{
return GPA_STATUS_ERROR_FAILED;
}
gpa_uint32 deviceId = 0;
if (pGLContext->m_hwInfo.GetDeviceID(deviceId) == false)
{
return GPA_STATUS_ERROR_FAILED;
}
gpa_uint32 revisionId = 0;
if (pGLContext->m_hwInfo.GetRevisionID(revisionId) == false)
{
return GPA_STATUS_ERROR_FAILED;
}
// generate the expected counters
GPA_Status status = GenerateCounters(GPA_API_OPENGL, vendorId, deviceId, revisionId, reinterpret_cast<GPA_ICounterAccessor**>(&(pGLContext->m_pCounterAccessor)), &(pGLContext->m_pCounterScheduler));
if (g_pCurrentContext->m_hwInfo.IsAMD() && status == GPA_STATUS_OK)
{
// now query the GL API to get the hardware counter group names and Ids so that the expected groups can be verified and the group Ids can be updated.
// Get the number of performance counter groups
GLint nNumGroups;
_oglGetPerfMonitorGroupsAMD(&nNumGroups, 0, nullptr);
assert(nNumGroups > 0);
if (nNumGroups == 0)
{
GPA_LogError("No counter groups are exposed by GL_AMD_performance_monitor.");
return GPA_STATUS_ERROR_FAILED;
}
GPA_HardwareCounters* pHardwareCounters = pGLContext->m_pCounterAccessor->GetHardwareCounters();
unsigned int expectedDriverGroups = pHardwareCounters->m_groupCount + pHardwareCounters->m_additionalGroupCount - 1;
if (nNumGroups < (int)expectedDriverGroups)
{
// We should not proceed if the driver exposes less groups that we expect
std::stringstream error;
error << "GL_AMD_performance_monitor exposes " << nNumGroups << " counter groups, but GPUPerfAPI requires at least " << (int)expectedDriverGroups << ".";
GPA_LogError(error.str().c_str());
return GPA_STATUS_ERROR_FAILED;
}
if (nNumGroups > (int)expectedDriverGroups)
{
// report an error if the driver exposes more groups than we expect, but allow the code to continue.
std::stringstream error;
error << "GL_AMD_performance_monitor exposes " << nNumGroups << " counter groups, but GPUPerfAPI expected " << (int)expectedDriverGroups << ".";
GPA_LogError(error.str().c_str());
}
// Get the group Ids
GLuint* pPerfGroups = new(std::nothrow) GLuint[nNumGroups];
if (nullptr == pPerfGroups)
{
GPA_LogError("Unable to allocate memory to store the group IDs.");
return GPA_STATUS_ERROR_FAILED;
}
_oglGetPerfMonitorGroupsAMD(nullptr, nNumGroups, pPerfGroups);
// declare this outside the loops
std::vector<GPA_HardwareCounterDescExt>::iterator internalCounterIter = pHardwareCounters->m_counters.begin();
int driverGroupNum = -1;
// for each group, get the group name, number of counters, and max counters (and maybe validate them)
for (int g = 0; g < (int)pHardwareCounters->m_groupCount; g++)
{
driverGroupNum++;
char strName[64];
memset(strName, 0, 64);
GLint nCounters = 0;
GLint nMaxActive = 0;
// Get the group name
if (g < nNumGroups)
{
_oglGetPerfMonitorGroupStringAMD(pPerfGroups[driverGroupNum], 64, nullptr, strName);
// Get the number of counters and max active counters
_oglGetPerfMonitorCountersAMD(pPerfGroups[driverGroupNum], &nCounters, &nMaxActive, 0, nullptr);
if (generation == GDT_HW_GENERATION_SEAISLAND && strncmp(strName, "TCS", 64) == 0)
{
// skip the TCS counter group because it is only exposed on Kabini and GPA GL does not currently support it.
GPA_LogMessage("Skipping TCS group.");
driverGroupNum++;
_oglGetPerfMonitorGroupStringAMD(pPerfGroups[driverGroupNum], 64, nullptr, strName);
// Get the number of counters and max active counters