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_TASK_MANAGER_H |
12 | #define PX_TASK_MANAGER_H |
13 | |
14 | #include "foundation/Px.h" |
15 | |
16 | #ifndef PX_DOXYGEN |
17 | namespace physx |
18 | { |
19 | #endif |
20 | |
21 | class PxProfileZoneManager; |
22 | |
23 | PX_PUSH_PACK_DEFAULT |
24 | |
25 | class PxBaseTask; |
26 | class PxTask; |
27 | class PxLightCpuTask; |
28 | class PxSpuTask; |
29 | typedef PxU32 PxTaskID; |
30 | |
31 | /** |
32 | \brief Identifies the type of each heavyweight PxTask object |
33 | |
34 | \note This enum type is only used by PxTask and GpuTask objects, LightCpuTasks do not use this enum. |
35 | |
36 | @see PxTask |
37 | @see PxLightCpuTask |
38 | */ |
39 | struct PxTaskType |
40 | { |
41 | /** |
42 | * \brief Identifies the type of each heavyweight PxTask object |
43 | */ |
44 | enum Enum |
45 | { |
46 | TT_CPU, //!< PxTask will be run on the CPU |
47 | TT_GPU, //!< PxTask will be run on the GPU |
48 | TT_NOT_PRESENT, //!< Return code when attempting to find a task that does not exist |
49 | TT_COMPLETED //!< PxTask execution has been completed |
50 | }; |
51 | }; |
52 | |
53 | class PxCpuDispatcher; |
54 | class PxSpuDispatcher; |
55 | class PxGpuDispatcher; |
56 | |
57 | /** |
58 | \brief The PxTaskManager interface |
59 | |
60 | A PxTaskManager instance holds references to user-provided dispatcher objects, when tasks are |
61 | submitted the PxTaskManager routes them to the appropriate dispatcher and handles task profiling if enabled. |
62 | Users should not implement the PxTaskManager interface, the SDK creates it's own concrete PxTaskManager object |
63 | per-scene which users can configure by passing dispatcher objects into the PxSceneDesc. |
64 | |
65 | @see PxSceneDesc |
66 | @see CpuDispatcher |
67 | @see PxGpuDispatcher |
68 | @see PxSpuDispatcher |
69 | */ |
70 | class PxTaskManager |
71 | { |
72 | public: |
73 | |
74 | /** |
75 | \brief Set the user-provided dispatcher object for CPU tasks |
76 | |
77 | \param[in] ref The dispatcher object. |
78 | |
79 | @see CpuDispatcher |
80 | */ |
81 | virtual void setCpuDispatcher(PxCpuDispatcher& ref) = 0; |
82 | |
83 | /** |
84 | \brief Set the user-provided dispatcher object for GPU tasks |
85 | |
86 | \param[in] ref The dispatcher object. |
87 | |
88 | @see PxGpuDispatcher |
89 | */ |
90 | virtual void setGpuDispatcher(PxGpuDispatcher& ref) = 0; |
91 | |
92 | /** |
93 | \brief Set the user-provided dispatcher object for SPU tasks |
94 | |
95 | \param[in] ref The dispatcher object. |
96 | |
97 | @see PxSpuDispatcher |
98 | */ |
99 | virtual void setSpuDispatcher(PxSpuDispatcher& ref) = 0; |
100 | |
101 | /** |
102 | \brief Set profile zone used for task profiling. |
103 | |
104 | \param[in] ref The profile zone manager |
105 | |
106 | @see PxProfileZoneManager |
107 | */ |
108 | virtual void initializeProfiling(PxProfileZoneManager& ref) = 0; |
109 | |
110 | /** |
111 | \brief Get the user-provided dispatcher object for CPU tasks |
112 | |
113 | \return The CPU dispatcher object. |
114 | |
115 | @see CpuDispatcher |
116 | */ |
117 | virtual PxCpuDispatcher* getCpuDispatcher() const = 0; |
118 | |
119 | /** |
120 | \brief Get the user-provided dispatcher object for GPU tasks |
121 | |
122 | \return The GPU dispatcher object. |
123 | |
124 | @see PxGpuDispatcher |
125 | */ |
126 | virtual PxGpuDispatcher* getGpuDispatcher() const = 0; |
127 | |
128 | /** |
129 | \brief Get the user-provided dispatcher object for SPU tasks |
130 | |
131 | \return The SPU dispatcher object. |
132 | |
133 | @see PxSpuDispatcher |
134 | */ |
135 | virtual PxSpuDispatcher* getSpuDispatcher() const = 0; |
136 | |
137 | /** |
138 | \brief Reset any dependencies between Tasks |
139 | |
140 | \note Will be called at the start of every frame before tasks are submited. |
141 | |
142 | @see PxTask |
143 | */ |
144 | virtual void resetDependencies() = 0; |
145 | |
146 | /** |
147 | \brief Called by the owning scene to start the task graph. |
148 | |
149 | \note All tasks with with ref count of 1 will be dispatched. |
150 | |
151 | @see PxTask |
152 | */ |
153 | virtual void startSimulation() = 0; |
154 | |
155 | /** |
156 | \brief Called by the owning scene at the end of a simulation step to synchronize the PxGpuDispatcher |
157 | |
158 | @see PxGpuDispatcher |
159 | */ |
160 | virtual void stopSimulation() = 0; |
161 | |
162 | /** |
163 | \brief Called by the worker threads to inform the PxTaskManager that a task has completed processing |
164 | |
165 | \param[in] task The task which has been completed |
166 | */ |
167 | virtual void taskCompleted(PxTask& task) = 0; |
168 | |
169 | /** |
170 | \brief Retrieve a task by name |
171 | |
172 | \param[in] name The unique name of a task |
173 | \return The ID of the task with that name, or TT_NOT_PRESENT if not found |
174 | */ |
175 | virtual PxTaskID getNamedTask(const char* name) = 0; |
176 | |
177 | /** |
178 | \brief Submit a task with a unique name. |
179 | |
180 | \param[in] task The task to be executed |
181 | \param[in] name The unique name of a task |
182 | \param[in] type The type of the task (default TT_CPU) |
183 | \return The ID of the task with that name, or TT_NOT_PRESENT if not found |
184 | |
185 | */ |
186 | virtual PxTaskID submitNamedTask(PxTask* task, const char* name, PxTaskType::Enum type = PxTaskType::TT_CPU) = 0; |
187 | |
188 | /** |
189 | \brief Submit an unnamed task. |
190 | |
191 | \param[in] task The task to be executed |
192 | \param[in] type The type of the task (default TT_CPU) |
193 | |
194 | \return The ID of the task with that name, or TT_NOT_PRESENT if not found |
195 | */ |
196 | virtual PxTaskID submitUnnamedTask(PxTask& task, PxTaskType::Enum type = PxTaskType::TT_CPU) = 0; |
197 | |
198 | /** |
199 | \brief Retrive a task given a task ID |
200 | |
201 | \param[in] id The ID of the task to return, a valid ID must be passed or results are undefined |
202 | |
203 | \return The task associated with the ID |
204 | */ |
205 | virtual PxTask* getTaskFromID(PxTaskID id) = 0; |
206 | |
207 | /** |
208 | \brief Release the PxTaskManager object, referneced dispatchers will not be released |
209 | */ |
210 | virtual void release() = 0; |
211 | |
212 | /** |
213 | \brief Construct a new PxTaskManager instance with the given [optional] dispatchers |
214 | */ |
215 | static PxTaskManager* createTaskManager(PxCpuDispatcher* = 0, PxGpuDispatcher* = 0, PxSpuDispatcher* = 0); |
216 | |
217 | protected: |
218 | virtual ~PxTaskManager() {} |
219 | |
220 | /*! \cond PRIVATE */ |
221 | |
222 | virtual void finishBefore(PxTask& task, PxTaskID taskID) = 0; |
223 | virtual void startAfter(PxTask& task, PxTaskID taskID) = 0; |
224 | |
225 | virtual void addReference(PxTaskID taskID) = 0; |
226 | virtual void decrReference(PxTaskID taskID) = 0; |
227 | virtual PxI32 getReference(PxTaskID taskID) const = 0; |
228 | |
229 | virtual void decrReference(PxLightCpuTask&) = 0; |
230 | virtual void addReference(PxLightCpuTask&) = 0; |
231 | |
232 | virtual void decrReference(PxSpuTask& spuTask) = 0; |
233 | |
234 | virtual void emitStartEvent(PxBaseTask&, PxU32 threadId=0) = 0; |
235 | virtual void emitStopEvent(PxBaseTask&, PxU32 threadId=0) = 0; |
236 | |
237 | /*! \endcond */ |
238 | |
239 | friend class PxBaseTask; |
240 | friend class PxTask; |
241 | friend class PxLightCpuTask; |
242 | friend class PxSpuTask; |
243 | friend class PxGpuWorkerThread; |
244 | }; |
245 | |
246 | PX_POP_PACK |
247 | |
248 | #ifndef PX_DOXYGEN |
249 | } // end physx namespace |
250 | #endif |
251 | |
252 | #endif |
253 | |