Added NVAPI support on windows

This commit is contained in:
Drake Arconis
2013-11-16 14:01:09 -05:00
parent 924908f2ad
commit 7fa5abd4d1
5 changed files with 176 additions and 0 deletions

View File

@@ -81,6 +81,7 @@ set(cmake_SOURCE_FILES
Linking.cmake
MediaPluginBase.cmake
NDOF.cmake
NVAPI.cmake
OPENAL.cmake
OpenGL.cmake
OpenJPEG.cmake

21
indra/cmake/NVAPI.cmake Normal file
View File

@@ -0,0 +1,21 @@
# -*- cmake -*-
include(Prebuilt)
include(Variables)
set(NVAPI ON CACHE BOOL "Use NVAPI.")
if (NVAPI)
if (WINDOWS)
use_prebuilt_binary(nvapi)
if (WORD_SIZE EQUAL 32)
set(NVAPI_LIBRARY nvapi)
elseif (WORD_SIZE EQUAL 64)
set(NVAPI_LIBRARY nvapi64)
endif (WORD_SIZE EQUAL 32)
else (WINDOWS)
set(NVAPI_LIBRARY "")
endif (WINDOWS)
else (NVAPI)
set(NVAPI_LIBRARY "")
endif (NVAPI)

View File

@@ -38,6 +38,7 @@ include(LLXML)
#include(LScript)
include(Linking)
include(NDOF)
include(NVAPI)
include(StateMachine)
include(TemplateCheck)
include(UI)
@@ -1598,6 +1599,7 @@ target_link_libraries(${VIEWER_BINARY_NAME}
${LLMATH_LIBRARIES}
${LLCOMMON_LIBRARIES}
${NDOF_LIBRARY}
${NVAPI_LIBRARY}
${viewer_LIBRARIES}
${Boost_CONTEXT_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}

View File

@@ -52,6 +52,11 @@
#include "llviewercontrol.h"
#include "lldxhardware.h"
#include "nvapi/nvapi.h"
#include "nvapi/NvApiDriverSettings.h"
#include <stdlib.h>
#include "llweb.h"
#include "llsecondlifeurls.h"
@@ -79,6 +84,19 @@ extern "C" {
const std::string LLAppViewerWin32::sWindowClass = "Second Life";
/*
This function is used to print to the command line a text message
describing the nvapi error and quits
*/
void nvapi_error(NvAPI_Status status)
{
NvAPI_ShortString szDesc = {0};
NvAPI_GetErrorMessage(status, szDesc);
llwarns << szDesc << llendl;
//should always trigger when asserts are enabled
//llassert(status == NVAPI_OK);
}
// Create app mutex creates a unique global windows object.
// If the object can be created it returns true, otherwise
@@ -101,6 +119,79 @@ bool create_app_mutex()
return result;
}
void ll_nvapi_init(NvDRSSessionHandle hSession)
{
// (2) load all the system settings into the session
NvAPI_Status status = NvAPI_DRS_LoadSettings(hSession);
if (status != NVAPI_OK)
{
nvapi_error(status);
return;
}
NvAPI_UnicodeString profile_name;
//std::string app_name = LLTrans::getString("APP_NAME");
std::string app_name("Second Life"); // <alchemy/>
llutf16string w_app_name = utf8str_to_utf16str(app_name);
wsprintf(profile_name, L"%s", w_app_name.c_str());
status = NvAPI_DRS_SetCurrentGlobalProfile(hSession, profile_name);
if (status != NVAPI_OK)
{
nvapi_error(status);
return;
}
// (3) Obtain the current profile.
NvDRSProfileHandle hProfile = 0;
status = NvAPI_DRS_GetCurrentGlobalProfile(hSession, &hProfile);
if (status != NVAPI_OK)
{
nvapi_error(status);
return;
}
// load settings for querying
status = NvAPI_DRS_LoadSettings(hSession);
if (status != NVAPI_OK)
{
nvapi_error(status);
return;
}
//get the preferred power management mode for Second Life
NVDRS_SETTING drsSetting = {0};
drsSetting.version = NVDRS_SETTING_VER;
status = NvAPI_DRS_GetSetting(hSession, hProfile, PREFERRED_PSTATE_ID, &drsSetting);
if (status == NVAPI_SETTING_NOT_FOUND)
{ //only override if the user hasn't specifically set this setting
// (4) Specify that we want the VSYNC disabled setting
// first we fill the NVDRS_SETTING struct, then we call the function
drsSetting.version = NVDRS_SETTING_VER;
drsSetting.settingId = PREFERRED_PSTATE_ID;
drsSetting.settingType = NVDRS_DWORD_TYPE;
drsSetting.u32CurrentValue = PREFERRED_PSTATE_PREFER_MAX;
status = NvAPI_DRS_SetSetting(hSession, hProfile, &drsSetting);
if (status != NVAPI_OK)
{
nvapi_error(status);
return;
}
// (5) Now we apply (or save) our changes to the system
status = NvAPI_DRS_SaveSettings(hSession);
if (status != NVAPI_OK)
{
nvapi_error(status);
return;
}
}
else if (status != NVAPI_OK)
{
nvapi_error(status);
return;
}
}
//#define DEBUGGING_SEH_FILTER 1
#if DEBUGGING_SEH_FILTER
# define WINMAIN DebuggingWinMain
@@ -157,6 +248,27 @@ int APIENTRY WINMAIN(HINSTANCE hInstance,
return -1;
}
NvAPI_Status status;
// Initialize NVAPI
status = NvAPI_Initialize();
NvDRSSessionHandle hSession = 0;
if (status == NVAPI_OK)
{
// Create the session handle to access driver settings
status = NvAPI_DRS_CreateSession(&hSession);
if (status != NVAPI_OK)
{
nvapi_error(status);
}
else
{
//override driver setting as needed
ll_nvapi_init(hSession);
}
}
// Have to wait until after logging is initialized to display LFH info
if (num_heaps > 0)
{
@@ -224,6 +336,15 @@ int APIENTRY WINMAIN(HINSTANCE hInstance,
LLAppViewer::sUpdaterInfo = NULL ;
}
// (NVAPI) (6) We clean up. This is analogous to doing a free()
if (hSession)
{
NvAPI_DRS_DestroySession(hSession);
hSession = 0;
}
return 0;
}

View File

@@ -1061,6 +1061,32 @@
</map>
</map>
</map>
<key>nvapi</key>
<map>
<key>copyright</key>
<string>Copyright (C) NVIDIA</string>
<key>description</key>
<string>NVAPI is the library suite to access nvidia profiles and performance options on windows</string>
<key>license</key>
<string>NVAPI</string>
<key>packages</key>
<map>
<key>windows</key>
<map>
<key>md5sum</key>
<string>99d1b70c1305257d521edfbd34587187</string>
<key>url</key>
<uri>https://bitbucket.org/SingularityViewer/libraries/downloads/nvapi-304-windows-20121116-singu.tar.bz2</uri>
</map>
<key>windows64</key>
<map>
<key>md5sum</key>
<string>5578017f13783fb7279dd39537d1e0fd</string>
<key>url</key>
<uri>https://bitbucket.org/SingularityViewer/libraries/downloads/nvapi-304-windows64-20131116-singu.tar.bz2</uri>
</map>
</map>
</map>
<key>ndofdev</key>
<map>
<key>copyright</key>
@@ -1873,6 +1899,11 @@ Cass Everitt - cass@r3.nu
<key>text</key>
<string>http://www.jclark.com/xml/copying.txt</string>
</map>
<key>NVAPI</key>
<map>
<key>url</key>
<string>Licenes dir</string>
</map>
<key>ogg-vorbis</key>
<map>
<key>url</key>