Bringing the work and refinment done in workload branch to master branch

This commit is contained in:
samcake 2018-05-03 17:46:50 -07:00
parent 82fac69e7a
commit 6d251c4cd3
6 changed files with 74 additions and 13 deletions

View file

@ -181,7 +181,7 @@ class DebugAmbientOcclusionConfig : public render::Job::Config {
Q_PROPERTY(bool showCursorPixel MEMBER showCursorPixel NOTIFY dirty)
Q_PROPERTY(glm::vec2 debugCursorTexcoord MEMBER debugCursorTexcoord NOTIFY dirty)
public:
DebugAmbientOcclusionConfig() : render::Job::Config(true) {}
DebugAmbientOcclusionConfig() : render::Job::Config(false) {}
bool showCursorPixel{ false };
glm::vec2 debugCursorTexcoord{ 0.5f, 0.5f };

View file

@ -195,7 +195,7 @@ class DebugLightClustersConfig : public render::Job::Config {
Q_PROPERTY(bool doDrawClusterFromDepth MEMBER doDrawClusterFromDepth NOTIFY dirty)
Q_PROPERTY(bool doDrawContent MEMBER doDrawContent NOTIFY dirty)
public:
DebugLightClustersConfig() : render::Job::Config(true){}
DebugLightClustersConfig() : render::Job::Config(false){}
bool doDrawGrid{ false };

View file

@ -149,7 +149,7 @@ class DebugSubsurfaceScatteringConfig : public render::Job::Config {
Q_PROPERTY(bool showCursorPixel MEMBER showCursorPixel NOTIFY dirty)
Q_PROPERTY(glm::vec2 debugCursorTexcoord MEMBER debugCursorTexcoord NOTIFY dirty)
public:
DebugSubsurfaceScatteringConfig() : render::Job::Config(true) {}
DebugSubsurfaceScatteringConfig() : render::Job::Config(false) {}
bool showProfile{ false };
bool showLUT{ false };

View file

@ -122,6 +122,7 @@ public:
Builder& withDynamic() { _flags.set(DYNAMIC); return (*this); }
Builder& withDeformed() { _flags.set(DEFORMED); return (*this); }
Builder& withInvisible() { _flags.set(INVISIBLE); return (*this); }
Builder& withVisible() { _flags.reset(INVISIBLE); return (*this); }
Builder& withShadowCaster() { _flags.set(SHADOW_CASTER); return (*this); }
Builder& withLayered() { _flags.set(LAYERED); return (*this); }
Builder& withMetaCullGroup() { _flags.set(META_CULL_GROUP); return (*this); }

View file

@ -12,6 +12,8 @@
#ifndef hifi_task_Config_h
#define hifi_task_Config_h
#include <chrono>
#include <QtCore/qobject.h>
#include <QtCore/qjsondocument.h>
#include <QtCore/qjsonobject.h>
@ -108,11 +110,19 @@ public:
Q_INVOKABLE QString toJSON() { return QJsonDocument(toJsonValue(*this).toObject()).toJson(QJsonDocument::Compact); }
Q_INVOKABLE void load(const QVariantMap& map) { qObjectFromJsonValue(QJsonObject::fromVariantMap(map), *this); emit loaded(); }
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(double mstime) { _msCPURunTime = mstime; emit newStats(); }
void setCPURunTime(const std::chrono::nanoseconds& runtime) { _msCPURunTime = std::chrono::duration<double, std::milli>(runtime).count(); emit newStats(); }
double getCPURunTime() const { return _msCPURunTime; }
// Describe the node graph data connections of the associated Job/Task
Q_INVOKABLE virtual bool isTask() const { return false; }
Q_INVOKABLE virtual QObjectList getSubConfigs() const { return QObjectList(); }
Q_INVOKABLE virtual int getNumSubs() const { return 0; }
Q_INVOKABLE virtual QObject* getSubConfig(int i) const { return nullptr; }
public slots:
void load(const QJsonObject& val) { qObjectFromJsonValue(val, *this); emit loaded(); }
@ -122,6 +132,8 @@ signals:
void dirtyEnabled();
};
using QConfigPointer = std::shared_ptr<JobConfig>;
class TConfigProxy {
public:
using Config = JobConfig;
@ -134,11 +146,9 @@ public:
using Persistent = PersistentConfig<TaskConfig>;
TaskConfig() = default ;
TaskConfig() = default;
TaskConfig(bool enabled) : JobConfig(enabled) {}
// Get a sub job config through task.getConfig(path)
// where path can be:
// - <job_name> search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root)
@ -170,6 +180,21 @@ public:
return root->findChild<typename T::Config*>(tokens.front());
}
Q_INVOKABLE bool isTask() const override { return true; }
Q_INVOKABLE QObjectList getSubConfigs() const override {
auto list = findChildren<JobConfig*>(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 override { return getSubConfigs().size(); }
Q_INVOKABLE QObject* getSubConfig(int i) const override {
auto subs = getSubConfigs();
return ((i < 0 || i >= subs.size()) ? nullptr : subs[i]);
}
void connectChildConfig(QConfigPointer childConfig, const std::string& name);
void transferChildrenConfigs(QConfigPointer source);
@ -179,8 +204,6 @@ public slots:
void refresh();
};
using QConfigPointer = std::shared_ptr<QObject>;
}
#endif // hifi_task_Config_h

View file

@ -80,10 +80,11 @@ public:
virtual const Varying getInput() const { return Varying(); }
virtual const Varying getOutput() const { return Varying(); }
virtual Varying& editInput() = 0;
virtual QConfigPointer& getConfiguration() { return _config; }
virtual void applyConfiguration() = 0;
void setCPURunTime(double mstime) { std::static_pointer_cast<Config>(_config)->setCPURunTime(mstime); }
void setCPURunTime(const std::chrono::nanoseconds& runtime) { std::static_pointer_cast<Config>(_config)->setCPURunTime(runtime); }
QConfigPointer _config;
protected:
@ -143,6 +144,10 @@ public:
const Varying getInput() const override { return _input; }
const Varying getOutput() const override { return _output; }
Varying& editInput() override { return _input; }
template <class I> void feedInput(const I& in) { _concept->editInput().template edit<I>() = in; }
template <class I, class S> void feedInput(int index, const S& inS) { (_concept->editInput().template editN<I>(index)).template edit<S>() = inS; }
template <class... A>
Model(const std::string& name, const Varying& input, QConfigPointer config, A&&... args) :
@ -201,11 +206,12 @@ public:
PerformanceTimer perfTimer(getName().c_str());
// NOTE: rather than use the PROFILE_RANGE macro, we create a Duration manually
Duration profileRange(jobContext->profileCategory, ("run::" + getName()).c_str());
auto start = usecTimestampNow();
auto startTime = std::chrono::high_resolution_clock::now();
_concept->run(jobContext);
_concept->setCPURunTime((double)(usecTimestampNow() - start) / 1000.0);
_concept->setCPURunTime((std::chrono::high_resolution_clock::now() - startTime));
}
protected:
@ -242,6 +248,8 @@ public:
const Varying getInput() const override { return _input; }
const Varying getOutput() const override { return _output; }
Varying& editInput() override { return _input; }
typename Jobs::iterator editJob(std::string name) {
typename Jobs::iterator jobIt;
for (jobIt = _jobs.begin(); jobIt != _jobs.end(); ++jobIt) {
@ -370,8 +378,36 @@ public:
protected:
};
}
template <class JC>
class Engine : public Task<JC> {
public:
using Context = JC;
using ContextPointer = std::shared_ptr<Context>;
using Config = TaskConfig;
using TaskType = Task<JC>;
using ConceptPointer = typename TaskType::ConceptPointer;
Engine(ConceptPointer concept) : TaskType(concept) {}
~Engine() = default;
void reset(const ContextPointer& context) { _context = context; }
void run() {
if (_context) {
run(_context);
}
}
protected:
void run(const ContextPointer& jobContext) override {
TaskType::run(_context);
}
ContextPointer _context;
};
}
#define Task_DeclareTypeAliases(ContextType) \
using JobConfig = task::JobConfig; \
@ -379,6 +415,7 @@ protected:
template <class T> using PersistentConfig = task::PersistentConfig<T>; \
using Job = task::Job<ContextType>; \
using Task = task::Task<ContextType>; \
using _Engine = task::Engine<ContextType>; \
using Varying = task::Varying; \
template < typename T0, typename T1 > using VaryingSet2 = task::VaryingSet2<T0, T1>; \
template < typename T0, typename T1, typename T2 > using VaryingSet3 = task::VaryingSet3<T0, T1, T2>; \