Testing a different approach

This commit is contained in:
Sam Gateau 2019-05-31 18:42:26 -07:00
parent 4e2480d032
commit 54d1705f06
5 changed files with 64 additions and 44 deletions

View file

@ -5361,25 +5361,9 @@ void Application::loadSettings() {
} }
} }
if (_firstRun.get()) { // Setup the PerformanceManager which will enforce the several settings to match the Preset
// If this is our first run, evalute the Platform Tier and assign the matching Performance profile by default. // On the first run, the Preset is evaluated from the
// A bunch of Performance, Simulation and Render settings will be set to a matching default value from this getPerformanceManager().setupPerformancePresetSettings(_firstRun.get());
// Here is the mapping between pelatformTIer and performance profile
const std::array<PerformanceManager::PerformancePreset, platform::Profiler::NumTiers> platformToPerformancePresetMap = {{
PerformanceManager::PerformancePreset::MID, // platform::Profiler::UNKNOWN
PerformanceManager::PerformancePreset::LOW, // platform::Profiler::LOW
PerformanceManager::PerformancePreset::MID, // platform::Profiler::MID
PerformanceManager::PerformancePreset::HIGH // platform::Profiler::HIGH
}};
// What is our profile?
auto platformTier = platform::Profiler::profilePlatform();
// Then let's assign the performance preset setting from it
getPerformanceManager().setPerformancePreset(platformToPerformancePresetMap[platformTier]);
}
// finish initializing the camera, based on everything we checked above. Third person camera will be used if no settings // 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 // dictated that we should be in first person

View file

