forked from kmkolasinski/AwesomeBump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpuinfo.cpp
146 lines (134 loc) · 3.82 KB
/
gpuinfo.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
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2015 <copyright holder> <email>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "gpuinfo.h"
GpuInfo::GpuInfo(QGLContext*& glContext)
{
//Initializing
m_curGlContext = NULL;
m_curGpu.availMem = 0;
m_curGpu.totalMem = 0;
m_curGpu.gpuMake = NONE;
setGlContext(glContext);
setGpuMake();
}
GpuInfo::~GpuInfo()
{
}
void GpuInfo::setGlContext(QGLContext*& glContext)
{
if(glContext->isValid())
m_curGlContext = glContext->contextHandle();
}
void GpuInfo::setGpuMake()
{
if(m_curGlContext->isValid())
{
char* rawMake = (char*) m_curGlContext->functions()->glGetString(GL_VENDOR);
if(strcmp(rawMake, "NVIDIA Corporation") == 0)
m_curGpu.gpuMake = NVIDIA;
else if (strcmp(rawMake, "ATI Technologies") == 0)
m_curGpu.gpuMake = ATI;
else if(strcmp(rawMake, "Intel Open Source Technology Center") == 0)
m_curGpu.gpuMake = INTEL;
else
m_curGpu.gpuMake = NONE; //Unknown vendor string or error
}
}
GpuInfo::gpuvendors GpuInfo::getGpuMake()
{
return m_curGpu.gpuMake;
}
GLint GpuInfo::getAvailMem()
{
if(m_curGlContext->isValid())
{
GLint gpuMetrics [] = {0, 0, 0, 0};
switch (getGpuMake())
{
case NVIDIA:
if(m_curGlContext->hasExtension("GL_NVX_gpu_memory_info"))
{
#define GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX 0x9049
m_curGlContext->functions()->glGetIntegerv(GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX,
gpuMetrics);
}
break;
case ATI:
if(m_curGlContext->hasExtension("GL_ATI_meminfo"))
{
#define VBO_FREE_MEMORY_ATI 0x87FB
m_curGlContext->functions()->glGetIntegerv(VBO_FREE_MEMORY_ATI,
gpuMetrics);
}
break;
case INTEL:
//Not sure how to get Intel stats yet
return 0;
break;
default: //Unsupported card
return 0;
break;
}
return gpuMetrics[0];
}
return 0; //Context needs to be valid
}
GLint GpuInfo::getTotalMem()
{
if(m_curGlContext->isValid())
{
switch (getGpuMake())
{
case NVIDIA:
{
if(m_curGlContext->hasExtension("GL_NVX_gpu_memory_info"))
{
#define GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX 0x9048
GLint nvTotalMem [] = {0, 0, 0, 0};
m_curGlContext->functions()->glGetIntegerv(GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX,
nvTotalMem);
return nvTotalMem[0];
}
break;
}
case ATI:
// This code doesn't work yet. I need to find the library/extension that these AMD OpenGL
// methods are defined in.
/*
UINT n = wglGetGPUIDsAMD(0, 0);
UINT *ids = new UINT[n];
size_t total_mem_mb = 0;
wglGetGPUIDsAMD(n, ids);
wglGetGPUInfoAMD(ids[0],
WGL_GPU_RAM_AMD,
GL_UNSIGNED_INT,
sizeof(size_t),
&total_mem_mb);
*/
break;
case INTEL:
//Not sure how to get Intel stats yet
break;
default: //Unsupported card
break;
}
return 0; //Cannot get memory info
}
return 0; //Context needs to be valid
}