Skip to content

Commit 32cb3e9

Browse files
committed
Remove link-time dependency on OpenGL lib -- it is now a runtime-only dependency. We can now build on Linux systems without needing both 64 and 32 bit versions of libGL.so
Change-Id: I43b1a4897bf459d40d2164fa122f8a70c206319f
1 parent 3fcebe4 commit 32cb3e9

File tree

9 files changed

+123
-25
lines changed

9 files changed

+123
-25
lines changed

Build/VS2015/GPUPerfAPIGL.vcxproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
4747
</PropertyGroup>
4848
<ItemDefinitionGroup>
49-
<Link>
50-
<AdditionalDependencies>opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
51-
</Link>
5249
</ItemDefinitionGroup>
5350
<ItemGroup>
5451
<None Include="..\..\PublicCounterCompilerInputFiles\CounterNamesGLGfx6.txt" />
@@ -89,4 +86,4 @@
8986
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
9087
<ImportGroup Label="ExtensionTargets">
9188
</ImportGroup>
92-
</Project>
89+
</Project>

Build/VS2015/GPUPerfAPIGLES.vcxproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
4747
</PropertyGroup>
4848
<ItemDefinitionGroup>
49-
<Link>
50-
<AdditionalDependencies>libEGL.lib;libGLESv2.lib;%(AdditionalDependencies)</AdditionalDependencies>
51-
</Link>
5249
<ClCompile>
5350
<PreprocessorDefinitions>BOOST_MEM_FN_ENABLE_STDCALL;GLES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
5451
</ClCompile>
@@ -88,4 +85,4 @@
8885
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
8986
<ImportGroup Label="ExtensionTargets">
9087
</ImportGroup>
91-
</Project>
88+
</Project>

Src/GPUPerfAPICounterGenerator/GLEntryPoints.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
#include "GLEntryPoints.h"
1010

11+
decltype(glFlush)* _oglFlush = nullptr;
12+
decltype(glGetString)* _oglGetString = nullptr;
13+
decltype(glGetIntegerv)* _oglGetIntegerv = nullptr;
14+
#ifdef _WIN32
15+
decltype(wglGetCurrentContext)* _wglGetCurrentContext = nullptr;
16+
#endif
1117
PFNGLGETPERFMONITORGROUPSAMDPROC _oglGetPerfMonitorGroupsAMD = nullptr;
1218
PFNGLGETPERFMONITORCOUNTERSAMDPROC _oglGetPerfMonitorCountersAMD = nullptr;
1319
PFNGLGETPERFMONITORGROUPSTRINGAMDPROC _oglGetPerfMonitorGroupStringAMD = nullptr;

Src/GPUPerfAPICounterGenerator/GLEntryPoints.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,18 @@
2323

2424
// used for defining the proc addresses which are initialized below
2525
#ifdef _WIN32
26+
extern decltype(wglGetProcAddress)* _wglGetProcAddress; ///< function pointer for wglGetProcAddress
2627
#define GET_PROC_ADDRESS(f,type,name)\
27-
(f) = (type) wglGetProcAddress(name);
28+
(f) = (type) _wglGetProcAddress(name);
2829
#endif
2930

3031
#ifdef _LINUX
32+
extern decltype(glXGetProcAddressARB)* _glXGetProcAddressARB; ///< function pointer for glXGetProcAddressARB
3133
#define GET_PROC_ADDRESS(f,type,name)\
32-
(f) = (type) glXGetProcAddressARB( (const GLubyte*) name);
34+
(f) = (type) _glXGetProcAddressARB( (const GLubyte*) name);
3335
#endif
3436

3537
#else
36-
// used for defining the proc addresses which are initialized below
37-
#define GET_PROC_ADDRESS(f,type,name)\
38-
(f) = (type) eglGetProcAddress(name);
3938

4039
#ifdef _WIN32
4140
typedef unsigned __int64 uint64_t;
@@ -49,10 +48,21 @@
4948
#include <GLES3/gl3.h>
5049
#include <GLES2/gl2ext.h>
5150

51+
// used for defining the proc addresses which are initialized below
52+
extern decltype(eglGetProcAddress)* _eglGetProcAddress; ///< function pointer for eglGetProcAddress
53+
#define GET_PROC_ADDRESS(f,type,name)\
54+
(f) = (type) _eglGetProcAddress(name);
55+
5256
#endif // GLES
5357

5458
typedef unsigned int GLhandle; ///< Workaround missing def in headers
5559

60+
extern decltype(glFlush)* _oglFlush; ///< function pointer for glFlush
61+
extern decltype(glGetString)* _oglGetString; ///< function pointer for glGetString
62+
extern decltype(glGetIntegerv)* _oglGetIntegerv; ///< function pointer for glGetIntegerv
63+
#ifdef _WIN32
64+
extern decltype(wglGetCurrentContext)* _wglGetCurrentContext; ///< function pointer for wglGetCurrentContext
65+
#endif
5666
extern PFNGLGETPERFMONITORGROUPSAMDPROC _oglGetPerfMonitorGroupsAMD; ///< function pointer for glGetPerfMonitorGroupsAMD
5767
extern PFNGLGETPERFMONITORCOUNTERSAMDPROC _oglGetPerfMonitorCountersAMD; ///< function pointer for glGetPerfMonitorCountersAMD
5868
extern PFNGLGETPERFMONITORGROUPSTRINGAMDPROC _oglGetPerfMonitorGroupStringAMD; ///< function pointer for glGetPerfMonitorGroupStringAMD

Src/GPUPerfAPIGL/ASICInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ bool GetASICInfo(ASICInfo& rASICInfo)
269269
// Since GL ES didn't exist before version 9551, there's no need to check the
270270
// version number. For now, it is assumed the version number will be >9551
271271

272-
const GLubyte* pVersion = glGetString(GL_VERSION);
272+
const GLubyte* pVersion = _oglGetString(GL_VERSION);
273273
int nVersion = extractVersionNumber(pVersion);
274274

275275
std::stringstream message;

Src/GPUPerfAPIGL/GLCounterDataRequest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "GLPerfMonitorCache.h"
1212

1313
#include "../GPUPerfAPI-Common/Logging.h"
14+
#include "../GPUPerfAPICounterGenerator/GLEntryPoints.h"
1415
#include <sstream>
1516
#ifdef _LINUX
1617
#include <string.h>
@@ -586,12 +587,12 @@ bool GLCounterDataRequest::EndRequest()
586587
// The effects of the first glFlush() is extremely noticeable with the GLFiveQuarterQuads test and the PostZSamplesPassing counter.
587588
// The effects of the second glFlush() are noticeable with last draw call of the GLFiveQuarterQuads test and the PreZSamplesPassing counter.
588589
// The effects of the second glFlush() are also noticeable with last draw call of the GLFiveQuarterQuads test and the CBMemWritten counter.
589-
glFlush();
590+
_oglFlush();
590591

591592
_oglEndPerfMonitorAMD(m_monitor);
592593
GPA_LogDebugMessage("glEndPerfMonitorAMD: %u", m_monitor);
593594

594-
glFlush();
595+
_oglFlush();
595596

596597
}
597598

Src/GPUPerfAPIGL/GPUPerfAPIGL.cpp

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include <assert.h>
1212
#include <sstream>
1313

14+
#ifdef _LINUX
15+
#include <dlfcn.h>
16+
#endif
17+
1418
#include "../GPUPerfAPI-Common/GPUPerfAPIImp.h"
1519
#include "../GPUPerfAPI-Common/GPACustomHWValidationManager.h"
1620

@@ -202,6 +206,21 @@ gpa_uint32 GPA_IMP_GetPreferredCheckResultFrequency()
202206
return 50;
203207
}
204208

