Пример #1
0
void EnumerateProfilesOnSystem()
{
  NvAPI_Status status;
  status = NvAPI_Initialize();
  if(status != NVAPI_OK)
    PrintError(status);

  NvDRSSessionHandle hSession = 0;
  status = NvAPI_DRS_CreateSession(&hSession);
  if(status != NVAPI_OK)
    PrintError(status);

  status = NvAPI_DRS_LoadSettings(hSession);
  if(status != NVAPI_OK)
    PrintError(status);

  NvDRSProfileHandle hProfile = 0;
  unsigned int index = 0;
  while((status = NvAPI_DRS_EnumProfiles(hSession, index, &hProfile)) == NVAPI_OK)
  {
    printf("Profile in position %d:\n", index);
    DisplayProfileContents(hSession, hProfile);
    index++;
  }
  if(status == NVAPI_END_ENUMERATION)
  {
    // this is expected at the end of the enumeration
  }
  else
    if(status != NVAPI_OK)
      PrintError(status);

  NvAPI_DRS_DestroySession(hSession);
  hSession = 0;
}
int APIENTRY WINMAIN(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	const S32 MAX_HEAPS = 255;
	DWORD heap_enable_lfh_error[MAX_HEAPS];
	S32 num_heaps = 0;
	
#if WINDOWS_CRT_MEM_CHECKS && !INCLUDE_VLD
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // dump memory leaks on exit
#elif 1
	// Experimental - enable the low fragmentation heap
	// This results in a 2-3x improvement in opening a new Inventory window (which uses a large numebr of allocations)
	// Note: This won't work when running from the debugger unless the _NO_DEBUG_HEAP environment variable is set to 1

	_CrtSetDbgFlag(0); // default, just making explicit
	
	ULONG ulEnableLFH = 2;
	HANDLE* hHeaps = new HANDLE[MAX_HEAPS];
	num_heaps = GetProcessHeaps(MAX_HEAPS, hHeaps);
	for(S32 i = 0; i < num_heaps; i++)
	{
		bool success = HeapSetInformation(hHeaps[i], HeapCompatibilityInformation, &ulEnableLFH, sizeof(ulEnableLFH));
		if (success)
			heap_enable_lfh_error[i] = 0;
		else
			heap_enable_lfh_error[i] = GetLastError();
	}
#endif
	
	// *FIX: global
	gIconResource = MAKEINTRESOURCE(IDI_LL_ICON);

	LLAppViewerWin32* viewer_app_ptr = new LLAppViewerWin32(lpCmdLine);
	
	viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash);

	// Set a debug info flag to indicate if multiple instances are running.
	bool found_other_instance = !create_app_mutex();
	gDebugInfo["FoundOtherInstanceAtStartup"] = LLSD::Boolean(found_other_instance);

	bool ok = viewer_app_ptr->init();
	if(!ok)
	{
		LL_WARNS() << "Application init failed." << LL_ENDL;
		return -1;
	}
	
#ifdef USE_NVAPI
	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);
		}
	}
#endif

	// Have to wait until after logging is initialized to display LFH info
	if (num_heaps > 0)
	{
		LL_INFOS() << "Attempted to enable LFH for " << num_heaps << " heaps." << LL_ENDL;
		for(S32 i = 0; i < num_heaps; i++)
		{
			if (heap_enable_lfh_error[i])
			{
				LL_INFOS() << "  Failed to enable LFH for heap: " << i << " Error: " << heap_enable_lfh_error[i] << LL_ENDL;
			}
		}
	}
	
	// Run the application main loop
	if(!LLApp::isQuitting()) 
	{
		viewer_app_ptr->mainLoop();
	}

	if (!LLApp::isError())
	{
		//
		// We don't want to do cleanup here if the error handler got called -
		// the assumption is that the error handler is responsible for doing
		// app cleanup if there was a problem.
		//
#if WINDOWS_CRT_MEM_CHECKS
    LL_INFOS() << "CRT Checking memory:" << LL_ENDL;
	if (!_CrtCheckMemory())
	{
		LL_WARNS() << "_CrtCheckMemory() failed at prior to cleanup!" << LL_ENDL;
	}
	else
	{
		LL_INFOS() << " No corruption detected." << LL_ENDL;
	}
#endif
	
	gGLActive = TRUE;

	viewer_app_ptr->cleanup();
	
#if WINDOWS_CRT_MEM_CHECKS
    LL_INFOS() << "CRT Checking memory:" << LL_ENDL;
	if (!_CrtCheckMemory())
	{
		LL_WARNS() << "_CrtCheckMemory() failed after cleanup!" << LL_ENDL;
	}
	else
	{
		LL_INFOS() << " No corruption detected." << LL_ENDL;
	}
#endif
	 
	}
	delete viewer_app_ptr;
	viewer_app_ptr = NULL;

	//start updater
	if(LLAppViewer::sUpdaterInfo)
	{
		_spawnl(_P_NOWAIT, LLAppViewer::sUpdaterInfo->mUpdateExePath.c_str(), LLAppViewer::sUpdaterInfo->mUpdateExePath.c_str(), LLAppViewer::sUpdaterInfo->mParams.str().c_str(), NULL);

		delete LLAppViewer::sUpdaterInfo ;
		LLAppViewer::sUpdaterInfo = NULL ;
	}

