From ca720efce60a63acebc4c4ffde6bf53d9c7a4071 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 18 Apr 2016 14:53:06 -0700 Subject: [PATCH] Exposing the timing of the jobs by default --- examples/utilities/render/stats.qml | 37 ++++++++++++++++++- .../render-utils/src/DeferredGlobalLight.slh | 30 +++------------ .../render-utils/src/RenderDeferredTask.cpp | 12 +----- .../render-utils/src/RenderDeferredTask.h | 27 +------------- libraries/render/src/render/Task.h | 16 ++++++++ 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/examples/utilities/render/stats.qml b/examples/utilities/render/stats.qml index 124d02f631..8c11fa1908 100644 --- a/examples/utilities/render/stats.qml +++ b/examples/utilities/render/stats.qml @@ -199,7 +199,42 @@ Item { color: "#FED959" } ] - } + } + + PlotPerf { + title: "Timing" + height: parent.evalEvenHeight() + object: parent.drawOpaqueConfig + valueUnit: "ms" + valueScale: 1000 + valueNumDigits: "1" + plots: [ + { + object: Render.getConfig("DrawOpaqueDeferred"), + prop: "cpuRunTime", + label: "Opaques", + color: "#1AC567" + }, + { + object: Render.getConfig("DrawTransparentDeferred"), + prop: "cpuRunTime", + label: "Translucents", + color: "#00B4EF" + }, + { + object: Render.getConfig("RenderDeferred"), + prop: "cpuRunTime", + label: "Lighting", + color: "#FED959" + }, + { + object: Render.getConfig("RenderDeferredTask"), + prop: "cpuRunTime", + label: "RenderFrame", + color: "#E2334D" + } + ] + } } } diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 0b582ca954..c87aa1cee2 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -30,8 +30,7 @@ vec4 evalSkyboxLight(vec3 direction, float lod) { // Transform directions to worldspace vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0)); - // vec3 fragEyeVector = vec3(invViewMat * vec4(-position, 0.0)); - vec3 fragEyeVector = vec3(invViewMat * vec4(-normalize(position), 0.0)); + vec3 fragEyeVector = vec3(invViewMat * vec4(-position, 0.0)); vec3 fragEyeDir = normalize(fragEyeVector); // Get light @@ -90,32 +89,15 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu color += (1 - metallic) * albedo * evalSphericalLight(getLightAmbientSphere(light), fragNormal).xyz * obscurance * getLightAmbientIntensity(light); // Specular highlight from ambient - //vec3 direction = -reflect(fragEyeDir, fragNormal); - // -normalize(position) - vec3 direction = -reflect(-normalize(position), normal); - // vec3 direction = normal; - - // if (gl_FragCoord.x > 1000) { - float angleY = fract(asin(direction.y)/ 0.314); - float angleX = fract(acos(normalize(direction.xz).x)/ 0.314); - float stripeY = step(0.05,abs(angleY)); - float stripeX = step(0.05,abs(angleX)); - float grid = max(stripeY, stripeX); - return mix( 0.5 * direction + vec3(0.5), mix(vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), stripeY), grid); -// } + vec3 direction = -reflect(fragEyeDir, fragNormal); float levels = getLightAmbientMapNumMips(light); float lod = min(floor((roughness) * levels), levels); - // vec4 skyboxLight = evalSkyboxLight(direction, lod); - vec4 skyboxLight = evalSkyboxLight(direction, levels * 0.5); - - return skyboxLight.xyz; + vec4 skyboxLight = evalSkyboxLight(direction, lod); + vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1 - roughness); + color += ambientFresnel * skyboxLight.rgb * obscurance * getLightAmbientIntensity(light); - - //vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1 - roughness); - //color += ambientFresnel * skyboxLight.rgb * obscurance * getLightAmbientIntensity(light); - - //return color; + return color; } <@endfunc@> diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index b5cd6b50ec..0a4cc45310 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -12,8 +12,6 @@ #include "RenderDeferredTask.h" -#include - #include #include #include @@ -47,13 +45,7 @@ void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderC } void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - QElapsedTimer cpuTimer; - cpuTimer.start(); - auto config = std::static_pointer_cast(renderContext->jobConfig); - DependencyManager::get()->render(renderContext); - - config->setStats(cpuTimer.elapsed()); } RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) { @@ -183,8 +175,6 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems) { assert(renderContext->args); assert(renderContext->args->_viewFrustum); - QElapsedTimer cpuTimer; - cpuTimer.start(); auto config = std::static_pointer_cast(renderContext->jobConfig); @@ -207,7 +197,7 @@ void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderCont args->_batch = nullptr; }); - config->setStats((int)inItems.size(), cpuTimer.elapsed()); + config->setNumDrawn((int)inItems.size()); } DrawOverlay3D::DrawOverlay3D(bool opaque) : diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index cb1a2e7141..427d3a9a47 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -30,44 +30,22 @@ public: using JobModel = render::Job::Model; }; -class RenderDeferredConfig : public render::Job::Config { - Q_OBJECT - Q_PROPERTY(quint64 cpuTime READ getCPUTime NOTIFY newStats) - -public: - - quint64 getCPUTime() { return _cpuTime; } - - void setStats(quint64 time) { _cpuTime = time; emit newStats(); } - -signals: - void newStats(); - -protected: - quint64 _cpuTime{ 0 }; -}; - class RenderDeferred { public: - using Config = RenderDeferredConfig; - using JobModel = render::Job::Model; + using JobModel = render::Job::Model; - void configure(const Config& config) {} void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); }; class DrawConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY newStats) - Q_PROPERTY(quint64 cpuTime READ getCPUTime NOTIFY newStats) Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty) public: int getNumDrawn() { return _numDrawn; } - double getCPUTime() { return _cpuTime; } - - void setStats(int numDrawn, quint64 time) { _numDrawn = numDrawn; _cpuTime = time; emit newStats(); } + void setNumDrawn(int numDrawn) { _numDrawn = numDrawn; emit newStats(); } int maxDrawn{ -1 }; @@ -76,7 +54,6 @@ signals: void dirty(); protected: - quint64 _cpuTime{ 0 }; int _numDrawn{ 0 }; }; diff --git a/libraries/render/src/render/Task.h b/libraries/render/src/render/Task.h index eabdc99338..300c0efd56 100644 --- a/libraries/render/src/render/Task.h +++ b/libraries/render/src/render/Task.h @@ -127,6 +127,9 @@ protected: // 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(quint64 cpuRunTime READ getCPUTRunTime NOTIFY newStats()) + + quint64 _CPURunTime{ 0 }; public: using Persistent = PersistentConfig; @@ -151,11 +154,17 @@ 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(); } + // Running Time measurement + // The new stats signal is emitted once per run time of a job when stats (cpu runtime) are updated + void setCPURunTime(quint64 ustime) { _CPURunTime = ustime; emit newStats(); } + quint64 getCPUTRunTime() const { return _CPURunTime; } + public slots: void load(const QJsonObject& val) { qObjectFromJsonValue(val, *this); emit loaded(); } signals: void loaded(); + void newStats(); }; class TaskConfig : public JobConfig { @@ -223,7 +232,11 @@ public: virtual void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) = 0; protected: + void setCPURunTime(quint64 ustime) { std::static_pointer_cast(_config)->setCPURunTime(ustime); } + QConfigPointer _config; + + friend class Job; }; using ConceptPointer = std::shared_ptr; @@ -278,8 +291,11 @@ public: void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { PerformanceTimer perfTimer(_name.c_str()); PROFILE_RANGE(_name.c_str()); + auto start = usecTimestampNow(); _concept->run(sceneContext, renderContext); + + _concept->setCPURunTime(usecTimestampNow() - start); } protected: