aboutsummaryrefslogtreecommitdiff
path: root/NvCloth/src/cuda/CuCloth.cpp
diff options
context:
space:
mode:
authorMarijn Tamis <[email protected]>2017-04-28 14:19:07 +0200
committerMarijn Tamis <[email protected]>2017-04-28 14:19:07 +0200
commitb350eb5f4d44e8448115796144375d79438d74ae (patch)
tree8e102e8c28f45a1b87bd335ceee4f33c3d4ee7c2 /NvCloth/src/cuda/CuCloth.cpp
parentAdd visual samples. (diff)
downloadnvcloth-b350eb5f4d44e8448115796144375d79438d74ae.tar.xz
nvcloth-b350eb5f4d44e8448115796144375d79438d74ae.zip
NvCloth 1.1.0 Release. (22041545)
Diffstat (limited to 'NvCloth/src/cuda/CuCloth.cpp')
-rw-r--r--NvCloth/src/cuda/CuCloth.cpp135
1 files changed, 60 insertions, 75 deletions
diff --git a/NvCloth/src/cuda/CuCloth.cpp b/NvCloth/src/cuda/CuCloth.cpp
index 93b2370..3e6175b 100644
--- a/NvCloth/src/cuda/CuCloth.cpp
+++ b/NvCloth/src/cuda/CuCloth.cpp
@@ -37,7 +37,6 @@
#include "../TripletScheduler.h"
#include "../ClothBase.h"
#include <foundation/PxMat44.h>
-#include <PsFoundation.h>
using namespace physx;
@@ -215,7 +214,7 @@ uint32_t cloth::CuCloth::getSharedMemorySize() const
return phaseConfigSize + sizeof(float) * (continuousCollisionSize + std::max(selfCollisionSize, discreteCollisionSize));
}
-void cloth::CuCloth::setPhaseConfig(Range<const PhaseConfig> configs)
+void cloth::CuCloth::setPhaseConfigInternal(Range<const PhaseConfig> configs)
{
mHostPhaseConfigs.assign(configs.begin(), configs.end());
@@ -317,69 +316,60 @@ namespace nv
namespace cloth
{
-// ClothImpl<CuCloth>::clone() implemented in CuClothClone.cpp
+// CuCloth::clone() implemented in CuClothClone.cpp
-template <>
-uint32_t ClothImpl<CuCloth>::getNumParticles() const
+uint32_t CuCloth::getNumParticles() const
{
- return mCloth.mNumParticles;
+ return mNumParticles;
}
-template <>
-void ClothImpl<CuCloth>::lockParticles() const
+void CuCloth::lockParticles() const
{
- const_cast<CuCloth&>(mCloth).syncHostParticles();
+ const_cast<CuCloth&>(*this).syncHostParticles();
}
-template <>
-void ClothImpl<CuCloth>::unlockParticles() const
+void CuCloth::unlockParticles() const
{
}
-template <>
-MappedRange<PxVec4> ClothImpl<CuCloth>::getCurrentParticles()
+MappedRange<PxVec4> CuCloth::getCurrentParticles()
{
- mCloth.wakeUp();
+ wakeUp();
lockParticles();
- mCloth.mDeviceParticlesDirty = true;
- return getMappedParticles(mCloth.mParticlesHostCopy.begin());
+ mDeviceParticlesDirty = true;
+ return getMappedParticles(mParticlesHostCopy.begin());
}
-template <>
-MappedRange<const PxVec4> ClothImpl<CuCloth>::getCurrentParticles() const
+MappedRange<const PxVec4> CuCloth::getCurrentParticles() const
{
lockParticles();
- return getMappedParticles(mCloth.mParticlesHostCopy.begin());
+ return getMappedParticles(mParticlesHostCopy.begin());
}
-template <>
-MappedRange<PxVec4> ClothImpl<CuCloth>::getPreviousParticles()
+MappedRange<PxVec4> CuCloth::getPreviousParticles()
{
- mCloth.wakeUp();
+ wakeUp();
lockParticles();
- mCloth.mDeviceParticlesDirty = true;
- return getMappedParticles(mCloth.mParticlesHostCopy.begin() + mCloth.mNumParticles);
+ mDeviceParticlesDirty = true;
+ return getMappedParticles(mParticlesHostCopy.begin() + mNumParticles);
}
-template <>
-MappedRange<const PxVec4> ClothImpl<CuCloth>::getPreviousParticles() const
+MappedRange<const PxVec4> CuCloth::getPreviousParticles() const
{
lockParticles();
- return getMappedParticles(mCloth.mParticlesHostCopy.begin() + mCloth.mNumParticles);
+ return getMappedParticles(mParticlesHostCopy.begin() + mNumParticles);
}
-template <>
-GpuParticles ClothImpl<CuCloth>::getGpuParticles()
+GpuParticles CuCloth::getGpuParticles()
{
- mCloth.syncDeviceParticles();
- mCloth.mHostParticlesDirty = true;
- PxVec4* particles = mCloth.mParticles.begin().get();
- GpuParticles result = { particles, particles + mCloth.mNumParticles, 0 };
+ syncDeviceParticles();
+ mHostParticlesDirty = true;
+ PxVec4* particles = mParticles.begin().get();
+ GpuParticles result = { particles, particles + mNumParticles, 0 };
return result;
}
-template <>
-void ClothImpl<CuCloth>::setPhaseConfig(Range<const PhaseConfig> configs)
+void CuCloth::setPhaseConfig(Range<const PhaseConfig> configs)
{
Vector<PhaseConfig>::Type transformedConfigs;
transformedConfigs.reserve(configs.size());
@@ -389,56 +379,52 @@ void ClothImpl<CuCloth>::setPhaseConfig(Range<const PhaseConfig> configs)
if (configs.front().mStiffness > 0.0f)
transformedConfigs.pushBack(transform(configs.front()));
- mCloth.setPhaseConfig(Range<const PhaseConfig>(transformedConfigs.begin(), transformedConfigs.end()));
- mCloth.notifyChanged();
- mCloth.wakeUp();
+ setPhaseConfigInternal(Range<const PhaseConfig>(transformedConfigs.begin(), transformedConfigs.end()));
+ notifyChanged();
+ wakeUp();
}
-template <>
-void ClothImpl<CuCloth>::setSelfCollisionIndices(Range<const uint32_t> indices)
+void CuCloth::setSelfCollisionIndices(Range<const uint32_t> indices)
{
- ContextLockType lock(mCloth.mFactory);
- mCloth.mSelfCollisionIndices.assign(indices.begin(), indices.end());
- mCloth.mSelfCollisionIndicesHost.assign(indices.begin(), indices.end());
- mCloth.notifyChanged();
- mCloth.wakeUp();
+ ContextLockType lock(mFactory);
+ mSelfCollisionIndices.assign(indices.begin(), indices.end());
+ mSelfCollisionIndicesHost.assign(indices.begin(), indices.end());
+ notifyChanged();
+ wakeUp();
}
-template <>
-uint32_t ClothImpl<CuCloth>::getNumVirtualParticles() const
+uint32_t CuCloth::getNumVirtualParticles() const
{
- return uint32_t(mCloth.mVirtualParticleIndices.size());
+ return uint32_t(mVirtualParticleIndices.size());
}
-template <>
-Range<PxVec4> ClothImpl<CuCloth>::getParticleAccelerations()
+Range<PxVec4> CuCloth::getParticleAccelerations()
{
- if (mCloth.mParticleAccelerations.empty())
+ if (mParticleAccelerations.empty())
{
- CuContextLock contextLock(mCloth.mFactory);
- mCloth.mParticleAccelerations.resize(mCloth.mNumParticles);
+ CuContextLock contextLock(mFactory);
+ mParticleAccelerations.resize(mNumParticles);
}
- if (!mCloth.mParticleAccelerationsHostCopy.capacity())
+ if (!mParticleAccelerationsHostCopy.capacity())
{
- CuContextLock contextLock(mCloth.mFactory);
- mCloth.mParticleAccelerationsHostCopy.reserve(mCloth.mNumParticles);
+ CuContextLock contextLock(mFactory);
+ mParticleAccelerationsHostCopy.reserve(mNumParticles);
}
- mCloth.mParticleAccelerationsHostCopy.resizeUninitialized(mCloth.mNumParticles);
+ mParticleAccelerationsHostCopy.resizeUninitialized(mNumParticles);
- mCloth.wakeUp();
+ wakeUp();
- PxVec4* data = mCloth.mParticleAccelerationsHostCopy.begin();
- return Range<PxVec4>(data, mCloth.mParticleAccelerationsHostCopy.end());
+ PxVec4* data = mParticleAccelerationsHostCopy.begin();
+ return Range<PxVec4>(data, mParticleAccelerationsHostCopy.end());
}
-template <>
-void ClothImpl<CuCloth>::clearParticleAccelerations()
+void CuCloth::clearParticleAccelerations()
{
- CuContextLock contextLock(mCloth.mFactory);
- CuDeviceVector<PxVec4>(mCloth.mFactory.mContext).swap(mCloth.mParticleAccelerations);
- CuHostVector<PxVec4, CU_MEMHOSTALLOC_DEVICEMAP>::Type().swap(mCloth.mParticleAccelerationsHostCopy);
- mCloth.wakeUp();
+ CuContextLock contextLock(mFactory);
+ CuDeviceVector<PxVec4>(mFactory.mContext).swap(mParticleAccelerations);
+ CuHostVector<PxVec4, CU_MEMHOSTALLOC_DEVICEMAP>::Type().swap(mParticleAccelerationsHostCopy);
+ wakeUp();
}
namespace
@@ -469,12 +455,11 @@ namespace
}
}
-template <>
-void ClothImpl<CuCloth>::setVirtualParticles(Range<const uint32_t[4]> indices, Range<const PxVec3> weights)
+void CuCloth::setVirtualParticles(Range<const uint32_t[4]> indices, Range<const PxVec3> weights)
{
// shuffle indices to form independent SIMD sets
TripletScheduler scheduler(indices);
- scheduler.warp(mCloth.mNumParticles, 32);
+ scheduler.warp(mNumParticles, 32);
// convert to 16bit indices
Vector<Vec4us>::Type hostIndices;
@@ -497,15 +482,15 @@ void ClothImpl<CuCloth>::setVirtualParticles(Range<const uint32_t[4]> indices, R
hostWeights.pushBack(PxVec4( w.x, w.y, w.z, scale ));
}
- CuContextLock contextLock(mCloth.mFactory);
+ CuContextLock contextLock(mFactory);
// todo: 'swap' these to force reallocation?
- mCloth.mVirtualParticleIndices = hostIndices;
- mCloth.mVirtualParticleSetSizes = scheduler.mSetSizes;
- mCloth.mVirtualParticleWeights = hostWeights;
+ mVirtualParticleIndices = hostIndices;
+ mVirtualParticleSetSizes = scheduler.mSetSizes;
+ mVirtualParticleWeights = hostWeights;
- mCloth.notifyChanged();
- mCloth.wakeUp();
+ notifyChanged();
+ wakeUp();
}
} // namespace cloth