From be27eaff24f42781b518e9e05bdb3a0ef586bcaa Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 29 Mar 2016 17:51:24 -0700 Subject: [PATCH 1/5] Moving the scripts for render that where in utilities/tools/render to utilities/render, adding counters for lights --- examples/utilities/{tools => }/render/BG.qml | 0 .../configSlider}/ConfigSlider.qml | 0 examples/utilities/render/configSlider/qmldir | 1 + examples/utilities/render/culling.qml | 114 ++++++++++++++++++ .../utilities/{tools => }/render/debug.js | 0 .../utilities/{tools => }/render/debugBG.js | 0 .../{tools => }/render/debugFramebuffer.js | 0 examples/utilities/render/debugRender.js | 21 ++++ .../{tools => }/render/framebuffer.qml | 0 .../utilities/{tools => }/render/main.qml | 1 + .../{tools => }/render/plotperf/PlotPerf.qml | 2 +- .../{tools => }/render/plotperf/qmldir | 0 .../{tools => }/render/renderStats.js | 0 .../utilities/{tools => }/render/stats.qml | 15 ++- .../utilities/tools/debugRenderCulling.js | 99 --------------- .../src/DeferredLightingEffect.cpp | 2 + .../render-utils/src/RenderDeferredTask.h | 3 +- libraries/render-utils/src/spot_light.slf | 3 + libraries/render/src/render/DrawSceneOctree.h | 28 +++-- libraries/render/src/render/DrawTask.cpp | 15 ++- libraries/render/src/render/DrawTask.h | 26 +++- 21 files changed, 211 insertions(+), 119 deletions(-) rename examples/utilities/{tools => }/render/BG.qml (100%) rename examples/utilities/{tools/render => render/configSlider}/ConfigSlider.qml (100%) create mode 100644 examples/utilities/render/configSlider/qmldir create mode 100644 examples/utilities/render/culling.qml rename examples/utilities/{tools => }/render/debug.js (100%) rename examples/utilities/{tools => }/render/debugBG.js (100%) rename examples/utilities/{tools => }/render/debugFramebuffer.js (100%) create mode 100644 examples/utilities/render/debugRender.js rename examples/utilities/{tools => }/render/framebuffer.qml (100%) rename examples/utilities/{tools => }/render/main.qml (99%) rename examples/utilities/{tools => }/render/plotperf/PlotPerf.qml (99%) rename examples/utilities/{tools => }/render/plotperf/qmldir (100%) rename examples/utilities/{tools => }/render/renderStats.js (100%) rename examples/utilities/{tools => }/render/stats.qml (85%) delete mode 100644 examples/utilities/tools/debugRenderCulling.js diff --git a/examples/utilities/tools/render/BG.qml b/examples/utilities/render/BG.qml similarity index 100% rename from examples/utilities/tools/render/BG.qml rename to examples/utilities/render/BG.qml diff --git a/examples/utilities/tools/render/ConfigSlider.qml b/examples/utilities/render/configSlider/ConfigSlider.qml similarity index 100% rename from examples/utilities/tools/render/ConfigSlider.qml rename to examples/utilities/render/configSlider/ConfigSlider.qml diff --git a/examples/utilities/render/configSlider/qmldir b/examples/utilities/render/configSlider/qmldir new file mode 100644 index 0000000000..6680ec9638 --- /dev/null +++ b/examples/utilities/render/configSlider/qmldir @@ -0,0 +1 @@ +ConfigSlider 1.0 ConfigSlider.qml \ No newline at end of file diff --git a/examples/utilities/render/culling.qml b/examples/utilities/render/culling.qml new file mode 100644 index 0000000000..e3f5e67bbe --- /dev/null +++ b/examples/utilities/render/culling.qml @@ -0,0 +1,114 @@ +// +// culling.qml +// examples/utilities/render +// +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import "configSlider" + +Column { + id: root + spacing: 8 + property var sceneOctree: Render.getConfig("DrawSceneOctree"); + property var itemSelection: Render.getConfig("DrawItemSelection"); + + Component.onCompleted: { + sceneOctree.enabled = true; + itemSelection.enabled = true; + sceneOctree.showVisibleCells = false; + sceneOctree.showEmptyCells = false; + itemSelection.showInsideItems = false; + itemSelection.showInsideSubcellItems = false; + itemSelection.showPartialItems = false; + itemSelection.showPartialSubcellItems = false; + } + Component.onDestruction: { + sceneOctree.enabled = false; + itemSelection.enabled = false; + Render.getConfig("FetchSceneSelection").freezeFrustum = false; + Render.getConfig("CullSceneSelection").freezeFrustum = false; + } + + GroupBox { + title: "Culling" + Row { + spacing: 8 + Column { + spacing: 8 + + CheckBox { + text: "Freeze Culling Frustum" + checked: false + onCheckedChanged: { + Render.getConfig("FetchSceneSelection").freezeFrustum = checked; + Render.getConfig("CullSceneSelection").freezeFrustum = checked; + } + } + Label { + text: "Octree" + } + CheckBox { + text: "Visible Cells" + checked: root.sceneOctree.showVisibleCells + onCheckedChanged: { root.sceneOctree.showVisibleCells = checked } + } + CheckBox { + text: "Empty Cells" + checked: false + onCheckedChanged: { root.sceneOctree.showEmptyCells = checked } + } + } + Column { + spacing: 8 + + Label { + text: "Frustum Items" + } + CheckBox { + text: "Inside Items" + checked: false + onCheckedChanged: { root.itemSelection.showInsideItems = checked } + } + CheckBox { + text: "Inside Sub-cell Items" + checked: false + onCheckedChanged: { root.itemSelection.showInsideSubcellItems = checked } + } + CheckBox { + text: "Partial Items" + checked: false + onCheckedChanged: { root.itemSelection.showPartialItems = checked } + } + CheckBox { + text: "Partial Sub-cell Items" + checked: false + onCheckedChanged: { root.itemSelection.showPartialSubcellItems = checked } + } + } + } + } + + GroupBox { + title: "Render Items" + + Column{ + Repeater { + model: [ "Opaque:DrawOpaqueDeferred", "Transparent:DrawTransparentDeferred", "Light:DrawLight", + "Opaque Overlays:DrawOverlay3DOpaque", "Transparent Overlays:DrawOverlay3DTransparent" ] + ConfigSlider { + label: qsTr(modelData.split(":")[0]) + integral: true + config: Render.getConfig(modelData.split(":")[1]) + property: "maxDrawn" + max: config.numDrawn + min: -1 + } + } + } + } +} diff --git a/examples/utilities/tools/render/debug.js b/examples/utilities/render/debug.js similarity index 100% rename from examples/utilities/tools/render/debug.js rename to examples/utilities/render/debug.js diff --git a/examples/utilities/tools/render/debugBG.js b/examples/utilities/render/debugBG.js similarity index 100% rename from examples/utilities/tools/render/debugBG.js rename to examples/utilities/render/debugBG.js diff --git a/examples/utilities/tools/render/debugFramebuffer.js b/examples/utilities/render/debugFramebuffer.js similarity index 100% rename from examples/utilities/tools/render/debugFramebuffer.js rename to examples/utilities/render/debugFramebuffer.js diff --git a/examples/utilities/render/debugRender.js b/examples/utilities/render/debugRender.js new file mode 100644 index 0000000000..788c7cb4a0 --- /dev/null +++ b/examples/utilities/render/debugRender.js @@ -0,0 +1,21 @@ +// +// debugRender.js +// examples/utilities/render +// +// Sam Gateau, created on 3/22/2016. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// Set up the qml ui +var qml = Script.resolvePath('culling.qml'); +var window = new OverlayWindow({ + title: 'Render Draws', + source: qml, + width: 300, + height: 200 +}); +window.setPosition(200, 50); +window.closed.connect(function() { Script.stop(); }); \ No newline at end of file diff --git a/examples/utilities/tools/render/framebuffer.qml b/examples/utilities/render/framebuffer.qml similarity index 100% rename from examples/utilities/tools/render/framebuffer.qml rename to examples/utilities/render/framebuffer.qml diff --git a/examples/utilities/tools/render/main.qml b/examples/utilities/render/main.qml similarity index 99% rename from examples/utilities/tools/render/main.qml rename to examples/utilities/render/main.qml index 22f263b2d0..aecd566207 100644 --- a/examples/utilities/tools/render/main.qml +++ b/examples/utilities/render/main.qml @@ -10,6 +10,7 @@ // import QtQuick 2.5 import QtQuick.Controls 1.4 +import "configSlider" Column { id: root diff --git a/examples/utilities/tools/render/plotperf/PlotPerf.qml b/examples/utilities/render/plotperf/PlotPerf.qml similarity index 99% rename from examples/utilities/tools/render/plotperf/PlotPerf.qml rename to examples/utilities/render/plotperf/PlotPerf.qml index 0e100e4e72..7141ea77d0 100644 --- a/examples/utilities/tools/render/plotperf/PlotPerf.qml +++ b/examples/utilities/render/plotperf/PlotPerf.qml @@ -1,6 +1,6 @@ // // PlotPerf.qml -// examples/utilities/tools/render +// examples/utilities/render/plotperf // // Created by Sam Gateau on 3//2016 // Copyright 2016 High Fidelity, Inc. diff --git a/examples/utilities/tools/render/plotperf/qmldir b/examples/utilities/render/plotperf/qmldir similarity index 100% rename from examples/utilities/tools/render/plotperf/qmldir rename to examples/utilities/render/plotperf/qmldir diff --git a/examples/utilities/tools/render/renderStats.js b/examples/utilities/render/renderStats.js similarity index 100% rename from examples/utilities/tools/render/renderStats.js rename to examples/utilities/render/renderStats.js diff --git a/examples/utilities/tools/render/stats.qml b/examples/utilities/render/stats.qml similarity index 85% rename from examples/utilities/tools/render/stats.qml rename to examples/utilities/render/stats.qml index aacc896444..ae5b433678 100644 --- a/examples/utilities/tools/render/stats.qml +++ b/examples/utilities/render/stats.qml @@ -1,6 +1,6 @@ // // stats.qml -// examples/utilities/tools/render +// examples/utilities/render // // Created by Zach Pomerantz on 2/8/2016 // Copyright 2016 High Fidelity, Inc. @@ -22,7 +22,7 @@ Item { anchors.fill:parent property var config: Render.getConfig("Stats") - + function evalEvenHeight() { // Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ? return (height - spacing * (children.length - 1)) / children.length @@ -65,5 +65,16 @@ Item { height: parent.evalEvenHeight() parameters: "1000:K:0:frameTriangleCount-frame-#E2334D:frameTriangleRate-rate-#1AC567-0.001-MT/s" } + + property var deferredTaskConfig: Render.getConfig("RenderDeferredTask") + property var drawLightConfig: deferredTaskConfig.getConfig("DrawLight") + + PlotPerf { + title: "Lights" + config: parent.drawLightConfig + height: parent.evalEvenHeight() + parameters: "1::0:numDrawn-frame-#E2334D" + } } + } diff --git a/examples/utilities/tools/debugRenderCulling.js b/examples/utilities/tools/debugRenderCulling.js deleted file mode 100644 index dbc5f07e0d..0000000000 --- a/examples/utilities/tools/debugRenderCulling.js +++ /dev/null @@ -1,99 +0,0 @@ -// -// debugRenderOctree.js -// examples/utilities/tools -// -// Sam Gateau -// Copyright 2016 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.include("cookies.js"); - -var panel = new Panel(10, 300); -var drawOctree = Render.RenderDeferredTask.DrawSceneOctree; -Render.RenderDeferredTask.DrawSceneOctree.enabled = true; -Render.RenderDeferredTask.DrawItemSelection.enabled = true; - -panel.newCheckbox("Show Octree Cells", - function(value) { Render.RenderDeferredTask.DrawSceneOctree.showVisibleCells = value; }, - function() { return (Render.RenderDeferredTask.DrawSceneOctree.showVisibleCells); }, - function(value) { return (value); } -); -panel.newCheckbox("Show Empty Cells", - function(value) { Render.RenderDeferredTask.DrawSceneOctree.showEmptyCells = value; }, - function() { return (Render.RenderDeferredTask.DrawSceneOctree.showEmptyCells); }, - function(value) { return (value); } -); -panel.newCheckbox("Freeze Frustum", - function(value) { Render.RenderDeferredTask.FetchSceneSelection.freezeFrustum = value; Render.RenderDeferredTask.CullSceneSelection.freezeFrustum = value; }, - function() { return (Render.RenderDeferredTask.FetchSceneSelection.freezeFrustum); }, - function(value) { return (value); } -); -panel.newCheckbox("Show Inside Items", - function(value) { Render.RenderDeferredTask.DrawItemSelection.showInsideItems = value; }, - function() { return (Render.RenderDeferredTask.DrawItemSelection.showInsideItems); }, - function(value) { return (value); } -); - -panel.newCheckbox("Show Inside Subcell Items", - function(value) { Render.RenderDeferredTask.DrawItemSelection.showInsideSubcellItems = value; }, - function() { return (Render.RenderDeferredTask.DrawItemSelection.showInsideSubcellItems); }, - function(value) { return (value); } -); - -panel.newCheckbox("Show Partial Items", - function(value) { Render.RenderDeferredTask.DrawItemSelection.showPartialItems = value; }, - function() { return (Render.RenderDeferredTask.DrawItemSelection.showPartialItems); }, - function(value) { return (value); } -); - -panel.newCheckbox("Show Partial Subcell Items", - function(value) { Render.RenderDeferredTask.DrawItemSelection.showPartialSubcellItems = value; }, - function() { return (Render.RenderDeferredTask.DrawItemSelection.showPartialSubcellItems); }, - function(value) { return (value); } -); - -/* -panel.newSlider('Cells Free / Allocated', -1, 1, - function(value) { value; }, // setter - function() { return Render.RenderDeferredTask.DrawSceneOctree.numFreeCells; }, // getter - function(value) { return value; }); - -this.update = function () { - var numFree = Render.RenderDeferredTask.DrawSceneOctree.numFreeCells; - var numAlloc = Render.RenderDeferredTask.DrawSceneOctree.numAllocatedCells; - var title = [ - ' ' + name, - numFree + ' / ' + numAlloc - ].join('\t'); - - widget.editTitle({ text: title }); - slider.setMaxValue(numAlloc); -}; -*/ -function mouseMoveEvent(event) { - panel.mouseMoveEvent(event); -} - -function mousePressEvent(event) { - panel.mousePressEvent(event); -} - -function mouseReleaseEvent(event) { - panel.mouseReleaseEvent(event); -} - -Controller.mouseMoveEvent.connect(mouseMoveEvent); -Controller.mousePressEvent.connect(mousePressEvent); -Controller.mouseReleaseEvent.connect(mouseReleaseEvent); - -function scriptEnding() { - panel.destroy(); - Render.RenderDeferredTask.DrawSceneOctree.enabled = false; - Render.RenderDeferredTask.DrawItemSelection.enabled = false; -} -Script.scriptEnding.connect(scriptEnding); - - diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index f3fa4a43b2..74795e6735 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -437,6 +437,7 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo // we should be able to draw thre same geometry use DepthClamp but for unknown reason it's s not working... if ((eyeHalfPlaneDistance > -nearRadius) && (glm::distance(eyePoint, glm::vec3(light->getPosition())) < expandedRadius + nearRadius)) { + light->setShowContour(true); coneParam.w = 0.0f; batch._glUniform4fv(_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam)); @@ -452,6 +453,7 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo batch.setProjectionTransform( projMats[side]); batch.setViewTransform(viewTransforms[side]); } else { + light->setShowContour(false); coneParam.w = 1.0f; batch._glUniform4fv(_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam)); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 0125ef79fe..9fb6802992 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -32,9 +32,10 @@ public: class RenderDeferred { public: + using JobModel = render::Job::Model; + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); - using JobModel = render::Job::Model; }; class DrawConfig : public render::Job::Config { diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index 69f8e836aa..1239628ac6 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -25,6 +25,7 @@ in vec4 _texCoord0; out vec4 _fragColor; void main(void) { + DeferredTransform deferredTransform = getDeferredTransform(); // Grab the fragment data from the uv @@ -36,6 +37,8 @@ void main(void) { // Kill if in front of the light volume float depth = frag.depthVal; if (depth < gl_FragCoord.z) { + _fragColor = vec4(1.0, 0.0, 0.0, 1.0); + return; discard; } diff --git a/libraries/render/src/render/DrawSceneOctree.h b/libraries/render/src/render/DrawSceneOctree.h index 60fc0bb2c4..530b7accac 100644 --- a/libraries/render/src/render/DrawSceneOctree.h +++ b/libraries/render/src/render/DrawSceneOctree.h @@ -20,17 +20,14 @@ namespace render { class DrawSceneOctreeConfig : public Job::Config { Q_OBJECT Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty()) - Q_PROPERTY(bool showVisibleCells MEMBER showVisibleCells WRITE setShowVisibleCells) - Q_PROPERTY(bool showEmptyCells MEMBER showEmptyCells WRITE setShowEmptyCells) + Q_PROPERTY(bool showVisibleCells READ getShowVisibleCells WRITE setShowVisibleCells NOTIFY dirty()) + Q_PROPERTY(bool showEmptyCells READ getShowEmptyCells WRITE setShowEmptyCells NOTIFY dirty()) Q_PROPERTY(int numAllocatedCells READ getNumAllocatedCells) Q_PROPERTY(int numFreeCells READ getNumFreeCells) public: DrawSceneOctreeConfig() : Job::Config(false) {} - - bool showVisibleCells{ true }; - bool showEmptyCells{ false }; int numAllocatedCells{ 0 }; int numFreeCells{ 0 }; @@ -38,6 +35,12 @@ namespace render { int getNumAllocatedCells() const { return numAllocatedCells; } int getNumFreeCells() const { return numFreeCells; } + bool showVisibleCells{ true }; + bool showEmptyCells{ false }; + + bool getShowVisibleCells() { return showVisibleCells; } + bool getShowEmptyCells() { return showEmptyCells; } + public slots: void setShowVisibleCells(bool show) { showVisibleCells = show; emit dirty(); } void setShowEmptyCells(bool show) { showEmptyCells = show; emit dirty(); } @@ -79,10 +82,10 @@ namespace render { class DrawItemSelectionConfig : public Job::Config { Q_OBJECT Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty()) - Q_PROPERTY(bool showInsideItems MEMBER showInsideItems WRITE setShowInsideItems) - Q_PROPERTY(bool showInsideSubcellItems MEMBER showInsideSubcellItems WRITE setShowInsideSubcellItems) - Q_PROPERTY(bool showPartialItems MEMBER showPartialItems WRITE setShowPartialItems) - Q_PROPERTY(bool showPartialSubcellItems MEMBER showPartialSubcellItems WRITE setShowPartialSubcellItems) + Q_PROPERTY(bool showInsideItems READ getShowInsideItems WRITE setShowInsideItems NOTIFY dirty()) + Q_PROPERTY(bool showInsideSubcellItems READ getShowInsideSubcellItems WRITE setShowInsideSubcellItems NOTIFY dirty()) + Q_PROPERTY(bool showPartialItems READ getShowPartialItems WRITE setShowPartialItems NOTIFY dirty()) + Q_PROPERTY(bool showPartialSubcellItems READ getShowPartialSubcellItems WRITE setShowPartialSubcellItems NOTIFY dirty()) public: DrawItemSelectionConfig() : Job::Config(false) {} @@ -92,7 +95,12 @@ namespace render { bool showPartialItems{ true }; bool showPartialSubcellItems{ true }; - public slots: + bool getShowInsideItems() const { return showInsideItems; }; + bool getShowInsideSubcellItems() const { return showInsideSubcellItems; }; + bool getShowPartialItems() const { return showPartialItems; }; + bool getShowPartialSubcellItems() const { return showPartialSubcellItems; }; + + public slots: void setShowInsideItems(bool show) { showInsideItems = show; emit dirty(); } void setShowInsideSubcellItems(bool show) { showInsideSubcellItems = show; emit dirty(); } void setShowPartialItems(bool show) { showPartialItems = show; emit dirty(); } diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index 733f7d9e9c..08ff97fd17 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -20,12 +20,16 @@ using namespace render; -void render::renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems) { +void render::renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems, int maxDrawnItems) { auto& scene = sceneContext->_scene; RenderArgs* args = renderContext->args; - for (const auto& itemDetails : inItems) { - auto& item = scene->getItem(itemDetails.id); + int numItemsToDraw = (int)inItems.size(); + if (maxDrawnItems != -1) { + numItemsToDraw = glm::min(numItemsToDraw, maxDrawnItems); + } + for (auto i = 0; i < numItemsToDraw; ++i) { + auto& item = scene->getItem(inItems[i].id); item.render(args); } } @@ -69,7 +73,10 @@ void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContext // render lights gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; - renderItems(sceneContext, renderContext, inLights); + renderItems(sceneContext, renderContext, inLights, _maxDrawn); args->_batch = nullptr; }); + + auto config = std::static_pointer_cast(renderContext->jobConfig); + config->setNumDrawn((int)inLights.size()); } diff --git a/libraries/render/src/render/DrawTask.h b/libraries/render/src/render/DrawTask.h index fc2ab9682f..8a0f951028 100755 --- a/libraries/render/src/render/DrawTask.h +++ b/libraries/render/src/render/DrawTask.h @@ -16,15 +16,37 @@ namespace render { -void renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems); +void renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems, int maxDrawnItems = -1); void renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems = -1); + + +class DrawLightConfig : public Job::Config { + Q_OBJECT + Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY numDrawnChanged) + Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty) +public: + int getNumDrawn() { return numDrawn; } + void setNumDrawn(int num) { numDrawn = num; emit numDrawnChanged(); } + + int maxDrawn{ -1 }; +signals: + void numDrawnChanged(); + void dirty(); + +protected: + int numDrawn{ 0 }; +}; + class DrawLight { public: - using JobModel = Job::ModelI; + using Config = DrawLightConfig; + using JobModel = Job::ModelI; + void configure(const Config& config) { _maxDrawn = config.maxDrawn; } void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inLights); protected: + int _maxDrawn; // initialized by Config }; } From b492c4b52c31c5cf61885486ee0c9a4687db8b6f Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Mar 2016 09:32:40 -0700 Subject: [PATCH 2/5] DUmb fix to the flickering issue by overshooting the inside volume of the light and avoid the failing region --- libraries/render-utils/src/DeferredLightingEffect.cpp | 4 ++-- libraries/render-utils/src/spot_light.slf | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 74795e6735..a0b8f0ae84 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -435,9 +435,9 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo float expandedRadius = light->getMaximumRadius() * (1.0f + SCALE_EXPANSION); // TODO: We shouldn;t have to do that test and use a different volume geometry for when inside the vlight volume, // we should be able to draw thre same geometry use DepthClamp but for unknown reason it's s not working... + const float OVER_CONSERVATIVE_SCALE = 1.1; if ((eyeHalfPlaneDistance > -nearRadius) && - (glm::distance(eyePoint, glm::vec3(light->getPosition())) < expandedRadius + nearRadius)) { - light->setShowContour(true); + (glm::distance(eyePoint, glm::vec3(light->getPosition())) < (expandedRadius * OVER_CONSERVATIVE_SCALE) + nearRadius)) { coneParam.w = 0.0f; batch._glUniform4fv(_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam)); diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index 1239628ac6..8355dcf91b 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -37,8 +37,6 @@ void main(void) { // Kill if in front of the light volume float depth = frag.depthVal; if (depth < gl_FragCoord.z) { - _fragColor = vec4(1.0, 0.0, 0.0, 1.0); - return; discard; } From 0ee1f039e9ba0dd52825e3fd3b2809aba8307cf6 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Mar 2016 11:15:10 -0700 Subject: [PATCH 3/5] Telling like it is... --- libraries/render-utils/src/DeferredLightingEffect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index a0b8f0ae84..ac24b09c40 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -435,7 +435,7 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo float expandedRadius = light->getMaximumRadius() * (1.0f + SCALE_EXPANSION); // TODO: We shouldn;t have to do that test and use a different volume geometry for when inside the vlight volume, // we should be able to draw thre same geometry use DepthClamp but for unknown reason it's s not working... - const float OVER_CONSERVATIVE_SCALE = 1.1; + const float OVER_CONSERVATIVE_SCALE = 1.1f; if ((eyeHalfPlaneDistance > -nearRadius) && (glm::distance(eyePoint, glm::vec3(light->getPosition())) < (expandedRadius * OVER_CONSERVATIVE_SCALE) + nearRadius)) { coneParam.w = 0.0f; From 3cf2eeb4d57e977a417c394d273255c82cc50321 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Mar 2016 13:58:32 -0700 Subject: [PATCH 4/5] IMproving the perfplot qml and adding 2 more info --- .../utilities/render/plotperf/PlotPerf.qml | 75 ++++++--- examples/utilities/render/stats.qml | 158 +++++++++++++++--- 2 files changed, 184 insertions(+), 49 deletions(-) diff --git a/examples/utilities/render/plotperf/PlotPerf.qml b/examples/utilities/render/plotperf/PlotPerf.qml index 7141ea77d0..179707c0f1 100644 --- a/examples/utilities/render/plotperf/PlotPerf.qml +++ b/examples/utilities/render/plotperf/PlotPerf.qml @@ -15,40 +15,64 @@ Item { id: root width: parent.width height: 100 + + // The title of the graph property string title - property var config - property string parameters - // THis is my hack to get the name of the first property and assign it to a trigger var in order to get + // THe object used as the default source object for the prop plots + property var object + + // THis is my hack to get a property and assign it to a trigger var in order to get // a signal called whenever the value changed - property var trigger: config[parameters.split(":")[3].split("-")[0]] + property var trigger + + // Plots is an array of plot descriptor + // a default plot descriptor expects the following object: + // prop: [ { + // object: {} // Optional: this is the object from which the prop will be fetched, + // if nothing than the object from root is used + // prop:"bufferCPUCount", // Needed the name of the property from the object to feed the plot + // label: "CPU", // Optional: Label as displayed on the plot + // color: "#00B4EF" // Optional: Color of the curve + // unit: "km/h" // Optional: Unit added to the value displayed, if nothing then the default unit is used + // scale: 1 // Optional: Extra scaling used to represent the value, this scale is combined with the global scale. + // }, + property var plots + + // Default value scale used to define the max value of the chart + property var valueScale: 1 + + // Default value unit appended to the value displayed + property var valueUnit: "" + + // Default number of digits displayed + property var valueNumDigits: 0 + - property var inputs: parameters.split(":") - property var valueScale: +inputs[0] - property var valueUnit: inputs[1] - property var valueNumDigits: inputs[2] - property var input_VALUE_OFFSET: 3 property var valueMax : 1 property var _values : new Array() property var tick : 0 function createValues() { - if (inputs.length > input_VALUE_OFFSET) { - for (var i = input_VALUE_OFFSET; i < inputs.length; i++) { - var varProps = inputs[i].split("-") - _values.push( { - value: varProps[0], - valueMax: 1, - numSamplesConstantMax: 0, - valueHistory: new Array(), - label: varProps[1], - color: varProps[2], - scale: (varProps.length > 3 ? varProps[3] : 1), - unit: (varProps.length > 4 ? varProps[4] : valueUnit) - }) - } - } + 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)); + _values.push( { + object: (plot["object"] !== undefined ? plot["object"] : root.object), + value: plot["prop"], + valueMax: 1, + numSamplesConstantMax: 0, + valueHistory: new Array(), + label: (plot["label"] !== undefined ? plot["label"] : ""), + color: (plot["color"] !== undefined ? plot["color"] : "white"), + scale: (plot["scale"] !== undefined ? plot["scale"] : 1), + unit: (plot["unit"] !== undefined ? plot["unit"] : valueUnit) + }) + } + } print("in creator" + JSON.stringify(_values)); } @@ -69,7 +93,8 @@ Item { var currentValueMax = 0 for (var i = 0; i < _values.length; i++) { - var currentVal = config[_values[i].value] * _values[i].scale; + var currentVal = _values[i].object[_values[i].value] * _values[i].scale; + _values[i].valueHistory.push(currentVal) _values[i].numSamplesConstantMax++; diff --git a/examples/utilities/render/stats.qml b/examples/utilities/render/stats.qml index ae5b433678..6326910220 100644 --- a/examples/utilities/render/stats.qml +++ b/examples/utilities/render/stats.qml @@ -30,51 +30,161 @@ Item { PlotPerf { title: "Num Buffers" - config: stats.config height: parent.evalEvenHeight() - parameters: "1::0:bufferCPUCount-CPU-#00B4EF:bufferGPUCount-GPU-#1AC567" + object: stats.config + trigger: stats.config["bufferCPUCount"] + plots: [ + { + prop: "bufferCPUCount", + label: "CPU", + color: "#00B4EF" + }, + { + prop: "bufferGPUCount", + label: "GPU", + color: "#1AC567" + } + ] } PlotPerf { title: "gpu::Buffer Memory" - config: stats.config height: parent.evalEvenHeight() - parameters: "1048576:Mb:1:bufferCPUMemoryUsage-CPU-#00B4EF:bufferGPUMemoryUsage-GPU-#1AC567" + object: stats.config + trigger: stats.config["bufferCPUMemoryUsage"] + valueScale: 1048576 + valueUnit: "Mb" + valueNumDigits: "1" + plots: [ + { + prop: "bufferCPUMemoryUsage", + label: "CPU", + color: "#00B4EF" + }, + { + prop: "bufferGPUMemoryUsage", + label: "GPU", + color: "#1AC567" + } + ] } - PlotPerf { title: "Num Textures" - config: stats.config height: parent.evalEvenHeight() - parameters: "1::0:textureCPUCount-CPU-#00B4EF:textureGPUCount-GPU-#1AC567:frameTextureCount-Frame-#E2334D" + object: stats.config + trigger: stats.config["textureCPUCount"] + plots: [ + { + prop: "textureCPUCount", + label: "CPU", + color: "#00B4EF" + }, + { + prop: "textureGPUCount", + label: "GPU", + color: "#1AC567" + }, + { + prop: "frameTextureCount", + label: "Frame", + color: "#E2334D" + } + ] } PlotPerf { title: "gpu::Texture Memory" - config: stats.config height: parent.evalEvenHeight() - parameters: "1048576:Mb:1:textureCPUMemoryUsage-CPU-#00B4EF:textureGPUMemoryUsage-GPU-#1AC567" + object: stats.config + trigger: stats.config["textureCPUMemoryUsage"] + valueScale: 1048576 + valueUnit: "Mb" + valueNumDigits: "1" + plots: [ + { + prop: "textureCPUMemoryUsage", + label: "CPU", + color: "#00B4EF" + }, + { + prop: "textureGPUMemoryUsage", + label: "GPU", + color: "#1AC567" + } + ] + } + + PlotPerf { + title: "Triangles" + height: parent.evalEvenHeight() + object: stats.config + trigger: stats.config["frameTriangleCount"] + valueScale: 1000 + valueUnit: "K" + plots: [ + { + prop: "frameTriangleCount", + label: "Frame", + color: "#E2334D" + }, + { + prop: "frameTriangleRate", + label: "rate", + color: "#1AC567", + scale: 0.001, + unit: "MT/s" + } + ] } PlotPerf { title: "Drawcalls" - config: stats.config height: parent.evalEvenHeight() - parameters: "1::0:frameDrawcallCount-frame-#E2334D:frameDrawcallRate-rate-#1AC567-0.001-K/s" + object: stats.config + trigger: stats.config["frameDrawcallCount"] + plots: [ + { + prop: "frameDrawcallCount", + label: "Frame", + color: "#E2334D" + }, + { + prop: "frameDrawcallRate", + label: "rate", + color: "#1AC567", + scale: 0.001, + unit: "K/s" + } + ] } - PlotPerf { - title: "Triangles" - config: stats.config - height: parent.evalEvenHeight() - parameters: "1000:K:0:frameTriangleCount-frame-#E2334D:frameTriangleRate-rate-#1AC567-0.001-MT/s" - } - - property var deferredTaskConfig: Render.getConfig("RenderDeferredTask") - property var drawLightConfig: deferredTaskConfig.getConfig("DrawLight") + + property var drawOpaqueConfig: Render.getConfig("DrawOpaqueDeferred") + property var drawTransparentConfig: Render.getConfig("DrawTransparentDeferred") + property var drawLightConfig: Render.getConfig("DrawLight") PlotPerf { - title: "Lights" - config: parent.drawLightConfig + title: "Items" height: parent.evalEvenHeight() - parameters: "1::0:numDrawn-frame-#E2334D" - } + object: parent.drawOpaqueConfig + trigger: Render.getConfig("DrawOpaqueDeferred")["numDrawn"] + plots: [ + { + object: Render.getConfig("DrawOpaqueDeferred"), + prop: "numDrawn", + label: "Opaques", + color: "#1AC567" + }, + { + object: Render.getConfig("DrawTransparentDeferred"), + prop: "numDrawn", + label: "Translucents", + color: "#00B4EF" + }, + { + object: Render.getConfig("DrawLight"), + prop: "numDrawn", + label: "Lights", + color: "#E2334D" + } + ] + } } } From 6213e0859d357bc11e99ff6fb7037fb35a5f15c2 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Mar 2016 15:07:45 -0700 Subject: [PATCH 5/5] Expose to counters fro drawcalls, one for the API drawcalls and the other for gpu drawcalls spawned --- examples/utilities/render/stats.qml | 17 +++++++++++------ libraries/gpu/src/gpu/Context.h | 1 + libraries/gpu/src/gpu/GLBackend.cpp | 8 +++++++- libraries/render/src/render/EngineStats.cpp | 1 + libraries/render/src/render/EngineStats.h | 2 ++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/examples/utilities/render/stats.qml b/examples/utilities/render/stats.qml index 6326910220..0e51cb8834 100644 --- a/examples/utilities/render/stats.qml +++ b/examples/utilities/render/stats.qml @@ -122,13 +122,13 @@ Item { plots: [ { prop: "frameTriangleCount", - label: "Frame", - color: "#E2334D" + label: "Triangles", + color: "#1AC567" }, { prop: "frameTriangleRate", label: "rate", - color: "#1AC567", + color: "#E2334D", scale: 0.001, unit: "MT/s" } @@ -140,15 +140,20 @@ Item { object: stats.config trigger: stats.config["frameDrawcallCount"] plots: [ + { + prop: "frameAPIDrawcallCount", + label: "API Drawcalls", + color: "#00B4EF" + }, { prop: "frameDrawcallCount", - label: "Frame", - color: "#E2334D" + label: "GPU Drawcalls", + color: "#1AC567" }, { prop: "frameDrawcallRate", label: "rate", - color: "#1AC567", + color: "#E2334D", scale: 0.001, unit: "K/s" } diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index b898bddef9..7f442895a5 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -35,6 +35,7 @@ public: int _RSNumTextureBounded = 0; + int _DSNumAPIDrawcalls = 0; int _DSNumDrawcalls = 0; int _DSNumTriangles = 0; diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index e847ad1a42..b5b6437ed8 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -326,6 +326,7 @@ void GLBackend::do_draw(Batch& batch, size_t paramOffset) { glDrawArrays(mode, startVertex, numVertices); _stats._DSNumTriangles += numVertices / 3; _stats._DSNumDrawcalls++; + _stats._DSNumAPIDrawcalls++; (void)CHECK_GL_ERROR(); } @@ -344,6 +345,7 @@ void GLBackend::do_drawIndexed(Batch& batch, size_t paramOffset) { glDrawElements(mode, numIndices, glType, indexBufferByteOffset); _stats._DSNumTriangles += numIndices / 3; _stats._DSNumDrawcalls++; + _stats._DSNumAPIDrawcalls++; (void) CHECK_GL_ERROR(); } @@ -358,6 +360,7 @@ void GLBackend::do_drawInstanced(Batch& batch, size_t paramOffset) { glDrawArraysInstancedARB(mode, startVertex, numVertices, numInstances); _stats._DSNumTriangles += (numInstances * numVertices) / 3; _stats._DSNumDrawcalls += numInstances; + _stats._DSNumAPIDrawcalls++; (void) CHECK_GL_ERROR(); } @@ -383,6 +386,7 @@ void GLBackend::do_drawIndexedInstanced(Batch& batch, size_t paramOffset) { #endif _stats._DSNumTriangles += (numInstances * numIndices) / 3; _stats._DSNumDrawcalls += numInstances; + _stats._DSNumAPIDrawcalls++; (void)CHECK_GL_ERROR(); } @@ -395,6 +399,8 @@ void GLBackend::do_multiDrawIndirect(Batch& batch, size_t paramOffset) { glMultiDrawArraysIndirect(mode, reinterpret_cast(_input._indirectBufferOffset), commandCount, (GLsizei)_input._indirectBufferStride); _stats._DSNumDrawcalls += commandCount; + _stats._DSNumAPIDrawcalls++; + #else // FIXME implement the slow path #endif @@ -410,7 +416,7 @@ void GLBackend::do_multiDrawIndexedIndirect(Batch& batch, size_t paramOffset) { glMultiDrawElementsIndirect(mode, indexType, reinterpret_cast(_input._indirectBufferOffset), commandCount, (GLsizei)_input._indirectBufferStride); _stats._DSNumDrawcalls += commandCount; - + _stats._DSNumAPIDrawcalls++; #else // FIXME implement the slow path #endif diff --git a/libraries/render/src/render/EngineStats.cpp b/libraries/render/src/render/EngineStats.cpp index ee96e0cd86..794f278fcf 100644 --- a/libraries/render/src/render/EngineStats.cpp +++ b/libraries/render/src/render/EngineStats.cpp @@ -36,6 +36,7 @@ void EngineStats::run(const SceneContextPointer& sceneContext, const RenderConte gpu::ContextStats gpuStats(_gpuStats); renderContext->args->_context->getStats(_gpuStats); + config->frameAPIDrawcallCount = _gpuStats._DSNumAPIDrawcalls - gpuStats._DSNumAPIDrawcalls; config->frameDrawcallCount = _gpuStats._DSNumDrawcalls - gpuStats._DSNumDrawcalls; config->frameDrawcallRate = config->frameDrawcallCount * frequency; diff --git a/libraries/render/src/render/EngineStats.h b/libraries/render/src/render/EngineStats.h index 478d94855e..4a57724644 100644 --- a/libraries/render/src/render/EngineStats.h +++ b/libraries/render/src/render/EngineStats.h @@ -34,6 +34,7 @@ namespace render { Q_PROPERTY(qint64 textureCPUMemoryUsage MEMBER textureCPUMemoryUsage NOTIFY dirty) Q_PROPERTY(qint64 textureGPUMemoryUsage MEMBER textureGPUMemoryUsage NOTIFY dirty) + Q_PROPERTY(quint32 frameAPIDrawcallCount MEMBER frameAPIDrawcallCount NOTIFY dirty) Q_PROPERTY(quint32 frameDrawcallCount MEMBER frameDrawcallCount NOTIFY dirty) Q_PROPERTY(quint32 frameDrawcallRate MEMBER frameDrawcallRate NOTIFY dirty) @@ -57,6 +58,7 @@ namespace render { qint64 textureCPUMemoryUsage{ 0 }; qint64 textureGPUMemoryUsage{ 0 }; + quint32 frameAPIDrawcallCount{ 0 }; quint32 frameDrawcallCount{ 0 }; quint32 frameDrawcallRate{ 0 };