/// <summary>
        /// Callback for any level change
        /// </summary>
        protected override void OnLevel()
        {
            float oldScaleFactor = Scale;
            float scaleIncrement = (MaxBound - MinBound) / MaxLevel;

            Scale = scaleIncrement * (MaxLevel - CurrentLevel) + MinBound;

            // if Gfx API does not support Dynamic resolution, currentCamera.allowDynamicResolution will be false
            if (IsDynamicResolutionSupported())
            {
                if (Scale != oldScaleFactor)
                {
                    ScalableBufferManager.ResizeBuffers(Scale, Scale);
                }
                int rezWidth  = (int)Mathf.Ceil(ScalableBufferManager.widthScaleFactor * Screen.currentResolution.width);
                int rezHeight = (int)Mathf.Ceil(ScalableBufferManager.heightScaleFactor * Screen.currentResolution.height);
                APLog.Debug(
                    $"Adaptive Resolution Scale: {Scale:F3} Resolution: {rezWidth}x{rezHeight} ScaleFactor: {ScalableBufferManager.widthScaleFactor:F3}x{ScalableBufferManager.heightScaleFactor:F3} Level:{CurrentLevel}/{MaxLevel}");
            }
            else
            {
                AdaptivePerformanceRenderSettings.RenderScaleMultiplier = Scale;
                APLog.Debug($"Dynamic resolution is not supported. Using fallback to Render Scale Multiplier : {Scale:F3}");
                // TODO: warn if unsupported render pipeline is used
                //Debug.Log("You might not use a supported Render Pipeline. Currently only Universal Render Pipeline and Built-in are supported by Adaptive Resolution.");
            }
        }
        public void Update()
        {
            if (m_Subsystem == null)
            {
                return;
            }

            UpdateSubsystem();

            Indexer.Update();

            if (Profiler.enabled)
            {
                CollectProfilerStats();
            }

            if (APLog.enabled && LoggingFrequencyInFrames > 0)
            {
                m_FrameCount++;
                if (m_FrameCount % LoggingFrequencyInFrames == 0)
                {
                    APLog.Debug(m_Subsystem.Stats);
                    APLog.Debug("Performance level CPU={0}/{1} GPU={2}/{3} thermal warn={4}({5}) thermal level={6} mode={7}", m_PerformanceMetrics.CurrentCpuLevel, MaxCpuPerformanceLevel,
                                m_PerformanceMetrics.CurrentGpuLevel, MaxGpuPerformanceLevel, m_ThermalMetrics.WarningLevel, (int)m_ThermalMetrics.WarningLevel, m_ThermalMetrics.TemperatureLevel, m_DevicePerfControl.PerformanceControlMode);
                    APLog.Debug("Average GPU frametime = {0} ms (Current = {1} ms)", m_FrameTiming.AverageGpuFrameTime * 1000.0f, m_FrameTiming.CurrentGpuFrameTime * 1000.0f);
                    APLog.Debug("Average CPU frametime = {0} ms (Current = {1} ms)", m_FrameTiming.AverageCpuFrameTime * 1000.0f, m_FrameTiming.CurrentCpuFrameTime * 1000.0f);
                    APLog.Debug("Average frametime = {0} ms (Current = {1} ms)", m_FrameTiming.AverageFrameTime * 1000.0f, m_FrameTiming.CurrentFrameTime * 1000.0f);
                    APLog.Debug("Bottleneck {0}, ThermalTrend {1}", m_PerformanceMetrics.PerformanceBottleneck, m_ThermalMetrics.TemperatureTrend);
                    APLog.Debug("CPU Boost Mode {0}, GPU Boost Mode {1}", m_PerformanceMetrics.CpuPerformanceBoost, m_PerformanceMetrics.GpuPerformanceBoost);
                    APLog.Debug("Cluster Info = Big Cores: {0} Medium Cores: {1} Little Cores: {2}", m_PerformanceMetrics.ClusterInfo.BigCore, m_PerformanceMetrics.ClusterInfo.MediumCore, m_PerformanceMetrics.ClusterInfo.LittleCore);
                    APLog.Debug("FPS = {0}", 1.0f / m_FrameTiming.AverageFrameTime);
                }
            }
        }
