PxGpuCopyDescQueue.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 
11 #ifndef PX_GPU_COPY_DESC_QUEUE_H
12 #define PX_GPU_COPY_DESC_QUEUE_H
13 
14 #include "foundation/PxAssert.h"
15 #include "pxtask/PxGpuCopyDesc.h"
16 #include "pxtask/PxGpuDispatcher.h"
18 
19 #ifndef PX_DOXYGEN
20 namespace physx
21 {
22 #endif
23 
25 
28 {
29 public:
32  : mDispatcher(d)
33  , mBuffer(0)
34  , mStream(0)
35  , mReserved(0)
36  , mOccupancy(0)
37  , mFlushed(0)
38  {
39  }
40 
43  {
44  if (mBuffer)
45  {
46  mDispatcher.getCudaContextManager()->getMemoryManager()->free(PxCudaBufferMemorySpace::T_PINNED_HOST, (size_t) mBuffer);
47  }
48  }
49 
55  void reset(CUstream stream, PxU32 reserveSize)
56  {
57  if (reserveSize > mReserved)
58  {
59  if (mBuffer)
60  {
61  mDispatcher.getCudaContextManager()->getMemoryManager()->free(
63  (size_t) mBuffer);
64  mReserved = 0;
65  }
66  mBuffer = (PxGpuCopyDesc*) mDispatcher.getCudaContextManager()->getMemoryManager()->alloc(
68  reserveSize * sizeof(PxGpuCopyDesc),
69  NV_ALLOC_INFO("PxGpuCopyDescQueue", GPU_UTIL));
70  if (mBuffer)
71  {
72  mReserved = reserveSize;
73  }
74  }
75 
76  mOccupancy = 0;
77  mFlushed = 0;
78  mStream = stream;
79  }
80 
82  void enqueue(PxGpuCopyDesc& desc)
83  {
84  PX_ASSERT(desc.isValid());
85  if (desc.bytes == 0)
86  {
87  return;
88  }
89 
90  if (mOccupancy < mReserved)
91  {
92  mBuffer[ mOccupancy++ ] = desc;
93  }
94  else
95  {
96  mDispatcher.launchCopyKernel(&desc, 1, mStream);
97  }
98  }
99 
101  void flushEnqueued()
102  {
103  if (mOccupancy > mFlushed)
104  {
105  mDispatcher.launchCopyKernel(mBuffer + mFlushed, mOccupancy - mFlushed, mStream);
106  mFlushed = mOccupancy;
107  }
108  }
109 
110 private:
117 
118  void operator=(const PxGpuCopyDescQueue&); // prevent a warning...
119 };
120 
122 
123 #ifndef PX_DOXYGEN
124 } // end physx namespace
125 #endif
126 
127 #endif


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