• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision8def3866579709b02d3a8ec6a7d77a49385696dd (tree)
Time2024-07-01 01:52:45
Authorsebastian_bugiu
Commitersebastian_bugiu

Log Message

Moved mMoved and mUpdated to SoA in Transform instead of bools in each PCZSceneNode.

Change Summary

Incremental Difference

diff -r b2744734c847 -r 8def38665797 OgreMain/include/Math/Array/OgreArrayMemoryManager.h
--- a/OgreMain/include/Math/Array/OgreArrayMemoryManager.h Sat Jun 29 15:48:56 2024 +0200
+++ b/OgreMain/include/Math/Array/OgreArrayMemoryManager.h Sun Jun 30 18:52:45 2024 +0200
@@ -299,6 +299,10 @@
299299 WorldMat,
300300 InheritOrientation,
301301 InheritScale,
302+#ifdef USE_PCZ
303+ Moved,
304+ Updated,
305+#endif
302306 NumMemoryTypes
303307 };
304308
diff -r b2744734c847 -r 8def38665797 OgreMain/include/Math/Array/OgreTransform.h
--- a/OgreMain/include/Math/Array/OgreTransform.h Sat Jun 29 15:48:56 2024 +0200
+++ b/OgreMain/include/Math/Array/OgreTransform.h Sun Jun 30 18:52:45 2024 +0200
@@ -73,6 +73,11 @@
7373 /// Stores whether this node inherits scale from it's parent.
7474 /// Ours is mInheritScale[mIndex]
7575 bool * RESTRICT_ALIAS mInheritScale;
76+
77+#ifdef USE_PCZ
78+ bool * RESTRICT_ALIAS mMoved;
79+ bool * RESTRICT_ALIAS mUpdated;
80+#endif
7681
7782 Transform() :
7883 mIndex( 0 ),
@@ -87,6 +92,10 @@
8792 mDerivedTransform( 0 ),
8893 mInheritOrientation( 0 ),
8994 mInheritScale( 0 )
95+#ifdef USE_PCZ
96+ , mMoved( 0 )
97+ , mUpdated( 0 )
98+#endif
9099 {
91100 }
92101
@@ -138,6 +147,11 @@
138147
139148 mInheritOrientation[mIndex] = inCopy.mInheritOrientation[inCopy.mIndex];
140149 mInheritScale[mIndex] = inCopy.mInheritScale[inCopy.mIndex];
150+
151+#ifdef USE_PCZ
152+ mMoved[mIndex] = inCopy.mMoved[inCopy.mIndex];
153+ mUpdated[mIndex] = inCopy.mUpdated[inCopy.mIndex];
154+#endif
141155 }
142156
143157 /** Rebases all the pointers from our SoA structs so that they point to a new location
@@ -174,6 +188,13 @@
174188 newBasePtrs[NodeArrayMemoryManager::InheritOrientation] + diff );
175189 mInheritScale = reinterpret_cast<bool*>(
176190 newBasePtrs[NodeArrayMemoryManager::InheritScale] + diff );
191+
192+#ifdef USE_PCZ
193+ mMoved = reinterpret_cast<bool*>(
194+ newBasePtrs[NodeArrayMemoryManager::Moved] + diff );
195+ mUpdated = reinterpret_cast<bool*>(
196+ newBasePtrs[NodeArrayMemoryManager::Updated] + diff );
197+#endif
177198 }
178199
179200 /** Advances all pointers to the next pack, i.e. if we're processing 4 elements at a time, move to
@@ -192,6 +213,11 @@
192213 mDerivedTransform += ARRAY_PACKED_REALS;
193214 mInheritOrientation += ARRAY_PACKED_REALS;
194215 mInheritScale += ARRAY_PACKED_REALS;
216+
217+#ifdef USE_PCZ
218+ mMoved += ARRAY_PACKED_REALS;
219+ mUpdated += ARRAY_PACKED_REALS;
220+#endif
195221 }
196222
197223 void advancePack( size_t numAdvance )
@@ -207,6 +233,11 @@
207233 mDerivedTransform += ARRAY_PACKED_REALS * numAdvance;
208234 mInheritOrientation += ARRAY_PACKED_REALS * numAdvance;
209235 mInheritScale += ARRAY_PACKED_REALS * numAdvance;
236+
237+#ifdef USE_PCZ
238+ mMoved += ARRAY_PACKED_REALS * numAdvance;
239+ mUpdated += ARRAY_PACKED_REALS * numAdvance;
240+#endif
210241 }
211242 };
212243 }
diff -r b2744734c847 -r 8def38665797 OgreMain/include/OgreSceneManager.h
--- a/OgreMain/include/OgreSceneManager.h Sat Jun 29 15:48:56 2024 +0200
+++ b/OgreMain/include/OgreSceneManager.h Sun Jun 30 18:52:45 2024 +0200
@@ -237,6 +237,24 @@
237237 {
238238 }
239239 };
240+
241+#ifdef USE_PCZ
242+ struct ResetUpdateFlagsRequest
243+ {
244+ Transform t;
245+ /// Number of nodes to process for each thread. Must be multiple of ARRAY_PACKED_REALS
246+ size_t numNodesPerThread;
247+ size_t numTotalNodes;
248+
249+ ResetUpdateFlagsRequest() :
250+ numNodesPerThread( 0 ), numTotalNodes( 0 ) {}
251+
252+ ResetUpdateFlagsRequest( const Transform &_t, size_t _numNodesPerThread, size_t _numTotalNodes ) :
253+ t( _t ), numNodesPerThread( _numNodesPerThread ), numTotalNodes( _numTotalNodes )
254+ {
255+ }
256+ };
257+#endif
240258
241259 struct InstanceBatchCullRequest
242260 {
@@ -916,6 +934,9 @@
916934 PCZ_CULL_FRUSTUM,
917935 UPDATE_ALL_ANIMATIONS,
918936 UPDATE_ALL_TRANSFORMS,
937+#ifdef USE_PCZ
938+ RESET_ALL_UPDATE_FLAGS,
939+#endif
919940 UPDATE_ALL_BONE_TO_TAG_TRANSFORMS,
920941 UPDATE_ALL_TAG_ON_TAG_TRANSFORMS,
921942 UPDATE_ALL_BOUNDS,
@@ -935,6 +956,9 @@
935956 PCZCullFrustumRequest mCurrentPCZCullFrustumRequest;
936957 UpdateLodRequest mUpdateLodRequest;
937958 UpdateTransformRequest mUpdateTransformRequest;
959+#ifdef USE_PCZ
960+ ResetUpdateFlagsRequest mResetUpdateFlagsRequest;
961+#endif
938962 ObjectMemoryManagerVec const *mUpdateBoundsRequest;
939963 InstancingThreadedCullingMethod mInstancingThreadedCullingMethod;
940964 InstanceBatchCullRequest mInstanceBatchCullRequest;
@@ -1027,6 +1051,10 @@
10271051 Must be unique for each worker thread
10281052 */
10291053 void updateAllTransformsThread( const UpdateTransformRequest &request, size_t threadIdx );
1054+
1055+#ifdef USE_PCZ
1056+ void resetAllUpdateFlagsThread( const ResetUpdateFlagsRequest &request, size_t threadIdx );
1057+#endif
10301058
10311059 /// @see TagPoint::updateAllTransformsBoneToTag
10321060 void updateAllTransformsBoneToTagThread( const UpdateTransformRequest &request,
@@ -1917,6 +1945,10 @@
19171945 could deadlock in the best of cases).
19181946 */
19191947 void updateAllTransforms();
1948+
1949+#ifdef USE_PCZ
1950+ void resetAllUpdateFlags();
1951+#endif
19201952
19211953 /** Updates all TagPoints, both TagPoints that are children of bones, and TagPoints that
19221954 are children of other TagPoints.
diff -r b2744734c847 -r 8def38665797 OgreMain/src/Math/Array/OgreNodeArrayMemoryManager.cpp
--- a/OgreMain/src/Math/Array/OgreNodeArrayMemoryManager.cpp Sat Jun 29 15:48:56 2024 +0200
+++ b/OgreMain/src/Math/Array/OgreNodeArrayMemoryManager.cpp Sun Jun 30 18:52:45 2024 +0200
@@ -49,6 +49,10 @@
4949 16 * sizeof( Ogre::Real ), //ArrayMemoryManager::WorldMat
5050 sizeof( bool ), //ArrayMemoryManager::InheritOrientation
5151 sizeof( bool ) //ArrayMemoryManager::InheritScale
52+#ifdef USE_PCZ
53+ , sizeof( bool ) //ArrayMemoryManager::Moved
54+ , sizeof( bool ) //ArrayMemoryManager::Updated
55+#endif
5256 };
5357 const CleanupRoutines NodeArrayMemoryManager::NodeInitRoutines[NumMemoryTypes] =
5458 {
@@ -63,6 +67,10 @@
6367 0, //ArrayMemoryManager::WorldMat
6468 0, //ArrayMemoryManager::InheritOrientation
6569 0 //ArrayMemoryManager::InheritScale
70+#ifdef USE_PCZ
71+ , 0 //ArrayMemoryManager::Moved
72+ , 0 //ArrayMemoryManager::Updated
73+#endif
6674 };
6775 const CleanupRoutines NodeArrayMemoryManager::NodeCleanupRoutines[NumMemoryTypes] =
6876 {
@@ -77,6 +85,10 @@
7785 cleanerFlat, //ArrayMemoryManager::WorldMat
7886 cleanerFlat, //ArrayMemoryManager::InheritOrientation
7987 cleanerFlat //ArrayMemoryManager::InheritScale
88+#ifdef USE_PCZ
89+ , cleanerFlat //ArrayMemoryManager::Moved
90+ , cleanerFlat //ArrayMemoryManager::Updated
91+#endif
8092 };
8193 //-----------------------------------------------------------------------------------
8294 NodeArrayMemoryManager::NodeArrayMemoryManager( uint16 depthLevel, size_t hintMaxNodes,
@@ -132,6 +144,13 @@
132144 nextSlotBase * mElementsMemSizes[InheritOrientation] );
133145 outTransform.mInheritScale = reinterpret_cast<bool*>( mMemoryPools[InheritScale] +
134146 nextSlotBase * mElementsMemSizes[InheritScale] );
147+
148+#ifdef USE_PCZ
149+ outTransform.mMoved = reinterpret_cast<bool*>( mMemoryPools[Moved] +
150+ nextSlotBase * mElementsMemSizes[Moved] );
151+ outTransform.mUpdated = reinterpret_cast<bool*>( mMemoryPools[Updated] +
152+ nextSlotBase * mElementsMemSizes[Updated] );
153+#endif
135154
136155 //Set default values
137156 outTransform.mParents[nextSlotIdx] = mDummyNode;
@@ -145,6 +164,10 @@
145164 outTransform.mDerivedTransform[nextSlotIdx] = Matrix4::IDENTITY;
146165 outTransform.mInheritOrientation[nextSlotIdx] = true;
147166 outTransform.mInheritScale[nextSlotIdx] = true;
167+#ifdef USE_PCZ
168+ outTransform.mMoved[nextSlotIdx] = true;
169+ outTransform.mUpdated[nextSlotIdx] = false;
170+#endif
148171 }
149172 //-----------------------------------------------------------------------------------
150173 void NodeArrayMemoryManager::destroyNode( Transform &inOutTransform )
@@ -175,6 +198,11 @@
175198 outTransform.mDerivedTransform = reinterpret_cast<Matrix4*>( mMemoryPools[WorldMat] );
176199 outTransform.mInheritOrientation= reinterpret_cast<bool*>( mMemoryPools[InheritOrientation] );
177200 outTransform.mInheritScale = reinterpret_cast<bool*>( mMemoryPools[InheritScale] );
201+
202+#ifdef USE_PCZ
203+ outTransform.mMoved = reinterpret_cast<bool*>( mMemoryPools[Moved] );
204+ outTransform.mUpdated = reinterpret_cast<bool*>( mMemoryPools[Updated] );
205+#endif
178206
179207 return mUsedMemory;
180208 }
diff -r b2744734c847 -r 8def38665797 OgreMain/src/OgreSceneManager.cpp
--- a/OgreMain/src/OgreSceneManager.cpp Sat Jun 29 15:48:56 2024 +0200
+++ b/OgreMain/src/OgreSceneManager.cpp Sun Jun 30 18:52:45 2024 +0200
@@ -2095,6 +2095,75 @@
20952095 ++itor;
20962096 }
20972097 }
2098+#ifdef USE_PCZ
2099+//-----------------------------------------------------------------------
2100+void SceneManager::resetAllUpdateFlagsThread( const ResetUpdateFlagsRequest &request, size_t threadIdx )
2101+{
2102+ Transform t( request.t );
2103+ const size_t toAdvance = std::min( threadIdx * request.numNodesPerThread,
2104+ request.numTotalNodes );
2105+
2106+ //Prevent going out of bounds (usually in the last threadIdx, or
2107+ //when there are less nodes than ARRAY_PACKED_REALS
2108+ const size_t numNodes = std::min( request.numNodesPerThread, request.numTotalNodes - toAdvance );
2109+ t.advancePack( toAdvance / ARRAY_PACKED_REALS );
2110+
2111+ for( size_t i=0; i<numNodes; i += ARRAY_PACKED_REALS )
2112+ {
2113+
2114+ t.mMoved[0] = true;
2115+ t.mMoved[1] = true;
2116+ t.mMoved[2] = true;
2117+ t.mMoved[3] = true;
2118+
2119+ t.mUpdated[0] = false;
2120+ t.mUpdated[1] = false;
2121+ t.mUpdated[2] = false;
2122+ t.mUpdated[3] = false;
2123+
2124+ t.advancePack();
2125+ }
2126+}
2127+//-----------------------------------------------------------------------
2128+void SceneManager::resetAllUpdateFlags()
2129+{
2130+ mRequestType = RESET_ALL_UPDATE_FLAGS;
2131+ NodeMemoryManagerVec::const_iterator it = mNodeMemoryManagerUpdateList.begin();
2132+ NodeMemoryManagerVec::const_iterator en = mNodeMemoryManagerUpdateList.end();
2133+
2134+ while( it != en )
2135+ {
2136+ NodeMemoryManager *nodeMemoryManager = *it;
2137+ const size_t numDepths = nodeMemoryManager->getNumDepths();
2138+
2139+ size_t start = nodeMemoryManager->getMemoryManagerType() == SCENE_STATIC ?
2140+ mStaticMinDepthLevelDirty : 0;
2141+
2142+ //Start from the zeroth level (root) unless static (start from first dirty)
2143+ for( size_t i=start; i<numDepths; ++i )
2144+ {
2145+ Transform t;
2146+ const size_t numNodes = nodeMemoryManager->getFirstNode( t, i );
2147+
2148+ //nodesPerThread must be multiple of ARRAY_PACKED_REALS
2149+ size_t nodesPerThread = ( numNodes + (mNumWorkerThreads-1) ) / mNumWorkerThreads;
2150+ nodesPerThread = ( (nodesPerThread + ARRAY_PACKED_REALS - 1) / ARRAY_PACKED_REALS ) *
2151+ ARRAY_PACKED_REALS;
2152+
2153+ if( numNodes )
2154+ {
2155+ //Send them to worker threads. We need to go depth by depth because
2156+ //we may depend on parents which could be processed by different threads.
2157+ mResetUpdateFlagsRequest = ResetUpdateFlagsRequest( t, nodesPerThread, numNodes );
2158+ fireWorkerThreadsAndWait();
2159+ //Node::updateAllTransforms( numNodes, t );
2160+ }
2161+ }
2162+
2163+ ++it;
2164+ }
2165+}
2166+#endif
20982167 //-----------------------------------------------------------------------
20992168 void SceneManager::updateAllTagPoints()
21002169 {
@@ -2825,6 +2894,9 @@
28252894 highLevelCull();
28262895 _applySceneAnimations();
28272896 updateAllTransforms();
2897+#ifdef USE_PCZ
2898+ resetAllUpdateFlags();
2899+#endif
28282900 updateAllAnimations();
28292901 updateAllTagPoints();
28302902 #ifdef OGRE_LEGACY_ANIMATIONS
@@ -5364,6 +5436,11 @@
53645436 case UPDATE_ALL_TRANSFORMS:
53655437 updateAllTransformsThread( mUpdateTransformRequest, threadIdx );
53665438 break;
5439+#ifdef USE_PCZ
5440+ case RESET_ALL_UPDATE_FLAGS:
5441+ resetAllUpdateFlagsThread( mResetUpdateFlagsRequest, threadIdx );
5442+ break;
5443+#endif
53675444 case UPDATE_ALL_BONE_TO_TAG_TRANSFORMS:
53685445 updateAllTransformsBoneToTagThread( mUpdateTransformRequest, threadIdx );
53695446 break;
diff -r b2744734c847 -r 8def38665797 PlugIns/PCZSceneManager/include/OgrePCZSceneNode.h
--- a/PlugIns/PCZSceneManager/include/OgrePCZSceneNode.h Sat Jun 29 15:48:56 2024 +0200
+++ b/PlugIns/PCZSceneManager/include/OgrePCZSceneNode.h Sun Jun 30 18:52:45 2024 +0200
@@ -120,11 +120,11 @@
120120 void updateZoneData(void);
121121 void enable(bool yesno) {mEnabled = yesno;}
122122 bool isEnabled(void) {return mEnabled;}
123- bool isMoved(void) {return mMoved;}
124- void setMoved(bool value) {mMoved = value;}
123+ bool isMoved(void) const;
124+ void setMoved(bool value);
125125 void nodeUpdated(const Node*);
126- void setUpdated( bool updated ) { mUpdated = updated; }
127- bool isUpdated() { return mUpdated; }
126+ void setUpdated( bool updated );
127+ bool isUpdated() const;
128128 protected:
129129 mutable Vector3 mNewPosition;
130130 PCZone * mHomeZone;
@@ -136,8 +136,8 @@
136136 PCZCamera* mLastVisibleFromCamera;
137137 ZoneDataMap mZoneData;
138138 bool mEnabled;
139- mutable bool mMoved;
140- bool mUpdated; // Only once per frame.
139+// mutable bool mMoved;
140+// mutable bool mUpdated; // Only once per frame.
141141 };
142142 }
143143
diff -r b2744734c847 -r 8def38665797 PlugIns/PCZSceneManager/src/OgrePCZSceneManager.cpp
--- a/PlugIns/PCZSceneManager/src/OgrePCZSceneManager.cpp Sat Jun 29 15:48:56 2024 +0200
+++ b/PlugIns/PCZSceneManager/src/OgrePCZSceneManager.cpp Sun Jun 30 18:52:45 2024 +0200
@@ -552,7 +552,7 @@
552552 return;
553553 }
554554 // TODO ugly workaround to not update multiple times per frame.
555- _resetPCZSceneNodes();
555+// _resetPCZSceneNodes();
556556 // First do the standard scene graph update
557557 SceneManager::updateSceneGraph();
558558 // Update the portal positions
@@ -561,7 +561,8 @@
561561 // check for portal zone-related changes (portals intersecting other portals)
562562 _updatePortalZoneData();
563563 // mark nodes dirty base on portals that changed.
564- _dirtyNodeByMovingPortals();
564+ // TODO is it faster to just dirty up everything instead of actually checking? Does this make sense for Octree based zones?
565+// _dirtyNodeByMovingPortals();
565566 // update all scene nodes
566567 _updatePCZSceneNodes();
567568 // calculate zones affected by each light
diff -r b2744734c847 -r 8def38665797 PlugIns/PCZSceneManager/src/OgrePCZSceneNode.cpp
--- a/PlugIns/PCZSceneManager/src/OgrePCZSceneNode.cpp Sat Jun 29 15:48:56 2024 +0200
+++ b/PlugIns/PCZSceneManager/src/OgrePCZSceneNode.cpp Sun Jun 30 18:52:45 2024 +0200
@@ -45,6 +45,12 @@
4545 #include "OgreSceneNode.h"
4646 #include "OgrePCZone.h"
4747
48+#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM
49+ #define CACHED_TRANSFORM_OUT_OF_DATE() this->_setCachedTransformOutOfDate()
50+#else
51+ #define CACHED_TRANSFORM_OUT_OF_DATE() ((void)0)
52+#endif
53+
4854 namespace Ogre
4955 {
5056 PCZSceneNode::PCZSceneNode( IdType id, SceneManager* creator, NodeMemoryManager *nodeMemoryManager,
@@ -55,8 +61,7 @@
5561 mAllowedToVisit(true),
5662 mLastVisibleFrame(0),
5763 mLastVisibleFromCamera(0),
58- mEnabled(true),
59- mMoved(false)
64+ mEnabled(true)
6065 {
6166 setListener( this );
6267 }
@@ -298,12 +303,37 @@
298303
299304 void PCZSceneNode::nodeUpdated(const Node*)
300305 {
301- if ( !mUpdated )
306+ if ( !isUpdated() )
302307 {
303308 mPrevPosition = mNewPosition;
304309 mNewPosition = _getDerivedPosition(); // TODO make sure that the position has been updated before any calls here.
305- mMoved = true;
306- mUpdated = true;
310+ setMoved( true );
311+ setUpdated( true );
307312 }
308313 }
314+
315+ //-----------------------------------------------------------------------
316+ void PCZSceneNode::setMoved(bool moved)
317+ {
318+ mTransform.mMoved[mTransform.mIndex] = moved;
319+// CACHED_TRANSFORM_OUT_OF_DATE();
320+ }
321+ //-----------------------------------------------------------------------
322+ bool PCZSceneNode::isMoved(void) const
323+ {
324+// OGRE_ASSERT_MEDIUM( !mCachedTransformOutOfDate );
325+ return mTransform.mMoved[mTransform.mIndex];
326+ }
327+ //-----------------------------------------------------------------------
328+ void PCZSceneNode::setUpdated(bool updated)
329+ {
330+ mTransform.mUpdated[mTransform.mIndex] = updated;
331+// CACHED_TRANSFORM_OUT_OF_DATE();
332+ }
333+ //-----------------------------------------------------------------------
334+ bool PCZSceneNode::isUpdated(void) const
335+ {
336+// OGRE_ASSERT_MEDIUM( !mCachedTransformOutOfDate );
337+ return mTransform.mUpdated[mTransform.mIndex];
338+ }
309339 }