Ejemplo n.º 3
0
        void OnEnable()
        {
            if (m_ManagerGameObject == null)
            {
                m_ManagerGameObject = new GameObject("AdaptivePerformanceManager");
                var ap = m_ManagerGameObject.AddComponent <AdaptivePerformanceManager>();

                // if no provider was found we can disable AP and destroy the game object, otherwise continue with initialization.
                if (ap.Indexer == null)
                {
                    Destroy(m_ManagerGameObject);
                    return;
                }

                Holder.Instance = ap;
                InstallScalers();
                DontDestroyOnLoad(m_ManagerGameObject);

                var settings       = ap.Settings;
                var scalerProfiles = settings.GetAvailableScalerProfiles();
                if (scalerProfiles.Length <= 0)
                {
                    APLog.Debug("No Scaler Profiles available. Did you remove all profiles manually from the provider Settings?");
                    return;
                }
                settings.LoadScalerProfile(scalerProfiles[settings.defaultScalerProfilerIndex]);
            }
        }
Ejemplo n.º 4
0
 private void RaiseCpuLevel(float timestamp)
 {
     ++m_PerfControl.CpuLevel;
     m_LastChangeTimeStamp        = timestamp;
     m_LastCpuLevelRaiseTimeStamp = timestamp;
     APLog.Debug("Auto Perf Level: raise CPU level to {0}", m_PerfControl.CpuLevel);
 }
        public void Update()
        {
            if (m_Subsystem == null)
            {
                return;
            }

            UpdateSubsystem();

            if (APLog.enabled && LoggingFrequencyInFrames > 0)
            {
                m_FrameCount++;
                if (m_FrameCount % LoggingFrequencyInFrames == 0)
                {
                    APLog.Debug(m_Subsystem.Stats);
                    APLog.Debug("Performance level CPU={0}/{1} GPU={2}/{3} warn={4}({5}) mode={6}", m_PerformanceMetrics.CurrentCpuLevel, MaxCpuPerformanceLevel,
                                m_PerformanceMetrics.CurrentGpuLevel, MaxGpuPerformanceLevel, m_ThermalMetrics.WarningLevel, (int)m_ThermalMetrics.WarningLevel, m_DevicePerfControl.PerformanceControlMode);
                    APLog.Debug("Average GPU frametime = {0} ms (Current = {1} ms)", m_FrameTiming.AverageGpuFrameTime * 1000.0f, m_FrameTiming.CurrentGpuFrameTime * 1000.0f);
                    APLog.Debug("Average CPU frametime = {0} ms (Current = {1} ms)", m_FrameTiming.AverageCpuFrameTime * 1000.0f, m_FrameTiming.CurrentCpuFrameTime * 1000.0f);
                    APLog.Debug("Average frametime = {0} ms (Current = {1} ms)", m_FrameTiming.AverageFrameTime * 1000.0f, m_FrameTiming.CurrentFrameTime * 1000.0f);
                    APLog.Debug("Bottleneck {0}", m_PerformanceMetrics.PerformanceBottleneck);
                    APLog.Debug("FPS = {0}", 1.0f / m_FrameTiming.AverageFrameTime);
                }
            }
        }
 /// <summary>
 /// Returns a list of all available scaler profiles.
 /// </summary>
 /// <returns></returns>
 public string[] GetAvailableScalerProfiles()
 {
     string[] scalerNames = new string[m_scalerProfileList.Length];
     if (m_scalerProfileList.Length <= 0)
     {
         APLog.Debug("No scaler profiles available. You can not load and apply profiles. Add more profiles in the Adaptive Performance settings.");
         return(scalerNames);
     }
     for (int i = 0; i < m_scalerProfileList.Length; i++)
     {
         AdaptivePerformanceScalerProfile scalerProfile = m_scalerProfileList[i];
         scalerNames[i] = scalerProfile.Name;
     }
     return(scalerNames);
 }
