PxCudaContextManager.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
00027 
00028 
00029 #ifndef PXCUDACONTEXTMANAGER_PXCUDACONTEXTMANAGER_H
00030 #define PXCUDACONTEXTMANAGER_PXCUDACONTEXTMANAGER_H
00031 
00032 #include "foundation/PxPreprocessor.h"
00033 
00034 #if PX_SUPPORT_GPU_PHYSX
00035 
00036 #include "foundation/PxSimpleTypes.h"
00037 #include "foundation/PxErrorCallback.h"
00038 #include "foundation/PxFlags.h"
00039 #include "task/PxTaskDefine.h"
00040 #include "cudamanager/PxCudaMemoryManager.h"
00041 
00042 /* Forward decl to avoid inclusion of cuda.h */
00043 typedef struct CUctx_st *CUcontext;
00044 typedef struct CUgraphicsResource_st *CUgraphicsResource;
00045 typedef int CUdevice;
00046 
00047 namespace physx
00048 { 
00049     
00050 class PxGpuDispatcher;
00051 
00052 
00054 struct PxCudaInteropMode
00055 {
00059     enum Enum
00060     {
00061         NO_INTEROP = 0,
00062         D3D10_INTEROP,
00063         D3D11_INTEROP,
00064         OGL_INTEROP,
00065 
00066         COUNT
00067     };
00068 };
00069 
00070 struct PxCudaInteropRegisterFlag
00071 {
00072     enum Enum
00073     {
00074         eNONE           = 0x00,
00075         eREAD_ONLY      = 0x01,
00076         eWRITE_DISCARD  = 0x02,
00077         eSURFACE_LDST   = 0x04,
00078         eTEXTURE_GATHER = 0x08
00079     };
00080 };
00081 
00087 typedef PxFlags<PxCudaInteropRegisterFlag::Enum, uint32_t> PxCudaInteropRegisterFlags;
00088 PX_FLAGS_OPERATORS(PxCudaInteropRegisterFlag::Enum, uint32_t)
00089 
00090 
00091 class PxCudaContextManagerDesc
00092 {
00093 public:
00115     CUcontext            *ctx;
00116 
00124     void                 *graphicsDevice;
00125 
00126 #if PX_SUPPORT_GPU_PHYSX
00127 
00134     const char*          appGUID;
00135 #endif
00136 
00143     PxCudaInteropMode::Enum interopMode;
00144 
00145 
00161     uint32_t    memoryBaseSize[PxCudaBufferMemorySpace::COUNT];
00162 
00172     uint32_t    memoryPageSize[PxCudaBufferMemorySpace::COUNT];
00173 
00180     uint32_t    maxMemorySize[PxCudaBufferMemorySpace::COUNT];
00181 
00182     PX_INLINE PxCudaContextManagerDesc()
00183     {
00184         ctx = NULL;
00185         interopMode = PxCudaInteropMode::NO_INTEROP;
00186         graphicsDevice = 0;
00187 #if PX_SUPPORT_GPU_PHYSX
00188         appGUID  = NULL;
00189 #endif
00190         for(uint32_t i = 0; i < PxCudaBufferMemorySpace::COUNT; i++)
00191         {
00192             memoryBaseSize[i] = 0;
00193             memoryPageSize[i] = 2 * 1024*1024;
00194             maxMemorySize[i] = UINT32_MAX;
00195         }
00196     }
00197 };
00198 
00199 
00217 class PxCudaContextManager
00218 {
00219 public:
00235     virtual void acquireContext() = 0;
00236 
00244     virtual void releaseContext() = 0;
00245 
00249     virtual CUcontext getContext() = 0;
00250 
00257     virtual PxCudaMemoryManager *getMemoryManager() = 0;
00258 
00263     virtual class physx::PxGpuDispatcher *getGpuDispatcher() = 0;
00264 
00274     virtual bool contextIsValid() const = 0;
00275 
00276     /* Query CUDA context and device properties, without acquiring context */
00277 
00278     virtual bool supportsArchSM10() const = 0;  
00279     virtual bool supportsArchSM11() const = 0;  
00280     virtual bool supportsArchSM12() const = 0;  
00281     virtual bool supportsArchSM13() const = 0;  
00282     virtual bool supportsArchSM20() const = 0;  
00283     virtual bool supportsArchSM30() const = 0;  
00284     virtual bool supportsArchSM35() const = 0;  
00285     virtual bool supportsArchSM50() const = 0;  
00286     virtual bool supportsArchSM52() const = 0;  
00287     virtual bool supportsArchSM60() const = 0;  
00288     virtual bool isIntegrated() const = 0;      
00289     virtual bool canMapHostMemory() const = 0;  
00290     virtual int  getDriverVersion() const = 0;  
00291     virtual size_t getDeviceTotalMemBytes() const = 0; 
00292     virtual int getMultiprocessorCount() const = 0; 
00293     virtual unsigned int getClockRate() const = 0; 
00294     virtual int  getSharedMemPerBlock() const = 0; 
00295     virtual int  getSharedMemPerMultiprocessor() const = 0; 
00296     virtual unsigned int getMaxThreadsPerBlock() const = 0; 
00297     virtual const char *getDeviceName() const = 0; 
00298     virtual CUdevice getDevice() const = 0; 
00299     virtual PxCudaInteropMode::Enum getInteropMode() const = 0; 
00300 
00301     virtual void setUsingConcurrentStreams(bool) = 0; 
00302     virtual bool getUsingConcurrentStreams() const = 0; 
00303     /* End query methods that don't require context to be acquired */
00304 
00325     virtual bool registerResourceInCudaGL(CUgraphicsResource &resource, uint32_t buffer, PxCudaInteropRegisterFlags flags = PxCudaInteropRegisterFlags()) = 0;
00326 
00347     virtual bool registerResourceInCudaD3D(CUgraphicsResource &resource, void *resourcePointer, PxCudaInteropRegisterFlags flags = PxCudaInteropRegisterFlags()) = 0;
00348 
00356     virtual bool unregisterResourceInCuda(CUgraphicsResource resource) = 0;
00357 
00365     virtual int usingDedicatedGPU() const = 0;
00366 
00382     virtual void release() = 0;
00383 
00384 protected:
00385 
00389     virtual ~PxCudaContextManager() {}
00390 };
00391 
00395 class PxScopedCudaLock
00396 {
00397 public:
00401     PxScopedCudaLock(PxCudaContextManager& ctx) : mCtx(&ctx)
00402     {
00403         mCtx->acquireContext();
00404     }
00405 
00409     ~PxScopedCudaLock()
00410     {
00411         mCtx->releaseContext();
00412     }
00413 
00414 protected:
00415 
00419     PxCudaContextManager* mCtx;
00420 };
00421 
00422 } // end physx namespace
00423 
00424 #endif // PX_SUPPORT_GPU_PHYSX
00425 #endif // PXCUDACONTEXTMANAGER_PXCUDACONTEXTMANAGER_H


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