@ -10,10 +10,34 @@
// //
#include "PerformanceManager.h" #include "PerformanceManager.h"
#include <platform/Profiler.h>
#include "scripting/RenderScriptingInterface.h" #include "scripting/RenderScriptingInterface.h"
PerformanceManager::PerformanceManager() PerformanceManager::PerformanceManager()
{ {
setPerformancePreset((PerformancePreset) _performancePresetSetting.get());
}
void PerformanceManager::setupPerformancePresetSettings(bool evaluatePlatformTier) {
if (evaluatePlatformTier || (getPerformancePreset() == UNKNOWN)) {
// If evaluatePlatformTier, 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::PerformancePreset, platform::Profiler::NumTiers> platformToPerformancePresetMap = { {
PerformanceManager::PerformancePreset::MID, // platform::Profiler::UNKNOWN
PerformanceManager::PerformancePreset::LOW, // platform::Profiler::LOW
PerformanceManager::PerformancePreset::MID, // platform::Profiler::MID
PerformanceManager::PerformancePreset::HIGH // platform::Profiler::HIGH
} };
// What is our profile?
auto platformTier = platform::Profiler::profilePlatform();
// Then let's assign the performance preset setting from it
setPerformancePreset(platformToPerformancePresetMap[platformTier]);
}
} }
void PerformanceManager::setPerformancePreset(PerformanceManager::PerformancePreset preset) { void PerformanceManager::setPerformancePreset(PerformanceManager::PerformancePreset preset) {
@ -27,7 +51,7 @@ void PerformanceManager::setPerformancePreset(PerformanceManager::PerformancePre
} }
PerformanceManager::PerformancePreset PerformanceManager::getPerformancePreset() const { PerformanceManager::PerformancePreset PerformanceManager::getPerformancePreset() const {
PerformancePreset preset = PerformancePreset::MID; PerformancePreset preset = PerformancePreset::UNKNOWN;
preset = (PerformancePreset) _performancePresetSettingLock.resultWithReadLock<int>([&] { preset = (PerformancePreset) _performancePresetSettingLock.resultWithReadLock<int>([&] {
return _performancePresetSetting.get(); return _performancePresetSetting.get();

View file

@ -30,12 +30,16 @@ public:
PerformanceManager(); PerformanceManager();
~PerformanceManager() = default; ~PerformanceManager() = default;
// Setup the PerformanceManager which will enforce the several settings to match the Preset
// If evaluatePlatformTier is true, the Preset is evaluated from the Platform::Profiler::profilePlatform()
void setupPerformancePresetSettings(bool evaluatePlatformTier);
void setPerformancePreset(PerformancePreset performancePreset); void setPerformancePreset(PerformancePreset performancePreset);
PerformancePreset getPerformancePreset() const; PerformancePreset getPerformancePreset() const;
private: private:
mutable ReadWriteLockable _performancePresetSettingLock; mutable ReadWriteLockable _performancePresetSettingLock;
Setting::Handle<int> _performancePresetSetting { "performancePreset", PerformanceManager::PerformancePreset::MID }; Setting::Handle<int> _performancePresetSetting { "performancePreset", PerformanceManager::PerformancePreset::UNKNOWN };
// The concrete performance preset changes // The concrete performance preset changes
void applyPerformancePreset(PerformanceManager::PerformancePreset performancePreset); void applyPerformancePreset(PerformanceManager::PerformancePreset performancePreset);

View file

@ -10,6 +10,7 @@
#include "LightingModel.h" #include "LightingModel.h"
#include "AntialiasingEffect.h" #include "AntialiasingEffect.h"
std::once_flag RenderScriptingInterface::registry_flag;
RenderScriptingInterface* RenderScriptingInterface::getInstance() { RenderScriptingInterface* RenderScriptingInterface::getInstance() {
static RenderScriptingInterface sharedInstance; static RenderScriptingInterface sharedInstance;
@ -17,32 +18,34 @@ RenderScriptingInterface* RenderScriptingInterface::getInstance() {
} }
RenderScriptingInterface::RenderScriptingInterface() { RenderScriptingInterface::RenderScriptingInterface() {
setRenderMethod((RenderMethod)_renderMethodSetting.get() == RenderMethod::DEFERRED ? RenderMethod::DEFERRED : RenderMethod::FORWARD); std::call_once(registry_flag, [] {
qmlRegisterType<RenderScriptingInterface>("RenderEnums", 1, 0, "RenderEnums");
});
setRenderMethod((RenderMethod)_renderMethodSettingLock.resultWithReadLock<int>([&] {
return _renderMethodSetting.get();
}));
setShadowsEnabled(_shadowsEnabledSetting.get()); setShadowsEnabled(_shadowsEnabledSetting.get());
setAmbientOcclusionEnabled(_ambientOcclusionEnabledSetting.get()); setAmbientOcclusionEnabled(_ambientOcclusionEnabledSetting.get());
setAntialiasingEnabled(_antialiasingEnabledSetting.get()); setAntialiasingEnabled(_antialiasingEnabledSetting.get());
} }
RenderScriptingInterface::RenderMethod RenderScriptingInterface::getRenderMethod() { RenderScriptingInterface::RenderMethod RenderScriptingInterface::getRenderMethod() {
return (RenderMethod)_renderMethodSetting.get() == RenderMethod::DEFERRED ? RenderMethod::DEFERRED : RenderMethod::FORWARD; return (RenderMethod) _renderMethod;
} }
void RenderScriptingInterface::setRenderMethod(RenderScriptingInterface::RenderMethod renderMethod) { void RenderScriptingInterface::setRenderMethod(RenderMethod renderMethod) {
RenderMethod newMethod = renderMethod == RenderMethod::FORWARD ? RenderMethod::FORWARD : RenderMethod::DEFERRED; if (_renderMethod != (int) renderMethod) {
if (_renderMethodSetting.get() == newMethod) { _renderMethodSettingLock.withWriteLock([&] {
return; _renderMethod = (int)renderMethod;
} _renderMethodSetting.set((int)renderMethod);
if (QThread::currentThread() != thread()) { auto config = dynamic_cast<task::SwitchConfig*>(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch"));
QMetaObject::invokeMethod(this, "setRenderMethod", Q_ARG(RenderScriptingInterface::RenderMethod, renderMethod)); if (config) {
return; _renderMethodSetting.set((int)renderMethod);
} config->setBranch((int)renderMethod);
}
auto config = dynamic_cast<task::SwitchConfig*>(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch")); });
if (config) {
_renderMethodSetting.set(newMethod);
config->setBranch(newMethod);
emit config->dirtyEnabled();
emit settingsChanged(); emit settingsChanged();
} }
} }

View file

@ -25,10 +25,10 @@
*/ */
class RenderScriptingInterface : public QObject { class RenderScriptingInterface : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(RenderMethod renderMethod READ getRenderMethod WRITE setRenderMethod NOTIFY settingsChanged) // Q_PROPERTY(RenderMethod renderMethod READ getRenderMethod WRITE setRenderMethod NOTIFY settingsChanged)
Q_PROPERTY(bool shadowsEnabled READ getShadowsEnabled WRITE setShadowsEnabled NOTIFY settingsChanged) // Q_PROPERTY(bool shadowsEnabled READ getShadowsEnabled WRITE setShadowsEnabled NOTIFY settingsChanged)
Q_PROPERTY(bool ambientOcclusionEnabled READ getAmbientOcclusionEnabled WRITE setAmbientOcclusionEnabled NOTIFY settingsChanged) // Q_PROPERTY(bool ambientOcclusionEnabled READ getAmbientOcclusionEnabled WRITE setAmbientOcclusionEnabled NOTIFY settingsChanged)
Q_PROPERTY(bool antialiasingEnabled READ getAntialiasingEnabled WRITE setAntialiasingEnabled NOTIFY settingsChanged) // Q_PROPERTY(bool antialiasingEnabled READ getAntialiasingEnabled WRITE setAntialiasingEnabled NOTIFY settingsChanged)
public: public:
RenderScriptingInterface(); RenderScriptingInterface();
@ -36,11 +36,11 @@ public:
static RenderScriptingInterface* getInstance(); static RenderScriptingInterface* getInstance();
// RenderMethod enum type // RenderMethod enum type
enum RenderMethod { enum class RenderMethod {
DEFERRED = render::Args::RenderMethod::DEFERRED, DEFERRED = render::Args::RenderMethod::DEFERRED,
FORWARD = render::Args::RenderMethod::FORWARD, FORWARD = render::Args::RenderMethod::FORWARD,
}; };
Q_ENUM(RenderMethod); Q_ENUM(RenderMethod)
public slots: public slots:
/**jsdoc /**jsdoc
@ -136,11 +136,16 @@ signals:
void settingsChanged(); void settingsChanged();
private: private:
int _renderMethod { -1 };
mutable ReadWriteLockable _renderMethodSettingLock;
Setting::Handle<int> _renderMethodSetting { "renderMethod", RENDER_FORWARD ? render::Args::RenderMethod::FORWARD : render::Args::RenderMethod::DEFERRED }; Setting::Handle<int> _renderMethodSetting { "renderMethod", RENDER_FORWARD ? render::Args::RenderMethod::FORWARD : render::Args::RenderMethod::DEFERRED };
Setting::Handle<bool> _shadowsEnabledSetting { "shadowsEnabled", true }; Setting::Handle<bool> _shadowsEnabledSetting { "shadowsEnabled", true };
Setting::Handle<bool> _ambientOcclusionEnabledSetting { "ambientOcclusionEnabled", false }; Setting::Handle<bool> _ambientOcclusionEnabledSetting { "ambientOcclusionEnabled", false };
Setting::Handle<bool> _antialiasingEnabledSetting { "antialiasingEnabled", true }; Setting::Handle<bool> _antialiasingEnabledSetting { "antialiasingEnabled", true };
Setting::Handle<float> _viewportResolutionScaleSetting{ "viewportResolutionScale", 1.0f }; Setting::Handle<float> _viewportResolutionScaleSetting{ "viewportResolutionScale", 1.0f };
static std::once_flag registry_flag;
}; };
#endif // hifi_RenderScriptingInterface_h #endif // hifi_RenderScriptingInterface_h