@@ -51,8 +51,11 @@ struct FFAdlData {
5151    FF_LIBRARY_SYMBOL (ADL2_Adapter_ASICFamilyType_Get )
5252    FF_LIBRARY_SYMBOL (ADL2_Overdrive_Caps )
5353    FF_LIBRARY_SYMBOL (ADL2_OverdriveN_Capabilities_Get )
54+     FF_LIBRARY_SYMBOL (ADL2_OverdriveN_SystemClocks_Get )
5455    FF_LIBRARY_SYMBOL (ADL2_OverdriveN_PerformanceStatus_Get )
5556    FF_LIBRARY_SYMBOL (ADL2_OverdriveN_Temperature_Get )
57+     FF_LIBRARY_SYMBOL (ADL2_Overdrive8_Current_Setting_Get )
58+     FF_LIBRARY_SYMBOL (ADL2_New_QueryPMLogData_Get )
5659    FF_LIBRARY_SYMBOL (ADL2_Overdrive6_CurrentStatus_Get )
5760    FF_LIBRARY_SYMBOL (ADL2_Overdrive6_Temperature_Get )
5861    FF_LIBRARY_SYMBOL (ADL2_Overdrive6_StateInfo_Get )
@@ -90,7 +93,10 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
9093        FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_Adapter_ASICFamilyType_Get )
9194        FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_Overdrive_Caps )
9295        FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_OverdriveN_Capabilities_Get )
96+         FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_OverdriveN_SystemClocks_Get )
9397        FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_OverdriveN_PerformanceStatus_Get )
98+         FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_Overdrive8_Current_Setting_Get )
99+         FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_New_QueryPMLogData_Get )
94100        FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_OverdriveN_Temperature_Get )
95101        FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_Overdrive6_CurrentStatus_Get )
96102        FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (atiadl , adlData , ADL2_Overdrive6_Temperature_Get )
@@ -163,6 +169,7 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
163169
164170        if  (status  ==  ADL_OK )
165171        {
172+             FF_DEBUG ("Core info - NumCUs: %d, NumPEsPerCU: %d" , coreInfo .iNumCUs , coreInfo .iNumPEsPerCU );
166173            * result .coreCount  =  (uint32_t ) coreInfo .iNumCUs  *  (uint32_t ) coreInfo .iNumPEsPerCU ;
167174            FF_DEBUG ("Got core count: %u" , * result .coreCount );
168175        }
@@ -179,8 +186,12 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
179186        FF_DEBUG ("ADL2_Adapter_DedicatedVRAMUsage_Get returned %s (%d), usage: %d MB" ,
180187            ffAdlStatusToString (status ), status , vramUsage );
181188
182-         if  (status  ==  ADL_OK )
189+         if  (status  ==  ADL_OK ) { 
183190            result .memory -> used  =  (uint64_t ) vramUsage  *  1024  *  1024 ;
191+             FF_DEBUG ("Dedicated VRAM usage: %llu bytes (%d MB)" , result .memory -> used , vramUsage );
192+         } else  {
193+             FF_DEBUG ("Failed to get dedicated VRAM usage" );
194+         }
184195
185196        if  (result .sharedMemory )
186197        {
@@ -189,8 +200,14 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
189200            FF_DEBUG ("ADL2_Adapter_VRAMUsage_Get returned %s (%d), usage: %d MB" ,
190201                ffAdlStatusToString (status ), status , vramUsage );
191202
192-             if  (status  ==  ADL_OK )
193-                 result .sharedMemory -> used  =  (uint64_t ) vramUsage  *  1024  *  1024  -  result .memory -> used ;
203+             if  (status  ==  ADL_OK ) {
204+                 uint64_t  totalUsage  =  (uint64_t ) vramUsage  *  1024  *  1024 ;
205+                 result .sharedMemory -> used  =  totalUsage  -  result .memory -> used ;
206+                 FF_DEBUG ("Total VRAM usage: %llu bytes, Shared VRAM usage: %llu bytes (%llu MB)" ,
207+                          totalUsage , result .sharedMemory -> used , result .sharedMemory -> used  / (1024  *  1024 ));
208+             } else  {
209+                 FF_DEBUG ("Failed to get total VRAM usage" );
210+             }
194211        }
195212    }
196213
@@ -202,6 +219,7 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
202219
203220        if  (status  ==  ADL_OK )
204221        {
222+             FF_DEBUG ("Memory info - Type: %s, Size: %lld MB" , memoryInfo .strMemoryType , memoryInfo .iMemorySize  / 1024  / 1024 );
205223            ffStrbufSetS (result .memoryType , memoryInfo .strMemoryType );
206224            FF_DEBUG ("Got memory type: %s" , memoryInfo .strMemoryType );
207225        }
@@ -223,7 +241,8 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
223241        {
224242            asicTypes  &= valids ; // This design is strange 
225243            * result .type  =  asicTypes  &  ADL_ASIC_INTEGRATED  ? FF_GPU_TYPE_INTEGRATED  : FF_GPU_TYPE_DISCRETE ;
226-             FF_DEBUG ("GPU type: %s" , * result .type  ==  FF_GPU_TYPE_INTEGRATED  ? "Integrated"  : "Discrete" );
244+             FF_DEBUG ("GPU type: %s (asicTypes: 0x%x, valids: 0x%x)" ,
245+                     * result .type  ==  FF_GPU_TYPE_INTEGRATED  ? "Integrated"  : "Discrete" , asicTypes , valids );
227246        }
228247        else 
229248        {
@@ -240,7 +259,7 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
240259    if  (result .name )
241260    {
242261        ffStrbufSetS (result .name , device -> strAdapterName );
243-         FF_DEBUG ("Setting adapter name: %s" , device -> strAdapterName );
262+         FF_DEBUG ("Setting adapter name: %s; UDID: %s, Present: %d, Exist: %d " , device -> strAdapterName ,  device -> strUDID ,  device -> iPresent ,  device -> iExist );
244263    }
245264
246265    int  odVersion  =  0 ;
@@ -249,23 +268,54 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
249268        int  odSupported  =  0 ;
250269        int  odEnabled  =  0 ;
251270        int  status  =  adlData .ffADL2_Overdrive_Caps (adlData .apiHandle , device -> iAdapterIndex , & odSupported , & odEnabled , & odVersion );
252-         FF_DEBUG ("ADL2_Overdrive_Caps returned %s (%d); supported %d, enabled %d; version %d" , ffAdlStatusToString (status ), status , odSupported , odEnabled , odVersion );
271+         FF_DEBUG ("ADL2_Overdrive_Caps returned %s (%d); supported %d, enabled %d; version %d" ,
272+                 ffAdlStatusToString (status ), status , odSupported , odEnabled , odVersion );
253273    }
254274
255-     if  (odVersion  >=  6 )
275+     if  (odVersion  >   8 )
256276    {
257277        FF_DEBUG ("Using OverdriveN API (odVersion=%d)" , odVersion );
258278
259279        if  (result .frequency )
260280        {
281+             // https://github.com/MaynardMiner/odvii/blob/master/OverdriveN.cpp#L176 
261282            ADLODNCapabilities  odCapabilities ;
262283            int  status  =  adlData .ffADL2_OverdriveN_Capabilities_Get (adlData .apiHandle , device -> iAdapterIndex , & odCapabilities );
263284            FF_DEBUG ("ADL2_OverdriveN_Capabilities_Get returned %s (%d)" , ffAdlStatusToString (status ), status );
264285
265286            if  (status  ==  ADL_OK )
266287            {
267-                 * result .frequency  =  (uint32_t ) odCapabilities .sEngineClockRange .iMax  / 100 ; // assume in 10 KHz 
268-                 FF_DEBUG ("Got max engine clock: %u MHz" , * result .frequency );
288+                 if  (odCapabilities .iMaximumNumberOfPerformanceLevels  ==  0 )
289+                 {
290+                     FF_DEBUG ("ADL2_OverdriveN_Capabilities_Get: no performance levels available" );
291+                 }
292+                 else 
293+                 {
294+                     FF_DEBUG ("ODN Capabilities - MaxPerformanceLevels: %d, GPU Clock Range: [%d - %d]" ,
295+                             odCapabilities .iMaximumNumberOfPerformanceLevels ,
296+                             odCapabilities .sEngineClockRange .iMin , odCapabilities .sEngineClockRange .iMax );
297+ 
298+                     size_t  size  =  sizeof (ADLODNPerformanceLevels ) +  sizeof (ADLODNPerformanceLevel ) *  ((unsigned ) odCapabilities .iMaximumNumberOfPerformanceLevels  -  1 );
299+                     FF_AUTO_FREE  ADLODNPerformanceLevels *  odPerfLevels  =  malloc (size );
300+                     * odPerfLevels  =  (ADLODNPerformanceLevels ) {
301+                         .iSize  =  (int ) size ,
302+                         .iNumberOfPerformanceLevels  =  odCapabilities .iMaximumNumberOfPerformanceLevels ,
303+                     };
304+                     int  status  =  adlData .ffADL2_OverdriveN_SystemClocks_Get (adlData .apiHandle , device -> iAdapterIndex , odPerfLevels );
305+                     FF_DEBUG ("ADL2_OverdriveN_SystemClocks_Get returned %s (%d), levels: %d" ,
306+                             ffAdlStatusToString (status ), status , odPerfLevels -> iNumberOfPerformanceLevels );
307+ 
308+                     * result .frequency  =  0 ;
309+                     for  (int  i  =  0 ; i  <  odPerfLevels -> iNumberOfPerformanceLevels ; i ++ )
310+                     {
311+                         uint32_t  clock  =  (uint32_t ) odPerfLevels -> aLevels [i ].iClock ;
312+                         FF_DEBUG ("Performance level %d: engine clock = %u" , i , clock );
313+                         if  (clock  >  * result .frequency )
314+                         * result .frequency  =  clock ;
315+                     }
316+                     * result .frequency  /= 10 ; // assume in 10 kHz 
317+                     FF_DEBUG ("Got max engine clock: %u MHz" , * result .frequency );
318+                 }
269319            }
270320            else 
271321            {
@@ -275,12 +325,17 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
275325
276326        if  (result .coreUsage )
277327        {
278-             ADLODNPerformanceStatus  performanceStatus ;
328+             ADLODNPerformanceStatus  performanceStatus   =  {} ;
279329            int  status  =  adlData .ffADL2_OverdriveN_PerformanceStatus_Get (adlData .apiHandle , device -> iAdapterIndex , & performanceStatus );
280330            FF_DEBUG ("ADL2_OverdriveN_PerformanceStatus_Get returned %s (%d)" , ffAdlStatusToString (status ), status );
281331
282332            if  (status  ==  ADL_OK )
283333            {
334+                 FF_DEBUG ("Performance Status - Activity: %d%%, CoreClock: %dMHz, MemoryClock: %dMHz" ,
335+                         performanceStatus .iGPUActivityPercent ,
336+                         performanceStatus .iCoreClock  / 100 ,
337+                         performanceStatus .iMemoryClock  / 100 );
338+ 
284339                * result .coreUsage  =  performanceStatus .iGPUActivityPercent ;
285340                FF_DEBUG ("Got GPU activity: %d%%" , performanceStatus .iGPUActivityPercent );
286341            }
@@ -294,21 +349,96 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
294349        {
295350            int  milliDegrees  =  0 ;
296351            int  status  =  adlData .ffADL2_OverdriveN_Temperature_Get (adlData .apiHandle , device -> iAdapterIndex , 1 , & milliDegrees );
297-             FF_DEBUG ("ADL2_OverdriveN_Temperature_Get returned %s (%d), temperature: %d milliC " ,
298-                 ffAdlStatusToString (status ), status ,  milliDegrees );
352+             FF_DEBUG ("ADL2_OverdriveN_Temperature_Get returned %s (%d)" ,
353+                 ffAdlStatusToString (status ), status );
299354
300355            if  (status  ==  ADL_OK )
301356            {
302357                * result .temp  =  milliDegrees  / 1000.0 ;
303-                 FF_DEBUG ("Temperature: %.1f°C" , * result .temp );
358+                 FF_DEBUG ("Temperature: %.1f°C (raw: %d milliC) " , * result .temp ,  milliDegrees );
304359            }
305360            else 
306361            {
307362                FF_DEBUG ("Failed to get temperature" );
308363            }
309364        }
310365    }
311-     else 
366+     else  if  (odVersion  ==  8 )
367+     {
368+         FF_DEBUG ("Using Overdrive8 API (odVersion=%d)" , odVersion );
369+ 
370+         if  (result .frequency )
371+         {
372+             ADLOD8CurrentSetting  currentSetting ;
373+             int  status  =  adlData .ffADL2_Overdrive8_Current_Setting_Get (adlData .apiHandle , device -> iAdapterIndex , & currentSetting );
374+             FF_DEBUG ("ADL2_Overdrive8_Current_Setting_Get returned %s (%d)" , ffAdlStatusToString (status ), status );
375+             if  (status  ==  ADL_OK )
376+             {
377+                 FF_DEBUG ("OD8 Settings count: %d" , currentSetting .count );
378+ 
379+                 * result .frequency  =  (uint32_t ) currentSetting .Od8SettingTable [OD8_GFXCLK_FMAX ];
380+                 FF_DEBUG ("Got max engine clock (OD8 GFXCLK_FMAX): %u MHz" , * result .frequency );
381+             }
382+             else 
383+             {
384+                 FF_DEBUG ("Failed to get max frequency information" );
385+             }
386+         }
387+ 
388+         if  (result .temp  ||  result .coreUsage )
389+         {
390+             ADLPMLogDataOutput  pmLogDataOutput ;
391+             int  status  =  adlData .ffADL2_New_QueryPMLogData_Get (adlData .apiHandle , device -> iAdapterIndex , & pmLogDataOutput );
392+             FF_DEBUG ("ADL2_New_QueryPMLogData_Get returned %s (%d)" , ffAdlStatusToString (status ), status );
393+             if  (status  ==  ADL_OK )
394+             {
395+                 if  (result .temp )
396+                 {
397+                     ADLSingleSensorData *  edge  =  & pmLogDataOutput .sensors [ADL_PMLOG_TEMPERATURE_EDGE ];
398+                     FF_DEBUG ("Sensor %d: %s, supported: %d, value: %d" , ADL_PMLOG_TEMPERATURE_EDGE , "ADL_PMLOG_TEMPERATURE_EDGE" , edge -> supported , edge -> value );
399+                     if  (edge -> supported )
400+                     {
401+                         * result .temp  =  edge -> value ;
402+                         FF_DEBUG ("Temperature: %.1f°C" , * result .temp );
403+                     }
404+                     else 
405+                     {
406+                         FF_DEBUG ("Sensor %d not supported" , ADL_PMLOG_TEMPERATURE_EDGE );
407+                         ADLSingleSensorData *  hotspot  =  & pmLogDataOutput .sensors [ADL_PMLOG_TEMPERATURE_EDGE ];
408+                         FF_DEBUG ("Sensor %d: %s, supported: %d, value: %d" , ADL_PMLOG_TEMPERATURE_EDGE , "ADL_PMLOG_TEMPERATURE_EDGE" , hotspot -> supported , hotspot -> value );
409+                         if  (hotspot -> supported )
410+                         {
411+                             * result .temp  =  hotspot -> value ;
412+                             FF_DEBUG ("Temperature: %.1f°C" , * result .temp );
413+                         }
414+                         else 
415+                         {
416+                             FF_DEBUG ("Sensor %d not supported" , PMLOG_TEMPERATURE_HOTSPOT );
417+                         }
418+                     }
419+                 }
420+                 if  (result .coreUsage )
421+                 {
422+                     ADLSingleSensorData *  activity  =  & pmLogDataOutput .sensors [ADL_PMLOG_INFO_ACTIVITY_GFX ];
423+                     FF_DEBUG ("Sensor %d: %s, supported: %d, value: %d" , ADL_PMLOG_INFO_ACTIVITY_GFX , "ADL_PMLOG_INFO_ACTIVITY_GFX" , activity -> supported , activity -> value );
424+                     if  (activity -> supported )
425+                     {
426+                         * result .coreUsage  =  activity -> value ;
427+                         FF_DEBUG ("Core usage: %.1f%%" , * result .coreUsage );
428+                     }
429+                     else 
430+                     {
431+                         FF_DEBUG ("Sensor %d not supported" , ADL_PMLOG_INFO_ACTIVITY_GFX );
432+                     }
433+                 }
434+             }
435+             else 
436+             {
437+                 FF_DEBUG ("Failed to get temperature / GPU activity" );
438+             }
439+         }
440+     }
441+     else  if  (odVersion  ==  6 )
312442    {
313443        FF_DEBUG ("Using Overdrive6 API (odVersion=%d)" , odVersion );
314444
@@ -372,6 +502,11 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
372502            }
373503        }
374504    }
375-     FF_DEBUG ("AMD GPU detection complete" );
505+     else 
506+     {
507+         FF_DEBUG ("Unknown Overdrive version: %d" , odVersion );
508+         return  "Unknown Overdrive version" ;
509+     }
510+     FF_DEBUG ("AMD GPU detection complete - returning success" );
376511    return  NULL ;
377512}
0 commit comments