From b9f43ad13b16812ccf1ac2ec8cda13502eb6d810 Mon Sep 17 00:00:00 2001 From: kgv Date: Fri, 17 Apr 2020 10:36:57 +0300 Subject: [PATCH] 0031505: Point Cloud Rendering - fix on-screen statistics about number of visible points OpenGl_Element now provide methods ::UpdateMemStats() and ::UpdateDrawStats() for unified request of statistics used by OpenGl_FrameStats instead of direct handling of OpenGl_PrimitiveArray. Graphic3d_FrameStatsCounter counters list has been extended by Graphic3d_FrameStatsCounter_NbLinesNotCulled. --- src/Graphic3d/Graphic3d_FrameStats.cxx | 9 ++ src/Graphic3d/Graphic3d_FrameStatsCounter.hxx | 2 + src/Graphic3d/Graphic3d_RenderingParams.hxx | 11 ++- src/OpenGl/OpenGl_Element.cxx | 20 ++++ src/OpenGl/OpenGl_Element.hxx | 11 +++ src/OpenGl/OpenGl_FrameStats.cxx | 90 +----------------- src/OpenGl/OpenGl_PrimitiveArray.cxx | 93 +++++++++++++++++++ src/OpenGl/OpenGl_PrimitiveArray.hxx | 4 + src/OpenGl/OpenGl_Text.cxx | 21 +++++ src/OpenGl/OpenGl_Text.hxx | 4 + src/ViewerTest/ViewerTest_ViewerCommands.cxx | 6 ++ 11 files changed, 180 insertions(+), 91 deletions(-) diff --git a/src/Graphic3d/Graphic3d_FrameStats.cxx b/src/Graphic3d/Graphic3d_FrameStats.cxx index eabb962825..01e0c65f91 100644 --- a/src/Graphic3d/Graphic3d_FrameStats.cxx +++ b/src/Graphic3d/Graphic3d_FrameStats.cxx @@ -305,6 +305,7 @@ TCollection_AsciiString Graphic3d_FrameStats::FormatStats (Graphic3d_RenderingPa if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Groups) != 0 || (theFlags & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0 || (theFlags & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0 + || (theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0 || (theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0 || (!myIsLongLineFormat && ((theFlags & Graphic3d_RenderingParams::PerfCounters_Structures) != 0 @@ -338,6 +339,10 @@ TCollection_AsciiString Graphic3d_FrameStats::FormatStats (Graphic3d_RenderingPa { formatCounter (aBuf, aValWidth, " Triangles: ", aStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled], "\n"); } + if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0) + { + formatCounter (aBuf, aValWidth, " Lines: ", aStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled], "\n"); + } if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0) { formatCounter (aBuf, aValWidth, " Points: ", aStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled], "\n"); @@ -437,6 +442,10 @@ void Graphic3d_FrameStats::FormatStats (TColStd_IndexedDataMapOfStringString& { addInfo (theDict, "Rendered triangles", aStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled]); } + if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0) + { + addInfo (theDict, "Rendered lines", aStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled]); + } if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0) { addInfo (theDict, "Rendered points", aStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled]); diff --git a/src/Graphic3d/Graphic3d_FrameStatsCounter.hxx b/src/Graphic3d/Graphic3d_FrameStatsCounter.hxx index f0a41e57dc..137cc4c2a7 100644 --- a/src/Graphic3d/Graphic3d_FrameStatsCounter.hxx +++ b/src/Graphic3d/Graphic3d_FrameStatsCounter.hxx @@ -28,7 +28,9 @@ enum Graphic3d_FrameStatsCounter Graphic3d_FrameStatsCounter_NbElemsPointNotCulled, //!< number of not culled OpenGl_PrimitiveArray drawing points Graphic3d_FrameStatsCounter_NbElemsTextNotCulled, //!< number of not culled OpenGl_Text Graphic3d_FrameStatsCounter_NbTrianglesNotCulled, //!< number of not culled (as structure) triangles + Graphic3d_FrameStatsCounter_NbLinesNotCulled, //!< number of not culled (as structure) line segments Graphic3d_FrameStatsCounter_NbPointsNotCulled, //!< number of not culled (as structure) points + //Graphic3d_FrameStatsCounter_NbGlyphsNotCulled, //!< number glyphs, to be considered in future Graphic3d_FrameStatsCounter_EstimatedBytesGeom, //!< estimated GPU memory used for geometry Graphic3d_FrameStatsCounter_EstimatedBytesFbos, //!< estimated GPU memory used for FBOs Graphic3d_FrameStatsCounter_EstimatedBytesTextures, //!< estimated GPU memory used for textures diff --git a/src/Graphic3d/Graphic3d_RenderingParams.hxx b/src/Graphic3d/Graphic3d_RenderingParams.hxx index fa18c5b73b..f4459300ba 100644 --- a/src/Graphic3d/Graphic3d_RenderingParams.hxx +++ b/src/Graphic3d/Graphic3d_RenderingParams.hxx @@ -60,19 +60,20 @@ public: // PerfCounters_Triangles = 0x040, //!< count Triangles PerfCounters_Points = 0x080, //!< count Points + PerfCounters_Lines = 0x100, //!< count Line segments // - PerfCounters_EstimMem = 0x100, //!< estimated GPU memory usage + PerfCounters_EstimMem = 0x200, //!< estimated GPU memory usage // - PerfCounters_FrameTime = 0x200, //!< frame CPU utilization time (rendering thread); @sa Graphic3d_FrameStatsTimer - PerfCounters_FrameTimeMax= 0x400, //!< maximum frame times + PerfCounters_FrameTime = 0x400, //!< frame CPU utilization time (rendering thread); @sa Graphic3d_FrameStatsTimer + PerfCounters_FrameTimeMax= 0x800, //!< maximum frame times // - PerfCounters_SkipImmediate = 0x800, //!< do not include immediate viewer updates (e.g. lazy updates without redrawing entire view content) + PerfCounters_SkipImmediate = 0x1000, //!< do not include immediate viewer updates (e.g. lazy updates without redrawing entire view content) //! show basic statistics PerfCounters_Basic = PerfCounters_FrameRate | PerfCounters_CPU | PerfCounters_Layers | PerfCounters_Structures, //! extended (verbose) statistics PerfCounters_Extended = PerfCounters_Basic | PerfCounters_Groups | PerfCounters_GroupArrays - | PerfCounters_Triangles | PerfCounters_Points + | PerfCounters_Triangles | PerfCounters_Points | PerfCounters_Lines | PerfCounters_EstimMem, //! all counters PerfCounters_All = PerfCounters_Extended diff --git a/src/OpenGl/OpenGl_Element.cxx b/src/OpenGl/OpenGl_Element.cxx index 6f8d87210e..28fcc76584 100755 --- a/src/OpenGl/OpenGl_Element.cxx +++ b/src/OpenGl/OpenGl_Element.cxx @@ -15,6 +15,7 @@ #include +#include #include // ======================================================================= @@ -35,6 +36,25 @@ OpenGl_Element::~OpenGl_Element() // } +// ======================================================================= +// function : UpdateMemStats +// purpose : +// ======================================================================= +void OpenGl_Element::UpdateMemStats (Graphic3d_FrameStatsDataTmp& theStats) const +{ + theStats[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += EstimatedDataSize(); +} + +// ======================================================================= +// function : UpdateDrawStats +// purpose : +// ======================================================================= +void OpenGl_Element::UpdateDrawStats (Graphic3d_FrameStatsDataTmp& , + bool ) const +{ + // +} + // ======================================================================= // function : DumpJson // purpose : diff --git a/src/OpenGl/OpenGl_Element.hxx b/src/OpenGl/OpenGl_Element.hxx index 324aa7db48..f4c67692e4 100644 --- a/src/OpenGl/OpenGl_Element.hxx +++ b/src/OpenGl/OpenGl_Element.hxx @@ -19,6 +19,7 @@ #include #include +class Graphic3d_FrameStatsDataTmp; class OpenGl_Workspace; class OpenGl_Context; @@ -63,6 +64,16 @@ public: //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. virtual Standard_Size EstimatedDataSize() const { return 0; } + //! Increment memory usage statistics. + //! Default implementation puts EstimatedDataSize() into Graphic3d_FrameStatsCounter_EstimatedBytesGeom. + Standard_EXPORT virtual void UpdateMemStats (Graphic3d_FrameStatsDataTmp& theStats) const; + + //! Increment draw calls statistics. + //! @param theStats [in] [out] frame counters to increment + //! @param theIsDetailed [in] indicate detailed dump (more counters - number of triangles, points, etc.) + Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats, + bool theIsDetailed) const; + //! Update parameters of the drawable elements. virtual void SynchronizeAspects() {} diff --git a/src/OpenGl/OpenGl_FrameStats.cxx b/src/OpenGl/OpenGl_FrameStats.cxx index b34eb69bbd..9828dd411e 100644 --- a/src/OpenGl/OpenGl_FrameStats.cxx +++ b/src/OpenGl/OpenGl_FrameStats.cxx @@ -92,6 +92,7 @@ void OpenGl_FrameStats::updateStatistics (const Handle(Graphic3d_CView)& theView const Graphic3d_RenderingParams::PerfCounters aBits = theView->RenderingParams().CollectedStats; const Standard_Boolean toCountMem = (aBits & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0; const Standard_Boolean toCountTris = (aBits & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0 + || (aBits & Graphic3d_RenderingParams::PerfCounters_Lines) != 0 || (aBits & Graphic3d_RenderingParams::PerfCounters_Points) != 0; const Standard_Boolean toCountElems = (aBits & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0 || toCountTris || toCountMem; const Standard_Boolean toCountGroups = (aBits & Graphic3d_RenderingParams::PerfCounters_Groups) != 0 || toCountElems; @@ -207,7 +208,7 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId, const OpenGl_Group* aGroup = aGroupIter.Value(); for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next) { - myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += aNodeIter->elem->EstimatedDataSize(); + aNodeIter->elem->UpdateMemStats (myCountersTmp); } } } @@ -227,92 +228,9 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId, { if (theToCountMem) { - myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += aNodeIter->elem->EstimatedDataSize(); - } - if (const OpenGl_PrimitiveArray* aPrim = dynamic_cast (aNodeIter->elem)) - { - ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled]; - if (aPrim->IsFillDrawMode()) - { - ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsFillNotCulled]; - if (!theToCountTris) - { - continue; - } - - const Handle(OpenGl_VertexBuffer)& anAttribs = aPrim->AttributesVbo(); - if (anAttribs.IsNull() - || !anAttribs->IsValid()) - { - continue; - } - - const Handle(OpenGl_VertexBuffer)& anIndices = aPrim->IndexVbo(); - const Standard_Integer aNbIndices = !anIndices.IsNull() ? anIndices->GetElemsNb() : anAttribs->GetElemsNb(); - const Standard_Integer aNbBounds = !aPrim->Bounds().IsNull() ? aPrim->Bounds()->NbBounds : 1; - switch (aPrim->DrawMode()) - { - case GL_TRIANGLES: - { - myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 3; - break; - } - case GL_TRIANGLE_STRIP: - case GL_TRIANGLE_FAN: - { - myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 2 * aNbBounds; - break; - } - case GL_TRIANGLES_ADJACENCY: - { - myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 6; - break; - } - case GL_TRIANGLE_STRIP_ADJACENCY: - { - myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 4 * aNbBounds; - break; - } - #if !defined(GL_ES_VERSION_2_0) - case GL_QUADS: - { - myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 2; - break; - } - case GL_QUAD_STRIP: - { - myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += (aNbIndices / 2 - aNbBounds) * 2; - break; - } - #endif - } - } - else if (aPrim->DrawMode() == GL_POINTS) - { - ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsPointNotCulled]; - if (theToCountTris) - { - const Handle(OpenGl_VertexBuffer)& anAttribs = aPrim->AttributesVbo(); - if (!anAttribs.IsNull() - && anAttribs->IsValid()) - { - const Handle(OpenGl_VertexBuffer)& anIndices = aPrim->IndexVbo(); - const Standard_Integer aNbIndices = !anIndices.IsNull() ? anIndices->GetElemsNb() : anAttribs->GetElemsNb(); - myCountersTmp[Graphic3d_FrameStatsCounter_NbPointsNotCulled] += aNbIndices; - } - } - } - else - { - ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled]; - } - } - else if (const OpenGl_Text* aText = dynamic_cast (aNodeIter->elem)) - { - (void )aText; - ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled]; - ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled]; + aNodeIter->elem->UpdateMemStats (myCountersTmp); } + aNodeIter->elem->UpdateDrawStats (myCountersTmp, theToCountTris); } } } diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 97c28f2481..38f04754dc 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -776,6 +776,99 @@ Standard_Size OpenGl_PrimitiveArray::EstimatedDataSize() const return aSize; } +// ======================================================================= +// function : UpdateDrawStats +// purpose : +// ======================================================================= +void OpenGl_PrimitiveArray::UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats, + bool theIsDetailed) const +{ + ++theStats[Graphic3d_FrameStatsCounter_NbElemsNotCulled]; + if (myIsFillType) + { + ++theStats[Graphic3d_FrameStatsCounter_NbElemsFillNotCulled]; + } + else if (myDrawMode == GL_POINTS) + { + ++theStats[Graphic3d_FrameStatsCounter_NbElemsPointNotCulled]; + } + else + { + ++theStats[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled]; + } + + if (!theIsDetailed + || myVboAttribs.IsNull() + || !myVboAttribs->IsValid()) + { + return; + } + + const Standard_Integer aNbIndices = !myVboIndices.IsNull() ? myVboIndices->GetElemsNb() : myVboAttribs->GetElemsNb(); + const Standard_Integer aNbBounds = !myBounds.IsNull() ? myBounds->NbBounds : 1; + switch (myDrawMode) + { + case GL_POINTS: + { + theStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled] += aNbIndices; + break; + } + case GL_LINES: + { + theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices / 2; + break; + } + case GL_LINE_STRIP: + { + theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices - aNbBounds; + break; + } + case GL_LINES_ADJACENCY: + { + theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices / 4; + break; + } + case GL_LINE_STRIP_ADJACENCY: + { + theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices - 4 * aNbBounds; + break; + } + case GL_TRIANGLES: + { + theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 3; + break; + } + case GL_TRIANGLE_STRIP: + case GL_TRIANGLE_FAN: + { + theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 2 * aNbBounds; + break; + } + case GL_TRIANGLES_ADJACENCY: + { + theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 6; + break; + } + case GL_TRIANGLE_STRIP_ADJACENCY: + { + theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 4 * aNbBounds; + break; + } + #if !defined(GL_ES_VERSION_2_0) + case GL_QUADS: + { + theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 2; + break; + } + case GL_QUAD_STRIP: + { + theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += (aNbIndices / 2 - aNbBounds) * 2; + break; + } + #endif + } +} + // ======================================================================= // function : Render // purpose : diff --git a/src/OpenGl/OpenGl_PrimitiveArray.hxx b/src/OpenGl/OpenGl_PrimitiveArray.hxx index 6947e63cf5..7f98265604 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.hxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.hxx @@ -61,6 +61,10 @@ public: //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE; + //! Increment draw calls statistics. + Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats, + bool theIsDetailed) const Standard_OVERRIDE; + //! Return true if VBOs initialization has been performed. //! VBO initialization is performed during first Render() call. //! Notice that this flag does not indicate VBOs validity. diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 4692b5e84f..a3c5be6a13 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -231,6 +231,27 @@ Standard_Size OpenGl_Text::EstimatedDataSize() const return aSize; } +// ======================================================================= +// function : UpdateDrawStats +// purpose : +// ======================================================================= +void OpenGl_Text::UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats, + bool theIsDetailed) const +{ + ++theStats[Graphic3d_FrameStatsCounter_NbElemsNotCulled]; + ++theStats[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled]; + if (theIsDetailed) + { + for (Standard_Integer anIter = myVertsVbo.Lower(); anIter <= myVertsVbo.Upper(); ++anIter) + { + if (const Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.Value (anIter)) + { + theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aVerts->GetElemsNb() / 3; // 2 non-indexed triangles per glyph + } + } + } +} + // ======================================================================= // function : StringSize // purpose : diff --git a/src/OpenGl/OpenGl_Text.hxx b/src/OpenGl/OpenGl_Text.hxx index a8a3cb3d31..5d8ac6f7d5 100755 --- a/src/OpenGl/OpenGl_Text.hxx +++ b/src/OpenGl/OpenGl_Text.hxx @@ -71,6 +71,10 @@ public: //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE; + //! Increment draw calls statistics. + Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats, + bool theIsDetailed) const Standard_OVERRIDE; + public: //! @name methods for compatibility with layers //! Empty constructor diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index c64f27916b..9bc02b1375 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -11325,6 +11325,7 @@ static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theVa || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles; else if (aVal == "pnts" || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points; + else if (aVal == "lines") aFlag = Graphic3d_RenderingParams::PerfCounters_Lines; else if (aVal == "mem" || aVal == "gpumem" || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem; @@ -11519,6 +11520,10 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI, { theDI << " tris"; } + if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Lines) != 0) + { + theDI << " lines"; + } if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0) { theDI << " pnts"; @@ -12496,6 +12501,7 @@ static Standard_Integer VStatProfiler (Draw_Interpretor& theDI, || aFlag == "pointarrays" || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays; else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles; + else if (aFlag == "lines") aParam = Graphic3d_RenderingParams::PerfCounters_Lines; else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points; else if (aFlag == "geommem" || aFlag == "texturemem" -- 2.20.1