From 6033ad81db9107bfcd0989d84783a5e84f05dc2a Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Mar 2016 16:09:33 -0700 Subject: [PATCH 1/4] Adding time counter --- examples/utilities/render/stats.qml | 6 +-- .../render-utils/src/RenderDeferredTask.cpp | 15 ++++++-- .../render-utils/src/RenderDeferredTask.h | 37 +++++++++++++++---- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/examples/utilities/render/stats.qml b/examples/utilities/render/stats.qml index 0e51cb8834..57da6fcf21 100644 --- a/examples/utilities/render/stats.qml +++ b/examples/utilities/render/stats.qml @@ -168,10 +168,10 @@ Item { title: "Items" height: parent.evalEvenHeight() object: parent.drawOpaqueConfig - trigger: Render.getConfig("DrawOpaqueDeferred")["numDrawn"] + trigger: parent.drawOpaqueConfig["numDrawn"] plots: [ { - object: Render.getConfig("DrawOpaqueDeferred"), + object: parent.drawOpaqueConfig, prop: "numDrawn", label: "Opaques", color: "#1AC567" @@ -186,7 +186,7 @@ Item { object: Render.getConfig("DrawLight"), prop: "numDrawn", label: "Lights", - color: "#E2334D" + color: "#FED959" } ] } diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index ba5b2a59d5..b5cd6b50ec 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -12,6 +12,8 @@ #include "RenderDeferredTask.h" +#include + #include #include #include @@ -45,7 +47,13 @@ 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) { @@ -175,6 +183,8 @@ 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); @@ -185,9 +195,6 @@ void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderCont batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - config->setNumDrawn((int)inItems.size()); - emit config->numDrawnChanged(); - glm::mat4 projMat; Transform viewMat; args->_viewFrustum->evalProjectionMatrix(projMat); @@ -199,6 +206,8 @@ void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderCont renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn); args->_batch = nullptr; }); + + config->setStats((int)inItems.size(), cpuTimer.elapsed()); } DrawOverlay3D::DrawOverlay3D(bool opaque) : diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 9fb6802992..cb1a2e7141 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -22,6 +22,7 @@ public: using JobModel = render::Job::Model; }; + class PrepareDeferred { public: void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); @@ -29,32 +30,54 @@ 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 JobModel = render::Job::Model; + using Config = RenderDeferredConfig; + 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 numDrawnChanged) + 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; } - void setNumDrawn(int num) { numDrawn = num; emit numDrawnChanged(); } + int getNumDrawn() { return _numDrawn; } + double getCPUTime() { return _cpuTime; } + + void setStats(int numDrawn, quint64 time) { _numDrawn = numDrawn; _cpuTime = time; emit newStats(); } int maxDrawn{ -1 }; signals: - void numDrawnChanged(); + void newStats(); void dirty(); protected: - int numDrawn{ 0 }; + quint64 _cpuTime{ 0 }; + int _numDrawn{ 0 }; }; class DrawDeferred { From 10ddecd5368664b578abfc618db6b98e80416e14 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 31 Mar 2016 01:51:26 -0700 Subject: [PATCH 2/4] Debuggingh the reflection jittering --- examples/utilities/render/framebuffer.qml | 1 + libraries/model/src/model/TextureMap.cpp | 2 +- .../render-utils/src/DeferredGlobalLight.slh | 20 ++++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/examples/utilities/render/framebuffer.qml b/examples/utilities/render/framebuffer.qml index d6f4ea7915..f13018142e 100644 --- a/examples/utilities/render/framebuffer.qml +++ b/examples/utilities/render/framebuffer.qml @@ -39,6 +39,7 @@ Column { "Shadow", "Pyramid Depth", "Ambient Occlusion", + "Ambient Occlusion Blurred", "Custom Shader" ] RadioButton { diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index 5173af438c..93ea920c90 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -583,7 +583,7 @@ gpu::Texture* TextureUsage::createCubeTextureFromImage(const QImage& srcImage, c // If the 6 faces have been created go on and define the true Texture if (faces.size() == gpu::Texture::NUM_FACES_PER_TYPE[gpu::Texture::TEX_CUBE]) { - theTexture = gpu::Texture::createCube(formatGPU, faces[0].width(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR, gpu::Sampler::WRAP_CLAMP)); + theTexture = gpu::Texture::createCube(formatGPU, faces[0].width(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR/*, gpu::Sampler::WRAP_CLAMP*/)); theTexture->autoGenerateMips(-1); int f = 0; for (auto& face : faces) { diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 71bc2dc6d0..8cc914b459 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -30,7 +30,8 @@ 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(-position, 0.0)); + vec3 fragEyeVector = vec3(invViewMat * vec4(-normalize(position), 0.0)); vec3 fragEyeDir = normalize(fragEyeVector); // Get light @@ -90,13 +91,22 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu // Specular highlight from ambient vec3 direction = -reflect(fragEyeDir, fragNormal); + + if (gl_FragCoord.x > 1000) + return 0.5 * direction + vec3(0.5); + float levels = getLightAmbientMapNumMips(light); float lod = min(floor((roughness) * levels), levels); - vec4 skyboxLight = evalSkyboxLight(direction, lod); - vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1 - roughness); - color += ambientFresnel * skyboxLight.rgb * obscurance * getLightAmbientIntensity(light); + // vec4 skyboxLight = evalSkyboxLight(direction, lod); + vec4 skyboxLight = evalSkyboxLight(direction, levels * 0.5); + + return skyboxLight.xyz; - return color; + + //vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1 - roughness); + //color += ambientFresnel * skyboxLight.rgb * obscurance * getLightAmbientIntensity(light); + + //return color; } <@endfunc@> From 1b54a294916dc650aff2f448d2c2db06f942edfd Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 31 Mar 2016 11:34:27 -0700 Subject: [PATCH 3/4] small improvments adn exploring the jittering bug for reflections --- examples/utilities/render/plotperf/PlotPerf.qml | 8 ++++---- examples/utilities/render/stats.qml | 2 ++ .../render-utils/src/DeferredGlobalLight.slh | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/examples/utilities/render/plotperf/PlotPerf.qml b/examples/utilities/render/plotperf/PlotPerf.qml index 179707c0f1..dfd72b95e8 100644 --- a/examples/utilities/render/plotperf/PlotPerf.qml +++ b/examples/utilities/render/plotperf/PlotPerf.qml @@ -55,11 +55,11 @@ Item { property var tick : 0 function createValues() { - print("trigger is: " + JSON.stringify(trigger)) + // print("trigger is: " + JSON.stringify(trigger)) if (Array.isArray(plots)) { for (var i =0; i < plots.length; i++) { var plot = plots[i]; - print(" a pnew Plot:" + JSON.stringify(plot)); + // print(" a pnew Plot:" + JSON.stringify(plot)); _values.push( { object: (plot["object"] !== undefined ? plot["object"] : root.object), value: plot["prop"], @@ -73,13 +73,13 @@ Item { }) } } - print("in creator" + JSON.stringify(_values)); + // print("in creator" + JSON.stringify(_values)); } Component.onCompleted: { createValues(); - print(JSON.stringify(_values)); + //print(JSON.stringify(_values)); } diff --git a/examples/utilities/render/stats.qml b/examples/utilities/render/stats.qml index 57da6fcf21..7d65aecd4f 100644 --- a/examples/utilities/render/stats.qml +++ b/examples/utilities/render/stats.qml @@ -10,6 +10,8 @@ // import QtQuick 2.5 import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.1 + import "plotperf" Item { diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 8cc914b459..0b582ca954 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -90,10 +90,19 @@ 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); + //vec3 direction = -reflect(fragEyeDir, fragNormal); + // -normalize(position) + vec3 direction = -reflect(-normalize(position), normal); + // vec3 direction = normal; - if (gl_FragCoord.x > 1000) - return 0.5 * direction + vec3(0.5); + // 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); +// } float levels = getLightAmbientMapNumMips(light); float lod = min(floor((roughness) * levels), levels); From ca720efce60a63acebc4c4ffde6bf53d9c7a4071 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 18 Apr 2016 14:53:06 -0700 Subject: [PATCH 4/4] 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: