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()) {
// 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::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]);
}
// Setup the PerformanceManager which will enforce the several settings to match the Preset
// On the first run, the Preset is evaluated from the
getPerformanceManager().setupPerformancePresetSettings(_firstRun.get());
// 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

View file

@ -10,10 +10,34 @@
//
#include "PerformanceManager.h"
#include <platform/Profiler.h>
#include "scripting/RenderScriptingInterface.h"
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) {
@ -27,7 +51,7 @@ void PerformanceManager::setPerformancePreset(PerformanceManager::PerformancePre
}
PerformanceManager::PerformancePreset PerformanceManager::getPerformancePreset() const {
PerformancePreset preset = PerformancePreset::MID;
PerformancePreset preset = PerformancePreset::UNKNOWN;
preset = (PerformancePreset) _performancePresetSettingLock.resultWithReadLock<int>([&] {
return _performancePresetSetting.get();

View file

@ -30,12 +30,16 @@ public:
PerformanceManager();
~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);
PerformancePreset getPerformancePreset() const;
private:
mutable ReadWriteLockable _performancePresetSettingLock;
Setting::Handle<int> _performancePresetSetting { "performancePreset", PerformanceManager::PerformancePreset::MID };
Setting::Handle<int> _performancePresetSetting { "performancePreset", PerformanceManager::PerformancePreset::UNKNOWN };
// The concrete performance preset changes
void applyPerformancePreset(PerformanceManager::PerformancePreset performancePreset);

View file

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

View file

@ -25,10 +25,10 @@
*/
class RenderScriptingInterface : public QObject {
Q_OBJECT
Q_PROPERTY(RenderMethod renderMethod READ getRenderMethod WRITE setRenderMethod 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 antialiasingEnabled READ getAntialiasingEnabled WRITE setAntialiasingEnabled 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 ambientOcclusionEnabled READ getAmbientOcclusionEnabled WRITE setAmbientOcclusionEnabled NOTIFY settingsChanged)
// Q_PROPERTY(bool antialiasingEnabled READ getAntialiasingEnabled WRITE setAntialiasingEnabled NOTIFY settingsChanged)
public:
RenderScriptingInterface();
@ -36,11 +36,11 @@ public:
static RenderScriptingInterface* getInstance();
// RenderMethod enum type
enum RenderMethod {
enum class RenderMethod {
DEFERRED = render::Args::RenderMethod::DEFERRED,
FORWARD = render::Args::RenderMethod::FORWARD,
};
Q_ENUM(RenderMethod);
Q_ENUM(RenderMethod)
public slots:
/**jsdoc
@ -136,11 +136,16 @@ signals:
void settingsChanged();
private:
int _renderMethod { -1 };
mutable ReadWriteLockable _renderMethodSettingLock;
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 };
static std::once_flag registry_flag;
};
#endif // hifi_RenderScriptingInterface_h