1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2018 NVIDIA Corporation. All rights reserved.
#ifndef MODULE_CLOTHING_IMPL_H
#define MODULE_CLOTHING_IMPL_H
#include "ModuleClothing.h"
#include "ClothingAsset.h"
#include "ApexSDKIntl.h"
#include "ModuleIntl.h"
#include "ModuleBase.h"
#include "ApexSDKHelpers.h"
#include "ModuleClothingRegistration.h"
#include "ClothStructs.h"
#include "ApexRWLockable.h"
#include "ApexPvdClient.h"
// The clothing GPU source is in a separate DLL, we're going to load it and get a CuFactory create method
#if PX_WINDOWS_FAMILY
#include "ModuleUpdateLoader.h"
#endif
class ClothingPhysicalMeshParameters;
namespace physx
{
class PxCudaContextManager;
}
namespace nvidia
{
#if APEX_CUDA_SUPPORT
namespace cloth
{
class CuFactory;
}
#endif
namespace apex
{
class ApexIsoMesh;
class RenderMeshAssetAuthoringIntl;
class ClothingAsset;
class ClothingAssetAuthoring;
}
namespace clothing
{
class ClothingScene;
class ClothingAssetImpl;
class ClothingAssetAuthoringImpl;
class ClothingPhysicalMeshImpl;
class CookingAbstract;
class DummyActor;
class DummyAsset;
class SimulationAbstract;
class BackendFactory
{
public:
virtual bool isMatch(const char* simulationBackend) = 0;
virtual const char* getName() = 0;
virtual uint32_t getCookingVersion() = 0;
virtual uint32_t getCookedDataVersion(const NvParameterized::Interface* cookedData) = 0;
virtual CookingAbstract* createCookingJob() = 0;
virtual void releaseCookedInstances(NvParameterized::Interface* cookedData) = 0;
virtual SimulationAbstract* createSimulation(ClothingScene* clothingScene, bool useHW) = 0;
};
class ModuleClothingImpl : public ModuleClothing, public ModuleIntl, public ModuleBase, public ApexRWLockable
{
public:
APEX_RW_LOCKABLE_BOILERPLATE
ModuleClothingImpl(ApexSDKIntl* sdk);
// from ApexInterface
PX_INLINE void release()
{
ModuleBase::release();
}
// from Module
void init(NvParameterized::Interface& desc);
NvParameterized::Interface* getDefaultModuleDesc();
PX_INLINE const char* getName() const
{
return ModuleBase::getName();
}
AuthObjTypeID getModuleID() const;
RenderableIterator* createRenderableIterator(const Scene&);
ClothingPhysicalMesh* createEmptyPhysicalMesh();
ClothingPhysicalMesh* createSingleLayeredMesh(RenderMeshAssetAuthoring* asset, uint32_t subdivisionSize, bool mergeVertices, bool closeHoles, IProgressListener* progress);
PX_INLINE NvParameterized::Interface* getApexClothingActorParams(void) const
{
return mApexClothingActorParams;
}
PX_INLINE NvParameterized::Interface* getApexClothingPreviewParams(void) const
{
return mApexClothingPreviewParams;
}
// from ModuleIntl
virtual void destroy();
virtual ModuleSceneIntl* createInternalModuleScene(SceneIntl&, RenderDebugInterface*);
virtual void releaseModuleSceneIntl(ModuleSceneIntl&);
virtual uint32_t forceLoadAssets();
#ifndef WITHOUT_PVD
virtual void initPvdClasses(pvdsdk::PvdDataStream& pvdDataStream);
virtual void initPvdInstances(pvdsdk::PvdDataStream& pvdDataStream);
virtual void destroyPvdInstances();
#endif
// own methods
ClothingScene* getClothingScene(const Scene& scene);
ClothingPhysicalMeshImpl* createPhysicalMeshInternal(ClothingPhysicalMeshParameters* mesh);
void releasePhysicalMesh(ClothingPhysicalMeshImpl* physicalMesh);
void unregisterAssetWithScenes(ClothingAssetImpl* asset);
void notifyReleaseGraphicalData(ClothingAssetImpl* asset);
Actor* getDummyActor();
// This pointer will not be released by this module!
virtual void registerBackendFactory(BackendFactory* factory);
virtual void unregisterBackendFactory(BackendFactory* factory);
// this works both with the name of the simulation backend, or the cooking data type
BackendFactory* getBackendFactory(const char* simulationBackend);
ClothFactory createClothFactory(PxCudaContextManager* contextManager);
void releaseClothFactory(PxCudaContextManager* contextManager);
PX_INLINE uint32_t getMaxUnusedPhysXResources() const
{
return mInternalModuleParams.maxUnusedPhysXResources;
}
PX_INLINE uint32_t getMaxNumCompartments() const
{
return mInternalModuleParams.maxNumCompartments;
}
PX_INLINE bool allowAsyncFetchResults() const
{
return mInternalModuleParams.asyncFetchResults;
}
PX_INLINE bool allowAsyncCooking() const
{
return mInternalModuleParams.allowAsyncCooking;
}
PX_INLINE uint32_t getAvgSimFrequencyWindowSize() const
{
return mInternalModuleParams.avgSimFrequencyWindow;
}
PX_INLINE bool allowApexWorkBetweenSubsteps() const
{
return mInternalModuleParams.allowApexWorkBetweenSubsteps;
}
PX_INLINE float getInterCollisionDistance() const
{
return mInternalModuleParams.interCollisionDistance;
}
PX_INLINE float getInterCollisionStiffness() const
{
return mInternalModuleParams.interCollisionStiffness;
}
PX_INLINE uint32_t getInterCollisionIterations() const
{
return mInternalModuleParams.interCollisionIterations;
}
PX_INLINE void setInterCollisionDistance(float distance)
{
mInternalModuleParams.interCollisionDistance = distance;
}
PX_INLINE void setInterCollisionStiffness(float stiffness)
{
mInternalModuleParams.interCollisionStiffness = stiffness;
}
PX_INLINE void setInterCollisionIterations(uint32_t iterations)
{
mInternalModuleParams.interCollisionIterations = iterations;
}
PX_INLINE bool useSparseSelfCollision() const
{
return mInternalModuleParams.sparseSelfCollision;
}
PX_INLINE uint32_t getMaxTimeRenderProxyInPool() const
{
return mInternalModuleParams.maxTimeRenderProxyInPool;
}
private:
ClothingPhysicalMesh* createSingleLayeredMeshInternal(RenderMeshAssetAuthoringIntl* asset, uint32_t subdivisionSize, bool mergeVertices, bool closeHoles, IProgressListener* progress);
ResourceList mClothingSceneList;
ResourceList mPhysicalMeshes;
ResourceList mAssetAuthorableObjectFactories;
DummyActor* mDummyActor;
DummyAsset* mDummyAsset;
nvidia::Mutex mDummyProtector;
class ClothingBackendFactory : public BackendFactory, public nvidia::UserAllocated
{
public:
virtual bool isMatch(const char* simulationBackend);
virtual const char* getName();
virtual uint32_t getCookingVersion();
virtual uint32_t getCookedDataVersion(const NvParameterized::Interface* cookedData);
virtual CookingAbstract* createCookingJob();
virtual void releaseCookedInstances(NvParameterized::Interface* cookedData);
virtual SimulationAbstract* createSimulation(ClothingScene* clothingScene, bool useHW);
};
ClothingBackendFactory mBackendFactory;
Array<BackendFactory*> mBackendFactories;
ClothingModuleParameters* mModuleParams;
ClothingModuleParametersNS::ParametersStruct mInternalModuleParams;
NvParameterized::Interface* mApexClothingActorParams;
NvParameterized::Interface* mApexClothingPreviewParams;
nvidia::Mutex mFactoryMutex;
cloth::Factory* mCpuFactory;
uint32_t mCpuFactoryReferenceCount;
#if APEX_CUDA_SUPPORT
void* mGpuDllHandle;
// this function is declared in CreateCuFactory.h and implemented in CreateCuFactory.cpp, which is in in APEX_ClothingGPU
typedef nvidia::cloth::CuFactory* (PxCreateCuFactory_FUNC)(PxCudaContextManager* contextManager);
PxCreateCuFactory_FUNC* mPxCreateCuFactoryFunc;
struct GpuFactoryEntry
{
GpuFactoryEntry(cloth::Factory* f, PxCudaContextManager* c) : factoryGpu(f), contextManager(c), referenceCount(0) {}
cloth::Factory* factoryGpu;
PxCudaContextManager* contextManager;
uint32_t referenceCount;
};
nvidia::Array<GpuFactoryEntry> mGpuFactories;
#endif
virtual ~ModuleClothingImpl() {}
};
}
} // namespace nvidia
#endif // MODULE_CLOTHING_IMPL_H
|