Ejemplo n.º 7
0
        private bool AllowRaiseLevels()
        {
            float tempLevel = m_ThermalStats.ThermalMetrics.TemperatureLevel;

            if (tempLevel < 0.0f)
            {
                return(true); // temperature level not supported, allow changing levels anyway
            }
            // raise CPU/GPU levels only as long as device is reasonably cool
            if (tempLevel < MaxTemperatureLevel)
            {
                return(true);
            }

            APLog.Debug("Auto Perf Level: cannot raise performance level, current temperature level ({0}) exceeds {1}", tempLevel, MaxTemperatureLevel);
            return(false);
        }
        private void OnDestroy()
        {
            --instanceCount;
            if (Scale == 1.0f)
            {
                return;
            }

            APLog.Debug("Restoring dynamic resolution scale factor to 1.0");
            if (IsDynamicResolutionSupported())
            {
                ScalableBufferManager.ResizeBuffers(1.0f, 1.0f);
            }
            else
            {
                AdaptivePerformanceRenderSettings.RenderScaleMultiplier = 1.0f;
            }
        }
        /// <summary>
        /// Load a scaler profile from the settings. Unity update the values of all scalers in the profile to new ones.
        /// This is a heavy operation using reflection and should not be used per frame and only in load operations as it causes hitching and possible screen artifacts depending on which scalers are used in a scene.
        /// </summary>
        /// <param name="scalerProfileName">Supply the name of the scaler. You can query a list of available scaler profiles via <see cref="IAdaptivePerformanceSettings.GetAvailableScalerProfiles"/>.</param>
        public void LoadScalerProfile(string scalerProfileName)
        {
            if (scalerProfileName == null || scalerProfileName.Length <= 0)
            {
                APLog.Debug("Scaler profile name empty. Can not load and apply profile.");
                return;
            }
            if (m_scalerProfileList.Length <= 0)
            {
                APLog.Debug("No scaler profiles available. Can not load and apply profile. Add more profiles in the Adaptive Performance settings.");
                return;
            }
            if (m_scalerProfileList.Length == 1)
            {
                APLog.Debug("Only default scaler profile available. Reset all scalers to default profile.");
            }

            for (int i = 0; i < m_scalerProfileList.Length; i++)
            {
                AdaptivePerformanceScalerProfile scalerProfile = m_scalerProfileList[i];
                if (scalerProfile == null)
                {
                    APLog.Debug("Scaler profile is null. Can not load and apply profile. Check Adaptive Performance settings.");
                    return;
                }
                if (scalerProfile.Name == null || scalerProfile.Name.Length <= 0)
                {
                    APLog.Debug("Scaler profile name is null or empty. Can not load and apply profile. Check Adaptive Performance settings.");
                    return;
                }
                if (scalerProfile.Name == scalerProfileName)
                {
                    scalerSettings.ApplySettings(scalerProfile);
                    break;
                }
            }
            if (ApplyScalerProfileToAllScalers())
            {
                APLog.Debug($"Scaler profile {scalerProfileName} loaded.");
            }
        }
        bool ApplyScalerProfileToAllScalers()
        {
            bool success = false;

            if (Holder.Instance == null || Holder.Instance.Indexer == null)
            {
                return(success);
            }

            List <AdaptivePerformanceScaler> allScalers = new List <AdaptivePerformanceScaler>();
            List <AdaptivePerformanceScaler> scalers    = new List <AdaptivePerformanceScaler>();

            Holder.Instance.Indexer.GetUnappliedScalers(ref scalers);
            allScalers.AddRange(scalers);
            Holder.Instance.Indexer.GetAppliedScalers(ref scalers);
            allScalers.AddRange(scalers);
            Holder.Instance.Indexer.GetDisabledScalers(ref scalers);
            allScalers.AddRange(scalers);

            if (allScalers.Count <= 0)
            {
                APLog.Debug($"No scalers found. No scaler profile applied.");
                return(success);
            }

            PropertyInfo[] properties = typeof(AdaptivePerformanceScalerSettings).GetProperties();

            foreach (PropertyInfo property in properties)
            {
                var aScaler = allScalers.Find(s => s.GetType().ToString().Contains(property.Name));
                if (aScaler)
                {
                    System.Reflection.PropertyInfo prop = typeof(AdaptivePerformanceScalerSettings).GetProperty(property.Name);
                    var value = prop.GetValue(scalerSettings);
                    aScaler.ApplyDefaultSetting((AdaptivePerformanceScalerSettingsBase)value);
                    success = true;
                }
            }
            return(success);
        }
        private bool InitializeSubsystem(Provider.AdaptivePerformanceSubsystem subsystem)
        {
            if (subsystem == null)
            {
                return(false);
            }

            subsystem.Start();

            if (subsystem.initialized)
            {
                m_Subsystem = subsystem;

                APLog.Debug("version={0}", m_Subsystem.Version);

                return(true);
            }
            else
            {
                subsystem.Destroy();

                return(false);
            }
        }
 private void LogBottleneckEvent(PerformanceBottleneckChangeEventArgs ev)
 {
     APLog.Debug("[perf event] bottleneck: {0}", ev.PerformanceBottleneck);
 }
 private void LogThermalEvent(ThermalMetrics ev)
 {
     APLog.Debug("[thermal event] temperature level: {0}, warning level: {1}, thermal trend: {2}", ev.TemperatureLevel, ev.WarningLevel, ev.TemperatureTrend);
 }
        public void Start()
        {
            APLog.enabled            = StartupSettings.Logging;
            LoggingFrequencyInFrames = StartupSettings.StatsLoggingFrequencyInFrames;
            if (!StartupSettings.Enable)
            {
                return;
            }

            if (InitializeSubsystem(StartupSettings.PreferredSubsystem))
            {
                m_Subsystem = StartupSettings.PreferredSubsystem;
            }
            else
            {
                System.Collections.Generic.List <Provider.AdaptivePerformanceSubsystemDescriptor> perfDescriptors = Provider.AdaptivePerformanceSubsystemRegistry.GetRegisteredDescriptors();
                if (perfDescriptors.Count == 0)
                {
                    APLog.Debug("No Subsystems found and initialized.");
                }
                foreach (var perfDesc in perfDescriptors)
                {
                    var subsystem = perfDesc.Create();
                    if (InitializeSubsystem(subsystem))
                    {
                        m_Subsystem = subsystem;
                        break;
                    }
                }
            }

            if (m_Subsystem != null)
            {
                m_DevicePerfControl = new DevicePerformanceControlImpl(m_Subsystem.PerformanceLevelControl);
                m_AutoPerformanceLevelController = new AutoPerformanceLevelController(m_DevicePerfControl, PerformanceStatus, ThermalStatus);

                m_AppLifecycle = m_Subsystem.ApplicationLifecycle;

                if (!m_Subsystem.Capabilities.HasFlag(Provider.Feature.CpuFrameTime))
                {
                    m_CpuFrameTimeProvider = new CpuTimeProvider();
                    StartCoroutine(InvokeEndOfFrame());
                }

                m_TemperatureTrend = new TemperatureTrend(m_Subsystem.Capabilities.HasFlag(Provider.Feature.TemperatureTrend));

                if (m_RequestedCpuLevel == Constants.UnknownPerformanceLevel)
                {
                    m_RequestedCpuLevel = m_DevicePerfControl.MaxCpuPerformanceLevel;
                }

                if (m_RequestedGpuLevel == Constants.UnknownPerformanceLevel)
                {
                    m_RequestedGpuLevel = m_DevicePerfControl.MaxGpuPerformanceLevel;
                }

                if (m_Subsystem.PerformanceLevelControl == null)
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.System;
                }
                else if (AutomaticPerformanceControl)
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.Automatic;
                }
                else
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.Manual;
                }

                ThermalEvent += (ThermalMetrics thermalMetrics) => LogThermalEvent(thermalMetrics);
                PerformanceBottleneckChangeEvent += (PerformanceBottleneckChangeEventArgs ev) => LogBottleneckEvent(ev);
                PerformanceLevelChangeEvent      += (PerformanceLevelChangeEventArgs ev) => LogPerformanceLevelEvent(ev);

                UpdateSubsystem();
            }
        }
