📄 nvcpl.cpp
字号:
#include <stdio.h>
#include <conio.h>
#include "NvCpl.h"
/*******************************************************************************
Main
*******************************************************************************/
static void InitInfo(HINSTANCE);
static void DesktopConfiguration(HINSTANCE);
static void GPUConfiguration(HINSTANCE);
int main(int argc, char* argv[])
{
printf("-- NVCPL Code Sample --\n\n");
// Load NVCPL library
HINSTANCE hLib = ::LoadLibrary("NVCPL.dll");
if (hLib == 0) {
printf("Unable to load NVCPL.dll\n");
return -1;
}
// MMW: It's possible to load nvcpl even when current the graphics
// card is not Nvidia: therefore also need to check for Nvidia
// card to make sure the results of these queries reflect reality.
InitInfo(hLib);
printf("\nDo you want to test the GPU configuration functions? [y|n]");
char c = getch();
printf("\n");
if (c == 'y')
{
// Use the GPU configuration functions
GPUConfiguration(hLib);
}
printf("\nDo you want to test the Desktop configuration functions? [y|n]");
c = getch();
printf("\n");
if (c == 'y')
{
// Use the desktop configuration functions if requested
DesktopConfiguration(hLib);
}
// Free NVCPL library
::FreeLibrary(hLib);
return 0;
}
/*******************************************************************************
Initial Info Display
*******************************************************************************/
static void InitInfo(HINSTANCE hLib)
{
// Get the NvGetDisplayInfo function pointer from the library
NVDISPLAYINFO displayInfo = {0};
fNvGetDisplayInfo pfNvGetDisplayInfo = (fNvGetDisplayInfo)::GetProcAddress(hLib, "NvGetDisplayInfo");
if (pfNvGetDisplayInfo == NULL)
printf("Unable to get a pointer to NvGetDisplayInfo\n");
else {
// displayInfo.cbSize must be set to size of structure
// displayInfo.dwInputFields1 must be set before call to indicate which fields to retrieve
// displayInfo.dwOutputFields1 will be set on return to indicate which fields were successfully retrived
// see NVDISPLAYINFO1_* bit definitions for field information, use 0xffffffff to retrieve all fields
memset(&displayInfo, 0, sizeof(displayInfo));
displayInfo.cbSize = sizeof(displayInfo);
displayInfo.dwInputFields1 = 0xffffffff; // 0xffffffff means all fields should be retrieved
displayInfo.dwInputFields2 = 0xffffffff; // 0xffffffff means all fields should be retrieved
if (!pfNvGetDisplayInfo("0", &displayInfo))
printf("Unable to retrieve display info\n");
else {
printf("Display Adapter : %s\n", displayInfo.szAdapterName);
if ((displayInfo.dwOutputFields1 & NVDISPLAYINFO1_BOARDTYPE) != 0) // not supported by all drivers
{
printf("Display Board : ");
switch (displayInfo.dwBoardType)
{
case NVBOARDTYPE_GEFORCE:
printf("GeForce");
break;
case NVBOARDTYPE_QUADRO:
printf("Quadro");
break;
case NVBOARDTYPE_NVS:
printf("NVS");
break;
default:
printf("0x%08lX", displayInfo.dwBoardType);
break;
}
printf("\n");
}
printf("Display Driver : %s\n", displayInfo.szDriverVersion);
}
}
}
/*******************************************************************************
GPU configuration
*******************************************************************************/
static void GPUConfiguration(HINSTANCE hLib)
{
printf("\nGPU CONFIGURATION:\n");
// Get the NvCplGetDataInt function pointer from the library
NvCplGetDataIntType NvCplGetDataInt = (NvCplGetDataIntType)::GetProcAddress(hLib, "NvCplGetDataInt");
if (NvCplGetDataInt == 0)
printf("- Unable to get a pointer to NvCplGetDataInt\n");
else {
// Get bus mode
long busMode;
printf("- Bus mode: ");
if (NvCplGetDataInt(NVCPL_API_AGP_BUS_MODE, &busMode) == FALSE)
printf("Unable to retrieve\n");
else {
// Graphics card connection to system
// Values are:
// 1 = PCI
// 4 = AGP
// 8 = PCI Express
switch (busMode) {
case 1:
printf("PCI\n");
break;
case 4:
printf("AGP\n");
break;
case 8:
printf("PCI Express\n");
break;
default:
printf("Unknown\n");
break;
}
}
// Get bus transfer rate
long busTransferRate;
printf("- Bus transfer rate: ");
if (NvCplGetDataInt(NVCPL_API_TX_RATE, &busTransferRate) == FALSE)
printf("Unable to retrieve\n");
else
printf("%dX\n", busTransferRate);
// Get AGP GART size
if (busMode == 4) {
long AGPGARTSize;
printf("- AGP GART/Memory size: ");
if (NvCplGetDataInt(NVCPL_API_AGP_LIMIT, &AGPGARTSize) == FALSE)
printf("Unable to retrieve\n");
else
{
// AGP GART Size is reported in Bytes: convert to MB before printing.
printf("%d MBytes\n", AGPGARTSize/(1024*1024));
}
}
// Get video memory size
long videoRAMSize;
printf("- Video memory size: ");
if (NvCplGetDataInt(NVCPL_API_VIDEO_RAM_SIZE, &videoRAMSize) == FALSE)
printf("Unable to retrieve\n");
else
printf("%d MBytes\n", videoRAMSize);
// Get antialiasing mode
long AAValue;
printf("- Antialiasing setting: ");
if (NvCplGetDataInt(NVCPL_API_CURRENT_AA_VALUE, &AAValue) == FALSE)
printf("Unable to retrieve\n");
else {
switch (AAValue) {
case NVCPL_API_AA_METHOD_OFF:
printf("Off\n");
break;
case NVCPL_API_AA_METHOD_2X:
printf("2X\n");
break;
case NVCPL_API_AA_METHOD_2XQ:
printf("2XQ\n");
break;
case NVCPL_API_AA_METHOD_4X:
printf("4X\n");
break;
case NVCPL_API_AA_METHOD_4X_GAUSSIAN:
printf("4X 9T\n");
break;
case NVCPL_API_AA_METHOD_4XS:
printf("4X Skewed\n");
break;
case NVCPL_API_AA_METHOD_6XS:
printf("6XS\n");
break;
case NVCPL_API_AA_METHOD_8XS:
printf("8XS\n");
break;
case NVCPL_API_AA_METHOD_16XS:
printf("16XS\n");
break;
default:
printf("Unknown\n");
break;
}
}
// Get and Modify Number of Frames Buffered
NvCplSetDataIntType NvCplSetDataInt = (NvCplSetDataIntType)::GetProcAddress(hLib, "NvCplSetDataInt");
if (NvCplSetDataInt == 0)
printf("- Unable to get a pointer to NvCplSetDataInt\n");
else
{
long numFramesBuffered;
printf("- Number of Frames Buffered: ");
if (NvCplGetDataInt(NVCPL_API_FRAME_QUEUE_LIMIT, &numFramesBuffered) == FALSE)
printf("Unable to retrieve\n");
else
printf("%d Frame(s)\n", numFramesBuffered);
long const kForceBufferedFrames = 1;
printf("- Setting Number of Frames Buffered to %d: ", kForceBufferedFrames);
if (NvCplSetDataInt(NVCPL_API_FRAME_QUEUE_LIMIT, kForceBufferedFrames) == FALSE)
printf("Unable to set\n");
else
{
long readbackValue;
if (NvCplGetDataInt(NVCPL_API_FRAME_QUEUE_LIMIT, &readbackValue) == FALSE)
printf("Unable to retrieve\n");
else
printf("%d Frame(s)\n", readbackValue);
}
printf("- Resetting Number of Frames Buffered to %d: ", numFramesBuffered);
if (NvCplSetDataInt(NVCPL_API_FRAME_QUEUE_LIMIT, numFramesBuffered) == FALSE)
printf("Unable to set\n");
else
{
long readbackValue;
if (NvCplGetDataInt(NVCPL_API_FRAME_QUEUE_LIMIT, &readbackValue) == FALSE)
printf("Unable to retrieve\n");
else
printf("%d Frame(s)\n", readbackValue);
}
}
// Get number of GPUs and number of SLI GPUs
long numGPUs = 0L;
long numSLIGPUs = 0L;
printf("- Number of GPUs: ");
if (NvCplGetDataInt(NVCPL_API_NUMBER_OF_GPUS, &numGPUs) == FALSE)
printf("Unable to retrieve\n");
else
printf("%ld.\n", numGPUs);
printf("- Number of GPUs in SLI mode: ");
if (NvCplGetDataInt(NVCPL_API_NUMBER_OF_SLI_GPUS, &numSLIGPUs) == FALSE)
printf("Unable to retrieve\n");
else
printf("%ld.\n", numSLIGPUs);
if (numSLIGPUs > 0L)
{
long SLIMode = 0L;
printf("- SLI rendering mode: ");
if (NvCplGetDataInt(NVCPL_API_SLI_MULTI_GPU_RENDERING_MODE, &SLIMode) == FALSE)
printf("Unable to retrieve\n");
else
{
if ((SLIMode & NVCPL_API_SLI_ENABLED) == 0L)
printf("SLI is not enabled.\n");
else
{
if ((SLIMode & NVCPL_API_SLI_RENDERING_MODE_AFR) != 0L)
printf("SLI is in AFR mode.\n");
else if ((SLIMode & NVCPL_API_SLI_RENDERING_MODE_SFR) != 0L)
printf("SLI is in SFR mode.\n");
else if ((SLIMode & NVCPL_API_SLI_RENDERING_MODE_SINGLE_GPU) != 0L)
printf("SLI is in single GPU mode.\n");
else
printf("SLI is in auto-select mode.\n");
printf("Setting SLI to AFR mode.\n");
long newSLIMode = NVCPL_API_SLI_RENDERING_MODE_AFR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -