From 767f413a2c1c16ccf02bf411900227154d256703 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 29 Jul 2019 00:07:16 -0700 Subject: [PATCH] merging the various job/task/switch congif into one --- .../scripting/RenderScriptingInterface.cpp | 2 +- libraries/render/src/render/Engine.h | 2 +- libraries/task/src/task/Config.cpp | 12 ++-- libraries/task/src/task/Config.h | 71 ++++++++++++++++--- libraries/task/src/task/Task.h | 56 +++++++++------ scripts/developer/utilities/lib/jet/jet.js | 8 ++- .../utilities/lib/jet/qml/TaskList.qml | 2 +- .../utilities/lib/jet/qml/TaskPropView.qml | 2 +- .../developer/utilities/lib/prop/PropItem.qml | 4 +- .../utilities/lib/prop/PropScalar.qml | 18 +++-- .../utilities/lib/prop/style/Global.qml | 8 ++- .../utilities/render/engineInspector.js | 62 ++-------------- .../utilities/render/engineInspector.qml | 2 +- .../developer/utilities/render/engineList.js | 18 ++--- .../developer/utilities/render/engineList.qml | 2 +- 15 files changed, 144 insertions(+), 125 deletions(-) diff --git a/interface/src/scripting/RenderScriptingInterface.cpp b/interface/src/scripting/RenderScriptingInterface.cpp index 338a5ab883..f23dc598a9 100644 --- a/interface/src/scripting/RenderScriptingInterface.cpp +++ b/interface/src/scripting/RenderScriptingInterface.cpp @@ -54,7 +54,7 @@ void RenderScriptingInterface::forceRenderMethod(RenderMethod renderMethod) { _renderMethod = (int)renderMethod; _renderMethodSetting.set((int)renderMethod); - auto config = dynamic_cast(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch")); + auto config = dynamic_cast(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch")); if (config) { config->setBranch((int)renderMethod); } diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index 130ed6533f..f1d59727d3 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -70,7 +70,7 @@ namespace render { GPUTaskConfig() = default; - GPUTaskConfig(bool enabled) : TaskConfig(enabled) {} + GPUTaskConfig(bool enabled) : render::TaskConfig(enabled) {} // Running Time measurement on GPU and for Batch execution void setGPUBatchRunTime(double msGpuTime, double msBatchTime) { _msGPURunTime = msGpuTime; _msBatchRunTime = msBatchTime; } diff --git a/libraries/task/src/task/Config.cpp b/libraries/task/src/task/Config.cpp index 79e0b9f7fb..bcf5eb7d1f 100644 --- a/libraries/task/src/task/Config.cpp +++ b/libraries/task/src/task/Config.cpp @@ -79,8 +79,8 @@ void JobConfig::refresh() { _jobConcept->applyConfiguration(); } -TaskConfig* TaskConfig::getRootConfig(const std::string& jobPath, std::string& jobName) const { - TaskConfig* root = const_cast (this); +JobConfig* JobConfig::getRootConfig(const std::string& jobPath, std::string& jobName) const { + JobConfig* root = const_cast (this); std::list tokens; std::size_t pos = 0, sepPos; @@ -105,7 +105,7 @@ TaskConfig* TaskConfig::getRootConfig(const std::string& jobPath, std::string& j while (tokens.size() > 1) { auto taskName = tokens.front(); tokens.pop_front(); - root = root->findChild((taskName.empty() ? QString() : QString(taskName.c_str()))); + root = root->findChild((taskName.empty() ? QString() : QString(taskName.c_str()))); if (!root) { return nullptr; } @@ -115,7 +115,7 @@ TaskConfig* TaskConfig::getRootConfig(const std::string& jobPath, std::string& j return root; } -JobConfig* TaskConfig::getJobConfig(const std::string& jobPath) const { +JobConfig* JobConfig::getJobConfig(const std::string& jobPath) const { std::string jobName; auto root = getRootConfig(jobPath, jobName); @@ -134,10 +134,10 @@ JobConfig* TaskConfig::getJobConfig(const std::string& jobPath) const { } } -void SwitchConfig::setBranch(uint8_t branch) { +void JobConfig::setBranch(uint8_t branch) { if (_branch != branch) { _branch = branch; // We can re-use this signal here emit dirtyEnabled(); } -} \ No newline at end of file +} diff --git a/libraries/task/src/task/Config.h b/libraries/task/src/task/Config.h index ab76bc5fba..8c674da31c 100644 --- a/libraries/task/src/task/Config.h +++ b/libraries/task/src/task/Config.h @@ -83,11 +83,19 @@ protected: Setting::Handle _preset; }; +class JobConfig; + +class TConfigProxy { +public: + using Config = JobConfig; +}; + // A default Config is always on; to create an enableable Config, use the ctor JobConfig(bool enabled) class JobConfig : public QObject { Q_OBJECT Q_PROPERTY(double cpuRunTime READ getCPURunTime NOTIFY newStats()) //ms Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY dirtyEnabled()) + Q_PROPERTY(int branch READ getBranch WRITE setBranch NOTIFY dirtyEnabled) double _msCPURunTime{ 0.0 }; @@ -96,7 +104,11 @@ protected: bool _isEnabled{ true }; + uint8_t _branch { 0 }; public: + bool _isTask{ false }; + bool _isSwitch{ false }; + using Persistent = PersistentConfig; JobConfig() = default; @@ -121,44 +133,86 @@ public: */ Q_INVOKABLE void load(const QVariantMap& map) { qObjectFromJsonValue(QJsonObject::fromVariantMap(map), *this); emit loaded(); } - Q_INVOKABLE QObject* getConfig(const QString& name) { return nullptr; } + //Q_INVOKABLE QObject* getConfig(const QString& name) { return nullptr; } // Running Time measurement // The new stats signal is emitted once per run time of a job when stats (cpu runtime) are updated void setCPURunTime(const std::chrono::nanoseconds& runtime) { _msCPURunTime = std::chrono::duration(runtime).count(); emit newStats(); } double getCPURunTime() const { return _msCPURunTime; } + /**jsdoc + * @function Render.getConfig + * @param {string} name + * @returns {object} + */ + // Get a sub job config through task.getConfig(path) + // where path can be: + // - search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root) + // - .[.] + // Allowing to first look for the parent_name job (from this task as root) and then search from there for the + // optional sub_parent_names and finally from there looking for the job_name (assuming every job in the path were found) + // + // getter for qml integration, prefer the templated getter + Q_INVOKABLE QObject* getConfig(const QString& name) { return getConfig(name.toStdString()); } + + // getter for cpp (strictly typed), prefer this getter + JobConfig* getRootConfig(const std::string& jobPath, std::string& jobName) const; + JobConfig* getJobConfig(const std::string& jobPath) const; + template typename T::Config* getConfig(std::string jobPath = "") const { + return dynamic_cast(getJobConfig(jobPath)); + } + + Q_INVOKABLE bool isTask() const { return _isTask; } + Q_INVOKABLE bool isSwitch() const { return _isSwitch; } + + Q_INVOKABLE QObjectList getSubConfigs() const { + auto list = findChildren(QRegExp(".*"), Qt::FindDirectChildrenOnly); + QObjectList returned; + for (int i = 0; i < list.size(); i++) { + returned.push_back(list[i]); + } + return returned; + } + Q_INVOKABLE int getNumSubs() const { return getSubConfigs().size(); } + Q_INVOKABLE QObject* getSubConfig(int i) const { + auto subs = getSubConfigs(); + return ((i < 0 || i >= subs.size()) ? nullptr : subs[i]); + } + // Describe the node graph data connections of the associated Job/Task /**jsdoc * @function Render.isTask * @returns {boolean} */ - Q_INVOKABLE virtual bool isTask() const { return false; } + //Q_INVOKABLE virtual bool isTask() const { return false; } /**jsdoc * @function Render.getSubConfigs * @returns {object[]} */ - Q_INVOKABLE virtual QObjectList getSubConfigs() const { return QObjectList(); } + // Q_INVOKABLE virtual QObjectList getSubConfigs() const { return QObjectList(); } /**jsdoc * @function Render.getNumSubs * @returns {number} */ - Q_INVOKABLE virtual int getNumSubs() const { return 0; } + // Q_INVOKABLE virtual int getNumSubs() const { return 0; } /**jsdoc * @function Render.getSubConfig * @param {number} index * @returns {object} */ - Q_INVOKABLE virtual QObject* getSubConfig(int i) const { return nullptr; } + //Q_INVOKABLE virtual QObject* getSubConfig(int i) const { return nullptr; } void connectChildConfig(std::shared_ptr childConfig, const std::string& name); void transferChildrenConfigs(std::shared_ptr source); JobConcept* _jobConcept; + uint8_t getBranch() const { return _branch; } + void setBranch(uint8_t index); + public slots: /**jsdoc @@ -195,12 +249,9 @@ signals: using QConfigPointer = std::shared_ptr; -class TConfigProxy { -public: - using Config = JobConfig; -}; +#ifdef SPECIALIZE_CONFIG /**jsdoc * @namespace Render * @@ -270,7 +321,7 @@ public: protected: uint8_t _branch { 0 }; }; - +#endif } #endif // hifi_task_Config_h diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index cdc279ff36..0871cb5982 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -69,7 +69,7 @@ class JobConcept { public: using Config = JobConfig; - JobConcept(const std::string& name, QConfigPointer config) : _config(config), _name(name) {} + JobConcept(const std::string& name, QConfigPointer config) : _config(config), _name(name) { config->_jobConcept = this; } virtual ~JobConcept() = default; const std::string& getName() const { return _name; } @@ -80,7 +80,8 @@ public: virtual QConfigPointer& getConfiguration() { return _config; } virtual void applyConfiguration() = 0; - void setCPURunTime(const std::chrono::nanoseconds& runtime) { std::static_pointer_cast(_config)->setCPURunTime(runtime); } + void setCPURunTime(const std::chrono::nanoseconds& runtime) { + /*std::static_pointer_cast*/(_config)->setCPURunTime(runtime); } QConfigPointer _config; protected: @@ -94,9 +95,9 @@ template void jobConfigure(T& data, const C& configuration) { template void jobConfigure(T&, const JobConfig&) { // nop, as the default JobConfig was used, so the data does not need a configure method } -template void jobConfigure(T&, const TaskConfig&) { +/*template void jobConfigure(T&, const TaskConfig&) { // nop, as the default TaskConfig was used, so the data does not need a configure method -} +}*/ template void jobRun(T& data, const JC& jobContext, const JobNoIO& input, JobNoIO& output) { data.run(jobContext); @@ -158,7 +159,17 @@ public: return std::make_shared(name, input, std::make_shared(), std::forward(args)...); } - + void createConfiguration() { + // A brand new config + auto config = std::make_shared(); + // Make sure we transfer the former children configs to the new config + config->transferChildrenConfigs(Concept::_config); + // swap + Concept::_config = config; + // Capture this + Concept::_config->_jobConcept = this; + } + void applyConfiguration() override { TimeProfiler probe(("configure::" + JobConcept::getName())); @@ -228,7 +239,7 @@ public: using Context = JC; using TimeProfiler = TP; using ContextPointer = std::shared_ptr; - using Config = TaskConfig; + using Config = JobConfig; //TaskConfig; using JobType = Job; using None = typename JobType::None; using Concept = typename JobType::Concept; @@ -247,14 +258,15 @@ public: const Varying getOutput() const override { return _output; } Varying& editInput() override { return _input; } - TaskConcept(const std::string& name, const Varying& input, QConfigPointer config) : Concept(name, config), _input(input) {} + TaskConcept(const std::string& name, const Varying& input, QConfigPointer config) : Concept(name, config), _input(input) {config->_isTask = true;} // Create a new job in the container's queue; returns the job's output template const Varying addJob(std::string name, const Varying& input, NA&&... args) { _jobs.emplace_back((NT::JobModel::create(name, input, std::forward(args)...))); // Conect the child config to this task's config - std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); + // std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); + std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); return _jobs.back().getOutput(); } @@ -285,8 +297,8 @@ public: model->_data.build(*(model), model->_input, model->_output, std::forward(args)...); } // Recreate the Config to use the templated type - model->createConfiguration(); - model->applyConfiguration(); + // model->createConfiguration(); + // model->applyConfiguration(); return model; } @@ -369,7 +381,7 @@ public: using Context = JC; using TimeProfiler = TP; using ContextPointer = std::shared_ptr; - using Config = SwitchConfig; + using Config = JobConfig; //SwitchConfig; using JobType = Job; using None = typename JobType::None; using Concept = typename JobType::Concept; @@ -388,14 +400,15 @@ public: const Varying getOutput() const override { return _output; } Varying& editInput() override { return _input; } - SwitchConcept(const std::string& name, const Varying& input, QConfigPointer config) : Concept(name, config), _input(input) {} + SwitchConcept(const std::string& name, const Varying& input, QConfigPointer config) : Concept(name, config), _input(input) + {config->_isTask = true; config->_isSwitch = true; } template const Varying addBranch(std::string name, uint8_t index, const Varying& input, NA&&... args) { auto& branch = _branches[index]; branch = JobType(NT::JobModel::create(name, input, std::forward(args)...)); // Conect the child config to this task's config - std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(branch.getConfiguration(), name); + std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(branch.getConfiguration(), name); return branch.getOutput(); } @@ -405,7 +418,7 @@ public: } }; - template class SwitchModel : public SwitchConcept { + template class SwitchModel : public SwitchConcept { public: using Data = T; using Input = I; @@ -427,8 +440,8 @@ public: model->_data.build(*(model), model->_input, model->_output, std::forward(args)...); } // Recreate the Config to use the templated type - model->createConfiguration(); - model->applyConfiguration(); + // model->createConfiguration(); + // model->applyConfiguration(); return model; } @@ -475,8 +488,8 @@ public: } } }; - template using Model = SwitchModel; - template using ModelI = SwitchModel; + template using Model = SwitchModel; + template using ModelI = SwitchModel; // TODO: Switches don't support Outputs yet //template using ModelO = SwitchModel; //template using ModelIO = SwitchModel; @@ -500,7 +513,7 @@ class Engine : public Task { public: using Context = JC; using ContextPointer = std::shared_ptr; - using Config = TaskConfig; + using Config = JobConfig; //TaskConfig; using TaskType = Task; using ConceptPointer = typename TaskType::ConceptPointer; @@ -526,10 +539,11 @@ protected: } + #define Task_DeclareTypeAliases(ContextType, TimeProfiler) \ using JobConfig = task::JobConfig; \ - using TaskConfig = task::TaskConfig; \ - using SwitchConfig = task::SwitchConfig; \ + using TaskConfig = task::JobConfig; \ + using SwitchConfig = task::JobConfig; \ template using PersistentConfig = task::PersistentConfig; \ using Job = task::Job; \ using Switch = task::Switch; \ diff --git a/scripts/developer/utilities/lib/jet/jet.js b/scripts/developer/utilities/lib/jet/jet.js index 52c13c5279..4c3188a5cf 100644 --- a/scripts/developer/utilities/lib/jet/jet.js +++ b/scripts/developer/utilities/lib/jet/jet.js @@ -18,7 +18,7 @@ // @param depth: the depth of the recurse loop since the initial call. function task_traverse(root, functor, depth) { if (root.isTask()) { - depth++; + depth++; for (var i = 0; i