Skip to content

Commit f139148

Browse files
committed
GPU (Windows): add OverdriveN functions for AMD
1 parent e2ec2c6 commit f139148

File tree

2 files changed

+127
-63
lines changed

2 files changed

+127
-63
lines changed

src/detection/gpu/adl.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,42 @@ extern int ADL2_Main_Control_Destroy(ADL_CONTEXT_HANDLE context);
1515
extern int ADL2_Adapter_AdapterInfoX3_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, int* numAdapters, AdapterInfo** lppAdapterInfo);
1616

1717
// Function to retrieve Graphic Core Info.
18-
// Return ADL_OK on success
1918
extern int ADL2_Adapter_Graphic_Core_Info_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, ADLGraphicCoreInfo* pGraphicCoreInfo);
2019

2120
// Function to retrieve memory information from the adapter. Version 2
22-
// Return ADL_OK on success
2321
extern int ADL2_Adapter_MemoryInfo2_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, ADLMemoryInfo2* lpMemoryInfo2);
2422

2523
// This function retrieves the VRAM usage of given adapter.
26-
// Return ADL_OK on success
2724
extern int ADL2_Adapter_VRAMUsage_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, int* iVRAMUsageInMB);
2825

2926
// This function retrieves the Dedicated VRAM usage of given adapter.
30-
// Return ADL_OK on success
3127
extern int ADL2_Adapter_DedicatedVRAMUsage_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, int* iVRAMUsageInMB);
3228

3329
// Function to get the ASICFamilyType from the adapter.
34-
// Return ADL_OK on success
3530
extern int ADL2_Adapter_ASICFamilyType_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, int* lpAsicTypes, int* lpValids);
3631

3732

3833
// Function to retrieve current power management capabilities.
39-
// Return ADL_OK on success
4034
extern int ADL2_Overdrive_Caps(ADL_CONTEXT_HANDLE context, int iAdapterIndex, int* iSupported, int* iEnabled, int* iVersion);
4135

4236
/////////// Overdrive 6 functions
4337

4438
// Function to retrieve current Overdrive and performance-related activity.
45-
// Return ADL_OK on success
4639
extern int ADL2_Overdrive6_CurrentStatus_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, ADLOD6CurrentStatus* lpCurrentStatus);
4740

4841
// Function to retrieve GPU temperature from the thermal controller.
49-
// Return ADL_OK on success
5042
extern int ADL2_Overdrive6_Temperature_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, int* lpTemperature);
5143

5244
// Function to retrieve the current or default Overdrive clock ranges.
53-
// Return ADL_OK on success
5445
extern int ADL2_Overdrive6_StateInfo_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, int iStateType, ADLOD6StateInfo* lpStateInfo);
5546

5647
/// Overdrive 8 functions
48+
49+
// Function to retrieve the OverdriveN capabilities.
50+
extern int ADL2_OverdriveN_Capabilities_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, ADLODNCapabilities* lpODCapabilities);
51+
52+
// Function to retrieve the current OD performance status.
53+
extern int ADL2_OverdriveN_PerformanceStatus_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, ADLODNPerformanceStatus *lpODPerformanceStatus);
54+
55+
// Function to retrieve the current temperature.
56+
extern int ADL2_OverdriveN_Temperature_Get(ADL_CONTEXT_HANDLE context, int iAdapterIndex, int iTemperatureType, int *iTemperature);

src/detection/gpu/gpu_amd.c

Lines changed: 118 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ struct FFAdlData {
5050
FF_LIBRARY_SYMBOL(ADL2_Adapter_VRAMUsage_Get)
5151
FF_LIBRARY_SYMBOL(ADL2_Adapter_ASICFamilyType_Get)
5252
FF_LIBRARY_SYMBOL(ADL2_Overdrive_Caps)
53+
FF_LIBRARY_SYMBOL(ADL2_OverdriveN_Capabilities_Get)
54+
FF_LIBRARY_SYMBOL(ADL2_OverdriveN_PerformanceStatus_Get)
55+
FF_LIBRARY_SYMBOL(ADL2_OverdriveN_Temperature_Get)
5356
FF_LIBRARY_SYMBOL(ADL2_Overdrive6_CurrentStatus_Get)
5457
FF_LIBRARY_SYMBOL(ADL2_Overdrive6_Temperature_Get)
5558
FF_LIBRARY_SYMBOL(ADL2_Overdrive6_StateInfo_Get)
@@ -77,27 +80,20 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
7780
adlData.inited = true;
7881
FF_DEBUG("Initializing ADL library");
7982
FF_LIBRARY_LOAD(atiadl, "dlopen atiadlxx failed", soName , 1);
80-
FF_DEBUG("Loading ADL2_Main_Control_Create");
8183
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(atiadl, ADL2_Main_Control_Create)
82-
FF_DEBUG("Loading ADL2_Main_Control_Destroy");
8384
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Main_Control_Destroy)
84-
FF_DEBUG("Loading ADL2_Adapter_AdapterInfoX3_Get");
8585
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Adapter_AdapterInfoX3_Get)
86-
FF_DEBUG("Loading ADL2_Adapter_Graphic_Core_Info_Get");
8786
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Adapter_Graphic_Core_Info_Get)
88-
FF_DEBUG("Loading ADL2_Adapter_MemoryInfo2_Get");
8987
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Adapter_MemoryInfo2_Get)
90-
FF_DEBUG("Loading ADL2_Adapter_DedicatedVRAMUsage_Get");
9188
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Adapter_DedicatedVRAMUsage_Get)
92-
FF_DEBUG("Loading ADL2_Adapter_VRAMUsage_Get");
9389
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Adapter_VRAMUsage_Get)
94-
FF_DEBUG("Loading ADL2_Adapter_ASICFamilyType_Get");
9590
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Adapter_ASICFamilyType_Get)
96-
FF_DEBUG("Loading ADL2_Overdrive6_CurrentStatus_Get");
91+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Overdrive_Caps)
92+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_OverdriveN_Capabilities_Get)
93+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_OverdriveN_PerformanceStatus_Get)
94+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_OverdriveN_Temperature_Get)
9795
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Overdrive6_CurrentStatus_Get)
98-
FF_DEBUG("Loading ADL2_Overdrive6_Temperature_Get");
9996
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Overdrive6_Temperature_Get)
100-
FF_DEBUG("Loading ADL2_Overdrive6_StateInfo_Get");
10197
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(atiadl, adlData, ADL2_Overdrive6_StateInfo_Get)
10298
FF_DEBUG("ADL library loaded");
10399

@@ -247,71 +243,139 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
247243
FF_DEBUG("Setting adapter name: %s", device->strAdapterName);
248244
}
249245

250-
adlData.ffADL2_Overdrive_Caps(adlData.apiHandle, device->iAdapterIndex, NULL, NULL, NULL);
246+
int overdrive_supported = 0;
247+
int odParam = 0;
248+
int activity_supported = 0;
249+
int caps_status = adlData.ffADL2_Overdrive_Caps(adlData.apiHandle, device->iAdapterIndex, &overdrive_supported, &odParam, &activity_supported);
250+
FF_DEBUG("ADL2_Overdrive_Caps returned %s (%d), overdrive_supported: %d", ffAdlStatusToString(caps_status), caps_status, overdrive_supported);
251251

