1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27
28#ifndef PXTASK_PXTASKMANAGER_H
29#define PXTASK_PXTASKMANAGER_H
30
31#include "task/PxTaskDefine.h"
32#include "foundation/PxSimpleTypes.h"
33#include "foundation/PxErrorCallback.h"
34
35namespace physx
36{
37PX_PUSH_PACK_DEFAULT
38
39class PxBaseTask;
40class PxTask;
41class PxLightCpuTask;
42typedef unsigned int PxTaskID;
43
44/**
45\brief Identifies the type of each heavyweight PxTask object
46
47\note This enum type is only used by PxTask and GpuTask objects, LightCpuTasks do not use this enum.
48
49@see PxTask
50@see PxLightCpuTask
51*/
52struct PxTaskType
53{
54 /**
55 * \brief Identifies the type of each heavyweight PxTask object
56 */
57 enum Enum
58 {
59 TT_CPU, //!< PxTask will be run on the CPU
60 TT_NOT_PRESENT, //!< Return code when attempting to find a task that does not exist
61 TT_COMPLETED //!< PxTask execution has been completed
62 };
63};
64
65class PxCpuDispatcher;
66
67/**
68 \brief The PxTaskManager interface
69
70 A PxTaskManager instance holds references to user-provided dispatcher objects, when tasks are
71 submitted the PxTaskManager routes them to the appropriate dispatcher and handles task profiling if enabled.
72 Users should not implement the PxTaskManager interface, the SDK creates its own concrete PxTaskManager object
73 per-scene which users can configure by passing dispatcher objects into the PxSceneDesc.
74
75 @see CpuDispatcher
76
77*/
78class PxTaskManager
79{
80public:
81
82 /**
83 \brief Set the user-provided dispatcher object for CPU tasks
84
85 \param[in] ref The dispatcher object.
86
87 @see CpuDispatcher
88 */
89 virtual void setCpuDispatcher(PxCpuDispatcher& ref) = 0;
90
91 /**
92 \brief Get the user-provided dispatcher object for CPU tasks
93
94 \return The CPU dispatcher object.
95
96 @see CpuDispatcher
97 */
98 virtual PxCpuDispatcher* getCpuDispatcher() const = 0;
99
100 /**
101 \brief Reset any dependencies between Tasks
102
103 \note Will be called at the start of every frame before tasks are submitted.
104
105 @see PxTask
106 */
107 virtual void resetDependencies() = 0;
108
109 /**
110 \brief Called by the owning scene to start the task graph.
111
112 \note All tasks with with ref count of 1 will be dispatched.
113
114 @see PxTask
115 */
116 virtual void startSimulation() = 0;
117
118 /**
119 \brief Called by the owning scene at the end of a simulation step.
120 */
121 virtual void stopSimulation() = 0;
122
123 /**
124 \brief Called by the worker threads to inform the PxTaskManager that a task has completed processing
125
126 \param[in] task The task which has been completed
127 */
128 virtual void taskCompleted(PxTask& task) = 0;
129
130 /**
131 \brief Retrieve a task by name
132
133 \param[in] name The unique name of a task
134 \return The ID of the task with that name, or TT_NOT_PRESENT if not found
135 */
136 virtual PxTaskID getNamedTask(const char* name) = 0;
137
138 /**
139 \brief Submit a task with a unique name.
140
141 \param[in] task The task to be executed
142 \param[in] name The unique name of a task
143 \param[in] type The type of the task (default TT_CPU)
144 \return The ID of the task with that name, or TT_NOT_PRESENT if not found
145 */
146 virtual PxTaskID submitNamedTask(PxTask* task, const char* name, PxTaskType::Enum type = PxTaskType::TT_CPU) = 0;
147
148 /**
149 \brief Submit an unnamed task.
150
151 \param[in] task The task to be executed
152 \param[in] type The type of the task (default TT_CPU)
153
154 \return The ID of the task with that name, or TT_NOT_PRESENT if not found
155 */
156 virtual PxTaskID submitUnnamedTask(PxTask& task, PxTaskType::Enum type = PxTaskType::TT_CPU) = 0;
157
158 /**
159 \brief Retrieve a task given a task ID
160
161 \param[in] id The ID of the task to return, a valid ID must be passed or results are undefined
162
163 \return The task associated with the ID
164 */
165 virtual PxTask* getTaskFromID(PxTaskID id) = 0;
166
167 /**
168 \brief Release the PxTaskManager object, referenced dispatchers will not be released
169 */
170 virtual void release() = 0;
171
172 /**
173 \brief Construct a new PxTaskManager instance with the given [optional] dispatchers
174 */
175 static PxTaskManager* createTaskManager(PxErrorCallback& errorCallback, PxCpuDispatcher* = 0);
176
177protected:
178 virtual ~PxTaskManager() {}
179
180 /*! \cond PRIVATE */
181
182 virtual void finishBefore(PxTask& task, PxTaskID taskID) = 0;
183 virtual void startAfter(PxTask& task, PxTaskID taskID) = 0;
184
185 virtual void addReference(PxTaskID taskID) = 0;
186 virtual void decrReference(PxTaskID taskID) = 0;
187 virtual int32_t getReference(PxTaskID taskID) const = 0;
188
189 virtual void decrReference(PxLightCpuTask&) = 0;
190 virtual void addReference(PxLightCpuTask&) = 0;
191
192 /*! \endcond */
193
194 friend class PxBaseTask;
195 friend class PxTask;
196 friend class PxLightCpuTask;
197};
198
199PX_POP_PACK
200
201} // end physx namespace
202
203
204#endif // PXTASK_PXTASKMANAGER_H
205

source code of qtquick3dphysics/src/3rdparty/PhysX/include/task/PxTaskManager.h