209+
210+
#ifndef GLES
211+
212+
#ifdef _WIN32
213+
decltype(wglGetProcAddress)* _wglGetProcAddress = nullptr;
214+
#endif
215+
216+
#ifdef _LINUX
217+
decltype(glXGetProcAddressARB)* _glXGetProcAddressARB = nullptr;
218+
#endif
219+
220+
#else
221+
decltype(eglGetProcAddress)* _eglGetProcAddress = nullptr;
222+
#endif
223+
205224
/// Checks the OpenGL extensions and initializes the various function pointers. The extensions queried are:
206225
/// -- GL_AMD_performance_monitor
207226
/// -- GL_ARB_timer_query (OpenGL)
@@ -219,6 +238,77 @@ GPA_Status InitializeGLFunctions()
219238
bool bDebugOutputExtFound = false;
220239
bool bMesaQueryRendererExtFound = false;
221240

241+
#ifdef _WIN32
242+
HMODULE module = LoadLibraryA("opengl32.dll");
243+
#else
244+
void* module = dlopen("libGL.so", RTLD_LAZY);
245+
#endif
246+
247+
if (nullptr == module)
248+
{
249+
return GPA_STATUS_ERROR_NULL_POINTER;
250+
}
251+
252+
#ifndef GLES
253+
254+
#ifdef _WIN32
255+
_wglGetCurrentContext = reinterpret_cast<decltype(wglGetCurrentContext)*>(GetProcAddress(module, "wglGetCurrentContext"));
256+
257+
_wglGetProcAddress = reinterpret_cast<decltype(wglGetProcAddress)*>(GetProcAddress(module, "wglGetProcAddress"));
258+
259+
if (nullptr == _wglGetProcAddress || nullptr == _wglGetCurrentContext)
260+
{
261+
return GPA_STATUS_ERROR_NULL_POINTER;
262+
}
263+
#endif
264+
265+
#ifdef _LINUX
266+
_glXGetProcAddressARB = reinterpret_cast<decltype(glXGetProcAddressARB)*>(dlsym(module, "glXGetProcAddressARB"));
267+
268+
if (nullptr == _glXGetProcAddressARB)
269+
{
270+
return GPA_STATUS_ERROR_NULL_POINTER;
271+
}
272+
#endif
273+
274+
#else // GLES
275+
276+
#ifdef _WIN32
277+
_eglGetProcAddress = reinterpret_cast<decltype(eglGetProcAddress)*>(GetProcAddress(module, "eglGetProcAddress"));
278+
279+
if (nullptr == _eglGetProcAddress)
280+
{
281+
return GPA_STATUS_ERROR_NULL_POINTER;
282+
}
283+
#endif
284+
285+
#ifdef _LINUX
286+
_eglGetProcAddress = reinterpret_cast<decltype(eglGetProcAddress)*>(dlsym(module, "eglGetProcAddress"));
287+
288+
if (nullptr == _eglGetProcAddress)
289+
{
290+
return GPA_STATUS_ERROR_NULL_POINTER;
291+
}
292+
#endif
293+
294+
#endif // GLES
295+
296+
#ifdef _WIN32
297+
_oglFlush = reinterpret_cast<decltype(glFlush)*>(GetProcAddress(module, "glFlush"));
298+
_oglGetString = reinterpret_cast<decltype(glGetString)*>(GetProcAddress(module, "glGetString"));
299+
_oglGetIntegerv = reinterpret_cast<decltype(glGetIntegerv)*>(GetProcAddress(module, "glGetIntegerv"));
300+
#endif
301+
#ifdef _LINUX
302+
_oglFlush = reinterpret_cast<decltype(glFlush)*>(dlsym(module, "glFlush"));
303+
_oglGetString = reinterpret_cast<decltype(glGetString)*>(dlsym(module, "glGetString"));
304+
_oglGetIntegerv = reinterpret_cast<decltype(glGetIntegerv)*>(dlsym(module, "glGetIntegerv"));
305+
#endif
306+
307+
if (nullptr == _oglFlush || nullptr == _oglGetString || nullptr == _oglGetIntegerv )
308+
{
309+
return GPA_STATUS_ERROR_NULL_POINTER;
310+
}
311+
222312
GET_PROC_ADDRESS(_oglGetStringi, PFNGLGETSTRINGIPROC, "glGetStringi");
223313

