PxGpuCopyDescQueue.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_GPU_COPY_DESC_QUEUE_H 00029 #define PX_GPU_COPY_DESC_QUEUE_H 00030 00036 #include "foundation/PxAssert.h" 00037 #include "pxtask/PxGpuCopyDesc.h" 00038 #include "pxtask/PxGpuDispatcher.h" 00039 #include "pxtask/PxCudaContextManager.h" 00040 00041 #ifndef PX_DOXYGEN 00042 namespace physx 00043 { 00044 #endif 00045 00046 namespace pxtask 00047 { 00048 00049 PX_PUSH_PACK_DEFAULT 00050 00052 class GpuCopyDescQueue 00053 { 00054 public: 00056 GpuCopyDescQueue(GpuDispatcher& d) 00057 : mDispatcher(d) 00058 , mBuffer(0) 00059 , mStream(0) 00060 , mReserved(0) 00061 , mOccupancy(0) 00062 , mFlushed(0) 00063 { 00064 } 00065 00067 ~GpuCopyDescQueue() 00068 { 00069 if (mBuffer) 00070 { 00071 mDispatcher.getCudaContextManager()->getMemoryManager()->free(CudaBufferMemorySpace::T_PINNED_HOST, (size_t) mBuffer); 00072 } 00073 } 00074 00080 void reset(CUstream stream, PxU32 reserveSize) 00081 { 00082 if (reserveSize > mReserved) 00083 { 00084 if (mBuffer) 00085 { 00086 mDispatcher.getCudaContextManager()->getMemoryManager()->free( 00087 CudaBufferMemorySpace::T_PINNED_HOST, 00088 (size_t) mBuffer); 00089 mReserved = 0; 00090 } 00091 mBuffer = (GpuCopyDesc*) mDispatcher.getCudaContextManager()->getMemoryManager()->alloc( 00092 CudaBufferMemorySpace::T_PINNED_HOST, 00093 reserveSize * sizeof(GpuCopyDesc), 00094 NV_ALLOC_INFO("PxGpuCopyDescQueue", GPU_UTIL)); 00095 if (mBuffer) 00096 { 00097 mReserved = reserveSize; 00098 } 00099 } 00100 00101 mOccupancy = 0; 00102 mFlushed = 0; 00103 mStream = stream; 00104 } 00105 00107 void enqueue(GpuCopyDesc& desc) 00108 { 00109 PX_ASSERT(desc.isValid()); 00110 if (desc.bytes == 0) 00111 { 00112 return; 00113 } 00114 00115 if (mOccupancy < mReserved) 00116 { 00117 mBuffer[ mOccupancy++ ] = desc; 00118 } 00119 else 00120 { 00121 mDispatcher.launchCopyKernel(&desc, 1, mStream); 00122 } 00123 } 00124 00126 void flushEnqueued() 00127 { 00128 if (mOccupancy > mFlushed) 00129 { 00130 mDispatcher.launchCopyKernel(mBuffer + mFlushed, mOccupancy - mFlushed, mStream); 00131 mFlushed = mOccupancy; 00132 } 00133 } 00134 00135 private: 00136 GpuDispatcher& mDispatcher; 00137 GpuCopyDesc* mBuffer; 00138 CUstream mStream; 00139 PxU32 mReserved; 00140 PxU32 mOccupancy; 00141 PxU32 mFlushed; 00142 00143 void operator=(const GpuCopyDescQueue&); // prevent a warning... 00144 }; 00145 00146 PX_POP_PACK 00147 00148 } // end pxtask namespace 00149 00150 #ifndef PX_DOXYGEN 00151 } // end physx namespace 00152 #endif 00153 00154 #endif
Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com