@@ -90,6 +90,47 @@ internal struct ADLPMLogDataOutput {
9090 public ADLSingleSensorData [ ] Sensors ;
9191 }
9292
93+ [ StructLayout ( LayoutKind . Sequential ) ]
94+ internal struct ADLODParameterRange {
95+ public int Min ;
96+ public int Max ;
97+ public int Step ;
98+ }
99+
100+ [ StructLayout ( LayoutKind . Sequential ) ]
101+ internal struct ADLODParameters {
102+ public int Size ;
103+ public int NumberOfPerformanceLevels ;
104+ public int ActivityReportingSupported ;
105+ public int DiscretePerformanceLevels ;
106+ public int Reserved ;
107+ public ADLODParameterRange EngineClock ;
108+ public ADLODParameterRange MemoryClock ;
109+ public ADLODParameterRange Vddc ;
110+ }
111+
112+ [ StructLayout ( LayoutKind . Sequential ) ]
113+ internal struct ADLODNPerformanceStatus {
114+ public int CoreClock ;
115+ public int MemoryClock ;
116+ public int DCEFClock ;
117+ public int GFXClock ;
118+ public int UVDClock ;
119+ public int VCEClock ;
120+ public int GPUActivityPercent ;
121+ public int CurrentCorePerformanceLevel ;
122+ public int CurrentMemoryPerformanceLevel ;
123+ public int CurrentDCEFPerformanceLevel ;
124+ public int CurrentGFXPerformanceLevel ;
125+ public int UVDPerformanceLevel ;
126+ public int VCEPerformanceLevel ;
127+ public int CurrentBusSpeed ;
128+ public int CurrentBusLanes ;
129+ public int MaximumBusLanes ;
130+ public int VDDC ;
131+ public int VDDCI ;
132+ }
133+
93134 internal enum ADLODNCurrentPowerType {
94135 TOTAL_POWER = 0 ,
95136 PPT_POWER ,
@@ -149,13 +190,110 @@ internal enum ADLSensorType {
149190 SMART_POWERSHIFT_DGPU = 39
150191 }
151192
193+ internal enum ADLStatus : int {
194+ /// <summary>
195+ /// All OK, but need to wait.
196+ /// </summary>
197+ OK_WAIT = 4 ,
198+
199+ /// <summary>
200+ /// All OK, but need restart.
201+ /// </summary>
202+ OK_RESTART = 3 ,
203+
204+ /// <summary>
205+ /// All OK but need mode change.
206+ /// </summary>
207+ OK_MODE_CHANGE = 2 ,
208+
209+ /// <summary>
210+ /// All OK, but with warning.
211+ /// </summary>
212+ OK_WARNING = 1 ,
213+
214+ /// <summary>
215+ /// ADL function completed successfully.
216+ /// </summary>
217+ OK = 0 ,
218+
219+ /// <summary>
220+ /// Generic Error. Most likely one or more of the Escape calls to the driver
221+ /// failed!
222+ /// </summary>
223+ ERR = - 1 ,
224+
225+ /// <summary>
226+ /// ADL not initialized.
227+ /// </summary>
228+ ERR_NOT_INIT = - 2 ,
229+
230+ /// <summary>
231+ /// One of the parameter passed is invalid.
232+ /// </summary>
233+ ERR_INVALID_PARAM = - 3 ,
234+
235+ /// <summary>
236+ /// One of the parameter size is invalid.
237+ /// </summary>
238+ ERR_INVALID_PARAM_SIZE = - 4 ,
239+
240+ /// <summary>
241+ /// Invalid ADL index passed.
242+ /// </summary>
243+ ERR_INVALID_ADL_IDX = - 5 ,
244+
245+ /// <summary>
246+ /// Invalid controller index passed.
247+ /// </summary>
248+ ERR_INVALID_CONTROLLER_IDX = - 6 ,
249+
250+ /// <summary>
251+ /// Invalid display index passed.
252+ /// </summary>
253+ ERR_INVALID_DIPLAY_IDX = - 7 ,
254+
255+ /// <summary>
256+ /// Function not supported by the driver.
257+ /// </summary>
258+ ERR_NOT_SUPPORTED = - 8 ,
259+
260+ /// <summary>
261+ /// Null Pointer error.
262+ /// </summary>
263+ ERR_NULL_POINTER = - 9 ,
264+
265+ /// <summary>
266+ /// Call can't be made due to disabled adapter.
267+ /// </summary>
268+ ERR_DISABLED_ADAPTER = - 10 ,
269+
270+ /// <summary>
271+ /// Invalid Callback.
272+ /// </summary>
273+ ERR_INVALID_CALLBACK = - 11 ,
274+
275+ /// <summary>
276+ /// Display Resource conflict.
277+ /// </summary>
278+ ERR_RESOURCE_CONFLICT = - 12 ,
279+
280+ /// <summary>
281+ /// Failed to update some of the values. Can be returned by set request that
282+ /// include multiple values if not all values were successfully committed.
283+ /// </summary>
284+ ERR_SET_INCOMPLETE = - 20 ,
285+
286+ /// <summary>
287+ /// There's no Linux XDisplay in Linux Console environment.
288+ /// </summary>
289+ ERR_NO_XDISPLAY = - 21
290+ }
291+
152292 internal class ADL {
153293 public const int ADL_MAX_PATH = 256 ;
154294 public const int ADL_MAX_ADAPTERS = 40 ;
155295 public const int ADL_MAX_DISPLAYS = 40 ;
156296 public const int ADL_MAX_DEVICENAME = 32 ;
157- public const int ADL_OK = 0 ;
158- public const int ADL_ERR = - 1 ;
159297 public const int ADL_DRIVER_OK = 0 ;
160298 public const int ADL_MAX_GLSYNC_PORTS = 8 ;
161299 public const int ADL_MAX_GLSYNC_PORT_LEDS = 8 ;
@@ -173,47 +311,52 @@ internal class ADL {
173311
174312 public const int ATI_VENDOR_ID = 0x1002 ;
175313
176- private delegate int ADL_Main_Control_CreateDelegate (
314+ private delegate ADLStatus ADL_Main_Control_CreateDelegate (
177315 ADL_Main_Memory_AllocDelegate callback , int enumConnectedAdapters ) ;
178- private delegate int ADL_Adapter_AdapterInfo_GetDelegate ( IntPtr info ,
316+ private delegate ADLStatus ADL_Adapter_AdapterInfo_GetDelegate ( IntPtr info ,
179317 int size ) ;
180318
181- public delegate int ADL_Main_Control_DestroyDelegate ( ) ;
182- public delegate int ADL_Adapter_NumberOfAdapters_GetDelegate (
319+ public delegate ADLStatus ADL_Main_Control_DestroyDelegate ( ) ;
320+ public delegate ADLStatus ADL_Adapter_NumberOfAdapters_GetDelegate (
183321 ref int numAdapters ) ;
184- public delegate int ADL_Adapter_ID_GetDelegate ( int adapterIndex ,
322+ public delegate ADLStatus ADL_Adapter_ID_GetDelegate ( int adapterIndex ,
185323 out int adapterID ) ;
186- public delegate int ADL_Display_AdapterID_GetDelegate ( int adapterIndex ,
324+ public delegate ADLStatus ADL_Display_AdapterID_GetDelegate ( int adapterIndex ,
187325 out int adapterID ) ;
188326 public delegate int ADL_Adapter_Active_GetDelegate ( int adapterIndex ,
189327 out int status ) ;
190- public delegate int ADL_Overdrive5_CurrentActivity_GetDelegate (
328+ public delegate ADLStatus ADL_Overdrive5_CurrentActivity_GetDelegate (
191329 int iAdapterIndex , ref ADLPMActivity activity ) ;
192- public delegate int ADL_Overdrive5_Temperature_GetDelegate ( int adapterIndex ,
330+ public delegate ADLStatus ADL_Overdrive5_Temperature_GetDelegate ( int adapterIndex ,
193331 int thermalControllerIndex , ref ADLTemperature temperature ) ;
194- public delegate int ADL_Overdrive5_FanSpeed_GetDelegate ( int adapterIndex ,
332+ public delegate ADLStatus ADL_Overdrive5_FanSpeed_GetDelegate ( int adapterIndex ,
195333 int thermalControllerIndex , ref ADLFanSpeedValue fanSpeedValue ) ;
196- public delegate int ADL_Overdrive5_FanSpeedInfo_GetDelegate (
334+ public delegate ADLStatus ADL_Overdrive5_FanSpeedInfo_GetDelegate (
197335 int adapterIndex , int thermalControllerIndex ,
198336 ref ADLFanSpeedInfo fanSpeedInfo ) ;
199- public delegate int ADL_Overdrive5_FanSpeedToDefault_SetDelegate (
337+ public delegate ADLStatus ADL_Overdrive5_FanSpeedToDefault_SetDelegate (
200338 int adapterIndex , int thermalControllerIndex ) ;
201- public delegate int ADL_Overdrive5_FanSpeed_SetDelegate ( int adapterIndex ,
339+ public delegate ADLStatus ADL_Overdrive5_FanSpeed_SetDelegate ( int adapterIndex ,
202340 int thermalControllerIndex , ref ADLFanSpeedValue fanSpeedValue ) ;
203- public delegate int ADL_Overdrive_CapsDelegate ( int adapterIndex ,
341+ public delegate ADLStatus ADL_Overdrive_CapsDelegate ( int adapterIndex ,
204342 out int supported , out int enabled , out int version ) ;
205- private delegate int ADL2_Main_Control_CreateDelegate (
343+ private delegate ADLStatus ADL2_Main_Control_CreateDelegate (
206344 ADL_Main_Memory_AllocDelegate callback , int enumConnectedAdapters ,
207345 out IntPtr context ) ;
208- public delegate int ADL2_Main_Control_DestroyDelegate ( IntPtr context ) ;
209- public delegate int ADL2_OverdriveN_Temperature_GetDelegate ( IntPtr context ,
346+ public delegate ADLStatus ADL2_Main_Control_DestroyDelegate ( IntPtr context ) ;
347+ public delegate ADLStatus ADL2_OverdriveN_Temperature_GetDelegate ( IntPtr context ,
210348 int adapterIndex , ADLODNTemperatureType temperatureType ,
211349 out int temperature ) ;
212- public delegate int ADL2_Overdrive6_CurrentPower_GetDelegate ( IntPtr context ,
350+ public delegate ADLStatus ADL2_Overdrive6_CurrentPower_GetDelegate ( IntPtr context ,
213351 int adapterIndex , ADLODNCurrentPowerType powerType ,
214352 out int currentValue ) ;
215- public delegate int ADL2_New_QueryPMLogData_GetDelegate ( IntPtr context ,
353+ public delegate ADLStatus ADL2_New_QueryPMLogData_GetDelegate ( IntPtr context ,
216354 int adapterIndex , out ADLPMLogDataOutput dataOutput ) ;
355+ public delegate ADLStatus ADL_Overdrive5_ODParameters_GetDelegate (
356+ int adapterIndex , out ADLODParameters parameters ) ;
357+ public delegate ADLStatus ADL2_OverdriveN_PerformanceStatus_GetDelegate (
358+ IntPtr context , int adapterIndex ,
359+ out ADLODNPerformanceStatus performanceStatus ) ;
217360
218361 private static ADL_Main_Control_CreateDelegate
219362 _ADL_Main_Control_Create ;
@@ -254,6 +397,10 @@ public static ADL2_Overdrive6_CurrentPower_GetDelegate
254397 ADL2_Overdrive6_CurrentPower_Get ;
255398 public static ADL2_New_QueryPMLogData_GetDelegate
256399 ADL2_New_QueryPMLogData_Get ;
400+ public static ADL_Overdrive5_ODParameters_GetDelegate
401+ ADL_Overdrive5_ODParameters_Get ;
402+ public static ADL2_OverdriveN_PerformanceStatus_GetDelegate
403+ ADL2_OverdriveN_PerformanceStatus_Get ;
257404
258405 private static string dllName ;
259406
@@ -312,6 +459,10 @@ private static void CreateDelegates(string name) {
312459 out ADL2_Overdrive6_CurrentPower_Get ) ;
313460 GetDelegate ( "ADL2_New_QueryPMLogData_Get" ,
314461 out ADL2_New_QueryPMLogData_Get ) ;
462+ GetDelegate ( "ADL_Overdrive5_ODParameters_Get" ,
463+ out ADL_Overdrive5_ODParameters_Get ) ;
464+ GetDelegate ( "ADL2_OverdriveN_PerformanceStatus_Get" ,
465+ out ADL2_OverdriveN_PerformanceStatus_Get ) ;
315466 }
316467
317468 static ADL ( ) {
@@ -320,7 +471,7 @@ static ADL() {
320471
321472 private ADL ( ) { }
322473
323- public static int ADL_Main_Control_Create ( int enumConnectedAdapters ) {
474+ public static ADLStatus ADL_Main_Control_Create ( int enumConnectedAdapters ) {
324475 try {
325476 try {
326477 return _ADL_Main_Control_Create ( Main_Memory_Alloc ,
@@ -331,30 +482,30 @@ public static int ADL_Main_Control_Create(int enumConnectedAdapters) {
331482 enumConnectedAdapters ) ;
332483 }
333484 } catch {
334- return ADL_ERR ;
485+ return ADLStatus . ERR ;
335486 }
336487 }
337488
338- public static int ADL2_Main_Control_Create ( int enumConnectedAdapters ,
489+ public static ADLStatus ADL2_Main_Control_Create ( int enumConnectedAdapters ,
339490 out IntPtr context )
340491 {
341492 try {
342493 var result = _ADL2_Main_Control_Create ( Main_Memory_Alloc ,
343494 enumConnectedAdapters , out context ) ;
344- if ( result != ADL . ADL_OK )
495+ if ( result != ADLStatus . OK )
345496 context = IntPtr . Zero ;
346497 return result ;
347498 } catch {
348499 context = IntPtr . Zero ;
349- return ADL_ERR ;
500+ return ADLStatus . ERR ;
350501 }
351502 }
352503
353- public static int ADL_Adapter_AdapterInfo_Get ( ADLAdapterInfo [ ] info ) {
504+ public static ADLStatus ADL_Adapter_AdapterInfo_Get ( ADLAdapterInfo [ ] info ) {
354505 int elementSize = Marshal . SizeOf ( typeof ( ADLAdapterInfo ) ) ;
355506 int size = info . Length * elementSize ;
356507 IntPtr ptr = Marshal . AllocHGlobal ( size ) ;
357- int result = _ADL_Adapter_AdapterInfo_Get ( ptr , size ) ;
508+ var status = _ADL_Adapter_AdapterInfo_Get ( ptr , size ) ;
358509 for ( int i = 0 ; i < info . Length ; i ++ )
359510 info [ i ] = ( ADLAdapterInfo )
360511 Marshal . PtrToStructure ( ( IntPtr ) ( ( long ) ptr + i * elementSize ) ,
@@ -377,10 +528,10 @@ public static int ADL_Adapter_AdapterInfo_Get(ADLAdapterInfo[] info) {
377528 }
378529 }
379530
380- return result ;
531+ return status ;
381532 }
382533
383- public static int ADL_Adapter_ID_Get ( int adapterIndex ,
534+ public static ADLStatus ADL_Adapter_ID_Get ( int adapterIndex ,
384535 out int adapterID ) {
385536 try {
386537 return _ADL_Adapter_ID_Get ( adapterIndex , out adapterID ) ;
@@ -389,7 +540,7 @@ public static int ADL_Adapter_ID_Get(int adapterIndex,
389540 return _ADL_Display_AdapterID_Get ( adapterIndex , out adapterID ) ;
390541 } catch ( EntryPointNotFoundException ) {
391542 adapterID = 1 ;
392- return ADL_OK ;
543+ return ADLStatus . OK ;
393544 }
394545 }
395546 }
0 commit comments