INtroducing the PerformanceManager

This commit is contained in:
Sam Gateau 2019-05-29 15:47:14 -07:00
parent 3c6eecbdb6
commit bf7617ea8e
8 changed files with 131 additions and 9 deletions

View file

@ -5361,6 +5361,26 @@ void Application::loadSettings() {
}
}
if (_firstRun.get()) {
// If this is our first run, evalute the Platform Tier and assign the matching Performance profile by default.
// A bunch of Performance, Simulation and Render settings will be set to a matching default value from this
// Here is the mapping between pelatformTIer and performance profile
const std::array<PerformanceManager::PerformanceProfile, platform::Profiler::NumTiers> platformToPerformanceProfileMap = {{
PerformanceManager::PerformanceProfile::MID, // platform::Profiler::UNKNOWN
PerformanceManager::PerformanceProfile::LOW, // platform::Profiler::LOW
PerformanceManager::PerformanceProfile::MID, // platform::Profiler::MID
PerformanceManager::PerformanceProfile::HIGH // platform::Profiler::HIGH
}};
// What is our profile?
auto platformTier = platform::Profiler::profilePlatform();
// Then let's assign the performance profile setting from it
getPerformanceManager().setPerformanceProfile(platformToPerformanceProfileMap[platformTier]);
}
// finish initializing the camera, based on everything we checked above. Third person camera will be used if no settings
// dictated that we should be in first person
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, isFirstPerson);

View file

@ -57,6 +57,7 @@
#include "gpu/Context.h"
#include "LoginStateManager.h"
#include "Menu.h"
#include "PerformanceManager.h"
#include "RefreshRateManager.h"
#include "octree/OctreePacketProcessor.h"
#include "render/Engine.h"
@ -203,6 +204,8 @@ public:
CompositorHelper& getApplicationCompositor() const;
Overlays& getOverlays() { return _overlays; }
PerformanceManager& getPerformanceManager() { return _performanceManager; }
RefreshRateManager& getRefreshRateManager() { return _refreshRateManager; }
size_t getRenderFrameCount() const { return _graphicsEngine.getRenderFrameCount(); }
@ -734,6 +737,7 @@ private:
QUuid _loginDialogID;
QUuid _avatarInputsBarID;
LoginStateManager _loginStateManager;
PerformanceManager _performanceManager;
RefreshRateManager _refreshRateManager;
quint64 _lastFaceTrackerUpdate;

View file

@ -0,0 +1,31 @@
//
// PerformanceManager.cpp
// interface/src/
//
// Created by Sam Gateau on 2019-05-29.
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "PerformanceManager.h"
PerformanceManager::PerformanceManager()
{
}
void PerformanceManager::setPerformanceProfile(PerformanceManager::PerformanceProfile performanceProfile) {
_performanceProfileSettingLock.withWriteLock([&] {
_performanceProfileSetting.set((int)performanceProfile);
});
}
PerformanceManager::PerformanceProfile PerformanceManager::getPerformanceProfile() const {
PerformanceProfile profile = PerformanceProfile::MID;
profile = (PerformanceProfile) _performanceProfileSettingLock.resultWithReadLock<int>([&] {
return _performanceProfileSetting.get();
});
return profile;
}

View file

@ -0,0 +1,40 @@
//
// PerformanceManager.h
// interface/src/
//
// Created by Sam Gateau on 2019-05-29.
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_PerformanceManager_h
#define hifi_PerformanceManager_h
#include <string>
#include <SettingHandle.h>
#include <shared/ReadWriteLockable.h>
class PerformanceManager {
public:
enum PerformanceProfile {
LOW = 0,
MID,
HIGH,
PROFILE_COUNT
};
PerformanceManager();
~PerformanceManager() = default;
void setPerformanceProfile(PerformanceProfile performanceProfile);
PerformanceProfile getPerformanceProfile() const;
private:
mutable ReadWriteLockable _performanceProfileSettingLock;
Setting::Handle<int> _performanceProfileSetting { "performanceProfile", PerformanceManager::PerformanceProfile::MID };
};
#endif

