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-2018 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() : mContextID(0), mTm(NULL) {}
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 
00081     virtual void        release() = 0;
00082 
00089     PX_FORCE_INLINE PxTaskManager* getTaskManager() const
00090     {
00091         return mTm;
00092     }
00093 
00094     PX_FORCE_INLINE void    setContextId(PxU64 id)          { mContextID = id;      }
00095     PX_FORCE_INLINE PxU64   getContextId()          const   { return mContextID;    }
00096 
00097 protected:
00098     PxU64               mContextID;     
00099     PxTaskManager*      mTm;            
00100 
00101     friend class PxTaskMgr;
00102 };
00103 
00104 
00111 class PxTask : public PxBaseTask
00112 {
00113 public:
00114     PxTask() : mTaskID(0) {}
00115     virtual ~PxTask() {}
00116 
00118     virtual void release()
00119     {
00120         PX_ASSERT(mTm);
00121 
00122         // clear mTm before calling taskCompleted() for safety
00123         PxTaskManager* save = mTm;
00124         mTm = NULL;
00125         save->taskCompleted( *this );
00126     }
00127 
00129     //         task is allowed to start.
00130     PX_INLINE void finishBefore( PxTaskID taskID )
00131     {
00132         PX_ASSERT(mTm);
00133         mTm->finishBefore( *this, taskID);
00134     }
00135 
00137     //         task has completed.
00138     PX_INLINE void startAfter( PxTaskID taskID )
00139     {
00140         PX_ASSERT(mTm);
00141         mTm->startAfter( *this, taskID );
00142     }
00143 
00148     PX_INLINE void addReference()
00149     {
00150         PX_ASSERT(mTm);
00151         mTm->addReference( mTaskID );
00152     }
00153 
00158     PX_INLINE void removeReference()
00159     {
00160         PX_ASSERT(mTm);
00161         mTm->decrReference( mTaskID );
00162     }
00163 
00167     PX_INLINE int32_t getReference() const
00168     {
00169         return mTm->getReference( mTaskID );
00170     }
00171     
00175     PX_INLINE PxTaskID      getTaskID() const
00176     {
00177         return mTaskID;
00178     }
00179 
00185     virtual void submitted()
00186     {
00187         mStreamIndex = 0;
00188         mPreSyncRequired = false;
00189     }
00190 
00194     PX_INLINE void      requestSyncPoint()
00195     {
00196         mPreSyncRequired = true;
00197     }
00198 
00199 protected:
00200     PxTaskID            mTaskID;            
00201     uint32_t            mStreamIndex;       
00202     bool                mPreSyncRequired;   
00203 
00204     friend class PxTaskMgr;
00205     friend class PxGpuWorkerThread;
00206 };
00207 
00208 
00222 class PxLightCpuTask : public PxBaseTask
00223 {
00224 public:
00225     PxLightCpuTask()
00226         : mCont( NULL )
00227         , mRefCount( 0 )
00228     {
00229     }
00230     virtual ~PxLightCpuTask()
00231     {
00232         mTm = NULL;
00233     }
00234 
00244     PX_INLINE void setContinuation(PxTaskManager& tm, PxBaseTask* c)
00245     {
00246         PX_ASSERT( mRefCount == 0 );
00247         mRefCount = 1;
00248         mCont = c;
00249         mTm = &tm;
00250         if( mCont )
00251         {
00252             mCont->addReference();
00253         }
00254     }
00255 
00263     PX_INLINE void setContinuation( PxBaseTask* c )
00264     {
00265         PX_ASSERT( c );
00266         PX_ASSERT( mRefCount == 0 );
00267         mRefCount = 1;
00268         mCont = c;
00269         if( mCont )
00270         {
00271             mCont->addReference();
00272             mTm = mCont->getTaskManager();
00273             PX_ASSERT( mTm );
00274         }
00275     }
00276 
00280     PX_INLINE PxBaseTask*   getContinuation()   const
00281     {
00282         return mCont;
00283     }
00284 
00289     PX_INLINE void removeReference()
00290     {
00291         mTm->decrReference(*this);
00292     }
00293 
00295     PX_INLINE int32_t getReference() const
00296     {
00297         return mRefCount;
00298     }
00299 
00304     PX_INLINE void addReference()
00305     {
00306         mTm->addReference(*this);
00307     }
00308 
00314     PX_INLINE void release()
00315     {
00316         if( mCont )
00317         {
00318             mCont->removeReference();
00319         }
00320     }
00321 
00322 protected:
00323 
00324     PxBaseTask*         mCont;          
00325     volatile int32_t    mRefCount;      
00326 
00327     friend class PxTaskMgr;
00328 };
00329 
00330 
00331 }// end physx namespace
00332 
00333 
00334 #endif // PXTASK_PXTASK_H


Copyright © 2008-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com