Skip to content

Commit 187059d

Browse files
committed
GPU (Windows): fix max frequency detection for AMD ODN
1 parent 5c9f184 commit 187059d

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

src/detection/gpu/gpu_amd.c

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,33 @@
66
#include "util/debug.h"
77

88
// Helper function to convert ADL status code to string
9-
static const char* ffAdlStatusToString(int status) {
9+
FF_MAYBE_UNUSED static const char* ffAdlStatusToString(int status) {
1010
switch (status) {
11-
case ADL_OK: return "ADL_OK";
12-
case ADL_OK_WARNING: return "ADL_OK_WARNING";
13-
case ADL_OK_MODE_CHANGE: return "ADL_OK_MODE_CHANGE";
14-
case ADL_OK_RESTART: return "ADL_OK_RESTART";
15-
case ADL_OK_WAIT: return "ADL_OK_WAIT";
16-
case ADL_ERR: return "ADL_ERR";
17-
case ADL_ERR_NOT_INIT: return "ADL_ERR_NOT_INIT";
18-
case ADL_ERR_INVALID_PARAM: return "ADL_ERR_INVALID_PARAM";
19-
case ADL_ERR_INVALID_PARAM_SIZE: return "ADL_ERR_INVALID_PARAM_SIZE";
20-
case ADL_ERR_INVALID_ADL_IDX: return "ADL_ERR_INVALID_ADL_IDX";
21-
case ADL_ERR_INVALID_CONTROLLER_IDX: return "ADL_ERR_INVALID_CONTROLLER_IDX";
22-
case ADL_ERR_INVALID_DIPLAY_IDX: return "ADL_ERR_INVALID_DIPLAY_IDX";
23-
case ADL_ERR_NOT_SUPPORTED: return "ADL_ERR_NOT_SUPPORTED";
24-
case ADL_ERR_NULL_POINTER: return "ADL_ERR_NULL_POINTER";
25-
case ADL_ERR_DISABLED_ADAPTER: return "ADL_ERR_DISABLED_ADAPTER";
26-
case ADL_ERR_INVALID_CALLBACK: return "ADL_ERR_INVALID_CALLBACK";
27-
case ADL_ERR_RESOURCE_CONFLICT: return "ADL_ERR_RESOURCE_CONFLICT";
28-
case ADL_ERR_SET_INCOMPLETE: return "ADL_ERR_SET_INCOMPLETE";
29-
case ADL_ERR_NO_XDISPLAY: return "ADL_ERR_NO_XDISPLAY";
30-
case ADL_ERR_CALL_TO_INCOMPATIABLE_DRIVER: return "ADL_ERR_CALL_TO_INCOMPATIABLE_DRIVER";
31-
case ADL_ERR_NO_ADMINISTRATOR_PRIVILEGES: return "ADL_ERR_NO_ADMINISTRATOR_PRIVILEGES";
32-
case ADL_ERR_FEATURESYNC_NOT_STARTED: return "ADL_ERR_FEATURESYNC_NOT_STARTED";
33-
case ADL_ERR_INVALID_POWER_STATE: return "ADL_ERR_INVALID_POWER_STATE";
11+
#define FF_ADL_STATUS_CASE(name) case name: return #name;
12+
FF_ADL_STATUS_CASE(ADL_OK)
13+
FF_ADL_STATUS_CASE(ADL_OK_WARNING)
14+
FF_ADL_STATUS_CASE(ADL_OK_MODE_CHANGE)
15+
FF_ADL_STATUS_CASE(ADL_OK_RESTART)
16+
FF_ADL_STATUS_CASE(ADL_OK_WAIT)
17+
FF_ADL_STATUS_CASE(ADL_ERR)
18+
FF_ADL_STATUS_CASE(ADL_ERR_NOT_INIT)
19+
FF_ADL_STATUS_CASE(ADL_ERR_INVALID_PARAM)
20+
FF_ADL_STATUS_CASE(ADL_ERR_INVALID_PARAM_SIZE)
21+
FF_ADL_STATUS_CASE(ADL_ERR_INVALID_ADL_IDX)
22+
FF_ADL_STATUS_CASE(ADL_ERR_INVALID_CONTROLLER_IDX)
23+
FF_ADL_STATUS_CASE(ADL_ERR_INVALID_DIPLAY_IDX)
24+
FF_ADL_STATUS_CASE(ADL_ERR_NOT_SUPPORTED)
25+
FF_ADL_STATUS_CASE(ADL_ERR_NULL_POINTER)
26+
FF_ADL_STATUS_CASE(ADL_ERR_DISABLED_ADAPTER)
27+
FF_ADL_STATUS_CASE(ADL_ERR_INVALID_CALLBACK)
28+
FF_ADL_STATUS_CASE(ADL_ERR_RESOURCE_CONFLICT)
29+
FF_ADL_STATUS_CASE(ADL_ERR_SET_INCOMPLETE)
30+
FF_ADL_STATUS_CASE(ADL_ERR_NO_XDISPLAY)
31+
FF_ADL_STATUS_CASE(ADL_ERR_CALL_TO_INCOMPATIABLE_DRIVER)
32+
FF_ADL_STATUS_CASE(ADL_ERR_NO_ADMINISTRATOR_PRIVILEGES)
33+
FF_ADL_STATUS_CASE(ADL_ERR_FEATURESYNC_NOT_STARTED)
34+
FF_ADL_STATUS_CASE(ADL_ERR_INVALID_POWER_STATE)
35+
#undef FF_ADL_STATUS_CASE
3436
default: return "Unknown ADL error";
3537
}
3638
}
@@ -394,22 +396,17 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
394396
FF_DEBUG("ADL2_OverdriveN_SystemClocksX2_Get returned %s (%d), levels: %d",
395397
ffAdlStatusToString(status), status, odPerfLevels->iNumberOfPerformanceLevels);
396398

397-
int frequency = 0;
398-
for (int i = 0; i < odPerfLevels->iNumberOfPerformanceLevels; i++)
399+
// lowest to highest
400+
for (int i = odPerfLevels->iNumberOfPerformanceLevels - 1; i >= 0 ; i--)
399401
{
400-
ADLODNPerformanceLevelX2* level = &odPerfLevels->aLevels[i];\
402+
ADLODNPerformanceLevelX2* level = &odPerfLevels->aLevels[i];
401403
FF_DEBUG("Performance level %d: enabled: %d, engine clock = %d", i, level->iEnabled, level->iClock);
402-
if (!level->iEnabled && level->iClock > frequency)
403-
frequency = level->iClock;
404-
}
405-
if (frequency != 0)
406-
{
407-
*result.frequency = (uint32_t) frequency;
408-
FF_DEBUG("Got max engine clock: %u MHz", *result.frequency);
409-
}
410-
else
411-
{
412-
FF_DEBUG("ADL2_OverdriveN_SystemClocksX2_Get: no enabled performance levels found");
404+
if (level->iEnabled)
405+
{
406+
*result.frequency = (uint32_t) level->iClock / 100; // in 10 kHz
407+
FF_DEBUG("Got max engine clock: %u MHz", *result.frequency);
408+
break;
409+
}
413410
}
414411
}
415412
}

0 commit comments

Comments
 (0)