View file

@ -19,6 +19,19 @@ PerformanceScriptingInterface::PerformanceScriptingInterface() {
});
}
void PerformanceScriptingInterface::setPerformanceProfile(PerformanceProfile performanceProfile) {
qApp->getPerformanceManager().setPerformanceProfile((PerformanceManager::PerformanceProfile)performanceProfile);
}
PerformanceScriptingInterface::PerformanceProfile PerformanceScriptingInterface::getPerformanceProfile() const {
return (PerformanceScriptingInterface::PerformanceProfile)qApp->getPerformanceManager().getPerformanceProfile();
}
QStringList PerformanceScriptingInterface::getPerformanceProfileNames() const {
static const QStringList performanceProfileNames = { "Low", "Mid", "High" };
return performanceProfileNames;
}
void PerformanceScriptingInterface::setRefreshRateProfile(RefreshRateProfile refreshRateProfile) {
qApp->getRefreshRateManager().setRefreshRateProfile((RefreshRateManager::RefreshRateProfile)refreshRateProfile);
}

View file

@ -14,12 +14,22 @@
#include <QObject>
#include "../PerformanceManager.h"
#include "../RefreshRateManager.h"
class PerformanceScriptingInterface : public QObject {
Q_OBJECT
public:
// PerformanceManager PerformanceProfile tri state level enums
enum PerformanceProfile {
LOW = PerformanceManager::PerformanceProfile::LOW,
MID = PerformanceManager::PerformanceProfile::MID,
HIGH = PerformanceManager::PerformanceProfile::HIGH,
};
// Q_ENUM(PerformanceProfile)
// Must match RefreshRateManager enums
enum RefreshRateProfile {
ECO = RefreshRateManager::RefreshRateProfile::ECO,
@ -28,12 +38,15 @@ public:
};
Q_ENUM(RefreshRateProfile)
PerformanceScriptingInterface();
~PerformanceScriptingInterface() = default;
public slots:
void setPerformanceProfile(PerformanceProfile performanceProfile);
PerformanceProfile getPerformanceProfile() const;
QStringList getPerformanceProfileNames() const;
void setRefreshRateProfile(RefreshRateProfile refreshRateProfile);
RefreshRateProfile getRefreshRateProfile() const;
QStringList getRefreshRateProfileNames() const;

View file

@ -124,4 +124,4 @@ void RenderScriptingInterface::setAntialiasingEnabled(bool enabled) {
mainViewAntialiasingConfig->setDebugFXAA(true);
}
}
}
}

View file

@ -119,24 +119,25 @@ public slots:
void setAntialiasingEnabled(bool enabled);
/**jsdoc
* Gets the current render resolution scale
* @function Render.getRenderResolutionScale
* Gets the current viewport resolution scale
* @function Render.getViewportResolutionScale
* @returns {number}
*/
// RenderMethod getRenderMethod();
// float getViewportResolutionScale();
/**jsdoc
* Sets the current render method
* @function Render.setRenderMethod
* @param {number} renderMethod - <code>"DEFERRED"</code> or <code>"FORWARD"</code>
* Sets the current viewport resolution scale
* @function Render.setViewportResolutionScale
* @param {number} resolutionScale - between epsilon and 1.0
*/
// void setRenderMethod(RenderMethod renderMethod);
// void setViewportResolutionScale(float resolutionScale);
private:
Setting::Handle<int> _renderMethodSetting { "renderMethod", RENDER_FORWARD ? render::Args::RenderMethod::FORWARD : render::Args::RenderMethod::DEFERRED };
Setting::Handle<bool> _shadowsEnabledSetting { "shadowsEnabled", true };
Setting::Handle<bool> _ambientOcclusionEnabledSetting { "ambientOcclusionEnabled", false };
Setting::Handle<bool> _antialiasingEnabledSetting { "antialiasingEnabled", true };
Setting::Handle<float> _viewportResolutionScaleSetting{ "viewportResolutionScale", 1.0f };
};
#endif // hifi_RenderScriptingInterface_h