diff options
| author | Marijn Tamis <[email protected]> | 2017-10-20 14:30:56 +0200 |
|---|---|---|
| committer | Marijn Tamis <[email protected]> | 2017-10-20 14:36:12 +0200 |
| commit | fabb251458f4a2d6d4f87dd36038fac2774b378c (patch) | |
| tree | 68a4a0ecd940dc949e0477d521d8c159968cfcd5 /NvCloth/src/dx | |
| parent | NvCloth 1.1.2 Release. (22576033) (diff) | |
| download | nvcloth-1.1.3.tar.xz nvcloth-1.1.3.zip | |
NvCloth 1.1.3 Release. (23014067)v1.1.3
Diffstat (limited to 'NvCloth/src/dx')
| -rw-r--r-- | NvCloth/src/dx/DxBatchedVector.h | 2 | ||||
| -rw-r--r-- | NvCloth/src/dx/DxClothData.h | 2 | ||||
| -rw-r--r-- | NvCloth/src/dx/DxFactory.cpp | 42 | ||||
| -rw-r--r-- | NvCloth/src/dx/DxSolver.cpp | 68 | ||||
| -rw-r--r-- | NvCloth/src/dx/DxSolver.h | 5 |
5 files changed, 71 insertions, 48 deletions
diff --git a/NvCloth/src/dx/DxBatchedVector.h b/NvCloth/src/dx/DxBatchedVector.h index 2c5e313..76b9b22 100644 --- a/NvCloth/src/dx/DxBatchedVector.h +++ b/NvCloth/src/dx/DxBatchedVector.h @@ -297,7 +297,7 @@ class DxBatchedVector void swap(DxBatchedVector<T>& other) { - PX_ASSERT(&mStorage == &other.mStorage); + NV_CLOTH_ASSERT(&mStorage == &other.mStorage); physx::shdfnd::swap(mOffset, other.mOffset); physx::shdfnd::swap(mSize, other.mSize); physx::shdfnd::swap(mCapacity, other.mCapacity); diff --git a/NvCloth/src/dx/DxClothData.h b/NvCloth/src/dx/DxClothData.h index f91d37d..4da9be2 100644 --- a/NvCloth/src/dx/DxClothData.h +++ b/NvCloth/src/dx/DxClothData.h @@ -31,7 +31,7 @@ #pragma once #include <foundation/Px.h> -#include "simd.h" +#include "Simd.h" namespace nv { diff --git a/NvCloth/src/dx/DxFactory.cpp b/NvCloth/src/dx/DxFactory.cpp index fbf0c51..91f5125 100644 --- a/NvCloth/src/dx/DxFactory.cpp +++ b/NvCloth/src/dx/DxFactory.cpp @@ -251,15 +251,15 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p void cloth::DxFactory::extractCollisionData(const Cloth& cloth, Range<PxVec4> spheres, Range<uint32_t> capsules, Range<PxVec4> planes, Range<uint32_t> convexes, Range<PxVec3> triangles) const { - PX_ASSERT(&cloth.getFactory() == this); + NV_CLOTH_ASSERT(&cloth.getFactory() == this); const DxCloth& dxCloth = static_cast<const DxCloth&>(cloth); - PX_ASSERT(spheres.empty() || spheres.size() == dxCloth.mStartCollisionSpheres.size()); - PX_ASSERT(capsules.empty() || capsules.size() == dxCloth.mCapsuleIndices.size() * 2); - PX_ASSERT(planes.empty() || planes.size() == dxCloth.mStartCollisionPlanes.size()); - PX_ASSERT(convexes.empty() || convexes.size() == dxCloth.mConvexMasks.size()); - PX_ASSERT(triangles.empty() || triangles.size() == dxCloth.mStartCollisionTriangles.size()); + NV_CLOTH_ASSERT(spheres.empty() || spheres.size() == dxCloth.mStartCollisionSpheres.size()); + NV_CLOTH_ASSERT(capsules.empty() || capsules.size() == dxCloth.mCapsuleIndices.size() * 2); + NV_CLOTH_ASSERT(planes.empty() || planes.size() == dxCloth.mStartCollisionPlanes.size()); + NV_CLOTH_ASSERT(convexes.empty() || convexes.size() == dxCloth.mConvexMasks.size()); + NV_CLOTH_ASSERT(triangles.empty() || triangles.size() == dxCloth.mStartCollisionTriangles.size()); // collision spheres are in pinned memory, so memcpy directly if (!dxCloth.mStartCollisionSpheres.empty() && !spheres.empty()) @@ -296,13 +296,13 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p void cloth::DxFactory::extractMotionConstraints(const Cloth& cloth, Range<PxVec4> destConstraints) const { - PX_ASSERT(&cloth.getFactory() == this); + NV_CLOTH_ASSERT(&cloth.getFactory() == this); const DxCloth& dxCloth = static_cast<const DxCloth&>(cloth); if (dxCloth.mMotionConstraints.mHostCopy.size()) { - PX_ASSERT(destConstraints.size() == dxCloth.mMotionConstraints.mHostCopy.size()); + NV_CLOTH_ASSERT(destConstraints.size() == dxCloth.mMotionConstraints.mHostCopy.size()); memcpy(destConstraints.begin(), dxCloth.mMotionConstraints.mHostCopy.begin(), sizeof(PxVec4) * dxCloth.mMotionConstraints.mHostCopy.size()); @@ -315,20 +315,20 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p ? dxCloth.mMotionConstraints.mTarget : dxCloth.mMotionConstraints.mStart; - PX_ASSERT(destConstraints.size() == srcConstraints.size()); + NV_CLOTH_ASSERT(destConstraints.size() == srcConstraints.size()); copyToHost(destConstraints.begin(), srcConstraints.buffer(), 0, destConstraints.size() * sizeof(PxVec4)); } } void cloth::DxFactory::extractSeparationConstraints(const Cloth& cloth, Range<PxVec4> destConstraints) const { - PX_ASSERT(&cloth.getFactory() == this); + NV_CLOTH_ASSERT(&cloth.getFactory() == this); const DxCloth& dxCloth = static_cast<const DxCloth&>(cloth); if (dxCloth.mSeparationConstraints.mHostCopy.size()) { - PX_ASSERT(destConstraints.size() == dxCloth.mSeparationConstraints.mHostCopy.size()); + NV_CLOTH_ASSERT(destConstraints.size() == dxCloth.mSeparationConstraints.mHostCopy.size()); memcpy(destConstraints.begin(), dxCloth.mSeparationConstraints.mHostCopy.begin(), sizeof(PxVec4) * dxCloth.mSeparationConstraints.mHostCopy.size()); @@ -341,7 +341,7 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p ? dxCloth.mSeparationConstraints.mTarget : dxCloth.mSeparationConstraints.mStart; - PX_ASSERT(destConstraints.size() == srcConstraints.size()); + NV_CLOTH_ASSERT(destConstraints.size() == srcConstraints.size()); copyToHost(destConstraints.begin(), srcConstraints.buffer(), 0, destConstraints.size() * sizeof(PxVec4)); } @@ -350,12 +350,12 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p void cloth::DxFactory::extractParticleAccelerations(const Cloth& cloth, Range<PxVec4> destAccelerations) const { /* - PX_ASSERT(&cloth.getFactory() == this); + NV_CLOTH_ASSERT(&cloth.getFactory() == this); const DxCloth& dxCloth = static_cast<const DxClothImpl&>(cloth).mCloth; if (dxCloth.mParticleAccelerationsHostCopy.size()) { - PX_ASSERT(dxCloth.mParticleAccelerationsHostCopy.size()); + NV_CLOTH_ASSERT(dxCloth.mParticleAccelerationsHostCopy.size()); memcpy(destAccelerations.begin(), dxCloth.mParticleAccelerationsHostCopy.begin(), sizeof(PxVec4) * dxCloth.mParticleAccelerationsHostCopy.size()); @@ -366,20 +366,20 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p DxBatchedVector<PxVec4> const& srcAccelerations = dxCloth.mParticleAccelerations; - PX_ASSERT(destAccelerations.size() == srcAccelerations.size()); + NV_CLOTH_ASSERT(destAccelerations.size() == srcAccelerations.size()); copyToHost(destAccelerations.begin(), srcAccelerations.buffer(), 0, destAccelerations.size() * sizeof(PxVec4)); } */ PX_UNUSED(&cloth); PX_UNUSED(&destAccelerations); - PX_ASSERT(0); + NV_CLOTH_ASSERT(0); } void cloth::DxFactory::extractVirtualParticles(const Cloth& cloth, Range<uint32_t[4]> destIndices, Range<PxVec3> destWeights) const { - PX_ASSERT(&cloth.getFactory() == this); + NV_CLOTH_ASSERT(&cloth.getFactory() == this); DxContextLock contextLock(*this); @@ -400,7 +400,7 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p for (; srcIt != srcEnd; ++srcIt, ++destIt) *destIt = reinterpret_cast<const PxVec3&>(*srcIt); - PX_ASSERT(destIt <= destWeights.end()); + NV_CLOTH_ASSERT(destIt <= destWeights.end()); } if (destIndices.size() > 0) @@ -418,14 +418,14 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p for (; srcIt != srcEnd; ++srcIt, ++destIt) *destIt = Vec4u(*srcIt); - PX_ASSERT(&array(*destIt) <= destIndices.end()); + NV_CLOTH_ASSERT(&array(*destIt) <= destIndices.end()); } } void cloth::DxFactory::extractSelfCollisionIndices(const Cloth& cloth, Range<uint32_t> destIndices) const { const DxCloth& dxCloth = static_cast<const DxCloth&>(cloth); - PX_ASSERT(destIndices.size() == dxCloth.mSelfCollisionIndices.size()); + NV_CLOTH_ASSERT(destIndices.size() == dxCloth.mSelfCollisionIndices.size()); intrinsics::memCopy(destIndices.begin(), dxCloth.mSelfCollisionIndicesHost.begin(), destIndices.size() * sizeof(uint32_t)); } @@ -433,7 +433,7 @@ void cloth::DxFactory::extractFabricData(const Fabric& fabric, Range<uint32_t> p void cloth::DxFactory::extractRestPositions(const Cloth& cloth, Range<PxVec4> destRestPositions) const { const DxCloth& dxCloth = static_cast<const DxCloth&>(cloth); - PX_ASSERT(destRestPositions.size() == dxCloth.mRestPositions.size()); + NV_CLOTH_ASSERT(destRestPositions.size() == dxCloth.mRestPositions.size()); intrinsics::memCopy(destRestPositions.begin(), DxCloth::MappedVec4fVectorType(const_cast<DxCloth&>(dxCloth).mRestPositions).begin(), destRestPositions.size() * sizeof(PxVec4)); } diff --git a/NvCloth/src/dx/DxSolver.cpp b/NvCloth/src/dx/DxSolver.cpp index ab030d5..66a8d8f 100644 --- a/NvCloth/src/dx/DxSolver.cpp +++ b/NvCloth/src/dx/DxSolver.cpp @@ -113,26 +113,9 @@ struct ClothSimCostGreater void cloth::DxSolver::addCloth(Cloth* cloth) { - DxCloth& dxCloth = static_cast<DxCloth&>(*cloth); - - NV_CLOTH_ASSERT(mCloths.find(&dxCloth) == mCloths.end()); - - mCloths.pushBack(&dxCloth); - // trigger update of mClothData array - dxCloth.notifyChanged(); - - // sort cloth instances by size - shdfnd::sort(mCloths.begin(), mCloths.size(), ClothSimCostGreater(), NonTrackingAllocator()); - - DxContextLock contextLock(mFactory); - - // resize containers and update kernel data - mClothDataHostCopy.resize(mCloths.size()); - mClothData.resize(mCloths.size()); - mFrameDataHostCopy.resize(mCloths.size()); - - // lazy compilation of compute shader - mComputeError |= mFactory.mSolverKernelComputeShader == nullptr; + addClothAppend(cloth); + addClothUpdateData(); + #if 0 if (!mSortComputeShader && !mComputeError) { @@ -197,7 +180,7 @@ void cloth::DxSolver::addCloth(Cloth* cloth) { uint32_t key = sortElems[i] & ~0xffff; uint32_t keyRef = _SortElemsRef[i] & ~0xffff; - PX_ASSERT(key == keyRef); + NV_CLOTH_ASSERT(key == keyRef); } _SortElemsHostCopy.unmap(); } @@ -208,6 +191,15 @@ void cloth::DxSolver::addCloth(Cloth* cloth) #endif } +void cloth::DxSolver::addCloths(Range<Cloth*> cloths) +{ + for (uint32_t i = 0; i < cloths.size(); ++i) + { + addClothAppend(*(cloths.begin() + i)); + } + addClothUpdateData(); +} + void cloth::DxSolver::removeCloth(Cloth* cloth) { DxCloth& dxCloth = static_cast<DxCloth&>(*cloth); @@ -232,10 +224,9 @@ int cloth::DxSolver::getNumCloths() const } cloth::Cloth * const * cloth::DxSolver::getClothList() const { - if(getNumCloths()) + if (getNumCloths() != 0) return reinterpret_cast<Cloth* const*>(&mCloths[0]); - else - return nullptr; + return nullptr; } bool cloth::DxSolver::beginSimulation(float dt) @@ -260,7 +251,34 @@ void cloth::DxSolver::endSimulation() } int cloth::DxSolver::getSimulationChunkCount() const { - return 1; + // 0 chunks when no cloth present in the solver, 1 otherwise + return getNumCloths() != 0; +} + +void cloth::DxSolver::addClothAppend(Cloth* cloth) +{ + DxCloth& dxCloth = static_cast<DxCloth&>(*cloth); + NV_CLOTH_ASSERT(mCloths.find(&dxCloth) == mCloths.end()); + + mCloths.pushBack(&dxCloth); + // trigger update of mClothData array + dxCloth.notifyChanged(); +} + +void cloth::DxSolver::addClothUpdateData() +{ + // sort cloth instances by size + shdfnd::sort(mCloths.begin(), mCloths.size(), ClothSimCostGreater(), NonTrackingAllocator()); + + DxContextLock contextLock(mFactory); + + // resize containers and update kernel data + mClothDataHostCopy.resize(mCloths.size()); + mClothData.resize(mCloths.size()); + mFrameDataHostCopy.resize(mCloths.size()); + + // lazy compilation of compute shader + mComputeError |= mFactory.mSolverKernelComputeShader == nullptr; } void cloth::DxSolver::beginFrame() diff --git a/NvCloth/src/dx/DxSolver.h b/NvCloth/src/dx/DxSolver.h index 09f523a..07d77dc 100644 --- a/NvCloth/src/dx/DxSolver.h +++ b/NvCloth/src/dx/DxSolver.h @@ -56,6 +56,7 @@ class DxSolver : private DxContextLock, public Solver ~DxSolver(); virtual void addCloth(Cloth*) override; + virtual void addCloths(Range<Cloth*> cloths) override; virtual void removeCloth(Cloth*) override; virtual int getNumCloths() const override; virtual Cloth * const * getClothList() const override; @@ -101,6 +102,10 @@ class DxSolver : private DxContextLock, public Solver } private: + // add cloth helper functions + void addClothAppend(Cloth* cloth); + void addClothUpdateData(); + // simulate helper functions void beginFrame(); void executeKernel(); |