#ifdef USE_NVAPI
	// (NVAPI) (6) We clean up. This is analogous to doing a free()
	if (hSession)
	{
		NvAPI_DRS_DestroySession(hSession);
		hSession = 0;
	}
#endif
	
	return 0;
}
Пример #3
0
int main()
{
  if (NvAPI_Initialize() != NVAPI_OK)
    throw std::runtime_error("NVIDIA Api not initialized");

  if (NvAPI_DRS_CreateSession(&_session) != NVAPI_OK)
    throw std::runtime_error("can't create session");

  if (NvAPI_DRS_LoadSettings(_session) != NVAPI_OK)
    throw std::runtime_error("can't load system settings");

  if (NvAPI_DRS_GetCurrentGlobalProfile(_session, &_profile) != NVAPI_OK)
    throw std::runtime_error("can't get current global profile");

  NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS];
  NvAPI_Status status;
  NvU32 GpuCount;
  NvU32 DeviceId;
  NvU32 SubSystemId;
  NvU32 RevisionId;
  NvU32 ExtDeviceId;
  NvU32 BusId;
  NvU32 BiosRevision;
  NvU32 BiosRevisionOEM;
  NV_BOARD_INFO BoardInfo;
  BoardInfo.version = NV_BOARD_INFO_VER;
  NvU32 ConfiguredFeatureMask;
  NvU32 ConsistentFeatureMask;
  NvU32 CoreCount;

  NvAPI_EnumPhysicalGPUs(nvGPUHandle, &GpuCount);

  NvAPI_ShortString str;
  NvAPI_GPU_GetFullName(nvGPUHandle[0], str);
  NvAPI_GPU_GetPCIIdentifiers(nvGPUHandle[0], &DeviceId, &SubSystemId, &RevisionId, &ExtDeviceId);
  NvAPI_GPU_GetBusId(nvGPUHandle[0], &BusId);
  NvAPI_GPU_GetVbiosRevision(nvGPUHandle[0], &BiosRevision);
  NvAPI_GPU_GetVbiosOEMRevision(nvGPUHandle[0], &BiosRevisionOEM);
  NvAPI_GPU_GetVbiosVersionString(nvGPUHandle[0], str);
  status = NvAPI_GPU_GetBoardInfo(nvGPUHandle[0], &BoardInfo);
  status = NvAPI_GPU_WorkstationFeatureQuery(nvGPUHandle[0], &ConfiguredFeatureMask, &ConsistentFeatureMask);
  status = NvAPI_GPU_GetGpuCoreCount(nvGPUHandle[0], &CoreCount);

  NV_CHIPSET_INFO info;
  info.version = NV_CHIPSET_INFO_VER_4;
   status =NvAPI_SYS_GetChipSetInfo(&info);
  NvAPI_GetInterfaceVersionString(str);

  unsigned int test= (unsigned int) -0x68;
  unsigned int index = 0;
  while ((status = NvAPI_DRS_EnumProfiles(_session, index, &_profile)) == NVAPI_OK)
  {
    _profInfo.version = NVDRS_PROFILE_VER;

    if (NvAPI_DRS_GetProfileInfo(_session, _profile, &_profInfo) != NVAPI_OK)
      throw std::runtime_error("can't get current global profile info");

    index++;
  }

  EnumerateProfilesOnSystem();

  NvAPI_DRS_DestroySession(_session);

  return 0;
}