static int x264_detect_switchable_graphics( void ) { void *hDLL; ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create; ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get; ADL_POWERXPRESS_SCHEME_GET ADL_PowerXpress_Scheme_Get; ADL_MAIN_CONTROL_DESTROY ADL_Main_Control_Destroy; int ret = 0; int numAdapters; int i; #ifdef _WIN32 hDLL = LoadLibraryW( L"atiadlxx.dll" ); if( !hDLL ) hDLL = LoadLibraryW( L"atiadlxy.dll" ); #else hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL ); #endif if( !hDLL ) goto fail0; ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE)adl_address(hDLL, "ADL_Main_Control_Create"); ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY)adl_address(hDLL, "ADL_Main_Control_Destroy"); ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET)adl_address(hDLL, "ADL_Adapter_NumberOfAdapters_Get"); ADL_PowerXpress_Scheme_Get = (ADL_POWERXPRESS_SCHEME_GET)adl_address(hDLL, "ADL_PowerXpress_Scheme_Get"); if( !ADL_Main_Control_Create || !ADL_Main_Control_Destroy || !ADL_Adapter_NumberOfAdapters_Get || !ADL_PowerXpress_Scheme_Get ) goto fail1; if( ADL_OK != ADL_Main_Control_Create( adl_malloc_wrapper, 1 ) ) goto fail1; if( ADL_OK != ADL_Adapter_NumberOfAdapters_Get( &numAdapters ) ) goto fail2; for( i = 0; i < numAdapters; i++ ) { int PXSchemeRange, PXSchemeCurrentState, PXSchemeDefaultState; if( ADL_OK != ADL_PowerXpress_Scheme_Get( i, &PXSchemeRange, &PXSchemeCurrentState, &PXSchemeDefaultState) ) break; if( PXSchemeRange >= ADL_PX_SCHEME_DYNAMIC ) { ret = 1; break; } } fail2: ADL_Main_Control_Destroy(); fail1: adl_close( hDLL ); fail0: return ret; }
int hc_ADL_Main_Control_Create (HM_LIB hDLL, ADL_MAIN_MALLOC_CALLBACK callback, int iEnumConnectedAdapters) { ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) GetProcAddress (hDLL, "ADL_Main_Control_Create"); if (ADL_Main_Control_Create == NULL) { log_error ("ERROR: %s\n", "ADL_Main_Control_Create() is missing"); exit (-1); } int ADL_rc = ADL_Main_Control_Create (callback, iEnumConnectedAdapters); if (ADL_rc != ADL_OK) { log_info ("WARN: %s: %d\n", "ADL_Main_Control_Create()", ADL_rc); } return (ADL_rc); }
PStateAMD::PStateAMD(void) { m_hDLL = LoadLibrary(_T("atiadlxx.dll")); if (m_hDLL == NULL) { // A 32 bit calling application on 64 bit OS will fail to LoadLIbrary. // Try to load the 32 bit library (atiadlxy.dll) instead m_hDLL = LoadLibrary(_T("atiadlxy.dll")); } if (m_hDLL == NULL) { throw "ADL library not found!"; return; } ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) GetProcAddress(m_hDLL,"ADL_Main_Control_Create"); ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY) GetProcAddress(m_hDLL,"ADL_Main_Control_Destroy"); //ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) GetProcAddress(hDLL,"ADL_Adapter_NumberOfAdapters_Get"); //ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET) GetProcAddress(hDLL,"ADL_Adapter_AdapterInfo_Get"); //ADL_Display_DisplayInfo_Get = (ADL_DISPLAY_DISPLAYINFO_GET) GetProcAddress(hDLL,"ADL_Display_DisplayInfo_Get"); ADL_Overdrive5_CurrentActivity_Get = (ADL_OVERDRIVE5_CURRENTACTIVITY_GET) GetProcAddress(m_hDLL,"ADL_Overdrive5_CurrentActivity_Get"); if ( ADL_Main_Control_Create == NULL || //OK ADL_Main_Control_Destroy == NULL || //OK // ADL_Adapter_NumberOfAdapters_Get == NULL || // ADL_Adapter_AdapterInfo_Get == NULL || // ADL_Display_DisplayInfo_Get == NULL || ADL_Overdrive5_CurrentActivity_Get == NULL) //OK { throw "ADL's API is missing!"; return; } if ( ADL_OK != ADL_Main_Control_Create(ADL_Main_Memory_Alloc, 1)) throw "ADL Initialization Error!"; m_activity.iSize = sizeof(ADLPMActivity); }
Bool VA_FGLRXGetClientDriverName( Display *dpy, int screen, int *ddxDriverMajorVersion, int *ddxDriverMinorVersion, int *ddxDriverPatchVersion, char **clientDriverName ) { ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create; ADL_MAIN_CONTROL_DESTROY ADL_Main_Control_Destroy; ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get; ADL_ADAPTER_ADAPTERINFO_GET ADL_Adapter_AdapterInfo_Get; ADL_ADAPTER_XSCREENINFO_GET ADL_Adapter_XScreenInfo_Get; LPAdapterInfo lpAdapterInfo = NULL; LPXScreenInfo lpXScreenInfo = NULL; void *libadl_handle = NULL; Bool success = False; int is_adl_initialized = 0; int i, num_adapters, lpAdapterInfo_size, lpXScreenInfo_size; if (ddxDriverMajorVersion) *ddxDriverMajorVersion = 0; if (ddxDriverMinorVersion) *ddxDriverMinorVersion = 0; if (ddxDriverPatchVersion) *ddxDriverPatchVersion = 0; if (clientDriverName) *clientDriverName = NULL; libadl_handle = dlopen("libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL); if (!libadl_handle) goto end; dlerror(); ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) dlsym(libadl_handle,"ADL_Main_Control_Create"); if (dlerror()) goto end; ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY) dlsym(libadl_handle,"ADL_Main_Control_Destroy"); if (dlerror()) goto end; ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) dlsym(libadl_handle,"ADL_Adapter_NumberOfAdapters_Get"); if (dlerror()) goto end; ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET) dlsym(libadl_handle,"ADL_Adapter_AdapterInfo_Get"); if (dlerror()) goto end; ADL_Adapter_XScreenInfo_Get = (ADL_ADAPTER_XSCREENINFO_GET) dlsym(libadl_handle,"ADL_Adapter_XScreenInfo_Get"); if (dlerror()) goto end; if (ADL_Main_Control_Create(ADL_Main_Memory_Alloc, 1) != ADL_OK) goto end; is_adl_initialized = 1; if (ADL_Adapter_NumberOfAdapters_Get(&num_adapters) != ADL_OK) goto end; if (num_adapters <= 0) goto end; lpAdapterInfo_size = num_adapters * sizeof(*lpAdapterInfo); lpAdapterInfo = ADL_Main_Memory_Alloc(lpAdapterInfo_size); if (!lpAdapterInfo) goto end; memset(lpAdapterInfo, 0, lpAdapterInfo_size); for (i = 0; i < num_adapters; i++) lpAdapterInfo[i].iSize = sizeof(lpAdapterInfo[i]); lpXScreenInfo_size = num_adapters * sizeof(*lpXScreenInfo); lpXScreenInfo = ADL_Main_Memory_Alloc(lpXScreenInfo_size); if (!lpXScreenInfo) goto end; memset(lpXScreenInfo, 0, lpXScreenInfo_size); if (ADL_Adapter_AdapterInfo_Get(lpAdapterInfo, lpAdapterInfo_size) != ADL_OK) goto end; if (ADL_Adapter_XScreenInfo_Get(lpXScreenInfo, lpXScreenInfo_size) != ADL_OK) goto end; for (i = 0; i < num_adapters; i++) { LPXScreenInfo const lpCurrXScreenInfo = &lpXScreenInfo[i]; LPAdapterInfo const lpCurrAdapterInfo = &lpAdapterInfo[i]; if (!lpCurrAdapterInfo->iPresent) continue; #if 0 printf("Adapter %d:\n", i); printf(" iAdapterIndex: %d\n", lpCurrAdapterInfo->iAdapterIndex); printf(" strUDID: '%s'\n", lpCurrAdapterInfo->strUDID); printf(" iBusNumber: %d\n", lpCurrAdapterInfo->iBusNumber); printf(" iDeviceNumber: %d\n", lpCurrAdapterInfo->iDeviceNumber); printf(" iFunctionNumber: %d\n", lpCurrAdapterInfo->iFunctionNumber); printf(" iVendorID: 0x%04x\n", lpCurrAdapterInfo->iVendorID); printf(" strAdapterName: '%s'\n", lpCurrAdapterInfo->strAdapterName); printf(" strDisplayName: '%s'\n", lpCurrAdapterInfo->strDisplayName); printf(" iPresent: %d\n", lpCurrAdapterInfo->iPresent); printf(" iXScreenNum: %d\n", lpCurrXScreenInfo->iXScreenNum); #endif if (screen == lpCurrXScreenInfo->iXScreenNum && match_display_name(dpy, lpCurrAdapterInfo->strDisplayName)) { if (clientDriverName) *clientDriverName = strdup("fglrx"); success = True; break; } } end: if (lpXScreenInfo) ADL_Main_Memory_Free(&lpXScreenInfo); if (lpAdapterInfo) ADL_Main_Memory_Free(&lpAdapterInfo); if (is_adl_initialized) ADL_Main_Control_Destroy(); if (libadl_handle) dlclose(libadl_handle); return success; }
HRESULT CGPUUsage::Init(CString DeviceName) { Clean(); { // ATI OverDrive ATIData.hAtiADL = LoadLibrary(L"atiadlxx.dll"); if (ATIData.hAtiADL == NULL) { ATIData.hAtiADL = LoadLibrary(L"atiadlxy.dll"); } if (ATIData.hAtiADL) { ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create; ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get; ADL_ADAPTER_ADAPTERINFO_GET ADL_Adapter_AdapterInfo_Get; ADL_ADAPTER_ACTIVE_GET ADL_Adapter_Active_Get; ADL_OVERDRIVE_CAPS ADL_Overdrive_Caps; ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE)GetProcAddress(ATIData.hAtiADL,"ADL_Main_Control_Create"); ATIData.ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY)GetProcAddress(ATIData.hAtiADL,"ADL_Main_Control_Destroy"); ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET)GetProcAddress(ATIData.hAtiADL,"ADL_Adapter_NumberOfAdapters_Get"); ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET)GetProcAddress(ATIData.hAtiADL,"ADL_Adapter_AdapterInfo_Get"); ADL_Adapter_Active_Get = (ADL_ADAPTER_ACTIVE_GET)GetProcAddress(ATIData.hAtiADL, "ADL_Adapter_Active_Get"); ADL_Overdrive_Caps = (ADL_OVERDRIVE_CAPS)GetProcAddress(ATIData.hAtiADL, "ADL_Overdrive_Caps"); if (NULL == ADL_Main_Control_Create || NULL == ATIData.ADL_Main_Control_Destroy || NULL == ADL_Adapter_NumberOfAdapters_Get || NULL == ADL_Adapter_AdapterInfo_Get || NULL == ADL_Adapter_Active_Get || NULL == ADL_Overdrive_Caps) { Clean(); } if (ATIData.hAtiADL) { int iNumberAdapters = 0; if (ADL_OK == ADL_Main_Control_Create(ADL_Main_Memory_Alloc, 1) && ADL_OK == ADL_Adapter_NumberOfAdapters_Get(&iNumberAdapters) && iNumberAdapters) { LPAdapterInfo lpAdapterInfo = DNew AdapterInfo[iNumberAdapters]; if (lpAdapterInfo) { memset(lpAdapterInfo, 0, sizeof(AdapterInfo) * iNumberAdapters); // Get the AdapterInfo structure for all adapters in the system ADL_Adapter_AdapterInfo_Get(lpAdapterInfo, sizeof(AdapterInfo) * iNumberAdapters); for (int i = 0; i < iNumberAdapters; i++ ) { int adapterActive = 0; AdapterInfo adapterInfo = lpAdapterInfo[i]; ADL_Adapter_Active_Get(adapterInfo.iAdapterIndex, &adapterActive); if (adapterActive && adapterInfo.iAdapterIndex >= 0 && adapterInfo.iVendorID == 1002) { if (DeviceName.GetLength() && DeviceName != CString(adapterInfo.strDisplayName)) { continue; } int iOverdriveSupported = 0; int iOverdriveEnabled = 0; if (ADL_OK != ADL_Overdrive_Caps(adapterInfo.iAdapterIndex, &iOverdriveSupported, &iOverdriveEnabled, &ATIData.iOverdriveVersion) || !iOverdriveSupported) { break; } if (ATIData.iOverdriveVersion == 5) { ADL_OVERDRIVE5_ODPARAMETERS_GET ADL_Overdrive5_ODParameters_Get; ADL_Overdrive5_ODParameters_Get = (ADL_OVERDRIVE5_ODPARAMETERS_GET)GetProcAddress(ATIData.hAtiADL, "ADL_Overdrive5_ODParameters_Get"); ATIData.ADL_Overdrive5_CurrentActivity_Get = (ADL_OVERDRIVE5_CURRENTACTIVITY_GET)GetProcAddress(ATIData.hAtiADL, "ADL_Overdrive5_CurrentActivity_Get"); if (NULL == ADL_Overdrive5_ODParameters_Get || NULL == ATIData.ADL_Overdrive5_CurrentActivity_Get) { break; } ADLODParameters overdriveParameters = {0}; overdriveParameters.iSize = sizeof (ADLODParameters); if (ADL_OK != ADL_Overdrive5_ODParameters_Get(adapterInfo.iAdapterIndex, &overdriveParameters) || !overdriveParameters.iActivityReportingSupported) { break; } ATIData.iAdapterId = adapterInfo.iAdapterIndex; } else if (ATIData.iOverdriveVersion == 6) { ADL_OVERDRIVE6_CAPABILITIES_GET ADL_Overdrive6_Capabilities_Get; ADL_Overdrive6_Capabilities_Get = (ADL_OVERDRIVE6_CAPABILITIES_GET)GetProcAddress(ATIData.hAtiADL, "ADL_Overdrive6_Capabilities_Get"); ATIData.ADL_Overdrive6_CurrentStatus_Get = (ADL_OVERDRIVE6_CURRENTSTATUS_GET)GetProcAddress(ATIData.hAtiADL, "ADL_Overdrive6_CurrentStatus_Get"); if (NULL == ADL_Overdrive6_Capabilities_Get || NULL == ATIData.ADL_Overdrive6_CurrentStatus_Get) { break; } ADLOD6Capabilities od6Capabilities = {0}; if (ADL_OK != ADL_Overdrive6_Capabilities_Get(adapterInfo.iAdapterIndex, &od6Capabilities) || (od6Capabilities.iCapabilities & ADL_OD6_CAPABILITY_GPU_ACTIVITY_MONITOR) != ADL_OD6_CAPABILITY_GPU_ACTIVITY_MONITOR) { break; } ATIData.iAdapterId = adapterInfo.iAdapterIndex; } break; } } delete [] lpAdapterInfo; } } } } if (ATIData.iAdapterId == -1 && ATIData.hAtiADL) { Clean(); } if (ATIData.iAdapterId >= 0 && ATIData.hAtiADL) { m_GPUType = ATI_GPU; } } if (m_GPUType == UNKNOWN_GPU) { // NVApi NVData.hNVApi = LoadLibrary(L"nvapi64.dll"); if (NVData.hNVApi == NULL) { NVData.hNVApi = LoadLibrary(L"nvapi.dll"); } if (NVData.hNVApi) { NvAPI_QueryInterface_t NvAPI_QueryInterface = (NvAPI_QueryInterface_t)GetProcAddress(NVData.hNVApi, "nvapi_QueryInterface"); NvAPI_Initialize_t NvAPI_Initialize = NULL; NvAPI_EnumPhysicalGPUs_t NvAPI_EnumPhysicalGPUs = NULL; if (NvAPI_QueryInterface) { NvAPI_Initialize = (NvAPI_Initialize_t)(NvAPI_QueryInterface)(0x0150E828); NvAPI_EnumPhysicalGPUs = (NvAPI_EnumPhysicalGPUs_t)(NvAPI_QueryInterface)(0xE5AC921F); NVData.NvAPI_GPU_GetUsages = (NvAPI_GPU_GetUsages_t)(NvAPI_QueryInterface)(0x189A1FDF); } if (NULL == NvAPI_QueryInterface || NULL == NvAPI_Initialize || NULL == NvAPI_EnumPhysicalGPUs || NULL == NVData.NvAPI_GPU_GetUsages) { Clean(); } if (NVData.hNVApi) { NvAPI_Initialize(); int gpuCount = 0; NvAPI_EnumPhysicalGPUs(NVData.gpuHandles, &gpuCount); if (!gpuCount) { Clean(); } } } if (NVData.hNVApi && NVData.NvAPI_GPU_GetUsages) { m_GPUType = NVIDIA_GPU; } } return m_GPUType == UNKNOWN_GPU ? E_FAIL : S_OK; }