252-
if (result.frequency)
252+
if (overdrive_supported >= 7)
253253
{
254-
ADLOD6StateInfo stateInfo;
255-
int status = adlData.ffADL2_Overdrive6_StateInfo_Get(adlData.apiHandle, device->iAdapterIndex, ADL_OD6_GETSTATEINFO_CUSTOM_PERFORMANCE, &stateInfo);
256-
FF_DEBUG("ADL2_Overdrive6_StateInfo_Get returned %s (%d), performance levels: %d",
257-
ffAdlStatusToString(status), status, stateInfo.iNumberOfPerformanceLevels);
254+
FF_DEBUG("Using OverdriveN API");
258255

259-
if (status == ADL_OK)
256+
if (result.frequency)
260257
{
261-
int clock = 0; // assume in 10 kHz
262-
for (int i = 0; i < stateInfo.iNumberOfPerformanceLevels; i++)
258+
ADLODNCapabilities odCapabilities;
259+
int status = adlData.ffADL2_OverdriveN_Capabilities_Get(adlData.apiHandle, device->iAdapterIndex, &odCapabilities);
260+
FF_DEBUG("ADL2_OverdriveN_Capabilities_Get returned %s (%d)", ffAdlStatusToString(status), status);
261+
262+
if (status == ADL_OK)
263263
{
264-
FF_DEBUG("Performance level %d: engine clock = %d", i, stateInfo.aLevels[i].iEngineClock);
265-
if (stateInfo.aLevels[i].iEngineClock > clock)
266-
clock = stateInfo.aLevels[i].iEngineClock;
264+
*result.frequency = (uint32_t) odCapabilities.sEngineClockRange.iMax / 100; // assume in 10 KHz
265+
FF_DEBUG("Got max engine clock: %u MHz", *result.frequency);
266+
}
267+
else
268+
{
269+
FF_DEBUG("Failed to get frequency information");
267270
}
268-
*result.frequency = (uint32_t) clock / 100;
269-
FF_DEBUG("Using max engine clock: %u MHz", *result.frequency);
270-
}
271-
else
272-
{
273-
FF_DEBUG("Failed to get frequency information");
274271
}
275-
}
276-
277-
if (result.coreUsage)
278-
{
279-
ADLOD6CurrentStatus status;
280-
int apiStatus = adlData.ffADL2_Overdrive6_CurrentStatus_Get(adlData.apiHandle, device->iAdapterIndex, &status);
281-
FF_DEBUG("ADL2_Overdrive6_CurrentStatus_Get returned %s (%d)", ffAdlStatusToString(apiStatus), apiStatus);
282272

283-
if (apiStatus == ADL_OK)
273+
if (result.coreUsage)
284274
{
285-
if (result.coreUsage)
275+
ADLODNPerformanceStatus performanceStatus;
276+
int status = adlData.ffADL2_OverdriveN_PerformanceStatus_Get(adlData.apiHandle, device->iAdapterIndex, &performanceStatus);
277+
FF_DEBUG("ADL2_OverdriveN_PerformanceStatus_Get returned %s (%d)", ffAdlStatusToString(status), status);
278+
279+
if (status == ADL_OK)
286280
{
287-
*result.coreUsage = status.iActivityPercent;
288-
FF_DEBUG("Got GPU activity: %d%%", status.iActivityPercent);
281+
*result.coreUsage = performanceStatus.iGPUActivityPercent;
282+
FF_DEBUG("Got GPU activity: %d%%", performanceStatus.iGPUActivityPercent);
283+
}
284+
else
285+
{
286+
FF_DEBUG("Failed to get GPU activity");
289287
}
290288
}
291-
else
289+
290+
if (result.temp)
292291
{
293-
FF_DEBUG("Failed to get GPU activity");
292+
int milliDegrees = 0;
293+
int status = adlData.ffADL2_OverdriveN_Temperature_Get(adlData.apiHandle, device->iAdapterIndex, 1, &milliDegrees);
294+
FF_DEBUG("ADL2_OverdriveN_Temperature_Get returned %s (%d), temperature: %d milliC",
295+
ffAdlStatusToString(status), status, milliDegrees);
296+
297+
if (status == ADL_OK)
298+
{
299+
*result.temp = milliDegrees / 1000.0;
300+
FF_DEBUG("Temperature: %.1f°C", *result.temp);
301+
}
302+
else
303+
{
304+
FF_DEBUG("Failed to get temperature");
305+
}
294306
}
295307
}
296-
297-
if (result.temp)
308+
else if (overdrive_supported >= 6)
298309
{
299-
int milliDegrees = 0;
300-
int status = adlData.ffADL2_Overdrive6_Temperature_Get(adlData.apiHandle, device->iAdapterIndex, &milliDegrees);
301-
FF_DEBUG("ADL2_Overdrive6_Temperature_Get returned %s (%d), temperature: %d milliC",
302-
ffAdlStatusToString(status), status, milliDegrees);
310+
FF_DEBUG("Using Overdrive8 API; to be supported");
311+
}
312+
else
313+
{
314+
FF_DEBUG("Using Overdrive6 API");
303315

304-
if (status == ADL_OK)
316+
if (result.frequency)
305317
{
306-
*result.temp = milliDegrees / 1000.0;
307-
FF_DEBUG("Temperature: %.1f°C", *result.temp);
318+
ADLOD6StateInfo stateInfo;
319+
int status = adlData.ffADL2_Overdrive6_StateInfo_Get(adlData.apiHandle, device->iAdapterIndex, ADL_OD6_GETSTATEINFO_CUSTOM_PERFORMANCE, &stateInfo);
320+
FF_DEBUG("ADL2_Overdrive6_StateInfo_Get returned %s (%d), performance levels: %d",
321+
ffAdlStatusToString(status), status, stateInfo.iNumberOfPerformanceLevels);
322+
323+
if (status == ADL_OK)
324+
{
325+
int clock = 0; // assume in 10 kHz
326+
for (int i = 0; i < stateInfo.iNumberOfPerformanceLevels; i++)
327+
{
328+
FF_DEBUG("Performance level %d: engine clock = %d", i, stateInfo.aLevels[i].iEngineClock);
329+
if (stateInfo.aLevels[i].iEngineClock > clock)
330+
clock = stateInfo.aLevels[i].iEngineClock;
331+
}
332+
*result.frequency = (uint32_t) clock / 100;
333+
FF_DEBUG("Using max engine clock: %u MHz", *result.frequency);
334+
}
335+
else
336+
{
337+
FF_DEBUG("Failed to get frequency information");
338+
}
308339
}
309-
else
340+
341+
if (result.coreUsage)
310342
{
311-
FF_DEBUG("Failed to get temperature");
343+
ADLOD6CurrentStatus status;
344+
int apiStatus = adlData.ffADL2_Overdrive6_CurrentStatus_Get(adlData.apiHandle, device->iAdapterIndex, &status);
345+
FF_DEBUG("ADL2_Overdrive6_CurrentStatus_Get returned %s (%d)", ffAdlStatusToString(apiStatus), apiStatus);
346+
347+
if (apiStatus == ADL_OK)
348+
{
349+
if (result.coreUsage)
350+
{
351+
*result.coreUsage = status.iActivityPercent;
352+
FF_DEBUG("Got GPU activity: %d%%", status.iActivityPercent);
353+
}
354+
}
355+
else
356+
{
357+
FF_DEBUG("Failed to get GPU activity");
358+
}
312359
}
313-
}
314360

361+
if (result.temp)
362+
{
363+
int milliDegrees = 0;
364+
int status = adlData.ffADL2_Overdrive6_Temperature_Get(adlData.apiHandle, device->iAdapterIndex, &milliDegrees);
365+
FF_DEBUG("ADL2_Overdrive6_Temperature_Get returned %s (%d), temperature: %d milliC",
366+
ffAdlStatusToString(status), status, milliDegrees);
367+
368+
if (status == ADL_OK)
369+
{
370+
*result.temp = milliDegrees / 1000.0;
371+
FF_DEBUG("Temperature: %.1f°C", *result.temp);
372+
}
373+
else
374+
{
375+
FF_DEBUG("Failed to get temperature");
376+
}
377+
}
378+
}
315379
FF_DEBUG("AMD GPU detection complete");
316380
return NULL;
317381
}

0 commit comments

Comments
 (0)