Ejemplo n.º 15
0
 private void LowerGpuLevel(float timestamp)
 {
     --m_PerfControl.GpuLevel;
     m_LastChangeTimeStamp = timestamp;
     APLog.Debug("Auto Perf Level: lower GPU level to {0}", m_PerfControl.GpuLevel);
 }
 private void LogPerformanceLevelEvent(PerformanceLevelChangeEventArgs ev)
 {
     APLog.Debug("[perf level change] cpu: {0}({1}) gpu: {2}({3}) control mode: {4} manual override: {5}", ev.CpuLevel, ToStringWithSign(ev.CpuLevelDelta), ev.GpuLevel, ToStringWithSign(ev.GpuLevelDelta), ev.PerformanceControlMode, ev.ManualOverride);
 }
 private void LogBoostEvent(PerformanceBoostChangeEventArgs ev)
 {
     APLog.Debug("[perf event] CPU boost: {0}, GPU boost: {1}", ev.CpuBoost, ev.GpuBoost);
 }
 private void LogPerformanceLevelEvent(PerformanceLevelChangeEventArgs ev)
 {
     APLog.Debug("[perf level change] cpu: {0}({1}) gpu: {2}({3})", ev.CpuLevel, ToStringWithSign(ev.CpuLevelDelta), ev.GpuLevel, ToStringWithSign(ev.GpuLevelDelta));
 }
 private void LogThermalEvent(ThermalMetrics ev)
 {
     AdaptivePerformanceAnalytics.SendAdaptivePerformanceThermalEvent(ev);
     APLog.Debug("[thermal event] temperature level: {0}, warning level: {1}, thermal trend: {2}", ev.TemperatureLevel, ev.WarningLevel, ev.TemperatureTrend);
 }
        public void Awake()
        {
            APLog.enabled = true;
            if (AdaptivePerformanceGeneralSettings.Instance == null)
            {
                APLog.Debug("No Provider was configured for use. Make sure you added at least one Provider in the Adaptive Performance Settings.");
                AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                return;
            }

            if (!AdaptivePerformanceGeneralSettings.Instance.InitManagerOnStart)
            {
                APLog.Debug("Adaptive Performance is disabled via Settings.");
                AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                return;
            }

            var activeLoader = AdaptivePerformanceGeneralSettings.Instance.Manager.ActiveLoaderAs <AdaptivePerformanceLoader>();

            if (activeLoader == null)
            {
                APLog.Debug("No Active Loader was found. Make sure to select your loader in the Adaptive Performance Settings for this platform.");
                AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                return;
            }

            m_Settings = activeLoader.GetSettings();
            if (m_Settings == null)
            {
                APLog.Debug("No Settings available. Did the Post Process Buildstep fail?");
                AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                return;
            }

            AutomaticPerformanceControl = m_Settings.automaticPerformanceMode;
            LoggingFrequencyInFrames    = m_Settings.statsLoggingFrequencyInFrames;
            APLog.enabled = m_Settings.logging;

            if (m_Subsystem == null)
            {
                var subsystem = (Provider.AdaptivePerformanceSubsystem)activeLoader.GetDefaultSubsystem();

                if (subsystem != null)
                {
                    if (subsystem.initialized)
                    {
                        m_Subsystem = subsystem;
                        APLog.Debug("Subsystem version={0}", m_Subsystem.Version);
                    }
                    else
                    {
                        subsystem.Destroy();
                        APLog.Debug("Subsystem not initialized.");
                        AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                        return;
                    }
                }
            }

            if (m_Subsystem != null)
            {
                m_UseProviderOverallFrameTime    = m_Subsystem.Capabilities.HasFlag(Provider.Feature.OverallFrameTime);
                m_DevicePerfControl              = new DevicePerformanceControlImpl(m_Subsystem.PerformanceLevelControl);
                m_AutoPerformanceLevelController = new AutoPerformanceLevelController(m_DevicePerfControl, PerformanceStatus, ThermalStatus);

                m_AppLifecycle = m_Subsystem.ApplicationLifecycle;

                if (!m_Subsystem.Capabilities.HasFlag(Provider.Feature.CpuFrameTime))
                {
                    m_CpuFrameTimeProvider = new CpuTimeProvider();
                    StartCoroutine(InvokeEndOfFrame());
                }

                if (!m_Subsystem.Capabilities.HasFlag(Provider.Feature.GpuFrameTime))
                {
                    m_GpuFrameTimeProvider = new GpuTimeProvider();
                }

                m_TemperatureTrend = new TemperatureTrend(m_Subsystem.Capabilities.HasFlag(Provider.Feature.TemperatureTrend));

                // Request maximum performance by default
                if (m_RequestedCpuLevel == Constants.UnknownPerformanceLevel)
                {
                    m_RequestedCpuLevel = m_DevicePerfControl.MaxCpuPerformanceLevel;
                }
                if (m_RequestedGpuLevel == Constants.UnknownPerformanceLevel)
                {
                    m_RequestedGpuLevel = m_DevicePerfControl.MaxGpuPerformanceLevel;
                }

                // Override to get maximum performance by default in 'auto' mode
                m_NewUserPerformanceLevelRequest = true;

                if (m_Subsystem.PerformanceLevelControl == null)
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.System;
                }
                else if (AutomaticPerformanceControl)
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.Automatic;
                }
                else
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.Manual;
                }

                ThermalEvent += (ThermalMetrics thermalMetrics) => LogThermalEvent(thermalMetrics);
                PerformanceBottleneckChangeEvent += (PerformanceBottleneckChangeEventArgs ev) => LogBottleneckEvent(ev);
                PerformanceLevelChangeEvent      += (PerformanceLevelChangeEventArgs ev) => LogPerformanceLevelEvent(ev);

                if (m_Subsystem.Capabilities.HasFlag(Provider.Feature.CpuPerformanceBoost))
                {
                    PerformanceBoostChangeEvent += (PerformanceBoostChangeEventArgs ev) => LogBoostEvent(ev);
                }

                Indexer = new AdaptivePerformanceIndexer(ref m_Settings);

                UpdateSubsystem();
            }
            AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
        }