224314
// if OpenGL 3.x method of getting the extensions is available, use that, otherwise try the old method
@@ -227,7 +317,7 @@ GPA_Status InitializeGLFunctions()
227317
GPA_LogMessage("Using OpenGL 3.x method to query extensions.");
228318

229319
GLint numExtensions = 0;
230-
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
320+
_oglGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
231321

232322
for (GLint i = 0; i < numExtensions; i++)
233323
{
@@ -276,7 +366,7 @@ GPA_Status InitializeGLFunctions()
276366
else
277367
{
278368
GPA_LogMessage("Using OpenGL 1.x method to query extensions.");
279-
const GLubyte* pExtensions = glGetString(GL_EXTENSIONS);
369+
const GLubyte* pExtensions = _oglGetString(GL_EXTENSIONS);
280370

281371
if (nullptr != pExtensions)
282372
{
@@ -476,11 +566,11 @@ GPA_Status GPA_IMP_GetHWInfo(void* pContext, GPA_HWInfo* pHwInfo)
476566
return status;
477567
}
478568

479-
const GLubyte* pRenderer = glGetString(GL_RENDERER);
569+
const GLubyte* pRenderer = _oglGetString(GL_RENDERER);
480570
pHwInfo->SetDeviceName(reinterpret_cast<const char*>(pRenderer));
481571

482572
// Handle non-AMD GPU vendors
483-
const GLubyte* pVendor = glGetString(GL_VENDOR);
573+
const GLubyte* pVendor = _oglGetString(GL_VENDOR);
484574

485575
//TODO: should at least support GPUTime for these vendors then
486576
if (nullptr != strstr(reinterpret_cast<const char*>(pVendor), pNVIDIARenderer))
@@ -693,7 +783,7 @@ GPA_Status GPA_IMP_CompareHWInfo(void* pContext, GPA_HWInfo* pHwInfo)
693783
return status;
694784
}
695785

696-
const GLubyte* pRenderer = glGetString(GL_RENDERER);
786+
const GLubyte* pRenderer = _oglGetString(GL_RENDERER);
697787

698788
const char* deviceName = nullptr;
699789
pHwInfo->GetDeviceName(deviceName);
@@ -717,7 +807,7 @@ GPA_Status GPA_IMP_CompareHWInfo(void* pContext, GPA_HWInfo* pHwInfo)
717807
return GPA_STATUS_OK;
718808
}
719809

720-
const GLubyte* pVendor = glGetString(GL_VENDOR);
810+
const GLubyte* pVendor = _oglGetString(GL_VENDOR);
721811

722812
if (strstr(reinterpret_cast<const char*>(pVendor), pNVIDIARenderer))
723813
{

Src/GPUPerfAPIGL/makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ INCLUDES = -I. \
1717
-I$(TSINGLETON_DIR)
1818

1919
LIBS = \
20-
-lGL \
2120
$(COMMON_LIBS) \
2221
$(COMMON_DEVICEINFO_LIB) \
2322
$(STANDARD_LIBS)

Src/GPUPerfAPIGLES/makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ INCLUDES = -I. \
1717
-I$(TSINGLETON_DIR)
1818

1919
LIBS = \
20-
-lGL \
21-
-lEGL \
2220
$(COMMON_LIBS) \
2321
$(COMMON_DEVICEINFO_LIB) \
2422
$(STANDARD_LIBS)

0 commit comments

Comments
 (0)