반응형
=================================
=================================
=================================
출처: http://arcaneness.tistory.com/entry/%EB%B9%84%EB%94%94%EC%98%A4-%EB%A9%94%EB%AA%A8%EB%A6%AC-%EA%B5%AC%ED%95%98%EA%B8%B0
http://code.msdn.microsoft.com/windowsdesktop/DirectX-Video-Memory-ee7d8319
여기에 나온 방법으로 했어도 실시간으로 변화하는 GPU 메모리 사용량을 표시 할수는 없었다. 내가... 잘 못한건가?.. 어째든 실시간 비디오 메모리 사용량을 측정하기 위해 Nvidia를 떠돌며 삽질만 하다가 Nvapi.dll을 통하여 해결하였다.
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
|
// KGpuMon.h 源代码 #pragma once #define MAX_GPU_NUM 4L // 监控的GPU个数(NVIDIA定义的最多GPU个数是64,这里最多只监控4个) #define MY_PROCESS_ERROR(Condition) do { if (!(Condition)) goto Exit0; } while (false) #define MAX_DISPLAY_CARDS 4 // 最多监控4块显卡(暂时应该够了吧) // 常量定义 #define MAX_PHYSICAL_GPUS 64 #define SHORT_STRING_MAX 64 #define MAX_THERMAL_SENSORS_PER_GPU 3 #define MAX_CLOCKS_PER_GPU 0x120 #define MAX_PSTATES_PER_GPU 8 #define MAX_USAGES_PER_GPU 33 #define MAX_COOLER_PER_GPU 20 #define MAX_MEMORY_VALUES_PER_GPU 5 // 接口ID值 #define ID_NvAPI_Initialize 0x0150E828 #define ID_NvAPI_GPU_GetFullName 0xCEEE8E9F #define ID_NvAPI_GPU_GetThermalSettings 0xE3640A56 #define ID_NvAPI_EnumNvidiaDisplayHandle 0x9ABDD40D #define ID_NvAPI_GetPhysicalGPUsFromDisplay 0x34EF9506 #define ID_NvAPI_EnumPhysicalGPUs 0xE5AC921F #define ID_NvAPI_GPU_GetTachReading 0x5F608315 #define ID_NvAPI_GPU_GetAllClocks 0x1BD69F49 #define ID_NvAPI_GPU_GetPStates 0x60DED2ED #define ID_NvAPI_GPU_GetUsages 0x189A1FDF #define ID_NvAPI_GPU_GetCoolerSettings 0xDA141340 #define ID_NvAPI_GPU_SetCoolerLevels 0x891FA0AE #define ID_NvAPI_GPU_GetMemoryInfo 0x774AA982 #define ID_NvAPI_GetDisplayDriverVersion 0xF951A4D1 #define ID_NvAPI_GetInterfaceVersionString 0x01053FA5 #define ID_NvAPI_GPU_GetPCIIdentifiers 0x2DDFB66E // 版本号参数定义 #define GPU_THERMAL_SETTINGS_VER (sizeof(NvGPUThermalSettings) | 0x10000) #define GPU_CLOCKS_VER (sizeof(NvClocks) | 0x20000) #define GPU_PSTATES_VER (sizeof(NvPStates) | 0x10000) #define GPU_USAGES_VER (sizeof(NvUsages) | 0x10000) #define GPU_COOLER_SETTINGS_VER (sizeof(NvGPUCoolerSettings) | 0x20000) #define GPU_MEMORY_INFO_VER (sizeof(NvMemoryInfo) | 0x20000) #define DISPLAY_DRIVER_VERSION_VER (sizeof(NvDisplayDriverVersion) | 0x10000) #define GPU_COOLER_LEVELS_VER (sizeof(NvGPUCoolerLevels) | 0x10000) enum NvStatus { enumNvStatus_OK = 0, enumNvStatus_ERROR = -1, enumNvStatus_LIBRARY_NOT_FOUND = -2, enumNvStatus_NO_IMPLEMENTATION = -3, enumNvStatus_API_NOT_INTIALIZED = -4, enumNvStatus_INVALID_ARGUMENT = -5, enumNvStatus_NVIDIA_DEVICE_NOT_FOUND = -6, enumNvStatus_END_ENUMERATION = -7, enumNvStatus_INVALID_HANDLE = -8, enumNvStatus_INCOMPATIBLE_STRUCT_VERSION = -9, enumNvStatus_HANDLE_INVALIDATED = -10, enumNvStatus_OPENGL_CONTEXT_NOT_CURRENT = -11, enumNvStatus_NO_GL_EXPERT = -12, enumNvStatus_INSTRUMENTATION_DISABLED = -13, enumNvStatus_EXPECTED_LOGICAL_GPU_HANDLE = -100, enumNvStatus_EXPECTED_PHYSICAL_GPU_HANDLE = -101, enumNvStatus_EXPECTED_DISPLAY_HANDLE = -102, enumNvStatus_INVALID_COMBINATION = -103, enumNvStatus_NOT_SUPPORTED = -104, enumNvStatus_PORTID_NOT_FOUND = -105, enumNvStatus_EXPECTED_UNATTACHED_DISPLAY_HANDLE = -106, enumNvStatus_INVALID_PERF_LEVEL = -107, enumNvStatus_DEVICE_BUSY = -108, enumNvStatus_NV_PERSIST_FILE_NOT_FOUND = -109, enumNvStatus_PERSIST_DATA_NOT_FOUND = -110, enumNvStatus_EXPECTED_TV_DISPLAY = -111, enumNvStatus_EXPECTED_TV_DISPLAY_ON_DCONNECTOR = -112, enumNvStatus_NO_ACTIVE_SLI_TOPOLOGY = -113, enumNvStatus_SLI_RENDERING_MODE_NOTALLOWED = -114, enumNvStatus_EXPECTED_DIGITAL_FLAT_PANEL = -115, enumNvStatus_ARGUMENT_EXCEED_MAX_SIZE = -116, enumNvStatus_DEVICE_SWITCHING_NOT_ALLOWED = -117, enumNvStatus_TESTING_CLOCKS_NOT_SUPPORTED = -118, enumNvStatus_UNKNOWN_UNDERSCAN_CONFIG = -119, enumNvStatus_TIMEOUT_RECONFIGURING_GPU_TOPO = -120, enumNvStatus_DATA_NOT_FOUND = -121, enumNvStatus_EXPECTED_ANALOG_DISPLAY = -122, enumNvStatus_NO_VIDLINK = -123, enumNvStatus_REQUIRES_REBOOT = -124, enumNvStatus_INVALID_HYBRID_MODE = -125, enumNvStatus_MIXED_TARGET_TYPES = -126, enumNvStatus_SYSWOW64_NOT_SUPPORTED = -127, enumNvStatus_IMPLICIT_SET_GPU_TOPOLOGY_CHANGE_NOT_ALLOWED = -128, enumNvStatus_REQUEST_USER_TO_CLOSE_NON_MIGRATABLE_APPS = -129, enumNvStatus_OUT_OF_MEMORY = -130, enumNvStatus_WAS_STILL_DRAWING = -131, enumNvStatus_FILE_NOT_FOUND = -132, enumNvStatus_TOO_MANY_UNIQUE_STATE_OBJECTS = -133, enumNvStatus_INVALID_CALL = -134, enumNvStatus_D3D10_1_LIBRARY_NOT_FOUND = -135, enumNvStatus_FUNCTION_NOT_FOUND = -136 }; enum NvThermalController { enumNvThermalController_NONE = 0, enumNvThermalController_GPU_INTERNAL, enumNvThermalController_ADM1032, enumNvThermalController_MAX6649, enumNvThermalController_MAX1617, enumNvThermalController_LM99, enumNvThermalController_LM89, enumNvThermalController_LM64, enumNvThermalController_ADT7473, enumNvThermalController_SBMAX6649, enumNvThermalController_VBIOSEVT, enumNvThermalController_OS, enumNvThermalController_UNKNOWN = -1, }; enum NvThermalTarget { enumNvThermalTarget_NONE = 0, enumNvThermalTarget_GPU = 1, enumNvThermalTarget_MEMORY = 2, enumNvThermalTarget_POWER_SUPPLY = 4, enumNvThermalTarget_BOARD = 8, enumNvThermalTarget_ALL = 15, enumNvThermalTarget_UNKNOWN = -1 }; typedef struct _NvSensor { NvThermalController Controller; unsigned int DefaultMinTemp; unsigned int DefaultMaxTemp; unsigned int CurrentTemp; NvThermalTarget Target; }NvSensor; typedef struct _NvGPUThermalSettings { unsigned int Version; unsigned int Count; NvSensor Sensor[MAX_THERMAL_SENSORS_PER_GPU]; }NvGPUThermalSettings; typedef struct _NvClocks { unsigned int Version; unsigned int Clock[MAX_CLOCKS_PER_GPU]; }NvClocks; typedef struct _NvPState { bool Present; int Percentage; }NvPState; typedef struct _NvPStates { unsigned int Version; unsigned int Flags; NvPState PStates[MAX_PSTATES_PER_GPU]; }NvPStates; typedef struct _NvUsages { unsigned int Version; unsigned int Usages[MAX_USAGES_PER_GPU]; }NvUsages; typedef struct _NvCooler { int Type; int Controller; int DefaultMin; int DefaultMax; int CurrentMin; int CurrentMax; int CurrentLevel; int DefaultPolicy; int CurrentPolicy; int Target; int ControlType; int Active; }NvCooler; typedef struct _NvGPUCoolerSettings { unsigned int Version; unsigned int Count; NvCooler Coolers[MAX_COOLER_PER_GPU]; }NvGPUCoolerSettings; typedef struct _NvLevel { int Level; int Policy; }NvLevel; typedef struct _NvGPUCoolerLevels { unsigned int Version; NvLevel Levels[MAX_COOLER_PER_GPU]; }NvGPUCoolerLevels; typedef struct _NvMemoryInfo { unsigned int Version; unsigned int Values[MAX_MEMORY_VALUES_PER_GPU]; }NvMemoryInfo; typedef struct _NvDisplayDriverVersion { unsigned int Version; unsigned int DriverVersion; unsigned int BldChangeListNum; char szBuildBranch[SHORT_STRING_MAX]; char szAdapter[SHORT_STRING_MAX]; }NvDisplayDriverVersion; typedef int NvPhysicalGpuHandle; typedef int NvDisplayHandle; // 函数定义 typedef void * (*nvapi_QueryInterfaceType)(unsigned int uiInterfaceID); typedef NvStatus (*NvAPI_InitializeType)(); typedef NvStatus (*NvAPI_GPU_GetFullNameType)( const NvPhysicalGpuHandle gpuHandle, char *pszName); typedef NvStatus (*NvAPI_GPU_GetThermalSettingsType)( const NvPhysicalGpuHandle gpuHandle, int sensorIndex, NvGPUThermalSettings *pnvGPUThermalSettings); typedef NvStatus (*NvAPI_EnumNvidiaDisplayHandleType)( const int thisEnum, NvDisplayHandle *pDisplayHandle); typedef NvStatus (*NvAPI_GetPhysicalGPUsFromDisplayType)( const NvDisplayHandle displayHandle, NvPhysicalGpuHandle *pGpuHandles, unsigned int *pGpuCount); typedef NvStatus (*NvAPI_EnumPhysicalGPUsType)(NvPhysicalGpuHandle *pGpuHandles, int *pGpuCount); typedef NvStatus (*NvAPI_GPU_GetTachReadingType)( const NvPhysicalGpuHandle gpuHandle, int *pnValue); typedef NvStatus (*NvAPI_GPU_GetAllClocksType)( const NvPhysicalGpuHandle gpuHandle, NvClocks *pnvClocks); typedef NvStatus (*NvAPI_GPU_GetPStatesType)( const NvPhysicalGpuHandle gpuHandle, NvPStates *pnvPStates); typedef NvStatus (*NvAPI_GPU_GetUsagesType)( const NvPhysicalGpuHandle gpuHandle, NvUsages *pnvUsages); typedef NvStatus (*NvAPI_GPU_GetCoolerSettingsType)( const NvPhysicalGpuHandle gpuHandle, int coolerIndex, NvGPUCoolerSettings *pnvGPUCoolerSettings); typedef NvStatus (*NvAPI_GPU_SetCoolerLevelsType)( const NvPhysicalGpuHandle gpuHandle, int coolerIndex, NvGPUCoolerLevels *pnvGPUCoolerLevels); typedef NvStatus (*NvAPI_GPU_GetMemoryInfoType)( const NvDisplayHandle displayHandle, NvMemoryInfo *pnvMemoryInfo); typedef NvStatus (*NvAPI_GetDisplayDriverVersionType)( const NvDisplayHandle displayHandle, NvDisplayDriverVersion *pnvDisplayDriverVersion); typedef NvStatus (*NvAPI_GetInterfaceVersionStringType)( char *pszVersion); typedef NvStatus (*NvAPI_GPU_GetPCIIdentifiersType)( const NvPhysicalGpuHandle gpuHandle, unsigned int *puiDeviceId, unsigned int *puiSubSystemId, unsigned int *puiRevisionId, unsigned int *puiExtDeviceId ); //*****************************以下是类内部使用的结构体************************************// /* * @brief GPU信息 */ typedef struct _GPU_INFO { NvPhysicalGpuHandle nvGpuHandle; // GPU句柄 int nUsage; // GPU占用率 }GPU_INFO; /* * @brief 显卡信息 */ typedef struct _DISPLAY_CARD_INFO { NvDisplayHandle nvDisplayHandle; // 显卡句柄 int nGpuCount; // Gpu个数 DWORD dwTotalMemory; // 总显存大小(KB) DWORD dwFreeMemory; // 空闲显存大小(KB) GPU_INFO sGpuInfo[MAX_GPU_NUM]; // GPU信息 }DISPLAY_CARD_INFO; //*****************************************************************************************// /* * @brief 显卡相关信息(可用于导出的结构体) */ typedef struct _DISPLAY_INFO { int nGpuCount; // Gpu个数 int nGpuUsages[MAX_GPU_NUM]; // Gpu占用率 DWORD dwTotalMemory; // 总显存大小(KB) DWORD dwFreeMemory; // 空闲显存大小(KB) }DISPLAY_INFO; class KGpuMon { public : KGpuMon( void ); ~KGpuMon( void ); BOOL Init(); BOOL Unit(); int GetDisplayCardCount(); BOOL GetDisplayInfo( const int nCardIndex, DISPLAY_INFO *pDisplayInfo); private : int EnumDisplayCards(); BOOL GetGpuHandles( const NvDisplayHandle nvDisplayHandle, DISPLAY_CARD_INFO *pCardInfo); BOOL GetDisplayCardGpuUsages( const NvDisplayHandle nvDisplayHandle, DISPLAY_CARD_INFO *pCardInfo); BOOL GetDisplayCardMemoryInfo( const NvDisplayHandle nvDisplayHandle, DISPLAY_CARD_INFO *pCardInfo); private : nvapi_QueryInterfaceType m_pfnNvapi_QueryInterface; NvAPI_InitializeType m_pfnNvAPI_Initialize; NvAPI_GPU_GetFullNameType m_pfnNvAPI_GPU_GetFullName; NvAPI_GPU_GetThermalSettingsType m_pfnNvAPI_GPU_GetThermalSettings; NvAPI_EnumNvidiaDisplayHandleType m_pfnNvAPI_EnumNvidiaDisplayHandle; NvAPI_GetPhysicalGPUsFromDisplayType m_pfnNvAPI_GetPhysicalGPUsFromDisplay; NvAPI_EnumPhysicalGPUsType m_pfnNvAPI_EnumPhysicalGPUs; NvAPI_GPU_GetTachReadingType m_pfnNvAPI_GPU_GetTachReading; NvAPI_GPU_GetAllClocksType m_pfnNvAPI_GPU_GetAllClocks; NvAPI_GPU_GetPStatesType m_pfnNvAPI_GPU_GetPStates; NvAPI_GPU_GetUsagesType m_pfnNvAPI_GPU_GetUsages; NvAPI_GPU_GetCoolerSettingsType m_pfnNvAPI_GPU_GetCoolerSettings; NvAPI_GPU_SetCoolerLevelsType m_pfnNvAPI_GPU_SetCoolerLevels; NvAPI_GPU_GetMemoryInfoType m_pfnNvAPI_GPU_GetMemoryInfo; NvAPI_GetDisplayDriverVersionType m_pfnNvAPI_GetDisplayDriverVersion; NvAPI_GetInterfaceVersionStringType m_pfnNvAPI_GetInterfaceVersionString; NvAPI_GPU_GetPCIIdentifiersType m_pfnNvAPI_GPU_GetPCIIdentifiers; int m_nDisplayCardCount; DISPLAY_CARD_INFO* m_pDisplayCards; HMODULE m_hNvApiDll; }; //**************************************************************************************************/ // KGpuMon.cpp 源代码 #include "StdAfx.h" #include "KGpuMon.h" KGpuMon::KGpuMon( void ) { m_hNvApiDll = NULL; m_nDisplayCardCount = 0; m_pDisplayCards = NULL; } KGpuMon::~KGpuMon( void ) { Unit(); } BOOL KGpuMon::Init() { BOOL bResult = FALSE; BOOL bRetCode = FALSE; int nIndex = 0; int nResult = 0; m_hNvApiDll = LoadLibrary(_T( "nvapi.dll" )); if (m_hNvApiDll) { m_pfnNvapi_QueryInterface = (nvapi_QueryInterfaceType)GetProcAddress(m_hNvApiDll, "nvapi_QueryInterface" ); if (m_pfnNvapi_QueryInterface) { m_pfnNvAPI_Initialize = (NvAPI_InitializeType)m_pfnNvapi_QueryInterface(ID_NvAPI_Initialize); m_pfnNvAPI_GPU_GetFullName = (NvAPI_GPU_GetFullNameType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetFullName); m_pfnNvAPI_GPU_GetThermalSettings = (NvAPI_GPU_GetThermalSettingsType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetThermalSettings); m_pfnNvAPI_EnumNvidiaDisplayHandle = (NvAPI_EnumNvidiaDisplayHandleType)m_pfnNvapi_QueryInterface(ID_NvAPI_EnumNvidiaDisplayHandle); m_pfnNvAPI_GetPhysicalGPUsFromDisplay = (NvAPI_GetPhysicalGPUsFromDisplayType)m_pfnNvapi_QueryInterface(ID_NvAPI_GetPhysicalGPUsFromDisplay); m_pfnNvAPI_EnumPhysicalGPUs = (NvAPI_EnumPhysicalGPUsType)m_pfnNvapi_QueryInterface(ID_NvAPI_EnumPhysicalGPUs); m_pfnNvAPI_GPU_GetTachReading = (NvAPI_GPU_GetTachReadingType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetTachReading); m_pfnNvAPI_GPU_GetAllClocks = (NvAPI_GPU_GetAllClocksType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetAllClocks); m_pfnNvAPI_GPU_GetPStates = (NvAPI_GPU_GetPStatesType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetPStates); m_pfnNvAPI_GPU_GetUsages = (NvAPI_GPU_GetUsagesType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetUsages); m_pfnNvAPI_GPU_GetCoolerSettings = (NvAPI_GPU_GetCoolerSettingsType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetCoolerSettings); m_pfnNvAPI_GPU_SetCoolerLevels = (NvAPI_GPU_SetCoolerLevelsType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_SetCoolerLevels); m_pfnNvAPI_GPU_GetMemoryInfo = (NvAPI_GPU_GetMemoryInfoType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetMemoryInfo); m_pfnNvAPI_GetDisplayDriverVersion = (NvAPI_GetDisplayDriverVersionType)m_pfnNvapi_QueryInterface(ID_NvAPI_GetDisplayDriverVersion); m_pfnNvAPI_GetInterfaceVersionString = (NvAPI_GetInterfaceVersionStringType)m_pfnNvapi_QueryInterface(ID_NvAPI_GetInterfaceVersionString); m_pfnNvAPI_GPU_GetPCIIdentifiers = (NvAPI_GPU_GetPCIIdentifiersType)m_pfnNvapi_QueryInterface(ID_NvAPI_GPU_GetPCIIdentifiers); if (m_pfnNvAPI_Initialize) { nResult = m_pfnNvAPI_Initialize(); if (enumNvStatus_OK == nResult) { m_pDisplayCards = new DISPLAY_CARD_INFO[MAX_DISPLAY_CARDS]; ZeroMemory(m_pDisplayCards, MAX_DISPLAY_CARDS * sizeof (DISPLAY_CARD_INFO)); // 获取显卡个数 nResult = EnumDisplayCards(); MY_PROCESS_ERROR(nResult > 0); // 获取每块显卡的GPU个数 for (nIndex = 0; nIndex < m_nDisplayCardCount; ++nIndex) { bRetCode = GetGpuHandles(m_pDisplayCards[nIndex].nvDisplayHandle, &m_pDisplayCards[nIndex]); MY_PROCESS_ERROR(bRetCode); } bResult = TRUE; } } } } Exit0: return bResult; } BOOL KGpuMon::Unit() { m_nDisplayCardCount = 0; if (m_pDisplayCards) { delete []m_pDisplayCards; m_pDisplayCards = NULL; } if (m_hNvApiDll) { FreeLibrary(m_hNvApiDll); m_hNvApiDll = NULL; } return TRUE; } BOOL KGpuMon::GetDisplayInfo( const int nCardIndex, DISPLAY_INFO *pDisplayInfo) { BOOL bResult = FALSE; int nIndex = 0; if (nCardIndex < m_nDisplayCardCount) { bResult = GetDisplayCardGpuUsages(m_pDisplayCards[nCardIndex].nvDisplayHandle, &m_pDisplayCards[nCardIndex]); MY_PROCESS_ERROR(bResult); pDisplayInfo->nGpuCount = m_pDisplayCards[nCardIndex].nGpuCount; for (nIndex = 0; nIndex < pDisplayInfo->nGpuCount; ++nIndex) { pDisplayInfo->nGpuUsages[nIndex] = m_pDisplayCards[nCardIndex].sGpuInfo[nIndex].nUsage; } bResult = GetDisplayCardMemoryInfo(m_pDisplayCards[nCardIndex].nvDisplayHandle, &m_pDisplayCards[nCardIndex]); MY_PROCESS_ERROR(bResult); pDisplayInfo->dwTotalMemory = m_pDisplayCards[nCardIndex].dwTotalMemory; pDisplayInfo->dwFreeMemory = m_pDisplayCards[nCardIndex].dwFreeMemory; } Exit0: return bResult; } int KGpuMon::GetDisplayCardCount() { return m_nDisplayCardCount; } int KGpuMon::EnumDisplayCards() { NvStatus nvResult; NvDisplayHandle nvDisplayCardHandle; int nIndex = 0; m_nDisplayCardCount = 0; if (m_pfnNvAPI_EnumNvidiaDisplayHandle) { for (nIndex = 0; nIndex < MAX_DISPLAY_CARDS; ++nIndex) { nvResult = m_pfnNvAPI_EnumNvidiaDisplayHandle(nIndex, &nvDisplayCardHandle); if (enumNvStatus_OK == nvResult) { m_pDisplayCards[m_nDisplayCardCount].nvDisplayHandle = nvDisplayCardHandle; ++m_nDisplayCardCount; } } } return m_nDisplayCardCount; } BOOL KGpuMon::GetGpuHandles( const NvDisplayHandle nvDisplayHandle, DISPLAY_CARD_INFO *pCardInfo) { BOOL bResult = FALSE; NvStatus nvStatus; NvPhysicalGpuHandle *pnvHandles = NULL; int nIndex = 0; unsigned int uiGpuCount = 0; if (m_pfnNvAPI_GetPhysicalGPUsFromDisplay) { pnvHandles = new NvPhysicalGpuHandle[MAX_PHYSICAL_GPUS]; nvStatus = m_pfnNvAPI_GetPhysicalGPUsFromDisplay(nvDisplayHandle, pnvHandles, &uiGpuCount); if (enumNvStatus_OK == nvStatus) { pCardInfo->nGpuCount = min(uiGpuCount, MAX_GPU_NUM); for (nIndex = 0; nIndex < pCardInfo->nGpuCount; ++nIndex) { pCardInfo->sGpuInfo[nIndex].nvGpuHandle = pnvHandles[nIndex]; } bResult = TRUE; } delete []pnvHandles; pnvHandles = NULL; } return bResult; } BOOL KGpuMon::GetDisplayCardGpuUsages( const NvDisplayHandle nvDisplayHandle, DISPLAY_CARD_INFO *pCardInfo) { BOOL bResult = FALSE; int nIndex = 0; NvStatus nvStatus = enumNvStatus_ERROR; NvUsages *pnvUsages = NULL; if (m_pfnNvAPI_GPU_GetUsages) { pnvUsages = new NvUsages; pnvUsages->Version = GPU_USAGES_VER; for (nIndex = 0; nIndex < pCardInfo->nGpuCount; ++nIndex) { nvStatus = m_pfnNvAPI_GPU_GetUsages(pCardInfo->sGpuInfo[nIndex].nvGpuHandle, pnvUsages); if (enumNvStatus_OK == nvStatus) { pCardInfo->sGpuInfo[nIndex].nUsage = pnvUsages->Usages[2]; } } delete pnvUsages; pnvUsages = NULL; bResult = (enumNvStatus_OK == nvStatus) ? TRUE : FALSE; } return bResult; } BOOL KGpuMon::GetDisplayCardMemoryInfo( const NvDisplayHandle nvDisplayHandle, DISPLAY_CARD_INFO *pCardInfo) { BOOL bResult = FALSE; int nIndex = 0; NvStatus nvStatus = enumNvStatus_ERROR; NvUsages *pnvUsages = NULL; NvMemoryInfo sMemoryInfo; if (m_pfnNvAPI_GPU_GetMemoryInfo) { sMemoryInfo.Version = GPU_MEMORY_INFO_VER; nvStatus = m_pfnNvAPI_GPU_GetMemoryInfo(nvDisplayHandle, &sMemoryInfo); if (enumNvStatus_OK == nvStatus) { pCardInfo->dwTotalMemory = ( DWORD )(sMemoryInfo.Values[0]); pCardInfo->dwFreeMemory = ( DWORD )(sMemoryInfo.Values[4]); bResult = TRUE; } } return bResult; } |
http://blog.csdn.net/paopaoc/article/details/9093125
=================================
=================================
=================================
반응형
'프로그래밍 관련 > 게임프로그래밍' 카테고리의 다른 글
리눅스에서 게임서버 만든다면 ... 어떤 언어 사용 하시나요??? 관련 (0) | 2020.09.13 |
---|---|
Game Loop (0) | 2017.11.13 |
게임개발 가변 프레임율이 지원되는 FrameSkip (1) | 2012.11.08 |
DirectX9를 이용한 3D GAME 프로그래밍 입문 ppt자료 (0) | 2011.03.30 |
[정보] MFC + DXUT 기본적으로 붙인것~ (타일붙인 파일포함) (0) | 2011.03.29 |