PxSpuTask.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_SPU_TASK_H
12 #define PX_SPU_TASK_H
13 
14 #include "pxtask/PxTask.h"
15 #include "pxtask/PxSpuDispatcher.h"
16 
17 #include "physxprofilesdk/PxProfileZone.h"
18 
19 #ifndef PX_DOXYGEN
20 namespace physx
21 {
22 #endif
23 
43 class PxSpuTask : public PxLightCpuTask
44 {
45 public:
46 
47  static const PxU32 kMaxSpus = 6;
48  static const PxU32 kArgsPerSpu = 2;
49 
57  PxSpuTask(const void* elfStart, PxU32 elfSize, PxU32 numSpus=1, const PxU32* args=NULL)
58  : mElfStart(elfStart)
59  , mElfSize(elfSize)
60  , mNbSpusToRun(numSpus)
61  , mNbSpusFinished(0)
62  , mEmitProfile(false)
63  {
64  if (args)
65  {
66  memcpy(mArgs, args, mNbSpusToRun*kArgsPerSpu*sizeof(PxU32));
67  }
68  }
69 
70  virtual ~PxSpuTask() {}
71 
75  PX_INLINE PxU32 getSpuCount() const
76  {
77  return mNbSpusToRun;
78  }
79 
83  PX_INLINE void setSpuCount(PxU32 numSpusToRun)
84  {
85  PX_ASSERT(numSpusToRun);
86  mNbSpusToRun = numSpusToRun;
87  }
88 
94  PX_INLINE const PxU32* getArgs(PxU32 spuIndex) const
95  {
96  PX_ASSERT(spuIndex < kMaxSpus);
97  return mArgs[spuIndex];
98  }
99 
100 
107  PX_INLINE void setArgs(PxU32 spuIndex, PxU32 arg0, PxU32 arg1)
108  {
109  PX_ASSERT(spuIndex < kMaxSpus);
110  PxU32* arguments = mArgs[spuIndex];
111  arguments[0]=arg0;
112  arguments[1]=arg1;
113  }
114 
118  PX_INLINE const void* getElfStart() const
119  {
120  return mElfStart;
121  }
122 
126  PX_INLINE PxU32 getElfSize() const
127  {
128  return mElfSize;
129  }
130 
136  PX_INLINE void notifySpuFinish()
137  {
138  ++mNbSpusFinished;
139 
140  // if all SPU tasks have finished clean-up and release
141  if (mNbSpusFinished == mNbSpusToRun)
142  {
143  // emit profiling event
144  if (mEmitProfile)
145  {
146  getTaskManager()->emitStopEvent(*this, PxProfileEventSender::CrossThreadId);
147  mEmitProfile = false;
148  }
149 
150  mNbSpusFinished = 0;
151  release();
152  }
153  }
154 
158  virtual void removeReference()
159  {
160  PX_ASSERT(mTm);
161  mTm->decrReference(*this);
162  }
163 
172  virtual void run() {}
173 
177  void runProfiled()
178  {
179  // emit profiling event
180  getTaskManager()->emitStartEvent(*this, PxProfileEventSender::CrossThreadId);
181  mEmitProfile = true;
182 
183  run();
184  }
185 
186 
187 protected:
188 
189  const void* mElfStart;
193  PxU32 mArgs[kMaxSpus][kArgsPerSpu];
195 
196 }
197 // wrap this in a macro so Doxygen doesn't get confused and output it
198 #ifndef PX_DOXYGEN
199 PX_ALIGN_SUFFIX(16)
200 #endif
201 ;
202 
203 #ifndef PX_DOXYGEN
204 } // end physx namespace
205 #endif
206 
207 #endif


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