using System;
namespace UnityEngine.AdaptivePerformance.Provider
{
///
/// Feature flags
/// See and .
///
[Flags]
public enum Feature
{
///
/// No features
///
None = 0,
///
/// See
///
WarningLevel = 0x1,
///
/// See
///
TemperatureLevel = 0x2,
///
/// See
///
TemperatureTrend = 0x4,
///
/// See and
///
CpuPerformanceLevel = 0x8,
///
/// See and
///
GpuPerformanceLevel = 0x10,
///
/// See and
///
PerformanceLevelControl = 0x20,
///
/// See
///
GpuFrameTime = 0x40,
///
/// See
///
CpuFrameTime = 0x80,
///
/// See
///
OverallFrameTime = 0x100,
///
/// See and
///
CpuPerformanceBoost = 0x200,
///
/// See and
///
GpuPerformanceBoost = 0x400,
///
/// See
///
ClusterInfo = 0x800
}
///
/// The performance data record stores all information about the thermal and performance status and delivers it from the provider subsystem to Adaptive Performance for further processing.
///
public struct PerformanceDataRecord
{
///
/// A bitset of features which indicate if their value changed in the last frame or at startup.
/// Unsupported features will never change.
/// Fields not changing always have valid data as long as its capability is supported.
///
/// Bitset
public Feature ChangeFlags { get; set; }
///
/// The current normalized temperature level in the range of [0.0, 1.0], or -1.0 when not supported or not available right now.
/// A level of 1.0 means that the device is thermal throttling.
/// The temperature level has changed when the bit is set in .
///
/// Temperature level in the range of [0.0, 1.0] or -1.0
public float TemperatureLevel { get; set; }
///
/// The current temperature trend in the range of [-1.0, 1.0] that is a metric of temperature change over time.
/// The temperature trend is constant at 0.0 in case the feature is not supported.
/// The temperature trend has changed when bit is set in .
///
/// Temperature trend in the range of [-1.0, 1.0]
public float TemperatureTrend { get; set; }
///
/// The current warning level as documented in .
/// The warning level has changed when bit is set in .
///
/// The current warning level
public WarningLevel WarningLevel { get; set; }
///
/// The currently active CPU performance level. This is typically the value previously set with once the levels are successfully applied.
/// Adaptive Performance might also change this level on its own. This typically happens when the device is thermal throttling or when failed.
/// CPU performance level has a value in the range of [, ], or .
/// A value of means that Adaptive Performance took control of performance levels.
/// CPU performance level has changed when bit is set in .
///
///
public int CpuPerformanceLevel { get; set; }
///
/// The currently active GPU performance level. This is typically the value previously set with once the levels are successfully applied.
/// Adaptive Performance might also change this level on its own. This typically happens when the device is thermal throttling or when failed.
/// GPU performance level has a value in the range of [, ], or .
/// A value of means that Adaptive Performance took control of performance levels.
/// GPU performance level has changed when bit is set in .
///
public int GpuPerformanceLevel { get; set; }
///
/// True if =performance levels can currently be controlled manually and aren't controlled by Adaptive Performance or the operating system.
/// Has changed when bit is set in .
///
public bool PerformanceLevelControlAvailable { get; set; }
///
/// The time in seconds spent by the CPU for rendering the last complete frame.
/// Has changed when bit is set in .
///
public float CpuFrameTime { get; set; }
///
/// The time in seconds spent by the GPU for rendering the last complete frame.
/// Has changed when bit is set in .
///
public float GpuFrameTime { get; set; }
///
/// The total time in seconds spent for the frame.
/// Has changed when bit is set in .
///
public float OverallFrameTime { get; set; }
///
/// The currently active CPU boost state. This is typically true if previously enabled with once the boost is successfully applied.
/// Adaptive Performance might also change this level on its own. This typically happens when the device is thermal throttling or when fails.
/// Once the CPU boost is enabled it is active until you receive a callback that it is disabled.
/// CPU boost level has changed when bit is set in .
///
public bool CpuPerformanceBoost { get; set; }
///
/// The currently active GPU boost state. This is typically true if previously enabled with once the boost is successfully applied.
/// Adaptive Performance might also change this level on its own. This typically happens when the device is thermal throttling or when fails.
/// Once the GPU boost is enabled it is active until you receive a callback that it is disabled.
/// GPU boost level has changed when bit is set in .
///
public bool GpuPerformanceBoost { get; set; }
///
/// Current CPU cluster information information. Includes number of big, medium and small cores use at the application startup.
///
public ClusterInfo ClusterInfo { get; set; }
}
///
/// This interface describes how the Adaptive Performance provider lifecycle behaves.
///
public interface IApplicationLifecycle
{
///
/// Called before an application pauses.
/// To be called from `MonoBehaviour.OnApplicationPause`.
///
void ApplicationPause();
///
/// Called after an application resumes.
/// To be called from `MonoBehaviour.OnApplicationPause`.
///
void ApplicationResume();
}
///
/// The device performance level control lets you change CPU and GPU levels and informs you about the current levels.
///
public interface IDevicePerformanceLevelControl
{
///
/// Maximum supported CPU performance level. This should not change after startup.
/// in case performance levels are not supported.
/// Value in the range of [, 10].
///
/// Value in the range of [, 10]
int MaxCpuPerformanceLevel { get; }
///
/// Maximum supported GPU performance level. This should not change after startup.
/// in case performance levels are not supported.
/// Value in the range of [, 10].
///
/// Value in the range of [, 10]
int MaxGpuPerformanceLevel { get; }
///
/// Request a performance level change.
/// If is passed, the subsystem picks the level to be used.
///
///
/// The new performance level. Can be or range of [, ].
/// If is not supported (see ), this parameter is ignored.
///
///
/// The new performance level. Can be or range of [, ].
/// If is not supported (see ), this parameter is ignored.
///
/// Returns true on success. When this fails, it means that the system took control of the active performance levels.
bool SetPerformanceLevel(ref int cpu, ref int gpu);
///
/// Request a CPU performance boost.
///
/// If is not supported (see ), this function is ignored.
/// Returns true on success. When this fails, it means that the system took control and does not allow boosts.
bool EnableCpuBoost();
///
/// Request a GPU performance boost.
///
/// If is not supported (see ), this function is ignored.
/// Returns true on success. When this fails, it means that the system took control and does not allow boosts.
bool EnableGpuBoost();
}
///
/// Use the Adaptive Performance Subsystem class to create your custom provider subsystem to deliver data from your provider to Adaptive Performance.
///
public abstract class AdaptivePerformanceSubsystem : AdaptivePerformanceSubsystemBase
{
///
/// Main constructor, not used in the subsystem specifically.
///
protected AdaptivePerformanceSubsystem()
{
}
///
/// Bitset of supported features.
/// Does not change after startup.
///
/// Bitset
public Feature Capabilities { get; protected set; }
///
/// To be called once per frame.
/// The returned data structure's fields are populated with the latest available data, according to the supported .
///
/// Data structure with the most recent performance data.
public abstract PerformanceDataRecord Update();
///
/// Application lifecycle events to be consumed by subsystem.
/// Can be null if the subsystem does not need special handling on life-cycle events.
/// The returned reference does not change after startup.
///
/// Application lifecycle object
public abstract IApplicationLifecycle ApplicationLifecycle { get; }
///
/// Control CPU or GPU performance levels of the device.
/// Can be null if the subsystem does not support controlling CPU/GPU performance levels.
/// Is null when the bit is not set in .
/// The returned reference does not change after startup.
///
/// Performance level control object
public abstract IDevicePerformanceLevelControl PerformanceLevelControl { get; }
///
/// Returns the version of the subsystem implementation.
/// Can be used together with SubsystemDescriptor to identify a subsystem.
///
/// Version number
public abstract Version Version { get; }
///
/// Generates a human readable string of subsystem internal stats.
/// Optional and only used for development.
///
/// String with subsystem specific statistics
public virtual string Stats { get { return ""; } }
}
///
/// This is the base class for and acts as a stub for backwards compability.
///
#pragma warning disable CS0618
public abstract class AdaptivePerformanceSubsystemBase : UnityEngine.Subsystem
{
///
/// Returns if the provider subsystem is currently running.
///
override public bool running { get { return initialized; } }
///
/// Returns if the provider subsystem was initialized successfully.
///
public bool initialized { get; protected set; }
}
#pragma warning restore CS0618
}