NVIDIA(R) PhysX(R) SDK 3.4 API Reference: PxTask.h Source File

NVIDIA PhysX SDK 3.4 API

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-2017 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 
00200 protected:
00201     PxTaskID            mTaskID;            
00202     uint32_t            mStreamIndex;       
00203     bool                mPreSyncRequired;   
00204 
00205     friend class PxTaskMgr;
00206     friend class PxGpuWorkerThread;
00207 };
00208 
00209 
00223 class PxLightCpuTask : public PxBaseTask
00224 {
00225 public:
00226     PxLightCpuTask()
00227         : mCont( NULL )
00228         , mRefCount( 0 )
00229     {
00230     }
00231     virtual ~PxLightCpuTask()
00232     {
00233         mTm = NULL;
00234     }
00235 
00245     PX_INLINE void setContinuation(PxTaskManager& tm, PxBaseTask* c)
00246     {
00247         PX_ASSERT( mRefCount == 0 );
00248         mRefCount = 1;
00249         mCont = c;
00250         mTm = &tm;
00251         if( mCont )
00252         {
00253             mCont->addReference();
00254         }
00255     }
00256 
00264     PX_INLINE void setContinuation( PxBaseTask* c )
00265     {
00266         PX_ASSERT( c );
00267         PX_ASSERT( mRefCount == 0 );
00268         mRefCount = 1;
00269         mCont = c;
00270         if( mCont )
00271         {
00272             mCont->addReference();
00273             mTm = mCont->getTaskManager();
00274             PX_ASSERT( mTm );
00275         }
00276     }
00277 
00281     PX_INLINE PxBaseTask*   getContinuation()   const
00282     {
00283         return mCont;
00284     }
00285 
00290     PX_INLINE void removeReference()
00291     {
00292         mTm->decrReference(*this);
00293     }
00294 
00296     PX_INLINE int32_t getReference() const
00297     {
00298         return mRefCount;
00299     }
00300 
00305     PX_INLINE void addReference()
00306     {
00307         mTm->addReference(*this);
00308     }
00309 
00315     PX_INLINE void release()
00316     {
00317         if( mCont )
00318         {
00319             mCont->removeReference();
00320         }
00321     }
00322 
00323 protected:
00324 
00325     PxBaseTask*         mCont;          
00326     volatile int32_t    mRefCount;      
00327 
00328     friend class PxTaskMgr;
00329 };
00330 
00331 
00332 }// end physx namespace
00333 
00334 
00335 #endif // PXTASK_PXTASK_H


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