PxTask.h
Go to the documentation of this file.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-2012 NVIDIA Corporation. All rights reserved. 00027 00028 #ifndef PX_TASK_H 00029 #define PX_TASK_H 00030 00031 #include "foundation/Px.h" 00032 #include "pxtask/PxTaskManager.h" 00033 #include "foundation/PxAssert.h" 00034 00035 #ifndef PX_DOXYGEN 00036 namespace physx 00037 { 00038 #endif 00039 00040 namespace pxtask 00041 { 00042 00048 class BaseTask 00049 { 00050 public: 00051 BaseTask() : mEventID(0xFFFF), mProfileStat(0), mTm(0) {} 00052 virtual ~BaseTask() {} 00053 00060 virtual void run() = 0; 00061 00069 virtual const char *getName() const = 0; 00070 00072 virtual void addReference() = 0; 00074 virtual void removeReference() = 0; 00076 virtual PxI32 getReference() const = 0; 00077 00079 virtual void release() = 0; 00080 00086 PX_INLINE void runProfiled() 00087 { 00088 mTm->emitStartEvent(*this); 00089 run(); 00090 mTm->emitStopEvent(*this); 00091 } 00092 00101 PX_INLINE void setProfileStat( PxU16 stat ) 00102 { 00103 mProfileStat = stat; 00104 } 00105 00112 PX_INLINE TaskManager* getTaskManager() const 00113 { 00114 return mTm; 00115 } 00116 00117 protected: 00118 PxU16 mEventID; 00119 PxU16 mProfileStat; 00120 TaskManager * mTm; 00121 00122 friend class TaskMgr; 00123 }; 00124 00125 00132 class Task : public BaseTask 00133 { 00134 public: 00135 Task() : mTaskID(0) {} 00136 virtual ~Task() {} 00137 00139 virtual void release() 00140 { 00141 PX_ASSERT(mTm); 00142 00143 // clear mTm before calling taskCompleted() for safety 00144 TaskManager *save = mTm; 00145 mTm = NULL; 00146 save->taskCompleted( *this ); 00147 } 00148 00150 // task is allowed to start. 00151 PX_INLINE void finishBefore( TaskID taskID ) 00152 { 00153 PX_ASSERT(mTm); 00154 mTm->finishBefore( *this, taskID); 00155 } 00156 00158 // task has completed. 00159 PX_INLINE void startAfter( TaskID taskID ) 00160 { 00161 PX_ASSERT(mTm); 00162 mTm->startAfter( *this, taskID ); 00163 } 00164 00169 PX_INLINE void addReference() 00170 { 00171 PX_ASSERT(mTm); 00172 mTm->addReference( mTaskID ); 00173 } 00174 00179 PX_INLINE void removeReference() 00180 { 00181 PX_ASSERT(mTm); 00182 mTm->decrReference( mTaskID ); 00183 } 00184 00188 PX_INLINE PxI32 getReference() const 00189 { 00190 return mTm->getReference( mTaskID ); 00191 } 00192 00196 PX_INLINE TaskID getTaskID() const 00197 { 00198 return mTaskID; 00199 } 00200 00206 virtual void submitted() 00207 { 00208 mStreamIndex = 0; 00209 mPreSyncRequired = false; 00210 mProfileStat = 0; 00211 } 00212 00216 PX_INLINE void requestSyncPoint() 00217 { 00218 mPreSyncRequired = true; 00219 } 00220 00221 00222 protected: 00223 TaskID mTaskID; 00224 PxU32 mStreamIndex; 00225 bool mPreSyncRequired; 00226 00227 friend class TaskMgr; 00228 friend class GpuWorkerThread; 00229 }; 00230 00231 00245 class LightCpuTask : public BaseTask 00246 { 00247 public: 00248 LightCpuTask() 00249 : mCont( NULL ) 00250 , mRefCount( 0 ) 00251 { 00252 } 00253 virtual ~LightCpuTask() 00254 { 00255 mTm = NULL; 00256 } 00257 00267 PX_INLINE void setContinuation(TaskManager& tm, BaseTask* c) 00268 { 00269 PX_ASSERT( mRefCount == 0 ); 00270 mRefCount = 1; 00271 mCont = c; 00272 mTm = &tm; 00273 if( mCont ) 00274 { 00275 mCont->addReference(); 00276 } 00277 } 00278 00286 PX_INLINE void setContinuation( BaseTask *c ) 00287 { 00288 PX_ASSERT( c ); 00289 PX_ASSERT( mRefCount == 0 ); 00290 mRefCount = 1; 00291 mCont = c; 00292 if( mCont ) 00293 { 00294 mCont->addReference(); 00295 mTm = mCont->getTaskManager(); 00296 PX_ASSERT( mTm ); 00297 } 00298 } 00299 00304 PX_INLINE void removeReference() 00305 { 00306 mTm->decrReference(*this); 00307 } 00308 00310 PX_INLINE PxI32 getReference() const 00311 { 00312 return mRefCount; 00313 } 00314 00319 PX_INLINE void addReference() 00320 { 00321 mTm->addReference(*this); 00322 } 00323 00329 PX_INLINE void release() 00330 { 00331 if( mCont ) 00332 { 00333 mCont->removeReference(); 00334 } 00335 } 00336 00337 protected: 00338 00339 BaseTask * mCont; 00340 volatile PxI32 mRefCount; 00341 00342 friend class TaskMgr; 00343 }; 00344 00345 00346 } // end pxtask namespace 00347 00348 #ifndef PX_DOXYGEN 00349 } // end physx namespace 00350 #endif 00351 00352 #endif
Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com