15669413 |
1 | // Copyright (c) 2017 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #include <OpenGl_FrameStats.hxx> |
15 | |
15669413 |
16 | #include <OpenGl_View.hxx> |
78c4e836 |
17 | #include <OpenGl_DepthPeeling.hxx> |
d84e8669 |
18 | #include <OpenGl_ShadowMap.hxx> |
1220d98e |
19 | #include <OpenGl_TextureBuffer.hxx> |
20 | #include <OpenGl_Window.hxx> |
15669413 |
21 | |
5e30547b |
22 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_FrameStats, Graphic3d_FrameStats) |
15669413 |
23 | |
24 | namespace |
25 | { |
15669413 |
26 | //! Return estimated data size. |
27 | static Standard_Size estimatedDataSize (const Handle(OpenGl_Resource)& theRes) |
28 | { |
29 | return !theRes.IsNull() ? theRes->EstimatedDataSize() : 0; |
30 | } |
31 | } |
32 | |
33 | // ======================================================================= |
34 | // function : OpenGl_FrameStats |
35 | // purpose : |
36 | // ======================================================================= |
37 | OpenGl_FrameStats::OpenGl_FrameStats() |
15669413 |
38 | { |
5e30547b |
39 | // |
15669413 |
40 | } |
41 | |
42 | // ======================================================================= |
43 | // function : ~OpenGl_FrameStats |
44 | // purpose : |
45 | // ======================================================================= |
46 | OpenGl_FrameStats::~OpenGl_FrameStats() |
47 | { |
48 | // |
49 | } |
50 | |
51 | // ======================================================================= |
5e30547b |
52 | // function : IsFrameUpdated |
15669413 |
53 | // purpose : |
54 | // ======================================================================= |
5e30547b |
55 | bool OpenGl_FrameStats::IsFrameUpdated (Handle(OpenGl_FrameStats)& thePrev) const |
15669413 |
56 | { |
5e30547b |
57 | const Graphic3d_FrameStatsData& aFrame = LastDataFrame(); |
58 | if (thePrev.IsNull()) |
15669413 |
59 | { |
5e30547b |
60 | thePrev = new OpenGl_FrameStats(); |
15669413 |
61 | } |
5e30547b |
62 | // check just a couple of major counters |
63 | else if (myLastFrameIndex == thePrev->myLastFrameIndex |
64 | && Abs (aFrame.FrameRate() - thePrev->myCountersTmp.FrameRate()) <= 0.001 |
65 | && Abs (aFrame.FrameRateCpu() - thePrev->myCountersTmp.FrameRateCpu()) <= 0.001 |
8f5760bc |
66 | && Abs (aFrame.ImmediateFrameRate() - thePrev->myCountersTmp.ImmediateFrameRate()) <= 0.001 |
67 | && Abs (aFrame.ImmediateFrameRateCpu() - thePrev->myCountersTmp.ImmediateFrameRateCpu()) <= 0.001 |
5e30547b |
68 | && aFrame[Graphic3d_FrameStatsCounter_NbLayers] == thePrev->myCountersTmp[Graphic3d_FrameStatsCounter_NbLayers] |
69 | && aFrame[Graphic3d_FrameStatsCounter_NbLayersNotCulled] == thePrev->myCountersTmp[Graphic3d_FrameStatsCounter_NbLayersNotCulled] |
70 | && aFrame[Graphic3d_FrameStatsCounter_NbStructs] == thePrev->myCountersTmp[Graphic3d_FrameStatsCounter_NbStructs] |
71 | && aFrame[Graphic3d_FrameStatsCounter_NbStructsNotCulled] == thePrev->myCountersTmp[Graphic3d_FrameStatsCounter_NbStructsNotCulled]) |
15669413 |
72 | { |
5e30547b |
73 | return false; |
15669413 |
74 | } |
15669413 |
75 | |
5e30547b |
76 | thePrev->myLastFrameIndex = myLastFrameIndex; |
77 | thePrev->myCountersTmp = aFrame; |
78 | return true; |
15669413 |
79 | } |
80 | |
81 | // ======================================================================= |
5e30547b |
82 | // function : updateStatistics |
15669413 |
83 | // purpose : |
84 | // ======================================================================= |
5e30547b |
85 | void OpenGl_FrameStats::updateStatistics (const Handle(Graphic3d_CView)& theView, |
86 | bool theIsImmediateOnly) |
15669413 |
87 | { |
5e30547b |
88 | const OpenGl_View* aView = dynamic_cast<const OpenGl_View*> (theView.get()); |
89 | if (aView == NULL) |
15669413 |
90 | { |
5e30547b |
91 | myCounters.SetValue (myLastFrameIndex, myCountersTmp); |
92 | myCountersTmp.Reset(); |
15669413 |
93 | return; |
94 | } |
95 | |
5e30547b |
96 | const Graphic3d_RenderingParams::PerfCounters aBits = theView->RenderingParams().CollectedStats; |
15669413 |
97 | const Standard_Boolean toCountMem = (aBits & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0; |
98 | const Standard_Boolean toCountTris = (aBits & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0 |
b9f43ad1 |
99 | || (aBits & Graphic3d_RenderingParams::PerfCounters_Lines) != 0 |
15669413 |
100 | || (aBits & Graphic3d_RenderingParams::PerfCounters_Points) != 0; |
101 | const Standard_Boolean toCountElems = (aBits & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0 || toCountTris || toCountMem; |
102 | const Standard_Boolean toCountGroups = (aBits & Graphic3d_RenderingParams::PerfCounters_Groups) != 0 || toCountElems; |
5dc0517d |
103 | const Standard_Boolean toCountStructs = (aBits & Graphic3d_RenderingParams::PerfCounters_Structures) != 0 |
104 | || (aBits & Graphic3d_RenderingParams::PerfCounters_Layers) != 0 || toCountGroups; |
105 | |
5e30547b |
106 | myCountersTmp[Graphic3d_FrameStatsCounter_NbLayers] = aView->LayerList().Layers().Size(); |
5dc0517d |
107 | if (toCountStructs |
108 | || (aBits & Graphic3d_RenderingParams::PerfCounters_Layers) != 0) |
15669413 |
109 | { |
5e30547b |
110 | const Standard_Integer aViewId = aView->Identification(); |
1c728f2d |
111 | for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (aView->LayerList().Layers()); aLayerIter.More(); aLayerIter.Next()) |
15669413 |
112 | { |
113 | const Handle(OpenGl_Layer)& aLayer = aLayerIter.Value(); |
5e30547b |
114 | myCountersTmp[Graphic3d_FrameStatsCounter_NbStructs] += aLayer->NbStructures(); |
115 | if (theIsImmediateOnly && !aLayer->LayerSettings().IsImmediate()) |
116 | { |
117 | continue; |
118 | } |
119 | |
15669413 |
120 | if (!aLayer->IsCulled()) |
121 | { |
5e30547b |
122 | ++myCountersTmp[Graphic3d_FrameStatsCounter_NbLayersNotCulled]; |
15669413 |
123 | } |
5e30547b |
124 | myCountersTmp[Graphic3d_FrameStatsCounter_NbStructsNotCulled] += aLayer->NbStructuresNotCulled(); |
15669413 |
125 | if (toCountGroups) |
126 | { |
5dc0517d |
127 | updateStructures (aViewId, aLayer->CullableStructuresBVH().Structures(), toCountElems, toCountTris, toCountMem); |
128 | updateStructures (aViewId, aLayer->CullableTrsfPersStructuresBVH().Structures(), toCountElems, toCountTris, toCountMem); |
129 | updateStructures (aViewId, aLayer->NonCullableStructures(), toCountElems, toCountTris, toCountMem); |
15669413 |
130 | } |
131 | } |
132 | } |
5e30547b |
133 | if (toCountMem) |
15669413 |
134 | { |
5e30547b |
135 | for (OpenGl_Context::OpenGl_ResourcesMap::Iterator aResIter (aView->GlWindow()->GetGlContext()->SharedResources()); |
15669413 |
136 | aResIter.More(); aResIter.Next()) |
137 | { |
5e30547b |
138 | myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesTextures] += aResIter.Value()->EstimatedDataSize(); |
15669413 |
139 | } |
140 | |
15669413 |
141 | { |
5e30547b |
142 | Standard_Size& aMemFbos = myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesFbos]; |
15669413 |
143 | // main FBOs |
144 | aMemFbos += estimatedDataSize (aView->myMainSceneFbos[0]); |
145 | aMemFbos += estimatedDataSize (aView->myMainSceneFbos[1]); |
146 | aMemFbos += estimatedDataSize (aView->myImmediateSceneFbos[0]); |
147 | aMemFbos += estimatedDataSize (aView->myImmediateSceneFbos[1]); |
148 | // OIT FBOs |
149 | aMemFbos += estimatedDataSize (aView->myMainSceneFbosOit[0]); |
150 | aMemFbos += estimatedDataSize (aView->myMainSceneFbosOit[1]); |
151 | aMemFbos += estimatedDataSize (aView->myImmediateSceneFbosOit[0]); |
152 | aMemFbos += estimatedDataSize (aView->myImmediateSceneFbosOit[1]); |
78c4e836 |
153 | aMemFbos += estimatedDataSize (aView->myDepthPeelingFbos); |
d84e8669 |
154 | // shadowmap FBOs |
155 | aMemFbos += aView->myShadowMaps->EstimatedDataSize(); |
15669413 |
156 | // dump FBO |
157 | aMemFbos += estimatedDataSize (aView->myFBO); |
158 | // RayTracing FBO |
159 | aMemFbos += estimatedDataSize (aView->myOpenGlFBO); |
160 | aMemFbos += estimatedDataSize (aView->myOpenGlFBO2); |
161 | aMemFbos += estimatedDataSize (aView->myRaytraceFBO1[0]); |
162 | aMemFbos += estimatedDataSize (aView->myRaytraceFBO1[1]); |
163 | aMemFbos += estimatedDataSize (aView->myRaytraceFBO2[0]); |
164 | aMemFbos += estimatedDataSize (aView->myRaytraceFBO2[1]); |
165 | // also RayTracing |
166 | aMemFbos += estimatedDataSize (aView->myRaytraceOutputTexture[0]); |
167 | aMemFbos += estimatedDataSize (aView->myRaytraceOutputTexture[1]); |
168 | aMemFbos += estimatedDataSize (aView->myRaytraceVisualErrorTexture[0]); |
169 | aMemFbos += estimatedDataSize (aView->myRaytraceVisualErrorTexture[1]); |
170 | aMemFbos += estimatedDataSize (aView->myRaytraceTileOffsetsTexture[0]); |
171 | aMemFbos += estimatedDataSize (aView->myRaytraceTileOffsetsTexture[1]); |
e084dbbc |
172 | aMemFbos += estimatedDataSize (aView->myRaytraceTileSamplesTexture[0]); |
173 | aMemFbos += estimatedDataSize (aView->myRaytraceTileSamplesTexture[1]); |
15669413 |
174 | } |
175 | { |
176 | // Ray Tracing geometry |
5e30547b |
177 | Standard_Size& aMemGeom = myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom]; |
15669413 |
178 | aMemGeom += estimatedDataSize (aView->mySceneNodeInfoTexture); |
179 | aMemGeom += estimatedDataSize (aView->mySceneMinPointTexture); |
180 | aMemGeom += estimatedDataSize (aView->mySceneMaxPointTexture); |
181 | aMemGeom += estimatedDataSize (aView->mySceneTransformTexture); |
182 | aMemGeom += estimatedDataSize (aView->myGeometryVertexTexture); |
183 | aMemGeom += estimatedDataSize (aView->myGeometryNormalTexture); |
184 | aMemGeom += estimatedDataSize (aView->myGeometryTexCrdTexture); |
185 | aMemGeom += estimatedDataSize (aView->myGeometryTriangTexture); |
186 | aMemGeom += estimatedDataSize (aView->myRaytraceMaterialTexture); |
187 | aMemGeom += estimatedDataSize (aView->myRaytraceLightSrcTexture); |
188 | } |
189 | } |
15669413 |
190 | } |
191 | |
192 | // ======================================================================= |
193 | // function : updateStructures |
194 | // purpose : |
195 | // ======================================================================= |
5dc0517d |
196 | void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId, |
d325cb7f |
197 | const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructures, |
15669413 |
198 | Standard_Boolean theToCountElems, |
199 | Standard_Boolean theToCountTris, |
200 | Standard_Boolean theToCountMem) |
201 | { |
d325cb7f |
202 | for (OpenGl_Structure::StructIterator aStructIter (theStructures); aStructIter.More(); aStructIter.Next()) |
15669413 |
203 | { |
204 | const OpenGl_Structure* aStruct = aStructIter.Value(); |
0de16e29 |
205 | const bool isStructHidden = aStruct->IsCulled() |
206 | || !aStruct->IsVisible (theViewId); |
207 | for (; aStruct != NULL; aStruct = aStruct->InstancedStructure()) |
15669413 |
208 | { |
0de16e29 |
209 | if (isStructHidden) |
15669413 |
210 | { |
0de16e29 |
211 | if (theToCountMem) |
15669413 |
212 | { |
0de16e29 |
213 | for (OpenGl_Structure::GroupIterator aGroupIter (aStruct->Groups()); aGroupIter.More(); aGroupIter.Next()) |
15669413 |
214 | { |
0de16e29 |
215 | const OpenGl_Group* aGroup = aGroupIter.Value(); |
216 | for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next) |
15669413 |
217 | { |
b9f43ad1 |
218 | aNodeIter->elem->UpdateMemStats (myCountersTmp); |
15669413 |
219 | } |
220 | } |
221 | } |
0de16e29 |
222 | continue; |
15669413 |
223 | } |
15669413 |
224 | |
5e30547b |
225 | myCountersTmp[Graphic3d_FrameStatsCounter_NbGroupsNotCulled] += aStruct->Groups().Size(); |
0de16e29 |
226 | if (!theToCountElems) |
227 | { |
228 | continue; |
229 | } |
15669413 |
230 | |
0de16e29 |
231 | for (OpenGl_Structure::GroupIterator aGroupIter (aStruct->Groups()); aGroupIter.More(); aGroupIter.Next()) |
15669413 |
232 | { |
0de16e29 |
233 | const OpenGl_Group* aGroup = aGroupIter.Value(); |
234 | for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next) |
15669413 |
235 | { |
3d60d73f |
236 | if (theToCountMem) |
237 | { |
b9f43ad1 |
238 | aNodeIter->elem->UpdateMemStats (myCountersTmp); |
15669413 |
239 | } |
b9f43ad1 |
240 | aNodeIter->elem->UpdateDrawStats (myCountersTmp, theToCountTris); |
15669413 |
241 | } |
15669413 |
242 | } |
243 | } |
244 | } |
245 | } |