00001 // This code contains NVIDIA Confidential Information and is disclosed to you 00002 // under a form of NVIDIA software license agreement provided separately to you. 00003 // 00004 // Notice 00005 // NVIDIA Corporation and its licensors retain all intellectual property and 00006 // proprietary rights in and to this software and related documentation and 00007 // any modifications thereto. Any use, reproduction, disclosure, or 00008 // distribution of this software and related documentation without an express 00009 // license agreement from NVIDIA Corporation is strictly prohibited. 00010 // 00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES 00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, 00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. 00015 // 00016 // Information and code furnished is believed to be accurate and reliable. 00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such 00018 // information or for any infringement of patents or other rights of third parties that may 00019 // result from its use. No license is granted by implication or otherwise under any patent 00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice. 00021 // This code supersedes and replaces all information previously supplied. 00022 // NVIDIA Corporation products are not authorized for use as critical 00023 // components in life support devices or systems without express written approval of 00024 // NVIDIA Corporation. 00025 // 00026 // Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. 00027 00028 #ifndef PXTASK_PXTASK_H 00029 #define PXTASK_PXTASK_H 00030 00031 #include "task/PxTaskDefine.h" 00032 #include "task/PxTaskManager.h" 00033 #include "task/PxCpuDispatcher.h" 00034 #include "task/PxGpuDispatcher.h" 00035 #include "foundation/PxAssert.h" 00036 00037 namespace physx 00038 { 00039 00045 class PxBaseTask 00046 { 00047 public: 00048 PxBaseTask() : mEventID(0xFFFF), mProfileStat(0), mTm(0) {} 00049 virtual ~PxBaseTask() {} 00050 00057 virtual void run() = 0; 00058 00066 virtual const char* getName() const = 0; 00067 00069 virtual void addReference() = 0; 00071 virtual void removeReference() = 0; 00073 virtual int32_t getReference() const = 0; 00074 00082 virtual void release() = 0; 00083 00091 PX_INLINE void runProfiled(uint32_t threadId=0) 00092 { 00093 mTm->emitStartEvent(*this, threadId); 00094 run(); 00095 mTm->emitStopEvent(*this, threadId); 00096 } 00097 00106 PX_INLINE void setProfileStat( uint16_t stat ) 00107 { 00108 mProfileStat = stat; 00109 } 00110 00117 PX_INLINE PxTaskManager* getTaskManager() const 00118 { 00119 return mTm; 00120 } 00121 00122 protected: 00123 uint16_t mEventID; 00124 uint16_t mProfileStat; 00125 PxTaskManager* mTm; 00126 00127 friend class PxTaskMgr; 00128 }; 00129 00130 00137 class PxTask : public PxBaseTask 00138 { 00139 public: 00140 PxTask() : mTaskID(0) {} 00141 virtual ~PxTask() {} 00142 00144 virtual void release() 00145 { 00146 PX_ASSERT(mTm); 00147 00148 // clear mTm before calling taskCompleted() for safety 00149 PxTaskManager* save = mTm; 00150 mTm = NULL; 00151 save->taskCompleted( *this ); 00152 } 00153 00155 // task is allowed to start. 00156 PX_INLINE void finishBefore( PxTaskID taskID ) 00157 { 00158 PX_ASSERT(mTm); 00159 mTm->finishBefore( *this, taskID); 00160 } 00161 00163 // task has completed. 00164 PX_INLINE void startAfter( PxTaskID taskID ) 00165 { 00166 PX_ASSERT(mTm); 00167 mTm->startAfter( *this, taskID ); 00168 } 00169 00174 PX_INLINE void addReference() 00175 { 00176 PX_ASSERT(mTm); 00177 mTm->addReference( mTaskID ); 00178 } 00179 00184 PX_INLINE void removeReference() 00185 { 00186 PX_ASSERT(mTm); 00187 mTm->decrReference( mTaskID ); 00188 } 00189 00193 PX_INLINE int32_t getReference() const 00194 { 00195 return mTm->getReference( mTaskID ); 00196 } 00197 00201 PX_INLINE PxTaskID getTaskID() const 00202 { 00203 return mTaskID; 00204 } 00205 00211 virtual void submitted() 00212 { 00213 mStreamIndex = 0; 00214 mPreSyncRequired = false; 00215 mProfileStat = 0; 00216 } 00217 00221 PX_INLINE void requestSyncPoint() 00222 { 00223 mPreSyncRequired = true; 00224 } 00225 00226 00227 protected: 00228 PxTaskID mTaskID; 00229 uint32_t mStreamIndex; 00230 bool mPreSyncRequired; 00231 00232 friend class PxTaskMgr; 00233 friend class PxGpuWorkerThread; 00234 }; 00235 00236 00250 class PxLightCpuTask : public PxBaseTask 00251 { 00252 public: 00253 PxLightCpuTask() 00254 : mCont( NULL ) 00255 , mRefCount( 0 ) 00256 { 00257 } 00258 virtual ~PxLightCpuTask() 00259 { 00260 mTm = NULL; 00261 } 00262 00272 PX_INLINE void setContinuation(PxTaskManager& tm, PxBaseTask* c) 00273 { 00274 PX_ASSERT( mRefCount == 0 ); 00275 mRefCount = 1; 00276 mCont = c; 00277 mTm = &tm; 00278 if( mCont ) 00279 { 00280 mCont->addReference(); 00281 } 00282 } 00283 00291 PX_INLINE void setContinuation( PxBaseTask* c ) 00292 { 00293 PX_ASSERT( c ); 00294 PX_ASSERT( mRefCount == 0 ); 00295 mRefCount = 1; 00296 mCont = c; 00297 if( mCont ) 00298 { 00299 mCont->addReference(); 00300 mTm = mCont->getTaskManager(); 00301 PX_ASSERT( mTm ); 00302 } 00303 } 00304 00308 PX_INLINE PxBaseTask* getContinuation() const 00309 { 00310 return mCont; 00311 } 00312 00317 PX_INLINE void removeReference() 00318 { 00319 mTm->decrReference(*this); 00320 } 00321 00323 PX_INLINE int32_t getReference() const 00324 { 00325 return mRefCount; 00326 } 00327 00332 PX_INLINE void addReference() 00333 { 00334 mTm->addReference(*this); 00335 } 00336 00342 PX_INLINE void release() 00343 { 00344 if( mCont ) 00345 { 00346 mCont->removeReference(); 00347 } 00348 } 00349 00350 protected: 00351 00352 PxBaseTask* mCont; 00353 volatile int32_t mRefCount; 00354 00355 friend class PxTaskMgr; 00356 }; 00357 00358 00359 }// end physx namespace 00360 00361 00362 #endif // PXTASK_PXTASK_H