diff options
Diffstat (limited to 'APEX_1.4/module/basicios/src')
| -rw-r--r-- | APEX_1.4/module/basicios/src/BasicIosActorCPU.cpp | 318 | ||||
| -rw-r--r-- | APEX_1.4/module/basicios/src/BasicIosActorGPU.cpp | 802 | ||||
| -rw-r--r-- | APEX_1.4/module/basicios/src/BasicIosActorImpl.cpp | 1221 | ||||
| -rw-r--r-- | APEX_1.4/module/basicios/src/BasicIosAssetImpl.cpp | 196 | ||||
| -rw-r--r-- | APEX_1.4/module/basicios/src/BasicIosScene.cpp | 469 | ||||
| -rw-r--r-- | APEX_1.4/module/basicios/src/ModuleBasicIosImpl.cpp | 416 | ||||
| -rw-r--r-- | APEX_1.4/module/basicios/src/autogen/BasicIOSAssetParam.cpp | 1406 | ||||
| -rw-r--r-- | APEX_1.4/module/basicios/src/autogen/BasicIosDebugRenderParams.cpp | 358 | ||||
| -rw-r--r-- | APEX_1.4/module/basicios/src/autogen/BasicIosModuleParameters.cpp | 318 |
9 files changed, 5504 insertions, 0 deletions
diff --git a/APEX_1.4/module/basicios/src/BasicIosActorCPU.cpp b/APEX_1.4/module/basicios/src/BasicIosActorCPU.cpp new file mode 100644 index 00000000..aec76a88 --- /dev/null +++ b/APEX_1.4/module/basicios/src/BasicIosActorCPU.cpp @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#include "Apex.h" +#include "SceneIntl.h" +#include "ApexSDKIntl.h" + +#include "BasicIosActor.h" +#include "BasicIosActorCPU.h" +#include "BasicIosAssetImpl.h" +#include "IofxAsset.h" +#include "IofxActor.h" +#include "ModuleBasicIosImpl.h" +#include "BasicIosSceneCPU.h" +#include "RenderDebugInterface.h" +#include "AuthorableObjectIntl.h" +#include "FieldSamplerQueryIntl.h" +#include "PxMath.h" +#include "ApexMirroredArray.h" + +namespace nvidia +{ +namespace basicios +{ + +#pragma warning(disable: 4355) // 'this' : used in base member initializer list + +BasicIosActorCPU::BasicIosActorCPU( + ResourceList& list, + BasicIosAssetImpl& asset, + BasicIosScene& scene, + nvidia::apex::IofxAsset& iofxAsset) + : BASIC_IOS_ACTOR(list, asset, scene, iofxAsset, false) + , mSimulateTask(*this) +{ + initStorageGroups(mSimulationStorage); + + mLifeTime.setSize(mMaxParticleCount); + mLifeSpan.setSize(mMaxTotalParticleCount); + mInjector.setSize(mMaxTotalParticleCount); + mBenefit.setSize(mMaxTotalParticleCount); + + if (mAsset->mParams->collisionWithConvex) + { + mConvexPlanes.reserve(MAX_CONVEX_PLANES_COUNT); + mConvexVerts.reserve(MAX_CONVEX_VERTS_COUNT); + mConvexPolygonsData.reserve(MAX_CONVEX_POLYGONS_DATA_SIZE); + } + if (mAsset->mParams->collisionWithTriangleMesh) + { + mTrimeshVerts.reserve(MAX_TRIMESH_VERTS_COUNT); + mTrimeshIndices.reserve(MAX_TRIMESH_INDICES_COUNT); + } + + mNewIndices.resize(mMaxParticleCount); +} +BasicIosActorCPU::~BasicIosActorCPU() +{ +} + +void BasicIosActorCPU::submitTasks() +{ + BasicIosActorImpl::submitTasks(); + + mInjectorsCounters.setSize(mInjectorList.getSize(), ApexMirroredPlace::CPU); + PxTaskManager* tm = mBasicIosScene->getApexScene().getTaskManager(); + tm->submitUnnamedTask(mSimulateTask); +} + +void BasicIosActorCPU::setTaskDependencies() +{ + BasicIosActorImpl::setTaskDependencies(&mSimulateTask, false); +} + +void BasicIosActorCPU::fetchResults() +{ + BASIC_IOS_ACTOR::fetchResults(); +} + +namespace +{ +class FieldAccessor +{ + const PxVec4* mField; +public: + explicit FieldAccessor(const PxVec4* field) + { + mField = field; + } + + PX_INLINE void operator()(unsigned int srcIdx, PxVec3& velocityDelta) + { + if (mField != NULL) + { + velocityDelta += mField[srcIdx].getXYZ(); + } + } +}; +} + +void BasicIosActorCPU::simulateParticles() +{ + float deltaTime = mBasicIosScene->getApexScene().getPhysXSimulateTime(); + const PxVec3& eyePos = mBasicIosScene->getApexScene().getEyePosition(); + + mTotalElapsedTime += deltaTime; + + PxVec3 gravity = -mUp; + + uint32_t totalCount = mParticleCount + mInjectedCount; + uint32_t activeCount = mLastActiveCount + mInjectedCount; + + mParticleBudget = mMaxParticleCount; + if (mParticleBudget > activeCount) + { + mParticleBudget = activeCount; + } + uint32_t targetCount = mParticleBudget; + + uint32_t maxStateID = 0; //we could drop state in case targetCount = 0 + + for(uint32_t i = 0; i < mInjectorList.getSize(); ++i) + { + mInjectorsCounters[i] = 0; + } + + if (targetCount > 0) + { + maxStateID = mParticleCount; + for (uint32_t i = 0; i < maxStateID; ++i) + { + mNewIndices[i] = IosBufferDescIntl::NOT_A_PARTICLE; + } + + uint32_t boundCount = 0; + if (activeCount > targetCount) + { + boundCount = activeCount - targetCount; + } + + float benefitMin = PxMin(mLastBenefitMin, mInjectedBenefitMin); + float benefitMax = PxMax(mLastBenefitMax, mInjectedBenefitMax); + PX_ASSERT(benefitMin <= benefitMax); + benefitMax *= 1.00001f; + + uint32_t boundBin = computeHistogram(totalCount, benefitMin, benefitMax, boundCount); + for (uint32_t i = 0, boundIndex = 0; i < totalCount; ++i) + { + float benefit = mBenefit[i]; + if (benefit > -FLT_MAX) + { + PX_ASSERT(benefit >= benefitMin && benefit < benefitMax); + + uint32_t bin = uint32_t((benefit - benefitMin) * HISTOGRAM_BIN_COUNT / (benefitMax - benefitMin)); + if (bin < boundBin) + { + mBenefit[i] = -FLT_MAX; + continue; + } + if (bin == boundBin && boundIndex < boundCount) + { + mBenefit[i] = -FLT_MAX; + ++boundIndex; + } + } + } + + checkBenefit(totalCount); + checkHoles(totalCount); + } + mLastActiveCount = 0; + mLastBenefitSum = 0.0f; + mLastBenefitMin = +FLT_MAX; + mLastBenefitMax = -FLT_MAX; + + if (targetCount > 0) + { + const InjectorParams* injectorParamsList = DYNAMIC_CAST(BasicIosSceneCPU*)(mBasicIosScene)->mInjectorParamsArray.begin(); + + FieldAccessor fieldAccessor(mFieldSamplerQuery ? mField.getPtr() : 0); + + SimulationParams simParams; + mSimulationParamsHandle.fetch(mSimulationStorage, simParams); + + for (uint32_t dest = 0, srcHole = targetCount; dest < targetCount; ++dest) + { + uint32_t src = dest; + //do we have a hole in dest region? + if (!(mBenefit[dest] > -FLT_MAX)) + { + //skip holes in src region + while (!(mBenefit[srcHole] > -FLT_MAX)) + { + ++srcHole; + } + PX_ASSERT(srcHole < totalCount); + src = srcHole++; + } + //do we have a new particle? + bool isNewParticle = (src >= mParticleCount); + + unsigned int injIndex; + float benefit = simulateParticle( + &simParams, mSimulationStorage, injectorParamsList, + deltaTime, gravity, eyePos, + isNewParticle, src, dest, + mBufDesc.pmaPositionMass->getPtr(), mBufDesc.pmaVelocityLife->getPtr(), mBufDesc.pmaActorIdentifiers->getPtr(), + mLifeSpan.getPtr(), mLifeTime.getPtr(), mInjector.getPtr(), mBufDesc.pmaCollisionNormalFlags->getPtr(), mBufDesc.pmaUserData->getPtr(), + fieldAccessor, injIndex + ); + + if (injIndex < mInjectorsCounters.getSize()) + { + ++mInjectorsCounters[injIndex]; + } + + if (!isNewParticle) + { + mNewIndices[src] = dest; + } + else + { + mBufDesc.pmaInStateToInput->get(maxStateID) = dest | IosBufferDescIntl::NEW_PARTICLE_FLAG; + ++maxStateID; + } + + mBenefit[dest] = benefit; + if (benefit > -FLT_MAX) + { + mLastBenefitSum += benefit; + mLastBenefitMin = PxMin(mLastBenefitMin, benefit); + mLastBenefitMax = PxMax(mLastBenefitMax, benefit); + ++mLastActiveCount; + } + } + + //update stateToInput + for (uint32_t i = 0; i < mParticleCount; ++i) + { + uint32_t src = mBufDesc.pmaOutStateToInput->get(i); + PX_ASSERT( src < mParticleCount ); + mBufDesc.pmaInStateToInput->get(i) = mNewIndices[src]; + } + } + checkInState(totalCount); + + mParticleCount = targetCount; + + /* Oh! Manager of the IOFX! do your thing */ + mIofxMgr->updateEffectsData(deltaTime, mParticleCount, mParticleCount, maxStateID); +} + +uint32_t BasicIosActorCPU::computeHistogram(uint32_t dataCount, float dataMin, float dataMax, uint32_t& bound) +{ + const float* dataArray = mBenefit.getPtr(); + + uint32_t histogram[HISTOGRAM_BIN_COUNT]; + + //clear Histogram + for (uint32_t i = 0; i < HISTOGRAM_BIN_COUNT; ++i) + { + histogram[i] = 0; + } + //accum Histogram + for (uint32_t i = 0; i < dataCount; ++i) + { + float data = dataArray[i]; + if (data >= dataMin && data < dataMax) + { + uint32_t bin = uint32_t((data - dataMin) * HISTOGRAM_BIN_COUNT / (dataMax - dataMin)); + ++histogram[bin]; + } + } + //compute CDF from Histogram + uint32_t countSum = 0; + for (uint32_t i = 0; i < HISTOGRAM_BIN_COUNT; ++i) + { + uint32_t count = histogram[i]; + countSum += count; + histogram[i] = countSum; + } + + //binary search in CDF + uint32_t beg = 0; + uint32_t end = HISTOGRAM_BIN_COUNT; + while (beg < end) + { + uint32_t mid = beg + ((end - beg) >> 1); + if (bound > histogram[mid]) + { + beg = mid + 1; + } + else + { + end = mid; + } + } + + checkHistogram(bound, histogram[beg], histogram[HISTOGRAM_BIN_COUNT - 1]); + + if (beg > 0) + { + bound -= histogram[beg - 1]; + } + + return beg; +} + +} +} // namespace nvidia diff --git a/APEX_1.4/module/basicios/src/BasicIosActorGPU.cpp b/APEX_1.4/module/basicios/src/BasicIosActorGPU.cpp new file mode 100644 index 00000000..0a4ef4ca --- /dev/null +++ b/APEX_1.4/module/basicios/src/BasicIosActorGPU.cpp @@ -0,0 +1,802 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#include "ApexDefs.h" +#if APEX_CUDA_SUPPORT + +#include "Apex.h" +#include "SceneIntl.h" +#include "ApexSDKIntl.h" + +#include "BasicIosActor.h" +#include "BasicIosActorGPU.h" +#include "BasicIosAssetImpl.h" +#include "IofxAsset.h" +#include "IofxActor.h" +#include "ModuleBasicIosImpl.h" +#include "BasicIosSceneGPU.h" +#include "RenderDebugInterface.h" +#include "AuthorableObjectIntl.h" + +#include "PxMath.h" + +//CUDA +#include "PxGpuTask.h" +#include "ApexCutil.h" + +#define CUDA_OBJ(name) SCENE_CUDA_OBJ(*mBasicIosScene, name) + +namespace nvidia +{ +namespace basicios +{ + +#pragma warning(disable: 4355) // 'this' : used in base member initializer list + +BasicIosActorGPU::BasicIosActorGPU( + ResourceList& list, + BasicIosAssetImpl& asset, + BasicIosScene& scene, + nvidia::apex::IofxAsset& iofxAsset, + const ApexMirroredPlace::Enum defaultPlace) + : BASIC_IOS_ACTOR(list, asset, scene, iofxAsset, true) + , mCopyQueue(*scene.getApexScene().getTaskManager()->getGpuDispatcher()) + , mHoleScanSum(scene.getApexScene()) + , mMoveIndices(scene.getApexScene()) + , mTmpReduce(scene.getApexScene()) + , mTmpHistogram(scene.getApexScene()) + , mTmpScan(scene.getApexScene()) + , mTmpScan1(scene.getApexScene()) + , mTmpOutput(scene.getApexScene()) + , mTmpOutput1(scene.getApexScene()) + , mLaunchTask(*this) +{ + initStorageGroups(CUDA_OBJ(simulateStorage)); + + //CUDA + mTmpOutput.setSize(4, ApexMirroredPlace::CPU_GPU); + mTmpOutput1.setSize(2, ApexMirroredPlace::CPU_GPU); + + const unsigned int ScanWarpsPerBlock = MAX_WARPS_PER_BLOCK; //CUDA_OBJ(scanKernel).getBlockDim().x / WARP_SIZE; + mTmpReduce.reserve(MAX_BOUND_BLOCKS * 4, defaultPlace); + mTmpHistogram.reserve(MAX_BOUND_BLOCKS * HISTOGRAM_SIMULATE_BIN_COUNT, defaultPlace); + mTmpScan.reserve(MAX_BOUND_BLOCKS * ScanWarpsPerBlock, defaultPlace); + mTmpScan1.reserve(MAX_BOUND_BLOCKS * ScanWarpsPerBlock, defaultPlace); + + mLifeTime.reserve(mMaxParticleCount, defaultPlace); + + mLifeSpan.reserve(mMaxTotalParticleCount, ApexMirroredPlace::CPU_GPU); + mInjector.reserve(mMaxTotalParticleCount, ApexMirroredPlace::CPU_GPU); + mBenefit.reserve(mMaxTotalParticleCount, ApexMirroredPlace::CPU_GPU); + + { + uint32_t size = mGridDensityParams.GridResolution; + if(size > 0) + { + mGridDensityGrid.setSize(size*size*size,ApexMirroredPlace::GPU); + mGridDensityGridLowPass.setSize(size*size*size,ApexMirroredPlace::GPU); + } + } + + if (mAsset->mParams->collisionWithConvex) + { + mConvexPlanes.reserve(MAX_CONVEX_PLANES_COUNT, ApexMirroredPlace::CPU_GPU); + mConvexVerts.reserve(MAX_CONVEX_VERTS_COUNT, ApexMirroredPlace::CPU_GPU); + mConvexPolygonsData.reserve(MAX_CONVEX_POLYGONS_DATA_SIZE, ApexMirroredPlace::CPU_GPU); + } + if (mAsset->mParams->collisionWithTriangleMesh) + { + mTrimeshVerts.reserve(MAX_TRIMESH_VERTS_COUNT, ApexMirroredPlace::CPU_GPU); + mTrimeshIndices.reserve(MAX_TRIMESH_INDICES_COUNT, ApexMirroredPlace::CPU_GPU); + } + + mHoleScanSum.reserve(mMaxTotalParticleCount, defaultPlace); + mMoveIndices.reserve(mMaxTotalParticleCount, defaultPlace); +} + +BasicIosActorGPU::~BasicIosActorGPU() +{ +} + +void BasicIosActorGPU::submitTasks() +{ + BasicIosActorImpl::submitTasks(); + + mInjectorsCounters.setSize(mInjectorList.getSize(), ApexMirroredPlace::CPU_GPU); + PxTaskManager* tm = mBasicIosScene->getApexScene().getTaskManager(); + tm->submitUnnamedTask(mLaunchTask, PxTaskType::TT_GPU); +} + +void BasicIosActorGPU::setTaskDependencies() +{ + BasicIosActorImpl::setTaskDependencies(&mLaunchTask, true); + + PxTaskManager* tm = mBasicIosScene->getApexScene().getTaskManager(); + if (tm->getGpuDispatcher()->getCudaContextManager()->supportsArchSM20()) + { + /* For Fermi devices, it pays to launch all IOS together. This also forces + * The IOFX managers to step at the same time. + */ + PxTaskID interlock = tm->getNamedTask("IOS::StepInterlock"); + mLaunchTask.startAfter(interlock); + } +} + +bool BasicIosActorGPU::launch(CUstream stream, int kernelIndex) +{ + float deltaTime = mBasicIosScene->getApexScene().getPhysXSimulateTime(); + + uint32_t activeCount = mLastActiveCount + mInjectedCount; + mParticleBudget = mMaxParticleCount; + if (mParticleBudget > activeCount) + { + mParticleBudget = activeCount; + } + uint32_t targetCount = mParticleBudget; + + if (targetCount == 0) + { + //reset output + float* pTmpOutput = (float*)mTmpOutput.getPtr(); + mTmpOutput[STATUS_LAST_ACTIVE_COUNT] = 0; + pTmpOutput[STATUS_LAST_BENEFIT_SUM] = 0.0f; + pTmpOutput[STATUS_LAST_BENEFIT_MIN] = +FLT_MAX; + pTmpOutput[STATUS_LAST_BENEFIT_MAX] = -FLT_MAX; + + for(uint32_t i = 0; i < mInjectorsCounters.getSize(); ++i) + { + mInjectorsCounters[i] = 0; + } + + //skip simulation & just call IofxManager + mIofxMgr->updateEffectsData(deltaTime, 0, 0, 0, stream); + return false; + } + + uint32_t lastCount = mParticleCount; + uint32_t injectCount = mInjectedCount; + uint32_t totalCount = lastCount + injectCount; + PX_ASSERT(targetCount <= totalCount); + uint32_t boundCount = 0; + if (activeCount > targetCount) + { + boundCount = activeCount - targetCount; + } + + BasicIosSceneGPU* sceneGPU = static_cast<BasicIosSceneGPU*>(mBasicIosScene); + bool useSyncKernels = !sceneGPU->getGpuDispatcher()->getCudaContextManager()->supportsArchSM20(); + + switch (kernelIndex) + { + case 0: + if (!mFieldSamplerQuery && mOnStartCallback) + { + (*mOnStartCallback)(stream); + } + + mCopyQueue.reset(stream, 24); + mIofxMgr->outputHostToDevice(mCopyQueue); + if (mInjectedCount > 0) + { + mBufDesc.pmaPositionMass->copyHostToDeviceQ(mCopyQueue, mInjectedCount, mParticleCount); + mBufDesc.pmaVelocityLife->copyHostToDeviceQ(mCopyQueue, mInjectedCount, mParticleCount); + mBufDesc.pmaActorIdentifiers->copyHostToDeviceQ(mCopyQueue, mInjectedCount, mParticleCount); + mLifeSpan.copyHostToDeviceQ(mCopyQueue, mInjectedCount, mParticleCount); + mInjector.copyHostToDeviceQ(mCopyQueue, mInjectedCount, mParticleCount); + mBenefit.copyHostToDeviceQ(mCopyQueue, mInjectedCount, mParticleCount); + mBufDesc.pmaUserData->copyHostToDeviceQ(mCopyQueue, mInjectedCount, mParticleCount); + } + if (mAsset->mParams->collisionWithConvex) + { + mConvexPlanes.copyHostToDeviceQ(mCopyQueue); + mConvexVerts.copyHostToDeviceQ(mCopyQueue); + mConvexPolygonsData.copyHostToDeviceQ(mCopyQueue); + } + if (mAsset->mParams->collisionWithTriangleMesh) + { + mTrimeshVerts.copyHostToDeviceQ(mCopyQueue); + mTrimeshIndices.copyHostToDeviceQ(mCopyQueue); + } + mCopyQueue.flushEnqueued(); + return true; + + case 1: + if (totalCount > 0) + { + float benefitMin = PxMin(mLastBenefitMin, mInjectedBenefitMin); + float benefitMax = PxMax(mLastBenefitMax, mInjectedBenefitMax); + PX_ASSERT(benefitMin <= benefitMax); + benefitMax *= 1.00001f; + + if (useSyncKernels) + { + CUDA_OBJ(histogramSyncKernel)( + stream, totalCount, + mBenefit.getGpuPtr(), boundCount, + benefitMin, benefitMax, + mTmpOutput1.getGpuPtr(), + mTmpHistogram.getGpuPtr() + ); + } + else + { + uint32_t histogramGridSize = + CUDA_OBJ(histogramKernel)( + stream, totalCount, + createApexCudaMemRef(mBenefit, totalCount, ApexCudaMemFlags::IN), + boundCount, benefitMin, benefitMax, + createApexCudaMemRef(mTmpOutput1, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpHistogram, ApexCudaMemFlags::OUT), + 1, 0 + ); + + //launch just 1 block + CUDA_OBJ(histogramKernel)( + stream, APEX_CUDA_SINGLE_BLOCK_LAUNCH, + createApexCudaMemRef(mBenefit, totalCount, ApexCudaMemFlags::IN), + boundCount, benefitMin, benefitMax, + createApexCudaMemRef(mTmpOutput1, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mTmpHistogram, ApexCudaMemFlags::IN_OUT), + 2, histogramGridSize + ); + } + } + return true; + + case 2: + if (totalCount > 0) + { + float benefitMin = PxMin(mLastBenefitMin, mInjectedBenefitMin); + float benefitMax = PxMax(mLastBenefitMax, mInjectedBenefitMax); + PX_ASSERT(benefitMin <= benefitMax); + benefitMax *= 1.00001f; + + if (useSyncKernels) + { + CUDA_OBJ(scanSyncKernel)( + stream, totalCount, + benefitMin, benefitMax, + mHoleScanSum.getGpuPtr(), mBenefit.getGpuPtr(), + mTmpOutput1.getGpuPtr(), + mTmpScan.getGpuPtr(), mTmpScan1.getGpuPtr() + ); + } + else + { + uint32_t scanGridSize = + CUDA_OBJ(scanKernel)( + stream, totalCount, + benefitMin, benefitMax, + createApexCudaMemRef(mHoleScanSum, totalCount, ApexCudaMemFlags::IN), + createApexCudaMemRef(mBenefit, totalCount, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpOutput1, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpScan, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mTmpScan1, ApexCudaMemFlags::OUT), + 1, 0 + ); + + //launch just 1 block + CUDA_OBJ(scanKernel)( + stream, APEX_CUDA_SINGLE_BLOCK_LAUNCH, + benefitMin, benefitMax, + createApexCudaMemRef(mHoleScanSum, totalCount, ApexCudaMemFlags::IN), + createApexCudaMemRef(mBenefit, totalCount, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpOutput1, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpScan, ApexCudaMemFlags::IN_OUT), + createApexCudaMemRef(mTmpScan1, ApexCudaMemFlags::IN_OUT), + 2, scanGridSize + ); + + CUDA_OBJ(scanKernel)( + stream, totalCount, + benefitMin, benefitMax, + createApexCudaMemRef(mHoleScanSum, totalCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mBenefit, totalCount, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpOutput1, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpScan, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpScan1, ApexCudaMemFlags::IN), + 3, 0 + ); + } + } + return true; + + case 3: + { + if (totalCount > 0) + { + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefCompactScanSum, mHoleScanSum); + const uint32_t injectorCount = mInjectorList.getSize(); + + CUDA_OBJ(compactKernel)( + stream, + PxMax(totalCount, injectorCount), + targetCount, + totalCount, + injectorCount, + createApexCudaMemRef(mMoveIndices, totalCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mTmpScan, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mInjectorsCounters, ApexCudaMemFlags::OUT) + ); + + } + return true; + } + + + case 4: + if (targetCount > 0) + { + uint32_t histogramGridSize = 0; + { + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefMoveIndices, mMoveIndices); + + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefPositionMass, *mBufDesc.pmaPositionMass); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefVelocityLife, *mBufDesc.pmaVelocityLife); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefIofxActorIDs, *mBufDesc.pmaActorIdentifiers); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefLifeSpan, mLifeSpan); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefLifeTime, mLifeTime); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefInjector, mInjector); + + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefUserData, *mBufDesc.pmaUserData); + + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefConvexPlanes, mConvexPlanes); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefConvexVerts, mConvexVerts); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefConvexPolygonsData, mConvexPolygonsData); + + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefTrimeshVerts, mTrimeshVerts); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefTrimeshIndices, mTrimeshIndices); + + PxVec3 gravity = -mUp; + const PxVec3& eyePos = mBasicIosScene->getApexScene().getEyePosition(); + + if (mFieldSamplerQuery != NULL) + { + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefField, mField); + + histogramGridSize = CUDA_OBJ(simulateApplyFieldKernel)(stream, + targetCount, + lastCount, + deltaTime, + gravity, + eyePos, + sceneGPU->mInjectorConstMemGroup.getStorage().mappedHandle(sceneGPU->mInjectorParamsArrayHandle), mInjectorsCounters.getSize(), + createApexCudaMemRef(mHoleScanSum, targetCount, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpScan, 1, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpHistogram, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mInjectorsCounters, mInjectorsCounters.getSize(), ApexCudaMemFlags::OUT), + createApexCudaMemRef((float4*)mBufDesc.pmaPositionMass->getGpuPtr(), targetCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef((float4*)mBufDesc.pmaVelocityLife->getGpuPtr(), targetCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef((float4*)mBufDesc.pmaCollisionNormalFlags->getGpuPtr(), targetCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mBufDesc.pmaUserData->getGpuPtr(), targetCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mLifeSpan, targetCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mLifeTime, targetCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mInjector, targetCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(*(mBufDesc.pmaActorIdentifiers), targetCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mBenefit, targetCount, ApexCudaMemFlags::OUT), + mSimulationStorageGroup.getStorage().mappedHandle(mSimulationParamsHandle) + ); + } + else + { + histogramGridSize = CUDA_OBJ(simulateKernel)(stream, targetCount, + lastCount, deltaTime, gravity, eyePos, + sceneGPU->mInjectorConstMemGroup.getStorage().mappedHandle(sceneGPU->mInjectorParamsArrayHandle), mInjectorsCounters.getSize(), + mHoleScanSum.getGpuPtr(), mTmpScan.getGpuPtr(), mTmpHistogram.getGpuPtr(), mInjectorsCounters.getGpuPtr(), + (float4*)mBufDesc.pmaPositionMass->getGpuPtr(), + (float4*)mBufDesc.pmaVelocityLife->getGpuPtr(), + (float4*)mBufDesc.pmaCollisionNormalFlags->getGpuPtr(), + mBufDesc.pmaUserData->getGpuPtr(), + mLifeSpan.getGpuPtr(), mLifeTime.getGpuPtr(), mInjector.getGpuPtr(), mBufDesc.pmaActorIdentifiers->getGpuPtr(), + mBenefit.getGpuPtr(), mSimulationStorageGroup.getStorage().mappedHandle(mSimulationParamsHandle) + ); + } + } + //new kernel invocation - to merge temp histograms + { + if(mInjectorsCounters.getSize() <= HISTOGRAM_SIMULATE_BIN_COUNT) + { + CUDA_OBJ(mergeHistogramKernel)(stream, APEX_CUDA_SINGLE_BLOCK_LAUNCH, + createApexCudaMemRef(mInjectorsCounters, mInjectorsCounters.getSize(), ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpHistogram, ApexCudaMemFlags::IN), + histogramGridSize, + mInjectorsCounters.getSize() + ); + } + + } + // calculate grid grid density + if (mGridDensityParams.Enabled) + { + mGridDensityParams.DensityOrigin = mDensityOrigin; + const unsigned int dim = mGridDensityParams.GridResolution; + // refreshed non-shared params + { + BasicIOSAssetParam* gridParams = (BasicIOSAssetParam*)(mAsset->getAssetNvParameterized()); + mGridDensityParams.GridSize = gridParams->GridDensity.GridSize; + mGridDensityParams.GridMaxCellCount = gridParams->GridDensity.MaxCellCount; + } + // extract frustum + if (mBasicIosScene->getApexScene().getNumProjMatrices() > 0) + { + PxMat44 matDen = PxMat44(PxIdentity); + GridDensityFrustumParams frustum; + PxMat44 matModel = mBasicIosScene->getApexScene().getViewMatrix(); + PxMat44 matProj = mBasicIosScene->getApexScene().getProjMatrix(); + PxMat44 mat = matProj*matModel; + PxMat44 matInv = inverse(mat); + const float targetDepth = mGridDensityParams.GridSize; + // for debug vis + mDensityDebugMatInv = matInv; + // to calculate w transform + float nearDimX = distance(matInv.transform(PxVec4(-1.f,0.f,0.f,1.f)),matInv.transform(PxVec4(1.f,0.f,0.f,1.f))); + float farDimX = distance(matInv.transform(PxVec4(-1.f,0.f,1.f,1.f)),matInv.transform(PxVec4(1.f,0.f,1.f,1.f))); + float nearDimY = distance(matInv.transform(PxVec4(0.f,-1.f,0.f,1.f)),matInv.transform(PxVec4(0.f,1.f,0.f,1.f))); + float farDimY = distance(matInv.transform(PxVec4(0.f,-1.f,1.f,1.f)),matInv.transform(PxVec4(0.f,1.f,1.f,1.f))); + float dimZ = distance(matInv.transform(PxVec4(0.f, 0.f,0.f,1.f)),matInv.transform(PxVec4(0.f,0.f,1.f,1.f))); + float myFarDimX = nearDimX*(1.f-targetDepth/dimZ) + farDimX*(targetDepth/dimZ); + float myFarDimY = nearDimY*(1.f-targetDepth/dimZ) + farDimY*(targetDepth/dimZ); + // grab necessary frustum coordinates + PxVec4 origin4 = matInv.transform(PxVec4(-1.f, 1.f,0.f,1.f)); + PxVec4 basisX4 = matInv.transform(PxVec4( 1.f, 1.f,0.f,1.f)); + PxVec4 basisY4 = matInv.transform(PxVec4(-1.f,-1.f,0.f,1.f)); + PxVec4 zDepth4 = matInv.transform(PxVec4(-1.f, 1.f,1.f,1.f)); + // create vec3 versions + PxVec3 origin3(origin4.x/origin4.w,origin4.y/origin4.w,origin4.z/origin4.w); + PxVec3 basisX3(basisX4.x/basisX4.w,basisX4.y/basisX4.w,basisX4.z/basisX4.w); + PxVec3 basisY3(basisY4.x/basisY4.w,basisY4.y/basisY4.w,basisY4.z/basisY4.w); + PxVec3 zDepth3(zDepth4.x/zDepth4.w,zDepth4.y/zDepth4.w,zDepth4.z/zDepth4.w); + // make everthing relative to origin + basisX3 -= origin3; + basisY3 -= origin3; + zDepth3 -= origin3; + // find third basis + PxVec3 basisZ3(basisX3.cross(basisY3)); + basisZ3.normalize(); + basisZ3*= targetDepth; + // see how skewed the eye point is + PxVec3 eye; + { + // find the eye point + PxVec4 a4 = matInv.transform(PxVec4(1.f,1.f,0.00f,1.f)); + PxVec4 b4 = matInv.transform(PxVec4(1.f,1.f,0.01f,1.f)); + PxVec4 c4 = matInv.transform(PxVec4(-1.f,-1.f,0.00f,1.f)); + PxVec4 d4 = matInv.transform(PxVec4(-1.f,-1.f,0.01f,1.f)); + PxVec3 a3 = a4.getXYZ()/a4.w; + PxVec3 b3 = b4.getXYZ()/b4.w; + PxVec3 c3 = c4.getXYZ()/c4.w; + PxVec3 d3 = d4.getXYZ()/d4.w; + PxVec3 a = b3-a3; + PxVec3 b = d3-c3; + PxVec3 c = a.cross(b); + PxVec3 d = a3-c3; + PxMat33 m(a,b,c); + PxMat33 mInv = m.getInverse(); + PxVec3 coord = mInv.transform(d); + eye = c3 + (d3-c3)*coord.y; + } + // build scale,rotation,translation matrix + PxMat44 mat1Inv = PxMat44(PxIdentity); + mat1Inv.column0 = PxVec4(basisX3,0.f); + mat1Inv.column1 = PxVec4(basisY3,0.f); + mat1Inv.column2 = PxVec4(basisZ3,0.f); + mat1Inv.column3 = PxVec4(origin3,1.f); + PxMat44 mat1 = inverse(mat1Inv); + PxVec3 eyeOffset = mat1.transform(eye); + // do perspective transform + PxMat44 mat2 = PxMat44(PxIdentity); + { + float xshift = -2.f*(eyeOffset.x-0.5f); + float yshift = -2.f*(eyeOffset.y-0.5f); + float left = -3.0f + xshift; + float right = 1.0f + xshift; + float top = 1.0f + yshift; + float bottom = -3.0f + yshift; + float nearVal = nearDimX/(0.5f*(myFarDimX-nearDimX)); + //float farVal = nearVal + 1.f; + // build matrix + mat2.column0.x = -2.f*nearVal/(right-left); + mat2.column1.y = -2.f*nearVal/(top-bottom); + mat2.column2.x = (right+left)/(right-left); + mat2.column2.y = (top+bottom)/(top-bottom); + //mat2.column2.z = -(farVal+nearVal)/(farVal-nearVal); + mat2.column2.w = -1.f; + //mat2.column3.z = -(2.f*farVal*nearVal)/(farVal-nearVal); + mat2.column3.w = 0.f; + } + // shrink to calculate density just outside of frustum + PxMat44 mat3 = PxMat44(PxIdentity); + float factor = PxMin((float)(mGridDensityParams.GridResolution-4) / (mGridDensityParams.GridResolution),0.75f); + { + mat3.column0.x = factor; + mat3.column1.y = factor; + mat3.column2.z = factor; + mat3.column3.x = (1.0f-factor)/2.0f; + mat3.column3.y = (1.0f-factor)/2.0f; + mat3.column3.z = (1.0f-factor)/2.0f; + } + // create final matrix + matDen = mat3*mat2*mat1; + // create frustum info + frustum.nearDimX = factor*nearDimX; + frustum.farDimX = factor*myFarDimX; + frustum.nearDimY = factor*nearDimY; + frustum.farDimY = factor*myFarDimY; + frustum.dimZ = factor*targetDepth; + // launch frustum kernels + CUDA_OBJ(gridDensityGridClearKernel)(stream, dim*dim*dim, + mGridDensityGrid.getGpuPtr(), + mGridDensityParams + ); + CUDA_OBJ(gridDensityGridFillFrustumKernel)(stream, targetCount, + (float4*)mBufDesc.pmaPositionMass->getGpuPtr(), + mGridDensityGrid.getGpuPtr(), + mGridDensityParams, + matDen, + frustum + ); + CUDA_OBJ(gridDensityGridLowPassKernel)(stream, dim*dim*dim, + mGridDensityGrid.getGpuPtr(), + mGridDensityGridLowPass.getGpuPtr(), + mGridDensityParams + ); + CUDA_OBJ(gridDensityGridApplyFrustumKernel)(stream, targetCount, + mBufDesc.pmaDensity != NULL ? (float*)mBufDesc.pmaDensity->getGpuPtr() : NULL, + (float4*)mBufDesc.pmaPositionMass->getGpuPtr(), + mGridDensityGridLowPass.getGpuPtr(), + mGridDensityParams, + matDen, + frustum + ); + } + } + } + return true; + + case 5: + if (targetCount > 0) + { + if (useSyncKernels) + { + CUDA_OBJ(reduceSyncKernel)( + stream, targetCount, + mBenefit.getGpuPtr(), (float4*)mTmpOutput.getGpuPtr(), mTmpReduce.getGpuPtr() + ); + } + else + { + uint32_t reduceGridSize = + CUDA_OBJ(reduceKernel)( + stream, targetCount, + createApexCudaMemRef(mBenefit, targetCount, ApexCudaMemFlags::IN), + createApexCudaMemRef((float4*)mTmpOutput.getGpuPtr(), 1, ApexCudaMemFlags::IN), + createApexCudaMemRef(mTmpReduce, ApexCudaMemFlags::OUT), + 1, 0 + ); + + //launch just 1 block + CUDA_OBJ(reduceKernel)( + stream, APEX_CUDA_SINGLE_BLOCK_LAUNCH, + createApexCudaMemRef(mBenefit, targetCount, ApexCudaMemFlags::IN), + createApexCudaMemRef((float4*)mTmpOutput.getGpuPtr(), 1, ApexCudaMemFlags::OUT), + createApexCudaMemRef(mTmpReduce, ApexCudaMemFlags::IN), + 2, reduceGridSize + ); + } + } + return true; + + case 6: + if (totalCount > 0) + { + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefHoleScanSum, mHoleScanSum); + APEX_CUDA_TEXTURE_SCOPE_BIND(texRefMoveIndices, mMoveIndices); + + CUDA_OBJ(stateKernel)(stream, totalCount, + lastCount, targetCount, + createApexCudaMemRef(mTmpScan, 1, ApexCudaMemFlags::IN), + createApexCudaMemRef(*mBufDesc.pmaInStateToInput, totalCount, ApexCudaMemFlags::OUT), + createApexCudaMemRef(*mBufDesc.pmaOutStateToInput, lastCount, ApexCudaMemFlags::IN) + ); + + } + return true; + + case 7: + mTmpOutput.copyDeviceToHostQ(mCopyQueue); + mInjectorsCounters.copyDeviceToHostQ(mCopyQueue); + + if (mTmpScan.cpuPtrIsValid()) + { + mTmpOutput1.copyDeviceToHostQ(mCopyQueue); + mTmpScan.copyDeviceToHostQ(mCopyQueue, 1); + mHoleScanSum.copyDeviceToHostQ(mCopyQueue, totalCount); + mMoveIndices.copyDeviceToHostQ(mCopyQueue, totalCount); + mTmpHistogram.copyDeviceToHostQ(mCopyQueue, HISTOGRAM_BIN_COUNT); + mBenefit.copyDeviceToHostQ(mCopyQueue, totalCount); + mBufDesc.pmaInStateToInput->copyDeviceToHostQ(mCopyQueue, totalCount); + mBufDesc.pmaPositionMass->copyDeviceToHostQ(mCopyQueue, targetCount); + } + mCopyQueue.flushEnqueued(); + + /* Oh! Manager of the IOFX! do your thing */ + mIofxMgr->updateEffectsData(deltaTime, targetCount, targetCount, totalCount, stream); + return false; + } + return false; +} + +void BasicIosActorGPU::fetchResults() +{ + BASIC_IOS_ACTOR::fetchResults(); + + uint32_t totalCount = mParticleCount + mInjectedCount; + checkBenefit(totalCount); + checkHoles(totalCount); + checkInState(totalCount); + /*checkHistogram(PxMax<int32_t>(mLastActiveCount + mInjectedCount - mParticleBudget, 0), mTmpHistogram[ mTmpOutput1[1] ], mTmpHistogram[ HISTOGRAM_BIN_COUNT - 1 ]);*/ + //this can be done only after TaskLaunchAfterLod is finished!!! + + mParticleCount = mParticleBudget; + + float* pTmpOutput = (float*)mTmpOutput.getPtr(); + mLastActiveCount = mTmpOutput[STATUS_LAST_ACTIVE_COUNT]; + mLastBenefitSum = pTmpOutput[STATUS_LAST_BENEFIT_SUM]; + mLastBenefitMin = pTmpOutput[STATUS_LAST_BENEFIT_MIN]; + mLastBenefitMax = pTmpOutput[STATUS_LAST_BENEFIT_MAX]; +} + + +PxMat44 BasicIosActorGPU::inverse(const PxMat44& in) +{ + PxMat44 ret; + float inv[16]; + float* invOut = &ret.column0.x; + const float* m = &in.column0.x; + int i; + + inv[0] = m[5] * m[10] * m[15] - + m[5] * m[11] * m[14] - + m[9] * m[6] * m[15] + + m[9] * m[7] * m[14] + + m[13] * m[6] * m[11] - + m[13] * m[7] * m[10]; + + inv[4] = -m[4] * m[10] * m[15] + + m[4] * m[11] * m[14] + + m[8] * m[6] * m[15] - + m[8] * m[7] * m[14] - + m[12] * m[6] * m[11] + + m[12] * m[7] * m[10]; + + inv[8] = m[4] * m[9] * m[15] - + m[4] * m[11] * m[13] - + m[8] * m[5] * m[15] + + m[8] * m[7] * m[13] + + m[12] * m[5] * m[11] - + m[12] * m[7] * m[9]; + + inv[12] = -m[4] * m[9] * m[14] + + m[4] * m[10] * m[13] + + m[8] * m[5] * m[14] - + m[8] * m[6] * m[13] - + m[12] * m[5] * m[10] + + m[12] * m[6] * m[9]; + + inv[1] = -m[1] * m[10] * m[15] + + m[1] * m[11] * m[14] + + m[9] * m[2] * m[15] - + m[9] * m[3] * m[14] - + m[13] * m[2] * m[11] + + m[13] * m[3] * m[10]; + + inv[5] = m[0] * m[10] * m[15] - + m[0] * m[11] * m[14] - + m[8] * m[2] * m[15] + + m[8] * m[3] * m[14] + + m[12] * m[2] * m[11] - + m[12] * m[3] * m[10]; + + inv[9] = -m[0] * m[9] * m[15] + + m[0] * m[11] * m[13] + + m[8] * m[1] * m[15] - + m[8] * m[3] * m[13] - + m[12] * m[1] * m[11] + + m[12] * m[3] * m[9]; + + inv[13] = m[0] * m[9] * m[14] - + m[0] * m[10] * m[13] - + m[8] * m[1] * m[14] + + m[8] * m[2] * m[13] + + m[12] * m[1] * m[10] - + m[12] * m[2] * m[9]; + + inv[2] = m[1] * m[6] * m[15] - + m[1] * m[7] * m[14] - + m[5] * m[2] * m[15] + + m[5] * m[3] * m[14] + + m[13] * m[2] * m[7] - + m[13] * m[3] * m[6]; + + inv[6] = -m[0] * m[6] * m[15] + + m[0] * m[7] * m[14] + + m[4] * m[2] * m[15] - + m[4] * m[3] * m[14] - + m[12] * m[2] * m[7] + + m[12] * m[3] * m[6]; + + inv[10] = m[0] * m[5] * m[15] - + m[0] * m[7] * m[13] - + m[4] * m[1] * m[15] + + m[4] * m[3] * m[13] + + m[12] * m[1] * m[7] - + m[12] * m[3] * m[5]; + + inv[14] = -m[0] * m[5] * m[14] + + m[0] * m[6] * m[13] + + m[4] * m[1] * m[14] - + m[4] * m[2] * m[13] - + m[12] * m[1] * m[6] + + m[12] * m[2] * m[5]; + + inv[3] = -m[1] * m[6] * m[11] + + m[1] * m[7] * m[10] + + m[5] * m[2] * m[11] - + m[5] * m[3] * m[10] - + m[9] * m[2] * m[7] + + m[9] * m[3] * m[6]; + + inv[7] = m[0] * m[6] * m[11] - + m[0] * m[7] * m[10] - + m[4] * m[2] * m[11] + + m[4] * m[3] * m[10] + + m[8] * m[2] * m[7] - + m[8] * m[3] * m[6]; + + inv[11] = -m[0] * m[5] * m[11] + + m[0] * m[7] * m[9] + + m[4] * m[1] * m[11] - + m[4] * m[3] * m[9] - + m[8] * m[1] * m[7] + + m[8] * m[3] * m[5]; + + inv[15] = m[0] * m[5] * m[10] - + m[0] * m[6] * m[9] - + m[4] * m[1] * m[10] + + m[4] * m[2] * m[9] + + m[8] * m[1] * m[6] - + m[8] * m[2] * m[5]; + + float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12]; + + if (det == 0) + return PxMat44(PxIdentity); + + det = 1.0f / det; + + for (i = 0; i < 16; i++) + invOut[i] = inv[i] * det; + + return ret; +} + +float BasicIosActorGPU::distance(PxVec4 a, PxVec4 b) +{ + PxVec3 a3(a.x/a.w,a.y/a.w,a.z/a.w); + PxVec3 b3(b.x/b.w,b.y/b.w,b.z/b.w); + PxVec3 diff(b3-a3); + return diff.magnitude(); +} + +} +} // namespace nvidia + +#endif //APEX_CUDA_SUPPORT diff --git a/APEX_1.4/module/basicios/src/BasicIosActorImpl.cpp b/APEX_1.4/module/basicios/src/BasicIosActorImpl.cpp new file mode 100644 index 00000000..5bb6ecd4 --- /dev/null +++ b/APEX_1.4/module/basicios/src/BasicIosActorImpl.cpp @@ -0,0 +1,1221 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#include "Apex.h" +#include "SceneIntl.h" +#include "ApexSDKIntl.h" +#include "ScopedPhysXLock.h" + +#include "BasicIosActor.h" +#include "BasicIosActorImpl.h" +#include "BasicIosAssetImpl.h" +#include "IofxAsset.h" +#include "IofxActor.h" +#include "ModuleBasicIosImpl.h" +#include "BasicIosScene.h" +#include "RenderDebugInterface.h" +#include "AuthorableObjectIntl.h" +#include "ModuleIofxIntl.h" +#include "FieldSamplerManagerIntl.h" +#include "FieldSamplerQueryIntl.h" +#include "ApexMirroredArray.h" +#include "ApexResourceHelper.h" +#include "PsAsciiConversion.h" + +#include "PxTask.h" + +#include <PxScene.h> +#include <PxConvexMesh.h> + +#include <PxShape.h> +#include <geometry/PxBoxGeometry.h> +#include <geometry/PxSphereGeometry.h> +#include <geometry/PxCapsuleGeometry.h> +#include <geometry/PxPlaneGeometry.h> +#include <geometry/PxTriangleMeshGeometry.h> +#include <geometry/PxTriangleMesh.h> + +#include <PxMaterial.h> + +#include <PxRigidActor.h> +#include <PxRigidBody.h> +#include <extensions/PxShapeExt.h> + +#include <PsAsciiConversion.h> + +#include "Lock.h" + +namespace nvidia +{ + namespace basicios + { + using namespace physx; + + class BasicIosInjectTask : public PxTask, public UserAllocated + { + public: + BasicIosInjectTask(BasicIosActorImpl* actor) : mActor(actor) {} + + const char* getName() const + { + return "BasicIosActorImpl::InjectTask"; + } + void run() + { + mActor->injectNewParticles(); + } + + protected: + BasicIosActorImpl* mActor; + }; + + void BasicIosActorImpl::initStorageGroups(InplaceStorage& storage) + { + mSimulationStorageGroup.init(storage); + } + + BasicIosActorImpl::BasicIosActorImpl( + ResourceList& list, + BasicIosAssetImpl& asset, + BasicIosScene& scene, + nvidia::apex::IofxAsset& iofxAsset, + bool isDataOnDevice) + : mAsset(&asset) + , mBasicIosScene(&scene) + , mIofxMgr(NULL) + , mTotalElapsedTime(0.0f) + , mParticleCount(0) + , mParticleBudget(UINT_MAX) + , mInjectedCount(0) + , mLastActiveCount(0) + , mLastBenefitSum(0) + , mLastBenefitMin(+FLT_MAX) + , mLastBenefitMax(-FLT_MAX) + , mLifeSpan(scene.getApexScene(), PX_ALLOC_INFO("mLifeSpan", PARTICLES)) + , mLifeTime(scene.getApexScene(), PX_ALLOC_INFO("mLifeTime", PARTICLES)) + , mInjector(scene.getApexScene(), PX_ALLOC_INFO("mInjector", PARTICLES)) + , mBenefit(scene.getApexScene(), PX_ALLOC_INFO("mBenefit", PARTICLES)) + , mConvexPlanes(scene.getApexScene(), PX_ALLOC_INFO("mConvexPlanes", PARTICLES)) + , mConvexVerts(scene.getApexScene(), PX_ALLOC_INFO("mConvexVerts", PARTICLES)) + , mConvexPolygonsData(scene.getApexScene(), PX_ALLOC_INFO("mConvexPolygonsData", PARTICLES)) + , mTrimeshVerts(scene.getApexScene(), PX_ALLOC_INFO("mTrimeshVerts", PARTICLES)) + , mTrimeshIndices(scene.getApexScene(), PX_ALLOC_INFO("mTrimeshIndices", PARTICLES)) + , mInjectorsCounters(scene.getApexScene(), PX_ALLOC_INFO("mInjectorsCounters", PARTICLES)) + , mGridDensityGrid(scene.getApexScene(), PX_ALLOC_INFO("mGridDensityGrid", PARTICLES)) + , mGridDensityGridLowPass(scene.getApexScene(), PX_ALLOC_INFO("mGridDensityGridLowPass", PARTICLES)) + , mFieldSamplerQuery(NULL) + , mField(scene.getApexScene(), PX_ALLOC_INFO("mField", PARTICLES)) + , mDensityOrigin(0.f,0.f,0.f) + , mOnStartCallback(NULL) + , mOnFinishCallback(NULL) + { + list.add(*this); + + mMaxParticleCount = mAsset->mParams->maxParticleCount; + mParticleBudget = mMaxParticleCount; + float maxInjectCount = mAsset->mParams->maxInjectedParticleCount; + mMaxTotalParticleCount = mMaxParticleCount + uint32_t(maxInjectCount <= 1.0f ? mMaxParticleCount * maxInjectCount : maxInjectCount); + + + IofxManagerDescIntl desc; + desc.iosAssetName = mAsset->getName(); + desc.iosSupportsDensity = mAsset->getSupportsDensity(); + desc.iosSupportsCollision = true; + desc.iosSupportsUserData = true; + desc.iosOutputsOnDevice = isDataOnDevice; + desc.maxObjectCount = mMaxParticleCount; + desc.maxInputCount = mMaxTotalParticleCount; + desc.maxInStateCount = mMaxTotalParticleCount; + + ModuleIofxIntl* moduleIofx = mAsset->mModule->getInternalModuleIofx(); + if (moduleIofx) + { + mIofxMgr = moduleIofx->createActorManager(*mBasicIosScene->mApexScene, iofxAsset, desc); + mIofxMgr->createSimulationBuffers(mBufDesc); + } + + mCollisionFilterData = ApexResourceHelper::resolveCollisionGroup128(mAsset->mParams->fieldSamplerFilterDataName); + + FieldSamplerManagerIntl* fieldSamplerManager = mBasicIosScene->getInternalFieldSamplerManager(); + if (fieldSamplerManager) + { + FieldSamplerQueryDescIntl queryDesc; + queryDesc.maxCount = mMaxParticleCount; + queryDesc.samplerFilterData = ApexResourceHelper::resolveCollisionGroup128(mAsset->mParams->fieldSamplerFilterDataName); + + mFieldSamplerQuery = fieldSamplerManager->createFieldSamplerQuery(queryDesc); + + if (isDataOnDevice) + { +#if APEX_CUDA_SUPPORT + mField.reserve(mMaxParticleCount, ApexMirroredPlace::GPU); +#endif + } + else + { + mField.reserve(mMaxParticleCount, ApexMirroredPlace::CPU); + } + } + + mInjectTask = PX_NEW(BasicIosInjectTask)(this); + + // Pull Grid Density Parameters + { + if(mBufDesc.pmaDensity) + { + BasicIOSAssetParam* gridParams = (BasicIOSAssetParam*)(mAsset->getAssetNvParameterized()); + mGridDensityParams.Enabled = gridParams->GridDensity.Enabled; + mGridDensityParams.GridSize = gridParams->GridDensity.GridSize; + mGridDensityParams.GridMaxCellCount = gridParams->GridDensity.MaxCellCount; + mGridDensityParams.GridResolution = general_string_parsing2::PxAsc::strToU32(&gridParams->GridDensity.Resolution[4],NULL); + mGridDensityParams.DensityOrigin = mDensityOrigin; + } + else + { + mGridDensityParams.Enabled = false; + mGridDensityParams.GridSize = 1.f; + mGridDensityParams.GridMaxCellCount = 1u; + mGridDensityParams.GridResolution = 8; + mGridDensityParams.DensityOrigin = mDensityOrigin; + } + } + + addSelfToContext(*scene.mApexScene->getApexContext()); // add self to Scene + addSelfToContext(*DYNAMIC_CAST(ApexContext*)(&scene)); // add self to BasicIosScene + } + + BasicIosActorImpl::~BasicIosActorImpl() + { + PX_DELETE(mInjectTask); + } + + void BasicIosActorImpl::release() + { + if (mInRelease) + { + return; + } + mInRelease = true; + mAsset->releaseIosActor(*this); + } + + void BasicIosActorImpl::destroy() + { + ApexActor::destroy(); + + setPhysXScene(NULL); + + // remove ourself from our asset's resource list, in case releasing our emitters + // causes our asset's resource count to reach zero and for it to be released. + ApexResource::removeSelf(); + + // Release all injectors, releasing all emitters and their IOFX asset references + while (mInjectorList.getSize()) + { + BasicParticleInjector* inj = DYNAMIC_CAST(BasicParticleInjector*)(mInjectorList.getResource(mInjectorList.getSize() - 1)); + inj->release(); + } + + if (mIofxMgr) + { + mIofxMgr->release(); + } + if (mFieldSamplerQuery) + { + mFieldSamplerQuery->release(); + } + + delete this; + } + + void BasicIosActorImpl::setPhysXScene(PxScene* scene) + { + if (scene) + { + putInScene(scene); + } + else + { + removeFromScene(); + } + } + PxScene* BasicIosActorImpl::getPhysXScene() const + { + return NULL; + } + void BasicIosActorImpl::putInScene(PxScene* scene) + { + SCOPED_PHYSX_LOCK_READ(scene); + PxVec3 gravity = scene->getGravity(); + setGravity(gravity); + } + + void BasicIosActorImpl::getLodRange(float& min, float& max, bool& intOnly) const + { + PX_UNUSED(min); + PX_UNUSED(max); + PX_UNUSED(intOnly); + APEX_INVALID_OPERATION("not implemented"); + } + + + float BasicIosActorImpl::getActiveLod() const + { + APEX_INVALID_OPERATION("BasicIosActor does not support this operation"); + return -1.0f; + } + + + void BasicIosActorImpl::forceLod(float lod) + { + PX_UNUSED(lod); + APEX_INVALID_OPERATION("not implemented"); + } + + + void BasicIosActorImpl::removeFromScene() + { + mParticleCount = 0; + } + + + const PxVec3* BasicIosActorImpl::getRecentPositions(uint32_t& count, uint32_t& stride) const + { + APEX_INVALID_OPERATION("not implemented"); + + count = 0; + stride = 0; + return NULL; + } + + PxVec3 BasicIosActorImpl::getGravity() const + { + return mGravityVec; + } + + void BasicIosActorImpl::setGravity(PxVec3& gravity) + { + mGravityVec = gravity; + mUp = mGravityVec; + + // apply asset's scene gravity scale and external acceleration + mUp *= mAsset->getSceneGravityScale(); + mUp += mAsset->getExternalAcceleration(); + + mGravity = mUp.magnitude(); + if (!PxIsFinite(mGravity)) + { + // and they could set both to 0,0,0 + mUp = PxVec3(0.0f, -1.0f, 0.0f); + mGravity = 1.0f; + } + mUp *= -1.0f; + + mIofxMgr->setSimulationParameters(getObjectRadius(), mUp, mGravity, getObjectDensity()); + } + + IosInjectorIntl* BasicIosActorImpl::allocateInjector(IofxAsset* iofxAsset) + { + BasicParticleInjector* inj = 0; + //createInjector + { + uint32_t injectorID = mBasicIosScene->getInjectorAllocator().allocateInjectorID(); + if (injectorID != BasicIosInjectorAllocator::NULL_INJECTOR_INDEX) + { + inj = PX_NEW(BasicParticleInjector)(mInjectorList, *this, injectorID); + } + } + if (inj == 0) + { + APEX_INTERNAL_ERROR("Failed to create new BasicIos injector."); + return NULL; + } + + inj->init(iofxAsset); + return inj; + } + + void BasicIosActorImpl::releaseInjector(IosInjectorIntl& injector) + { + BasicParticleInjector* inj = DYNAMIC_CAST(BasicParticleInjector*)(&injector); + + //destroyInjector + { + //set mLODBias to FLT_MAX to mark released injector + //all particles from released injectors will be removed in simulation + InjectorParams injParams; + mBasicIosScene->fetchInjectorParams(inj->mInjectorID, injParams); + injParams.mLODBias = FLT_MAX; + mBasicIosScene->updateInjectorParams(inj->mInjectorID, injParams); + + mBasicIosScene->getInjectorAllocator().releaseInjectorID(inj->mInjectorID); + inj->destroy(); + } + + if (mInjectorList.getSize() == 0) + { + //if we have no injectors - release self + release(); + } + } + + + void BasicIosActorImpl::visualize() + { + if ( !mEnableDebugVisualization ) return; +#ifndef WITHOUT_DEBUG_VISUALIZE + RenderDebugInterface* renderer = mBasicIosScene->mDebugRender; + const physx::PxMat44& savedPose = *RENDER_DEBUG_IFACE(renderer)->getPoseTyped(); + RENDER_DEBUG_IFACE(renderer)->setIdentityPose(); + if(mBasicIosScene->mBasicIosDebugRenderParams->VISUALIZE_BASIC_IOS_GRID_DENSITY) + { + if(mGridDensityParams.Enabled) + { + RENDER_DEBUG_IFACE(renderer)->setCurrentColor(0x0000ff); + float factor = PxMin((float)(mGridDensityParams.GridResolution-4) / (mGridDensityParams.GridResolution),0.75f); + uint32_t onScreenRes = (uint32_t)(factor*mGridDensityParams.GridResolution); + for (uint32_t i = 0 ; i <= onScreenRes; i++) + { + float u = 2.f*((float)i/(onScreenRes))-1.f; + PxVec4 a = mDensityDebugMatInv.transform(PxVec4(u,-1.f,0.1f,1.f)); + PxVec4 b = mDensityDebugMatInv.transform(PxVec4(u, 1.f,0.1f,1.f)); + PxVec4 c = mDensityDebugMatInv.transform(PxVec4(-1.f,u,0.1f,1.f)); + PxVec4 d = mDensityDebugMatInv.transform(PxVec4( 1.f,u,0.1f,1.f)); + RENDER_DEBUG_IFACE(renderer)->debugLine(PxVec3(a.getXYZ()/a.w), PxVec3(b.getXYZ()/b.w)); + RENDER_DEBUG_IFACE(renderer)->debugLine(PxVec3(c.getXYZ()/c.w), PxVec3(d.getXYZ()/d.w)); + } + } + } + if(mBasicIosScene->mBasicIosDebugRenderParams->VISUALIZE_BASIC_IOS_COLLIDE_SHAPES) + { + INPLACE_STORAGE_GROUP_SCOPE(mSimulationStorageGroup); + SimulationParams simParams; + mSimulationParamsHandle.fetch(_storage_, simParams); + + RenderDebugInterface* renderer = mBasicIosScene->mDebugRender; + RENDER_DEBUG_IFACE(renderer)->setCurrentColor(RENDER_DEBUG_IFACE(renderer)->getDebugColor(RENDER_DEBUG::DebugColors::Blue)); + + for(uint32_t i = 0; i < (uint32_t)simParams.boxes.getSize(); ++i) + { + CollisionBoxData boxData; + simParams.boxes.fetchElem(_storage_, boxData, i); + + const PxTransform& pose = boxData.pose; + PxVec3 position = pose.p; + PxVec3 halfSize = boxData.halfSize; + RENDER_DEBUG_IFACE(renderer)->setPose(pose); + RENDER_DEBUG_IFACE(renderer)->debugBound(PxBounds3(-halfSize, halfSize)); + } + + for(uint32_t i = 0; i < (uint32_t)simParams.spheres.getSize(); ++i) + { + CollisionSphereData sphereData; + simParams.spheres.fetchElem(_storage_, sphereData, i); + + float r = sphereData.radius; + PxVec3 pos = sphereData.pose.p; + RENDER_DEBUG_IFACE(renderer)->debugSphere(pos, r); + } + + for(uint32_t i = 0; i < (uint32_t)simParams.capsules.getSize(); ++i) + { + CollisionCapsuleData capsuleData; + simParams.capsules.fetchElem(_storage_, capsuleData, i); + + float r = capsuleData.radius, h = capsuleData.halfHeight; + const PxTransform& pose = capsuleData.pose; + RENDER_DEBUG_IFACE(renderer)->setPose(pose); + RENDER_DEBUG_IFACE(renderer)->debugCapsule(r, 2 * h); + } + } + RENDER_DEBUG_IFACE(renderer)->setPose(savedPose); +#endif + } + + void BasicIosActorImpl::FillCollisionData(CollisionData& baseData, PxShape* shape) + { + PxTransform actorGlobalPose = shape->getActor()->getGlobalPose(); + + if (PxRigidBody* pxBody = shape->getActor()->is<physx::PxRigidBody>()) + { + baseData.bodyCMassPosition = actorGlobalPose.transform(pxBody->getCMassLocalPose().p); + baseData.bodyLinearVelocity = pxBody->getLinearVelocity(); + baseData.bodyAngluarVelocity = pxBody->getAngularVelocity(); + + baseData.materialRestitution = mAsset->mParams->restitutionForDynamicShapes; + } + else + { + baseData.bodyCMassPosition = actorGlobalPose.p; + baseData.bodyLinearVelocity = PxVec3(0, 0, 0); + baseData.bodyAngluarVelocity = PxVec3(0, 0, 0); + + baseData.materialRestitution = mAsset->mParams->restitutionForStaticShapes; + } + //PxMaterial* PxMaterial = shape->getMaterialFromInternalFaceIndex(0); + //PX_ASSERT(PxMaterial); + //baseData->materialRestitution = PxMaterial->getRestitution(); + } + + void BasicIosActorImpl::submitTasks() + { + PxTaskManager* tm = mBasicIosScene->getApexScene().getTaskManager(); + tm->submitUnnamedTask(*mInjectTask); + + //compile a list of actually colliding objects and process them to be used by the simulation + INPLACE_STORAGE_GROUP_SCOPE(mSimulationStorageGroup); + + SimulationParams simParams; + if (mSimulationParamsHandle.allocOrFetch(_storage_, simParams)) + { + //one time initialization on alloc + simParams.collisionThreshold = mAsset->mParams->collisionThreshold; + simParams.collisionDistance = mAsset->mParams->particleRadius * mAsset->mParams->collisionDistanceMultiplier; +#if APEX_CUDA_SUPPORT +#define GET_PTR(x) x.getGpuPtr() ? x.getGpuPtr() : x.getPtr() +#else +#define GET_PTR(x) x.getPtr() +#endif + simParams.convexPlanes = GET_PTR(mConvexPlanes); + simParams.convexVerts = GET_PTR(mConvexVerts); + simParams.convexPolygonsData = GET_PTR(mConvexPolygonsData); + + simParams.trimeshVerts = GET_PTR(mTrimeshVerts); + simParams.trimeshIndices = GET_PTR(mTrimeshIndices); + } + + uint32_t numBoxes = 0; + uint32_t numSpheres = 0; + uint32_t numCapsules = 0; + uint32_t numHalfSpaces = 0; + uint32_t numConvexMeshes = 0; + uint32_t numTriMeshes = 0; + + mConvexPlanes.setSize(0); + mConvexVerts.setSize(0); + mConvexPolygonsData.setSize(0); + + mTrimeshVerts.setSize(0); + mTrimeshIndices.setSize(0); + + const float collisionRadius = simParams.collisionThreshold + simParams.collisionDistance; + uint32_t numCollidingObjects = 0; + PxBounds3 bounds = mIofxMgr->getBounds(); + if ((mAsset->mParams->staticCollision || mAsset->mParams->dynamicCollision) && !bounds.isEmpty()) + { + PX_ASSERT(!bounds.isEmpty()); + bounds.fattenFast(collisionRadius); + + const uint32_t maxCollidingObjects = mAsset->mParams->maxCollidingObjects; + + mOverlapHits.resize(maxCollidingObjects); + PxBoxGeometry overlapGeom(bounds.getExtents()); + PxTransform overlapPose(bounds.getCenter()); + + PxQueryFilterData overlapFilterData; + overlapFilterData.data = mCollisionFilterData; + + overlapFilterData.flags = PxQueryFlag::eNO_BLOCK | PxQueryFlag::ePREFILTER; + if (mAsset->mParams->staticCollision) overlapFilterData.flags |= PxQueryFlag::eSTATIC; + if (mAsset->mParams->dynamicCollision) overlapFilterData.flags |= PxQueryFlag::eDYNAMIC; + + SCOPED_PHYSX_LOCK_READ(mBasicIosScene->getModulePhysXScene()); + + class OverlapFilter : public physx::PxQueryFilterCallback + { + public: + virtual PxQueryHitType::Enum preFilter( + const PxFilterData& filterData, const PxShape* shape, const PxRigidActor* actor, physx::PxHitFlags& queryFlags) + { + PX_UNUSED(queryFlags); + + const PxFilterData shapeFilterData = shape->getQueryFilterData(); + const physx::PxFilterObjectAttributes iosAttributes = PxFilterObjectType::ePARTICLE_SYSTEM; + physx::PxFilterObjectAttributes actorAttributes = actor->getType(); + if (const PxRigidBody* rigidBody = actor->is<physx::PxRigidBody>()) + { + if (rigidBody->getRigidBodyFlags() & PxRigidBodyFlag::eKINEMATIC) + { + actorAttributes |= PxFilterObjectFlag::eKINEMATIC; + } + } + + physx::PxPairFlags pairFlags; + physx::PxFilterFlags filterFlags = mFilterShader(iosAttributes, filterData, actorAttributes, shapeFilterData, pairFlags, mFilterShaderData, mFilterShaderDataSize); + return (filterFlags & (PxFilterFlag::eKILL | PxFilterFlag::eSUPPRESS)) ? PxQueryHitType::eNONE : PxQueryHitType::eTOUCH; + } + + virtual PxQueryHitType::Enum postFilter(const PxFilterData& filterData, const PxQueryHit& hit) + { + PX_UNUSED(filterData); + PX_UNUSED(hit); + return PxQueryHitType::eNONE; + } + + OverlapFilter(PxScene* scene) + { + mFilterShader = scene->getFilterShader(); + mFilterShaderData = scene->getFilterShaderData(); + mFilterShaderDataSize = scene->getFilterShaderDataSize(); + } + + private: + physx::PxSimulationFilterShader mFilterShader; + const void* mFilterShaderData; + uint32_t mFilterShaderDataSize; + + } overlapFilter(mBasicIosScene->getModulePhysXScene()); + + physx::PxOverlapBuffer ovBuffer(&mOverlapHits[0], mOverlapHits.size()); + mBasicIosScene->getModulePhysXScene()->overlap(overlapGeom, overlapPose, ovBuffer, overlapFilterData, &overlapFilter); + numCollidingObjects = ovBuffer.getNbTouches(); + + for (uint32_t iShape = 0; iShape < numCollidingObjects; iShape++) + { + PxShape* shape = mOverlapHits[iShape].shape; + + switch (shape->getGeometryType()) + { + case PxGeometryType::eBOX: + { + ++numBoxes; + } + break; + case PxGeometryType::eSPHERE: + { + ++numSpheres; + } + break; + case PxGeometryType::eCAPSULE: + { + ++numCapsules; + } + break; + case PxGeometryType::ePLANE: + { + ++numHalfSpaces; + } + break; + case PxGeometryType::eCONVEXMESH: + { + if (mAsset->mParams->collisionWithConvex) + { + ++numConvexMeshes; + } + } + break; + case PxGeometryType::eTRIANGLEMESH: + { + if (mAsset->mParams->collisionWithTriangleMesh) + { + ++numTriMeshes; + } + } + break; + default: + break; + } + } + } + + simParams.boxes.resize(_storage_ , numBoxes); + simParams.spheres.resize(_storage_ , numSpheres); + simParams.capsules.resize(_storage_ , numCapsules); + simParams.halfSpaces.resize(_storage_ , numHalfSpaces); + simParams.convexMeshes.resize(_storage_ , numConvexMeshes); + simParams.trimeshes.resize(_storage_ , numTriMeshes); + + numBoxes = 0; + numSpheres = 0; + numCapsules = 0; + numHalfSpaces = 0; + numConvexMeshes = 0; + numTriMeshes = 0; + + if (numCollidingObjects > 0) + { + SCOPED_PHYSX_LOCK_READ(mBasicIosScene->getModulePhysXScene()); + for (uint32_t iShape = 0; iShape < numCollidingObjects; iShape++) + { + PxShape* shape = mOverlapHits[iShape].shape; + PxRigidActor* actor = mOverlapHits[iShape].actor; + + PxBounds3 shapeWorldBounds = PxShapeExt::getWorldBounds(*shape, *actor); + PxTransform actorGlobalPose = shape->getActor()->getGlobalPose(); + PxTransform shapeGlobalPose = actorGlobalPose.transform(shape->getLocalPose()); + + PX_ASSERT(!shapeWorldBounds.isEmpty()); + shapeWorldBounds.fattenFast(collisionRadius); + + switch (shape->getGeometryType()) + { + case PxGeometryType::eBOX: + { + PxBoxGeometry boxGeom; + shape->getBoxGeometry(boxGeom); + + CollisionBoxData data; + + data.aabb = shapeWorldBounds; + data.pose = shapeGlobalPose; + data.inversePose = data.pose.getInverse(); + + data.halfSize = boxGeom.halfExtents; + + FillCollisionData(data, shape); + simParams.boxes.updateElem(_storage_, data, numBoxes++); + } + break; + case PxGeometryType::eSPHERE: + { + PxSphereGeometry sphereGeom; + shape->getSphereGeometry(sphereGeom); + + CollisionSphereData data; + + data.aabb = shapeWorldBounds; + data.pose = shapeGlobalPose; + data.inversePose = data.pose.getInverse(); + + data.radius = sphereGeom.radius; + //extend + data.radius += simParams.collisionDistance; + + FillCollisionData(data, shape); + simParams.spheres.updateElem(_storage_, data, numSpheres++); + } + break; + case PxGeometryType::eCAPSULE: + { + PxCapsuleGeometry capsuleGeom; + shape->getCapsuleGeometry(capsuleGeom); + + CollisionCapsuleData data; + + data.aabb = shapeWorldBounds; + data.pose = shapeGlobalPose; + data.inversePose = data.pose.getInverse(); + + data.halfHeight = capsuleGeom.halfHeight; + data.radius = capsuleGeom.radius; + //extend + data.radius += simParams.collisionDistance; + + FillCollisionData(data, shape); + simParams.capsules.updateElem(_storage_, data, numCapsules++); + } + break; + case PxGeometryType::ePLANE: + { + CollisionHalfSpaceData data; + + data.origin = shapeGlobalPose.p; + data.normal = shapeGlobalPose.rotate(PxVec3(1, 0, 0)); + //extend + data.origin += data.normal * simParams.collisionDistance; + + FillCollisionData(data, shape); + simParams.halfSpaces.updateElem(_storage_, data, numHalfSpaces++); + } + break; + case PxGeometryType::eCONVEXMESH: + { + if (mAsset->mParams->collisionWithConvex) + { + PxConvexMeshGeometry convexGeom; + shape->getConvexMeshGeometry(convexGeom); + + CollisionConvexMeshData data; + + data.aabb = shapeWorldBounds; + data.pose = shapeGlobalPose; + data.inversePose = data.pose.getInverse(); + + //get ConvexMesh + const PxConvexMesh* convexMesh = convexGeom.convexMesh; + + uint32_t numPolygons = convexMesh->getNbPolygons(); + uint32_t numVertices = convexMesh->getNbVertices(); + uint32_t polygonsDataSize = 0; + for (uint32_t i = 0; i < numPolygons; i++) + { + physx::PxHullPolygon polygon; + bool polygonDataTest = convexMesh->getPolygonData(i, polygon); + PX_UNUSED( polygonDataTest ); + PX_ASSERT( polygonDataTest ); + + polygonsDataSize += (1 + polygon.mNbVerts); + } + + if (mConvexPlanes.getSize() + numPolygons <= mConvexPlanes.getCapacity() && + mConvexVerts.getSize() + numVertices <= mConvexVerts.getCapacity() && + mConvexPolygonsData.getSize() + polygonsDataSize <= mConvexPolygonsData.getCapacity()) + { + data.numPolygons = numPolygons; + data.firstPlane = mConvexPlanes.getSize(); + data.firstVertex = mConvexVerts.getSize(); + data.polygonsDataOffset = mConvexPolygonsData.getSize(); + + PxPlane* convexPlanes = mConvexPlanes.getPtr() + data.firstPlane; + PxVec4* convexVerts = mConvexVerts.getPtr() + data.firstVertex; + uint32_t* convexPolygonsData = mConvexPolygonsData.getPtr() + data.polygonsDataOffset; + + mConvexPlanes.setSize(data.firstPlane + numPolygons); + mConvexVerts.setSize(data.firstVertex + numVertices); + mConvexPolygonsData.setSize(data.polygonsDataOffset + polygonsDataSize); + + const PxMeshScale convexScaleInv( convexGeom.scale.getInverse() ); + //copy Convex Planes & Polygon Data + const uint8_t* srcIndices = convexMesh->getIndexBuffer(); + for (uint32_t i = 0; i < numPolygons; i++) + { + physx::PxHullPolygon polygon; + bool polygonDataTest = convexMesh->getPolygonData(i, polygon); + PX_UNUSED( polygonDataTest ); + PX_ASSERT( polygonDataTest ); + PxPlane plane(polygon.mPlane[0], polygon.mPlane[1], polygon.mPlane[2], polygon.mPlane[3]); + plane.n = convexScaleInv.transform(plane.n); + plane.normalize(); + *convexPlanes++ = plane; + + const uint32_t polygonVertCount = polygon.mNbVerts; + const uint8_t* polygonIndices = srcIndices + polygon.mIndexBase; + + *convexPolygonsData++ = polygonVertCount; + for (uint32_t j = 0; j < polygonVertCount; ++j) + { + *convexPolygonsData++ = *polygonIndices++; + } + } + + //copy Convex Vertices + const PxVec3* srcVertices = convexMesh->getVertices(); + for (uint32_t i = 0; i < numVertices; i++) + { + *convexVerts++ = PxVec4(convexGeom.scale.transform(*srcVertices++), 0); + } + } + else + { + APEX_DEBUG_WARNING("BasicIosActorImpl: out of memory to store Convex data"); + + data.numPolygons = 0; + data.firstPlane = 0; + data.firstVertex = 0; + data.polygonsDataOffset = 0; + } + + FillCollisionData(data, shape); + simParams.convexMeshes.updateElem(_storage_, data, numConvexMeshes++); + } + break; + } + case PxGeometryType::eTRIANGLEMESH: + { + if (mAsset->mParams->collisionWithTriangleMesh) + { + PxTriangleMeshGeometry trimeshGeom; + shape->getTriangleMeshGeometry(trimeshGeom); + + CollisionTriMeshData data; + + data.aabb = shapeWorldBounds; + PX_ASSERT(!data.aabb.isEmpty()); + data.aabb.fattenFast( simParams.collisionDistance + simParams.collisionThreshold ); + data.pose = shapeGlobalPose; + data.inversePose = data.pose.getInverse(); + + //triangle mesh data + const PxTriangleMesh* trimesh = trimeshGeom.triangleMesh; + + const uint32_t numTrimeshIndices = trimesh->getNbTriangles() * 3; + const uint32_t numTrimeshVerts = trimesh->getNbVertices(); + + if (mTrimeshIndices.getSize() + numTrimeshIndices <= mTrimeshIndices.getCapacity() && + mTrimeshVerts.getSize() + numTrimeshVerts <= mTrimeshVerts.getCapacity()) + { + data.numTriangles = trimesh->getNbTriangles(); + data.firstIndex = mTrimeshIndices.getSize(); + data.firstVertex = mTrimeshVerts.getSize(); + + mTrimeshIndices.setSize(data.firstIndex + numTrimeshIndices); + //copy TriangleMesh indices + uint32_t* trimeshIndices = mTrimeshIndices.getPtr() + data.firstIndex; + + const bool has16BitIndices = (trimesh->getTriangleMeshFlags() & PxTriangleMeshFlag::e16_BIT_INDICES); + if (has16BitIndices) + { + const uint16_t* srcIndices = static_cast<const uint16_t*>(trimesh->getTriangles()); + for( uint32_t i = 0; i < numTrimeshIndices; i++) + { + trimeshIndices[i] = srcIndices[i]; + } + } + else + { + const uint32_t* srcIndices = static_cast<const uint32_t*>(trimesh->getTriangles()); + for( uint32_t i = 0; i < numTrimeshIndices; i++) + { + trimeshIndices[i] = srcIndices[i]; + } + } + + mTrimeshVerts.setSize(data.firstVertex + numTrimeshVerts); + //copy TriangleMesh vertices + PxVec4* trimeshVerts = mTrimeshVerts.getPtr() + data.firstVertex; + const PxVec3* srcVertices = trimesh->getVertices(); + for( uint32_t i = 0; i < numTrimeshVerts; i++) + { + trimeshVerts[i] = PxVec4(trimeshGeom.scale.transform(srcVertices[i]), 0); + } + } + else + { + APEX_DEBUG_WARNING("BasicIosActorImpl: out of memory to store TriangleMesh data"); + + data.numTriangles = 0; + data.firstIndex = 0; + data.firstVertex = 0; + } + + FillCollisionData(data, shape); + simParams.trimeshes.updateElem(_storage_, data, numTriMeshes++); + } + break; + } + default: + break; + } + + } + + } + mSimulationParamsHandle.update(_storage_, simParams); + } + + void BasicIosActorImpl::setTaskDependencies(PxTask* iosTask, bool isDataOnDevice) + { + PxTaskManager* tm = mBasicIosScene->getApexScene().getTaskManager(); + + iosTask->startAfter(mInjectTask->getTaskID()); + + if (mFieldSamplerQuery != NULL) + { + float deltaTime = mBasicIosScene->getApexScene().getPhysXSimulateTime(); + + FieldSamplerQueryDataIntl queryData; + queryData.timeStep = deltaTime; + queryData.count = mParticleCount; + queryData.isDataOnDevice = isDataOnDevice; + queryData.positionStrideBytes = sizeof(PxVec4); + queryData.velocityStrideBytes = sizeof(PxVec4); + queryData.massStrideBytes = sizeof(PxVec4); + queryData.pmaInIndices = 0; + if (isDataOnDevice) + { +#if APEX_CUDA_SUPPORT + queryData.pmaInPosition = (float*)mBufDesc.pmaPositionMass->getGpuPtr(); + queryData.pmaInVelocity = (float*)mBufDesc.pmaVelocityLife->getGpuPtr(); + queryData.pmaInMass = &mBufDesc.pmaPositionMass->getGpuPtr()->w; + queryData.pmaOutField = mField.getGpuPtr(); +#endif + } + else + { + queryData.pmaInPosition = (float*)mBufDesc.pmaPositionMass->getPtr(); + queryData.pmaInVelocity = (float*)mBufDesc.pmaVelocityLife->getPtr(); + queryData.pmaInMass = &mBufDesc.pmaPositionMass->getPtr()->w; + queryData.pmaOutField = mField.getPtr(); + } + mFieldSamplerQuery->submitFieldSamplerQuery(queryData, iosTask->getTaskID()); + } + + PxTaskID postIofxTaskID = tm->getNamedTask(AST_PHYSX_FETCH_RESULTS); + PxTaskID iofxTaskID = mIofxMgr->getUpdateEffectsTaskID(postIofxTaskID); + if (iofxTaskID == (PxTaskID)0xFFFFFFFF) + { + iofxTaskID = postIofxTaskID; + } + iosTask->finishBefore(iofxTaskID); + } + + void BasicIosActorImpl::fetchResults() + { + for(uint32_t i = 0; i < mInjectorList.getSize(); ++i) + { + BasicParticleInjector* inj = DYNAMIC_CAST(BasicParticleInjector*)(mInjectorList.getResource(i)); + inj->assignSimParticlesCount(mInjectorsCounters.get(i)); + } + } + + void BasicIosActorImpl::injectNewParticles() + { + mInjectedBenefitSum = 0; + mInjectedBenefitMin = +FLT_MAX; + mInjectedBenefitMax = -FLT_MAX; + + uint32_t maxInjectCount = (mMaxTotalParticleCount - mParticleCount); + + uint32_t injectCount = 0; + uint32_t lastInjectCount = 0; + do + { + lastInjectCount = injectCount; + for (uint32_t i = 0; i < mInjectorList.getSize(); i++) + { + BasicParticleInjector* inj = DYNAMIC_CAST(BasicParticleInjector*)(mInjectorList.getResource(i)); + if (inj->mInjectedParticles.size() == 0) + { + continue; + } + + if (injectCount < maxInjectCount) + { + IosNewObject obj; + if (inj->mInjectedParticles.popFront(obj)) + { + uint32_t injectIndex = mParticleCount + injectCount; + + float particleMass = mAsset->getParticleMass(); + mBufDesc.pmaPositionMass->get(injectIndex) = PxVec4(obj.initialPosition.x, obj.initialPosition.y, obj.initialPosition.z, particleMass); + mBufDesc.pmaVelocityLife->get(injectIndex) = PxVec4(obj.initialVelocity.x, obj.initialVelocity.y, obj.initialVelocity.z, 1.0f); + mBufDesc.pmaActorIdentifiers->get(injectIndex) = obj.iofxActorID; + + mBufDesc.pmaUserData->get(injectIndex) = obj.userData; + + mLifeSpan[injectIndex] = obj.lifetime; + mInjector[injectIndex] = inj->mInjectorID; + mBenefit[injectIndex] = obj.lodBenefit; + + mInjectedBenefitSum += obj.lodBenefit; + mInjectedBenefitMin = PxMin(mInjectedBenefitMin, obj.lodBenefit); + mInjectedBenefitMax = PxMax(mInjectedBenefitMax, obj.lodBenefit); + + ++injectCount; + } + } + } + } + while (injectCount > lastInjectCount); + + mInjectedCount = injectCount; + + //clear injectors FIFO + for (uint32_t i = 0; i < mInjectorList.getSize(); i++) + { + BasicParticleInjector* inj = DYNAMIC_CAST(BasicParticleInjector*)(mInjectorList.getResource(i)); + + IosNewObject obj; + while (inj->mInjectedParticles.popFront(obj)) + { + ; + } + } + } + + //////////////////////////////////////////////////////////////////////////////// + + BasicParticleInjector::BasicParticleInjector(ResourceList& list, BasicIosActorImpl& actor, uint32_t injectorID) + : mIosActor(&actor) + , mIofxClient(NULL) + , mVolume(NULL) + , mLastRandomID(0) + , mVolumeID(IofxActorIDIntl::NO_VOLUME) + , mInjectorID(injectorID) + , mSimulatedParticlesCount(0) + { + mRand.setSeed(actor.mBasicIosScene->getApexScene().getSeed()); + + list.add(*this); + + setLODWeights(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); + + mInjectedParticles.reserve(actor.mMaxTotalParticleCount); + } + + BasicParticleInjector::~BasicParticleInjector() + { + } + + void BasicParticleInjector::setListIndex(ResourceList& list, uint32_t index) + { + m_listIndex = index; + m_list = &list; + + InjectorParams injParams; + mIosActor->mBasicIosScene->fetchInjectorParams(mInjectorID, injParams); + + injParams.mLocalIndex = index; + + mIosActor->mBasicIosScene->updateInjectorParams(mInjectorID, injParams); + } + + + /* Emitter calls this function to adjust their particle weights with respect to other emitters */ + void BasicParticleInjector::setLODWeights(float maxDistance, float distanceWeight, float speedWeight, float lifeWeight, float separationWeight, float bias) + { + PX_UNUSED(separationWeight); + + InjectorParams injParams; + mIosActor->mBasicIosScene->fetchInjectorParams(mInjectorID, injParams); + + //normalize weights + float totalWeight = distanceWeight + speedWeight + lifeWeight; + if (totalWeight > PX_EPS_F32) + { + distanceWeight /= totalWeight; + speedWeight /= totalWeight; + lifeWeight /= totalWeight; + } + + injParams.mLODMaxDistance = maxDistance; + injParams.mLODDistanceWeight = distanceWeight; + injParams.mLODSpeedWeight = speedWeight; + injParams.mLODLifeWeight = lifeWeight; + injParams.mLODBias = bias; + + mIosActor->mBasicIosScene->updateInjectorParams(mInjectorID, injParams); + } + + + PxTaskID BasicParticleInjector::getCompletionTaskID() const + { + return mIosActor->mInjectTask->getTaskID(); + } + + void BasicParticleInjector::setObjectScale(float objectScale) + { + PX_ASSERT(mIofxClient); + IofxManagerClientIntl::Params params; + mIofxClient->getParams(params); + params.objectScale = objectScale; + mIofxClient->setParams(params); + } + + void BasicParticleInjector::init(IofxAsset* iofxAsset) + { + mIofxClient = mIosActor->mIofxMgr->createClient(iofxAsset, IofxManagerClientIntl::Params()); + + /* add this injector to the IOFX asset's context (so when the IOFX goes away our ::release() is called) */ + iofxAsset->addDependentActor(this); + + mRandomActorClassIDs.clear(); + if (iofxAsset->getMeshAssetCount() < 2) + { + mRandomActorClassIDs.pushBack(mIosActor->mIofxMgr->getActorClassID(mIofxClient, 0)); + return; + } + + /* Cache actorClassIDs for this asset */ + physx::Array<uint16_t> temp; + for (uint32_t i = 0 ; i < iofxAsset->getMeshAssetCount() ; i++) + { + uint32_t w = iofxAsset->getMeshAssetWeight(i); + uint16_t acid = mIosActor->mIofxMgr->getActorClassID(mIofxClient, (uint16_t) i); + for (uint32_t j = 0 ; j < w ; j++) + { + temp.pushBack(acid); + } + } + + mRandomActorClassIDs.reserve(temp.size()); + while (temp.size()) + { + uint32_t index = (uint32_t)mRand.getScaled(0, (float)temp.size()); + mRandomActorClassIDs.pushBack(temp[ index ]); + temp.replaceWithLast(index); + } + } + + + void BasicParticleInjector::release() + { + if (mInRelease) + { + return; + } + mInRelease = true; + mIosActor->releaseInjector(*this); + } + + void BasicParticleInjector::destroy() + { + ApexActor::destroy(); + + mIosActor->mIofxMgr->releaseClient(mIofxClient); + + delete this; + } + + void BasicParticleInjector::setPreferredRenderVolume(nvidia::apex::RenderVolume* volume) + { + mVolume = volume; + mVolumeID = mVolume ? mIosActor->mIofxMgr->getVolumeID(mVolume) : IofxActorIDIntl::NO_VOLUME; + } + + /* Emitter calls this virtual injector API to insert new particles. It is safe for an emitter to + * call this function at any time except for during the IOS::fetchResults(). Since + * ParticleScene::fetchResults() is single threaded, it should be safe to call from + * emitter::fetchResults() (destruction may want to do this because of contact reporting) + */ + void BasicParticleInjector::createObjects(uint32_t count, const IosNewObject* createList) + { + PX_PROFILE_ZONE("BasicIosCreateObjects", GetInternalApexSDK()->getContextId()); + + if (mRandomActorClassIDs.size() == 0) + { + return; + } + + PxVec3 eyePos; + { + SceneIntl& apexScene = mIosActor->mBasicIosScene->getApexScene(); + READ_LOCK(apexScene); + eyePos = apexScene.getEyePosition(); + } + InjectorParams injParams; + mIosActor->mBasicIosScene->fetchInjectorParams(mInjectorID, injParams); + // Append new objects to our FIFO. We do copies because we must perform buffering for the + // emitters. We have to hold these new objects until there is room in the TurbulenceFS and the + // injector's virtID range to emit them. + for (uint32_t i = 0 ; i < count ; i++) + { + if (mInjectedParticles.size() == mInjectedParticles.capacity()) + { + break; + } + + IosNewObject obj = *createList++; + + obj.lodBenefit = calcParticleBenefit(injParams, eyePos, obj.initialPosition, obj.initialVelocity, 1.0f); + obj.iofxActorID.set(mVolumeID, mRandomActorClassIDs[ mLastRandomID++ ]); + mLastRandomID = mLastRandomID == mRandomActorClassIDs.size() ? 0 : mLastRandomID; + //mInjectedParticleBenefit += obj.lodBenefit; + mInjectedParticles.pushBack(obj); + } + } + +#if APEX_CUDA_SUPPORT + void BasicParticleInjector::createObjects(ApexMirroredArray<const IosNewObject>& createArray) + { + PX_UNUSED(createArray); + + // An emitter will call this API when it has filled a host or device buffer. The injector + // should trigger a copy to the location it would like to see the resulting data when the + // IOS is finally ticked. + + PX_ALWAYS_ASSERT(); /* Not yet supported */ + } +#endif + + } +} // namespace nvidia + diff --git a/APEX_1.4/module/basicios/src/BasicIosAssetImpl.cpp b/APEX_1.4/module/basicios/src/BasicIosAssetImpl.cpp new file mode 100644 index 00000000..5fbf7296 --- /dev/null +++ b/APEX_1.4/module/basicios/src/BasicIosAssetImpl.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#include "Apex.h" + +#include "BasicIosAssetImpl.h" +#include "BasicIosActorImpl.h" +//#include "ApexSharedSerialization.h" +#include "ModuleBasicIosImpl.h" +#include "ApexUsingNamespace.h" + +#if APEX_CUDA_SUPPORT +#include "BasicIosActorGPU.h" +#endif + +namespace nvidia +{ +namespace basicios +{ + +void BasicIosAssetImpl::processParams() +{ + NvParameterized::Handle handle(mParams); + if (NvParameterized::ERROR_NONE != mParams->getParameterHandle("particleMass.type", handle)) + { + PX_ALWAYS_ASSERT(); + return; + } + + const char* type = 0; + if (NvParameterized::ERROR_NONE != handle.getParamEnum(type)) + { + PX_ALWAYS_ASSERT(); + return; + } + + mMassDistribType = 0 == nvidia::strcmp("uniform", type) ? UNIFORM : NORMAL; +} + +BasicIosAssetImpl::BasicIosAssetImpl(ModuleBasicIosImpl* module, ResourceList& list, NvParameterized::Interface* params, const char* name) : + mModule(module), + mName(name), + mParams((BasicIOSAssetParam*)params) +{ + list.add(*this); + processParams(); +} + +BasicIosAssetImpl::BasicIosAssetImpl(ModuleBasicIosImpl* module, ResourceList& list, const char* name): + mModule(module), + mName(name), + mParams(0) +{ + NvParameterized::Traits* traits = GetInternalApexSDK()->getParameterizedTraits(); + mParams = (BasicIOSAssetParam*)traits->createNvParameterized(BasicIOSAssetParam::staticClassName()); + + list.add(*this); + + processParams(); +} + +float BasicIosAssetImpl::getParticleMass() const +{ + READ_ZONE(); + float m = 0.0f; + switch (mMassDistribType) + { + case UNIFORM: + m = mParams->particleMass.center + mParams->particleMass.spread * mSRand.getNext(); + break; + case NORMAL: + m = mNormRand.getScaled(mParams->particleMass.center, mParams->particleMass.spread); + break; + default: + PX_ALWAYS_ASSERT(); + } + + return m <= 0 ? mParams->particleMass.center : m; // Clamp +} + +void BasicIosAssetImpl::release() +{ + mModule->mSdk->releaseAsset(*this); +} + +void BasicIosAssetImpl::destroy() +{ + if (mParams) + { + mParams->destroy(); + mParams = NULL; + } + + delete this; +} + +BasicIosAssetImpl::~BasicIosAssetImpl() +{ +} + +BasicIosActorImpl* BasicIosAssetImpl::getIosActorInScene(Scene& scene, bool mesh) const +{ + BasicIosScene* iosScene = mModule->getBasicIosScene(scene); + if (iosScene != 0) + { + for (uint32_t i = 0 ; i < mIosActorList.getSize() ; i++) + { + BasicIosActorImpl* iosActor = DYNAMIC_CAST(BasicIosActorImpl*)(mIosActorList.getResource(i)); + if (iosActor->mBasicIosScene == iosScene && iosActor->mIsMesh == mesh) + { + return iosActor; + } + } + } + return NULL; +} + +Actor* BasicIosAssetImpl::createIosActor(Scene& scene, nvidia::apex::IofxAsset* iofxAsset) +{ + BasicIosActorImpl* iosActor = getIosActorInScene(scene, iofxAsset->getMeshAssetCount() > 0); + if (iosActor == 0) + { + BasicIosScene* iosScene = mModule->getBasicIosScene(scene); + if (iosScene != 0) + { + iosActor = iosScene->createIosActor(mIosActorList, *this, *iofxAsset); + iosActor->mIsMesh = iofxAsset->getMeshAssetCount() > 0; + } + } + PX_ASSERT(iosActor); + return iosActor; +} + +void BasicIosAssetImpl::releaseIosActor(Actor& actor) +{ + BasicIosActorImpl* iosActor = DYNAMIC_CAST(BasicIosActorImpl*)(&actor); + iosActor->destroy(); +} + +uint32_t BasicIosAssetImpl::forceLoadAssets() +{ + return 0; +} + +bool BasicIosAssetImpl::getSupportsDensity() const +{ + BasicIOSAssetParam* gridParams = (BasicIOSAssetParam*)(getAssetNvParameterized()); + return (gridParams->GridDensity.Enabled); +} + +#ifndef WITHOUT_APEX_AUTHORING +/******************* BasicIosAssetAuthoringImpl *******************/ +BasicIosAssetAuthoringImpl::BasicIosAssetAuthoringImpl(ModuleBasicIosImpl* module, ResourceList& list): + BasicIosAssetImpl(module, list, "Authoring") +{ +} +BasicIosAssetAuthoringImpl::BasicIosAssetAuthoringImpl(ModuleBasicIosImpl* module, ResourceList& list, const char* name): + BasicIosAssetImpl(module, list, name) +{ +} + +BasicIosAssetAuthoringImpl::BasicIosAssetAuthoringImpl(ModuleBasicIosImpl* module, ResourceList& list, NvParameterized::Interface* params, const char* name) : + BasicIosAssetImpl(module, list, params, name) +{ +} + +void BasicIosAssetAuthoringImpl::release() +{ + delete this; +} + +void BasicIosAssetAuthoringImpl::setCollisionGroupName(const char* collisionGroupName) +{ + NvParameterized::Handle h(*mParams, "collisionGroupName"); + h.setParamString(collisionGroupName); +} + +void BasicIosAssetAuthoringImpl::setCollisionGroupMaskName(const char* collisionGroupMaskName) +{ + NvParameterized::Handle h(*mParams, "collisionGroupMaskName"); + h.setParamString(collisionGroupMaskName); +} + + +#endif + +} +} // namespace nvidia diff --git a/APEX_1.4/module/basicios/src/BasicIosScene.cpp b/APEX_1.4/module/basicios/src/BasicIosScene.cpp new file mode 100644 index 00000000..c142a5e4 --- /dev/null +++ b/APEX_1.4/module/basicios/src/BasicIosScene.cpp @@ -0,0 +1,469 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#include "Apex.h" + +#include "BasicIosScene.h" +#include "ModuleBasicIosImpl.h" +#include "BasicIosActorImpl.h" +#include "BasicIosActorCPU.h" +#include "ApexUsingNamespace.h" +#include "SceneIntl.h" +#include "ModulePerfScope.h" +#include "ModuleFieldSamplerIntl.h" +#include "RenderDebugInterface.h" + +#if APEX_CUDA_SUPPORT +#include <cuda.h> +#include "ApexCutil.h" +#include "BasicIosActorGPU.h" + +#include "ApexCudaSource.h" +#endif + +#include <PxScene.h> + +namespace nvidia +{ +namespace basicios +{ + +#pragma warning(push) +#pragma warning(disable:4355) + +BasicIosScene::BasicIosScene(ModuleBasicIosImpl& _module, SceneIntl& scene, RenderDebugInterface* debugRender, ResourceList& list) + : mPhysXScene(NULL) + , mModule(&_module) + , mApexScene(&scene) + , mDebugRender(debugRender) + , mSumBenefit(0.0f) + , mFieldSamplerManager(NULL) + , mInjectorAllocator(this) +{ + list.add(*this); + + /* Initialize reference to BasicIosDebugRenderParams */ + mDebugRenderParams = DYNAMIC_CAST(DebugRenderParams*)(mApexScene->getDebugRenderParams()); + PX_ASSERT(mDebugRenderParams); + NvParameterized::Handle handle(*mDebugRenderParams), memberHandle(*mDebugRenderParams); + int size; + + if (mDebugRenderParams->getParameterHandle("moduleName", handle) == NvParameterized::ERROR_NONE) + { + handle.getArraySize(size, 0); + handle.resizeArray(size + 1); + if (handle.getChildHandle(size, memberHandle) == NvParameterized::ERROR_NONE) + { + memberHandle.initParamRef(BasicIosDebugRenderParams::staticClassName(), true); + } + } + + /* Load reference to BasicIosDebugRenderParams */ + NvParameterized::Interface* refPtr = NULL; + memberHandle.getParamRef(refPtr); + mBasicIosDebugRenderParams = DYNAMIC_CAST(BasicIosDebugRenderParams*)(refPtr); + PX_ASSERT(mBasicIosDebugRenderParams); +} + +#pragma warning(pop) + +BasicIosScene::~BasicIosScene() +{ +} + +void BasicIosScene::destroy() +{ + removeAllActors(); + mApexScene->moduleReleased(*this); + delete this; +} + +void BasicIosScene::setModulePhysXScene(PxScene* s) +{ + if (mPhysXScene == s) + { + return; + } + + mPhysXScene = s; + for (uint32_t i = 0; i < mActorArray.size(); ++i) + { + BasicIosActorImpl* actor = DYNAMIC_CAST(BasicIosActorImpl*)(mActorArray[i]); + actor->setPhysXScene(mPhysXScene); + } +} + +void BasicIosScene::visualize() +{ +#ifndef WITHOUT_DEBUG_VISUALIZE + if (!mBasicIosDebugRenderParams->VISUALIZE_BASIC_IOS_ACTOR) + { + return; + } + + RENDER_DEBUG_IFACE(mDebugRender)->pushRenderState(); + for (uint32_t i = 0 ; i < mActorArray.size() ; i++) + { + BasicIosActorImpl* testActor = DYNAMIC_CAST(BasicIosActorImpl*)(mActorArray[ i ]); + testActor->visualize(); + } + RENDER_DEBUG_IFACE(mDebugRender)->popRenderState(); +#endif +} + +void BasicIosScene::submitTasks(float /*elapsedTime*/, float /*substepSize*/, uint32_t /*numSubSteps*/) +{ + for (uint32_t i = 0; i < mActorArray.size(); ++i) + { + BasicIosActorImpl* actor = DYNAMIC_CAST(BasicIosActorImpl*)(mActorArray[i]); + if (mPhysXScene) + { + PxVec3 gravity = mApexScene->getGravity(); + + if (actor->getGravity() != gravity) + { + actor->setGravity(gravity); + } + } + actor->submitTasks(); + } +} + +void BasicIosScene::setTaskDependencies() +{ + for (uint32_t i = 0; i < mActorArray.size(); ++i) + { + BasicIosActorImpl* actor = DYNAMIC_CAST(BasicIosActorImpl*)(mActorArray[i]); + actor->setTaskDependencies(); + } + + onSimulationStart(); +} + +void BasicIosScene::fetchResults() +{ + onSimulationFinish(); + + for (uint32_t i = 0; i < mActorArray.size(); ++i) + { + BasicIosActorImpl* actor = DYNAMIC_CAST(BasicIosActorImpl*)(mActorArray[i]); + actor->fetchResults(); + } +} + +FieldSamplerManagerIntl* BasicIosScene::getInternalFieldSamplerManager() +{ + if (mFieldSamplerManager == NULL) + { + ModuleFieldSamplerIntl* moduleFieldSampler = mModule->getInternalModuleFieldSampler(); + if (moduleFieldSampler != NULL) + { + mFieldSamplerManager = moduleFieldSampler->getInternalFieldSamplerManager(*mApexScene); + PX_ASSERT(mFieldSamplerManager != NULL); + } + } + return mFieldSamplerManager; +} + +/******************************** CPU Version ********************************/ + +void BasicIosSceneCPU::TimerCallback::operator()(void* stream) +{ + PX_UNUSED(stream); + + float elapsed = (float)mTimer.peekElapsedSeconds(); + mMinTime = PxMin(elapsed, mMinTime); + mMaxTime = PxMax(elapsed, mMaxTime); +} + +void BasicIosSceneCPU::TimerCallback::reset() +{ + mTimer.getElapsedSeconds(); + mMinTime = 1e20; + mMaxTime = 0.f; +} + +float BasicIosSceneCPU::TimerCallback::getElapsedTime() const +{ + return (mMaxTime - mMinTime) * 1000.f; +} + +BasicIosSceneCPU::BasicIosSceneCPU(ModuleBasicIosImpl& module, SceneIntl& scene, RenderDebugInterface* debugRender, ResourceList& list) + : BASIC_IOS_SCENE(module, scene, debugRender, list) +{ +} + +BasicIosSceneCPU::~BasicIosSceneCPU() +{ +} + + +void BasicIosSceneCPU::setCallbacks(BasicIosActorCPU* actor) +{ + actor->setOnStartFSCallback(&mTimerCallback); + actor->setOnFinishIOFXCallback(&mTimerCallback); +} + + +BasicIosActorImpl* BasicIosSceneCPU::createIosActor(ResourceList& list, BasicIosAssetImpl& asset, nvidia::apex::IofxAsset& iofxAsset) +{ + BasicIosActorCPU* actor = PX_NEW(BasicIosActorCPU)(list, asset, *this, iofxAsset); + setCallbacks(actor); + return actor; +} + +void BasicIosSceneCPU::fetchResults() +{ + BasicIosScene::fetchResults(); + + nvidia::apex::StatValue val; + val.Float = mTimerCallback.getElapsedTime(); + mTimerCallback.reset(); + if (val.Float > 0.f) + { + mApexScene->setApexStatValue(SceneIntl::ParticleSimulationTime, val); + } +} + +/******************************** GPU Version ********************************/ + +#if APEX_CUDA_SUPPORT + +BasicIosSceneGPU::EventCallback::EventCallback() : mIsCalled(false), mEvent(NULL) +{ +} +void BasicIosSceneGPU::EventCallback::init() +{ + if (mEvent == NULL) + { + CUT_SAFE_CALL(cuEventCreate((CUevent*)(&mEvent), CU_EVENT_DEFAULT)); + } +} + +BasicIosSceneGPU::EventCallback::~EventCallback() +{ + if (mEvent != NULL) + { + CUT_SAFE_CALL(cuEventDestroy((CUevent)mEvent)); + } +} + +void BasicIosSceneGPU::EventCallback::operator()(void* stream) +{ + if (mEvent != NULL) + { + CUT_SAFE_CALL(cuEventRecord((CUevent)mEvent, (CUstream)stream)); + mIsCalled = true; + } +} + +BasicIosSceneGPU::BasicIosSceneGPU(ModuleBasicIosImpl& module, SceneIntl& scene, RenderDebugInterface* debugRender, ResourceList& list) + : BASIC_IOS_SCENE(module, scene, debugRender, list) + , CudaModuleScene(scene, *mModule, APEX_CUDA_TO_STR(APEX_CUDA_MODULE_PREFIX)) + , mInjectorConstMemGroup(APEX_CUDA_OBJ_NAME(simulateStorage)) +{ + { + PxGpuDispatcher* gd = mApexScene->getTaskManager()->getGpuDispatcher(); + PX_ASSERT(gd != NULL); + PxScopedCudaLock _lock_(*gd->getCudaContextManager()); + + mOnSimulationStart.init(); + +//CUDA module objects +#include "../cuda/include/moduleList.h" + } + + { + mInjectorConstMemGroup.begin(); + + mInjectorParamsArrayHandle.alloc(mInjectorConstMemGroup.getStorage()); + + mInjectorConstMemGroup.end(); + } + +} + +BasicIosSceneGPU::~BasicIosSceneGPU() +{ + for (uint32_t i = 0; i < mOnStartCallbacks.size(); i++) + { + PX_DELETE(mOnStartCallbacks[i]); + } + for (uint32_t i = 0; i < mOnFinishCallbacks.size(); i++) + { + PX_DELETE(mOnFinishCallbacks[i]); + } + CudaModuleScene::destroy(*mApexScene); +} + + +void BasicIosSceneGPU::setCallbacks(BasicIosActorGPU* actor) +{ + mOnStartCallbacks.pushBack(PX_NEW(EventCallback)()); + mOnFinishCallbacks.pushBack(PX_NEW(EventCallback)()); + { + PxGpuDispatcher* gd = mApexScene->getTaskManager()->getGpuDispatcher(); + PX_ASSERT(gd != NULL); + PxScopedCudaLock _lock_(*gd->getCudaContextManager()); + + mOnStartCallbacks.back()->init(); + mOnFinishCallbacks.back()->init(); + } + actor->setOnStartFSCallback(mOnStartCallbacks.back()); + actor->setOnFinishIOFXCallback(mOnFinishCallbacks.back()); +} + + +BasicIosActorImpl* BasicIosSceneGPU::createIosActor(ResourceList& list, BasicIosAssetImpl& asset, nvidia::apex::IofxAsset& iofxAsset) +{ + BasicIosActorGPU* actor = PX_NEW(BasicIosActorGPU)(list, asset, *this, iofxAsset); + setCallbacks(actor); + return actor; +} + +void BasicIosSceneGPU::fetchInjectorParams(uint32_t injectorID, InjectorParams& injParams) +{ + APEX_CUDA_CONST_MEM_GROUP_SCOPE(mInjectorConstMemGroup); + + InjectorParamsArray injectorParamsArray; + mInjectorParamsArrayHandle.fetch(_storage_, injectorParamsArray); + PX_ASSERT(injectorID < injectorParamsArray.getSize()); + injectorParamsArray.fetchElem(_storage_, injParams, injectorID); +} +void BasicIosSceneGPU::updateInjectorParams(uint32_t injectorID, const InjectorParams& injParams) +{ + APEX_CUDA_CONST_MEM_GROUP_SCOPE(mInjectorConstMemGroup); + + InjectorParamsArray injectorParamsArray; + mInjectorParamsArrayHandle.fetch(_storage_, injectorParamsArray); + PX_ASSERT(injectorID < injectorParamsArray.getSize()); + injectorParamsArray.updateElem(_storage_, injParams, injectorID); +} + +bool BasicIosSceneGPU::growInjectorStorage(uint32_t newSize) +{ + APEX_CUDA_CONST_MEM_GROUP_SCOPE(mInjectorConstMemGroup); + + if (mApexScene->isSimulating()) + { + APEX_INTERNAL_ERROR("BasicIosSceneGPU::growInjectorStorage - is called while ApexScene in simulating!"); + PX_ASSERT(0); + } + + InjectorParamsArray injectorParamsArray; + mInjectorParamsArrayHandle.fetch(_storage_, injectorParamsArray); + if (injectorParamsArray.resize(_storage_, newSize)) + { + mInjectorParamsArrayHandle.update(_storage_, injectorParamsArray); + return true; + } + return false; +} + + +void BasicIosSceneGPU::onSimulationStart() +{ + BasicIosScene::onSimulationStart(); + + PxGpuDispatcher* gd = mApexScene->getTaskManager()->getGpuDispatcher(); + PX_ASSERT(gd != NULL); + PxScopedCudaLock _lock_(*gd->getCudaContextManager()); + + //we pass default 0 stream so that this copy happens before any kernel launches + APEX_CUDA_OBJ_NAME(simulateStorage).copyToDevice(gd->getCudaContextManager(), 0); + + mOnSimulationStart(NULL); +} + +void BasicIosSceneGPU::fetchResults() +{ + BasicIosScene::fetchResults(); + + PxGpuDispatcher* gd = mApexScene->getTaskManager()->getGpuDispatcher(); + PX_ASSERT(gd != NULL); + PxScopedCudaLock _lock_(*gd->getCudaContextManager()); + + nvidia::apex::StatValue val; + val.Float = 0.f; + float minTime = 1e30; + + for (uint32_t i = 0 ; i < this->mOnStartCallbacks.size(); i++) + { + if (mOnStartCallbacks[i]->mIsCalled && mOnFinishCallbacks[i]->mIsCalled) + { + mOnStartCallbacks[i]->mIsCalled = false; + mOnFinishCallbacks[i]->mIsCalled = false; + CUT_SAFE_CALL(cuEventSynchronize((CUevent)mOnStartCallbacks[i]->getEvent())); + CUT_SAFE_CALL(cuEventSynchronize((CUevent)mOnFinishCallbacks[i]->getEvent())); + float tmp; + CUT_SAFE_CALL(cuEventElapsedTime(&tmp, (CUevent)mOnSimulationStart.getEvent(), (CUevent)mOnStartCallbacks[i]->getEvent())); + minTime = PxMin(tmp, minTime); + CUT_SAFE_CALL(cuEventElapsedTime(&tmp, (CUevent)mOnSimulationStart.getEvent(), (CUevent)mOnFinishCallbacks[i]->getEvent())); + val.Float = PxMax(tmp, val.Float); + } + } + val.Float -= PxMin(minTime, val.Float); + + if (val.Float > 0.f) + { + mApexScene->setApexStatValue(SceneIntl::ParticleSimulationTime, val); + } +} +#endif + +// BasicIosInjectorAllocator +uint32_t BasicIosInjectorAllocator::allocateInjectorID() +{ + uint32_t size = mInjectorList.size(); + if (mFreeInjectorListStart == NULL_INJECTOR_INDEX) + { + //try to get new injectors + if (mStorage->growInjectorStorage(size + 1) == false) + { + return NULL_INJECTOR_INDEX; + } + + mFreeInjectorListStart = size; + + mInjectorList.resize(size + 1); + mInjectorList.back() = NULL_INJECTOR_INDEX; + } + uint32_t injectorID = mFreeInjectorListStart; + mFreeInjectorListStart = mInjectorList[injectorID]; + mInjectorList[injectorID] = USED_INJECTOR_INDEX; + return injectorID; +} + +void BasicIosInjectorAllocator::releaseInjectorID(uint32_t injectorID) +{ + //add to released injector list + PX_ASSERT(mInjectorList[injectorID] == USED_INJECTOR_INDEX); + mInjectorList[injectorID] = mReleasedInjectorListStart; + mReleasedInjectorListStart = injectorID; +} + +void BasicIosInjectorAllocator::flushReleased() +{ + //add all released injectors to free injector list + while (mReleasedInjectorListStart != NULL_INJECTOR_INDEX) + { + uint32_t injectorID = mInjectorList[mReleasedInjectorListStart]; + + //add to free injector list + mInjectorList[mReleasedInjectorListStart] = mFreeInjectorListStart; + mFreeInjectorListStart = mReleasedInjectorListStart; + + mReleasedInjectorListStart = injectorID; + } +} + +} +} // namespace nvidia diff --git a/APEX_1.4/module/basicios/src/ModuleBasicIosImpl.cpp b/APEX_1.4/module/basicios/src/ModuleBasicIosImpl.cpp new file mode 100644 index 00000000..4d149ded --- /dev/null +++ b/APEX_1.4/module/basicios/src/ModuleBasicIosImpl.cpp @@ -0,0 +1,416 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#include "Apex.h" +#include "ApexSDKIntl.h" +#include "ModuleBasicIosImpl.h" +#include "ModuleBasicIosRegistration.h" +#include "ModulePerfScope.h" +#include "ApexUsingNamespace.h" +#include "BasicIosSceneCPU.h" +#if APEX_CUDA_SUPPORT +#include "BasicIosSceneGPU.h" +#endif +#if ENABLE_TEST +#include "BasicIosTestSceneCPU.h" +#if APEX_CUDA_SUPPORT +#include "BasicIosTestSceneGPU.h" +#endif +#endif +#include "BasicIosAssetImpl.h" +#include "BasicIosActorImpl.h" + +#include "SceneIntl.h" +#include "ModuleIofxIntl.h" +#include "ModuleFieldSamplerIntl.h" +#include "PsMemoryBuffer.h" + +#include "Lock.h" + +#include "ReadCheck.h" + +using namespace basicios; + +namespace nvidia +{ +namespace apex +{ + +#if defined(_USRDLL) + +/* Modules don't have to link against the framework, they keep their own */ +ApexSDKIntl* gApexSdk = 0; +ApexSDK* GetApexSDK() +{ + return gApexSdk; +} +ApexSDKIntl* GetInternalApexSDK() +{ + return gApexSdk; +} + +APEX_API Module* CALL_CONV createModule( + ApexSDKIntl* inSdk, + ModuleIntl** niRef, + uint32_t APEXsdkVersion, + uint32_t PhysXsdkVersion, + ApexCreateError* errorCode) +{ + if (APEXsdkVersion != APEX_SDK_VERSION) + { + if (errorCode) + { + *errorCode = APEX_CE_WRONG_VERSION; + } + return NULL; + } + + if (PhysXsdkVersion != PX_PHYSICS_VERSION) + { + if (errorCode) + { + *errorCode = APEX_CE_WRONG_VERSION; + } + return NULL; + } + + /* Setup common module global variables */ + gApexSdk = inSdk; + + ModuleBasicIosImpl* impl = PX_NEW(ModuleBasicIos)(inSdk); + *niRef = (ModuleIntl*) impl; + return (ModuleBase*) impl; +} +#else +/* Statically linking entry function */ +void instantiateModuleBasicIos() +{ + ApexSDKIntl* sdk = GetInternalApexSDK(); + basicios::ModuleBasicIosImpl* impl = PX_NEW(basicios::ModuleBasicIosImpl)(sdk); + sdk->registerExternalModule((Module*) impl, (ModuleIntl*) impl); +} +#endif +} + +namespace basicios +{ +/* =================== ModuleBasicIosImpl =================== */ + + +AuthObjTypeID BasicIosAssetImpl::mAssetTypeID; + +#ifdef WITHOUT_APEX_AUTHORING + +class BasicIosAssetDummyAuthoring : public AssetAuthoring, public UserAllocated +{ +public: + BasicIosAssetDummyAuthoring(ModuleBasicIosImpl* module, ResourceList& list, NvParameterized::Interface* params, const char* name) + { + PX_UNUSED(module); + PX_UNUSED(list); + PX_UNUSED(params); + PX_UNUSED(name); + } + + BasicIosAssetDummyAuthoring(ModuleBasicIosImpl* module, ResourceList& list, const char* name) + { + PX_UNUSED(module); + PX_UNUSED(list); + PX_UNUSED(name); + } + + BasicIosAssetDummyAuthoring(ModuleBasicIosImpl* module, ResourceList& list) + { + PX_UNUSED(module); + PX_UNUSED(list); + } + + virtual void setToolString(const char* /*toolName*/, const char* /*toolVersion*/, uint32_t /*toolChangelist*/) + { + + } + + + virtual void release() + { + destroy(); + } + + // internal + void destroy() + { + delete this; + } + + /** + * \brief Returns the name of this APEX authorable object type + */ + virtual const char* getObjTypeName() const + { + return BasicIosAssetImpl::getClassName(); + } + + /** + * \brief Prepares a fully authored Asset Authoring object for a specified platform + */ + virtual bool prepareForPlatform(nvidia::apex::PlatformTag) + { + PX_ASSERT(0); + return false; + } + + const char* getName(void) const + { + return NULL; + } + + /** + * \brief Save asset's NvParameterized interface, may return NULL + */ + virtual NvParameterized::Interface* getNvParameterized() const + { + PX_ASSERT(0); + return NULL; + } + + virtual NvParameterized::Interface* releaseAndReturnNvParameterizedInterface(void) + { + PX_ALWAYS_ASSERT(); + return NULL; + } +}; + +typedef ApexAuthorableObject<ModuleBasicIosImpl, BasicIosAssetImpl, BasicIosAssetDummyAuthoring> BasicIOSAO; + +#else +typedef ApexAuthorableObject<ModuleBasicIosImpl, BasicIosAssetImpl, BasicIosAssetAuthoringImpl> BasicIOSAO; +#endif + +ModuleBasicIosImpl::ModuleBasicIosImpl(ApexSDKIntl* sdk) +{ + mSdk = sdk; + mApiProxy = this; + mName = "BasicIOS"; + mModuleParams = NULL; + mIofxModule = NULL; + mFieldSamplerModule = NULL; + + /* Register this module's authorable object types and create their namespaces */ + const char* pName = BasicIOSAssetParam::staticClassName(); + BasicIOSAO* eAO = PX_NEW(BasicIOSAO)(this, mAuthorableObjects, pName); + BasicIosAssetImpl::mAssetTypeID = eAO->getResID(); + + /* Register the NvParameterized factories */ + NvParameterized::Traits* traits = mSdk->getParameterizedTraits(); + ModuleBasicIosRegistration::invokeRegistration(traits); +} + +AuthObjTypeID ModuleBasicIosImpl::getModuleID() const +{ + return BasicIosAssetImpl::mAssetTypeID; +} + +ModuleBasicIosImpl::~ModuleBasicIosImpl() +{ +} + +void ModuleBasicIosImpl::destroy() +{ + NvParameterized::Traits* traits = mSdk->getParameterizedTraits(); + + if (mModuleParams) + { + mModuleParams->destroy(); + mModuleParams = NULL; + } + + ModuleBase::destroy(); + + if (traits) + { + /* Remove the NvParameterized factories */ + ModuleBasicIosRegistration::invokeUnregistration(traits); + } + + delete this; +} + +void ModuleBasicIosImpl::init(const ModuleBasicIosDesc&) +{ +} + +void ModuleBasicIosImpl::init(NvParameterized::Interface&) +{ + ModuleBasicIosDesc desc; + init(desc); +} + +NvParameterized::Interface* ModuleBasicIosImpl::getDefaultModuleDesc() +{ + NvParameterized::Traits* traits = mSdk->getParameterizedTraits(); + + if (!mModuleParams) + { + mModuleParams = DYNAMIC_CAST(BasicIosModuleParameters*) + (traits->createNvParameterized("BasicIosModuleParameters")); + PX_ASSERT(mModuleParams); + } + else + { + mModuleParams->initDefaults(); + } + + return mModuleParams; +} + +uint32_t ModuleBasicIosImpl::forceLoadAssets() +{ + return 0; +} + +BasicIosScene* ModuleBasicIosImpl::getBasicIosScene(const Scene& apexScene) +{ + const SceneIntl* niScene = DYNAMIC_CAST(const SceneIntl*)(&apexScene); + for (uint32_t i = 0 ; i < mBasicIosSceneList.getSize() ; i++) + { + BasicIosScene* ps = DYNAMIC_CAST(BasicIosScene*)(mBasicIosSceneList.getResource(i)); + if (ps->mApexScene == niScene) + { + return ps; + } + } + + PX_ASSERT(!"Unable to locate an appropriate BasicIosScene"); + return NULL; +} + +const BasicIosScene* ModuleBasicIosImpl::getBasicIosScene(const Scene& apexScene) const +{ + const SceneIntl* niScene = DYNAMIC_CAST(const SceneIntl*)(&apexScene); + for (uint32_t i = 0 ; i < mBasicIosSceneList.getSize() ; i++) + { + BasicIosScene* ps = DYNAMIC_CAST(BasicIosScene*)(mBasicIosSceneList.getResource(i)); + if (ps->mApexScene == niScene) + { + return ps; + } + } + + PX_ASSERT(!"Unable to locate an appropriate BasicIosScene"); + return NULL; +} + +RenderableIterator* ModuleBasicIosImpl::createRenderableIterator(const Scene& apexScene) +{ + BasicIosScene* ps = getBasicIosScene(apexScene); + if (ps) + { + return ps->createRenderableIterator(); + } + + return NULL; +} + +ModuleSceneIntl* ModuleBasicIosImpl::createInternalModuleScene(SceneIntl& scene, RenderDebugInterface* renderDebug) +{ + READ_LOCK(scene); +#if APEX_CUDA_SUPPORT + if (scene.getTaskManager()->getGpuDispatcher() && scene.isUsingCuda()) + { +#if ENABLE_TEST + return PX_NEW(BasicIosTestSceneGPU)(*this, scene, renderDebug, mBasicIosSceneList); +#else + return PX_NEW(BasicIosSceneGPU)(*this, scene, renderDebug, mBasicIosSceneList); +#endif + } + else +#endif + { +#if ENABLE_TEST + return PX_NEW(BasicIosTestSceneCPU)(*this, scene, renderDebug, mBasicIosSceneList); +#else + return PX_NEW(BasicIosSceneCPU)(*this, scene, renderDebug, mBasicIosSceneList); +#endif + } +} + +void ModuleBasicIosImpl::releaseModuleSceneIntl(ModuleSceneIntl& scene) +{ + BasicIosScene* ps = DYNAMIC_CAST(BasicIosScene*)(&scene); + ps->destroy(); +} + +const char* ModuleBasicIosImpl::getBasicIosTypeName() +{ + READ_ZONE(); + return BasicIosAssetImpl::getClassName(); +} + + +ApexActor* ModuleBasicIosImpl::getApexActor(Actor* nxactor, AuthObjTypeID type) const +{ + if (type == BasicIosAssetImpl::mAssetTypeID) + { + return static_cast<BasicIosActorImpl*>(nxactor); + } + + return NULL; +} + +ModuleIofxIntl* ModuleBasicIosImpl::getInternalModuleIofx() +{ + if (!mIofxModule ) + { + ModuleIntl* nim = mSdk->getInternalModuleByName("IOFX"); + if (nim) + { + mIofxModule = DYNAMIC_CAST(ModuleIofxIntl*)(nim); + } + } + return mIofxModule; +} + +ModuleFieldSamplerIntl* ModuleBasicIosImpl::getInternalModuleFieldSampler() +{ + if (!mFieldSamplerModule) + { + ModuleIntl* nim = mSdk->getInternalModuleByName("FieldSampler"); + if (nim) + { + mFieldSamplerModule = DYNAMIC_CAST(ModuleFieldSamplerIntl*)(nim); + } + } + return mFieldSamplerModule; +} + +const TestBase* ModuleBasicIosImpl::getTestBase(Scene* apexScene) const +{ + + const BasicIosScene* scene = getBasicIosScene(*apexScene); + +#if APEX_CUDA_SUPPORT && ENABLE_TEST + if (scene->getApexScene().getTaskManager()->getGpuDispatcher() && scene->getApexScene().isUsingCuda()) + { + return static_cast<const TestBase*>(DYNAMIC_CAST(const BasicIosTestSceneGPU*)(scene)); + } +#endif + +#if ENABLE_TEST + return static_cast<const TestBase*>(DYNAMIC_CAST(const BasicIosTestSceneCPU*)(scene)); +#else + PX_UNUSED(scene); + return 0; +#endif + +} + +} +} // namespace nvidia diff --git a/APEX_1.4/module/basicios/src/autogen/BasicIOSAssetParam.cpp b/APEX_1.4/module/basicios/src/autogen/BasicIOSAssetParam.cpp new file mode 100644 index 00000000..2fd5f901 --- /dev/null +++ b/APEX_1.4/module/basicios/src/autogen/BasicIOSAssetParam.cpp @@ -0,0 +1,1406 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2015 NVIDIA Corporation. All rights reserved. + +// This file was generated by NvParameterized/scripts/GenParameterized.pl + + +#include "BasicIOSAssetParam.h" +#include <string.h> +#include <stdlib.h> + +using namespace NvParameterized; + +namespace nvidia +{ +namespace basicios +{ + +using namespace BasicIOSAssetParamNS; + +const char* const BasicIOSAssetParamFactory::vptr = + NvParameterized::getVptr<BasicIOSAssetParam, BasicIOSAssetParam::ClassAlignment>(); + +const uint32_t NumParamDefs = 38; +static NvParameterized::DefinitionImpl* ParamDefTable; // now allocated in buildTree [NumParamDefs]; + + +static const size_t ParamLookupChildrenTable[] = +{ + 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 28, 29, 30, + 34, 9, 10, 11, 23, 24, 25, 26, 31, 32, 33, 35, 36, 37, +}; + +#define TENUM(type) nvidia::##type +#define CHILDREN(index) &ParamLookupChildrenTable[index] +static const NvParameterized::ParamLookupNode ParamLookupTable[NumParamDefs] = +{ + { TYPE_STRUCT, false, 0, CHILDREN(0), 24 }, + { TYPE_F32, false, (size_t)(&((ParametersStruct*)0)->restDensity), NULL, 0 }, // restDensity + { TYPE_F32, false, (size_t)(&((ParametersStruct*)0)->particleRadius), NULL, 0 }, // particleRadius + { TYPE_U32, false, (size_t)(&((ParametersStruct*)0)->maxParticleCount), NULL, 0 }, // maxParticleCount + { TYPE_F32, false, (size_t)(&((ParametersStruct*)0)->maxInjectedParticleCount), NULL, 0 }, // maxInjectedParticleCount + { TYPE_U32, false, (size_t)(&((ParametersStruct*)0)->maxCollidingObjects), NULL, 0 }, // maxCollidingObjects + { TYPE_F32, false, (size_t)(&((ParametersStruct*)0)->sceneGravityScale), NULL, 0 }, // sceneGravityScale + { TYPE_VEC3, false, (size_t)(&((ParametersStruct*)0)->externalAcceleration), NULL, 0 }, // externalAcceleration + { TYPE_STRUCT, false, (size_t)(&((ParametersStruct*)0)->particleMass), CHILDREN(24), 3 }, // particleMass + { TYPE_F32, false, (size_t)(&((RandomF32_Type*)0)->center), NULL, 0 }, // particleMass.center + { TYPE_F32, false, (size_t)(&((RandomF32_Type*)0)->spread), NULL, 0 }, // particleMass.spread + { TYPE_ENUM, false, (size_t)(&((RandomF32_Type*)0)->type), NULL, 0 }, // particleMass.type + { TYPE_STRING, false, (size_t)(&((ParametersStruct*)0)->collisionFilterDataName), NULL, 0 }, // collisionFilterDataName + { TYPE_STRING, false, (size_t)(&((ParametersStruct*)0)->fieldSamplerFilterDataName), NULL, 0 }, // fieldSamplerFilterDataName + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->staticCollision), NULL, 0 }, // staticCollision + { TYPE_F32, false, (size_t)(&((ParametersStruct*)0)->restitutionForStaticShapes), NULL, 0 }, // restitutionForStaticShapes + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->dynamicCollision), NULL, 0 }, // dynamicCollision + { TYPE_F32, false, (size_t)(&((ParametersStruct*)0)->restitutionForDynamicShapes), NULL, 0 }, // restitutionForDynamicShapes + { TYPE_F32, false, (size_t)(&((ParametersStruct*)0)->collisionDistanceMultiplier), NULL, 0 }, // collisionDistanceMultiplier + { TYPE_F32, false, (size_t)(&((ParametersStruct*)0)->collisionThreshold), NULL, 0 }, // collisionThreshold + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->collisionWithConvex), NULL, 0 }, // collisionWithConvex + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->collisionWithTriangleMesh), NULL, 0 }, // collisionWithTriangleMesh + { TYPE_STRUCT, false, (size_t)(&((ParametersStruct*)0)->GridDensity), CHILDREN(27), 4 }, // GridDensity + { TYPE_BOOL, false, (size_t)(&((GridDensityParams_Type*)0)->Enabled), NULL, 0 }, // GridDensity.Enabled + { TYPE_ENUM, false, (size_t)(&((GridDensityParams_Type*)0)->Resolution), NULL, 0 }, // GridDensity.Resolution + { TYPE_F32, false, (size_t)(&((GridDensityParams_Type*)0)->GridSize), NULL, 0 }, // GridDensity.GridSize + { TYPE_U32, false, (size_t)(&((GridDensityParams_Type*)0)->MaxCellCount), NULL, 0 }, // GridDensity.MaxCellCount + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->enableTemperatureBuffer), NULL, 0 }, // enableTemperatureBuffer + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->enableDensityBuffer), NULL, 0 }, // enableDensityBuffer + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->enableCouplingOverride), NULL, 0 }, // enableCouplingOverride + { TYPE_STRUCT, false, (size_t)(&((ParametersStruct*)0)->particleToGridCoupling), CHILDREN(31), 3 }, // particleToGridCoupling + { TYPE_F32, false, (size_t)(&((ParticleToGridCouplingParams_Type*)0)->accelTimeConstant), NULL, 0 }, // particleToGridCoupling.accelTimeConstant + { TYPE_F32, false, (size_t)(&((ParticleToGridCouplingParams_Type*)0)->decelTimeConstant), NULL, 0 }, // particleToGridCoupling.decelTimeConstant + { TYPE_F32, false, (size_t)(&((ParticleToGridCouplingParams_Type*)0)->thresholdMultiplier), NULL, 0 }, // particleToGridCoupling.thresholdMultiplier + { TYPE_STRUCT, false, (size_t)(&((ParametersStruct*)0)->gridToParticleCoupling), CHILDREN(34), 3 }, // gridToParticleCoupling + { TYPE_F32, false, (size_t)(&((GridToParticleCouplingParams_Type*)0)->accelTimeConstant), NULL, 0 }, // gridToParticleCoupling.accelTimeConstant + { TYPE_F32, false, (size_t)(&((GridToParticleCouplingParams_Type*)0)->decelTimeConstant), NULL, 0 }, // gridToParticleCoupling.decelTimeConstant + { TYPE_F32, false, (size_t)(&((GridToParticleCouplingParams_Type*)0)->thresholdMultiplier), NULL, 0 }, // gridToParticleCoupling.thresholdMultiplier +}; + + +bool BasicIOSAssetParam::mBuiltFlag = false; +NvParameterized::MutexType BasicIOSAssetParam::mBuiltFlagMutex; + +BasicIOSAssetParam::BasicIOSAssetParam(NvParameterized::Traits* traits, void* buf, int32_t* refCount) : + NvParameters(traits, buf, refCount) +{ + //mParameterizedTraits->registerFactory(className(), &BasicIOSAssetParamFactoryInst); + + if (!buf) //Do not init data if it is inplace-deserialized + { + initDynamicArrays(); + initStrings(); + initReferences(); + initDefaults(); + } +} + +BasicIOSAssetParam::~BasicIOSAssetParam() +{ + freeStrings(); + freeReferences(); + freeDynamicArrays(); +} + +void BasicIOSAssetParam::destroy() +{ + // We cache these fields here to avoid overwrite in destructor + bool doDeallocateSelf = mDoDeallocateSelf; + NvParameterized::Traits* traits = mParameterizedTraits; + int32_t* refCount = mRefCount; + void* buf = mBuffer; + + this->~BasicIOSAssetParam(); + + NvParameters::destroy(this, traits, doDeallocateSelf, refCount, buf); +} + +const NvParameterized::DefinitionImpl* BasicIOSAssetParam::getParameterDefinitionTree(void) +{ + if (!mBuiltFlag) // Double-checked lock + { + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + if (!mBuiltFlag) + { + buildTree(); + } + } + + return(&ParamDefTable[0]); +} + +const NvParameterized::DefinitionImpl* BasicIOSAssetParam::getParameterDefinitionTree(void) const +{ + BasicIOSAssetParam* tmpParam = const_cast<BasicIOSAssetParam*>(this); + + if (!mBuiltFlag) // Double-checked lock + { + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + if (!mBuiltFlag) + { + tmpParam->buildTree(); + } + } + + return(&ParamDefTable[0]); +} + +NvParameterized::ErrorType BasicIOSAssetParam::getParameterHandle(const char* long_name, Handle& handle) const +{ + ErrorType Ret = NvParameters::getParameterHandle(long_name, handle); + if (Ret != ERROR_NONE) + { + return(Ret); + } + + size_t offset; + void* ptr; + + getVarPtr(handle, ptr, offset); + + if (ptr == NULL) + { + return(ERROR_INDEX_OUT_OF_RANGE); + } + + return(ERROR_NONE); +} + +NvParameterized::ErrorType BasicIOSAssetParam::getParameterHandle(const char* long_name, Handle& handle) +{ + ErrorType Ret = NvParameters::getParameterHandle(long_name, handle); + if (Ret != ERROR_NONE) + { + return(Ret); + } + + size_t offset; + void* ptr; + + getVarPtr(handle, ptr, offset); + + if (ptr == NULL) + { + return(ERROR_INDEX_OUT_OF_RANGE); + } + + return(ERROR_NONE); +} + +void BasicIOSAssetParam::getVarPtr(const Handle& handle, void*& ptr, size_t& offset) const +{ + ptr = getVarPtrHelper(&ParamLookupTable[0], const_cast<BasicIOSAssetParam::ParametersStruct*>(¶meters()), handle, offset); +} + + +/* Dynamic Handle Indices */ + +void BasicIOSAssetParam::freeParameterDefinitionTable(NvParameterized::Traits* traits) +{ + if (!traits) + { + return; + } + + if (!mBuiltFlag) // Double-checked lock + { + return; + } + + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + + if (!mBuiltFlag) + { + return; + } + + for (uint32_t i = 0; i < NumParamDefs; ++i) + { + ParamDefTable[i].~DefinitionImpl(); + } + + traits->free(ParamDefTable); + + mBuiltFlag = false; +} + +#define PDEF_PTR(index) (&ParamDefTable[index]) + +void BasicIOSAssetParam::buildTree(void) +{ + + uint32_t allocSize = sizeof(NvParameterized::DefinitionImpl) * NumParamDefs; + ParamDefTable = (NvParameterized::DefinitionImpl*)(mParameterizedTraits->alloc(allocSize)); + memset(ParamDefTable, 0, allocSize); + + for (uint32_t i = 0; i < NumParamDefs; ++i) + { + NV_PARAM_PLACEMENT_NEW(ParamDefTable + i, NvParameterized::DefinitionImpl)(*mParameterizedTraits); + } + + // Initialize DefinitionImpl node: nodeIndex=0, longName="" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[0]; + ParamDef->init("", TYPE_STRUCT, "STRUCT", true); + + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=1, longName="restDensity" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[1]; + ParamDef->init("restDensity", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("gameScale", "true", true); + HintTable[1].init("min", uint64_t(0), true); + ParamDefTable[1].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#else + + static HintImpl HintTable[4]; + static Hint* HintPtrTable[4] = { &HintTable[0], &HintTable[1], &HintTable[2], &HintTable[3], }; + HintTable[0].init("gameScale", "true", true); + HintTable[1].init("longDescription", "\nAuthored density of the instanced objects simulated by this IOS. Emitters need this\nvalue for constant density emitter effects.\n", true); + HintTable[2].init("min", uint64_t(0), true); + HintTable[3].init("shortDescription", "Rest density of particles", true); + ParamDefTable[1].setHints((const NvParameterized::Hint**)HintPtrTable, 4); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=2, longName="particleRadius" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[2]; + ParamDef->init("particleRadius", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("gameScale", "true", true); + HintTable[1].init("min", uint64_t(0), true); + ParamDefTable[2].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#else + + static HintImpl HintTable[4]; + static Hint* HintPtrTable[4] = { &HintTable[0], &HintTable[1], &HintTable[2], &HintTable[3], }; + HintTable[0].init("gameScale", "true", true); + HintTable[1].init("longDescription", "\nRadius of a particle.\n", true); + HintTable[2].init("min", uint64_t(0), true); + HintTable[3].init("shortDescription", "Radius of a particle", true); + ParamDefTable[2].setHints((const NvParameterized::Hint**)HintPtrTable, 4); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=3, longName="maxParticleCount" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[3]; + ParamDef->init("maxParticleCount", TYPE_U32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("min", uint64_t(0), true); + ParamDefTable[3].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("min", uint64_t(0), true); + HintTable[1].init("shortDescription", "Maximum particle count", true); + ParamDefTable[3].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=4, longName="maxInjectedParticleCount" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[4]; + ParamDef->init("maxInjectedParticleCount", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("min", uint64_t(0), true); + ParamDefTable[4].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[3]; + static Hint* HintPtrTable[3] = { &HintTable[0], &HintTable[1], &HintTable[2], }; + HintTable[0].init("longDescription", "\nThe maximum number of new particles to be spawned on each frame. Use values >1 to provide the absolute value,\nor 0 <= x <= 1 to provide the percentage rate to overall number of particles. \n", true); + HintTable[1].init("min", uint64_t(0), true); + HintTable[2].init("shortDescription", "Maximum number of newly created particles on each frame", true); + ParamDefTable[4].setHints((const NvParameterized::Hint**)HintPtrTable, 3); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=5, longName="maxCollidingObjects" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[5]; + ParamDef->init("maxCollidingObjects", TYPE_U32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("min", uint64_t(1), true); + ParamDefTable[5].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[3]; + static Hint* HintPtrTable[3] = { &HintTable[0], &HintTable[1], &HintTable[2], }; + HintTable[0].init("longDescription", "Maximum number of objects that are able to collide with each other (boxes, spheres, capsules, hspaces, convexmeshes, trimeshes).\n", true); + HintTable[1].init("min", uint64_t(1), true); + HintTable[2].init("shortDescription", "Maximum number of particles that are able to collide with each other.", true); + ParamDefTable[5].setHints((const NvParameterized::Hint**)HintPtrTable, 3); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=6, longName="sceneGravityScale" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[6]; + ParamDef->init("sceneGravityScale", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("min", uint64_t(0), true); + ParamDefTable[6].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("min", uint64_t(0), true); + HintTable[1].init("shortDescription", "Used to scale, or even disable the basic IOS's gravity", true); + ParamDefTable[6].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=7, longName="externalAcceleration" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[7]; + ParamDef->init("externalAcceleration", TYPE_VEC3, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("gameScale", "true", true); + ParamDefTable[7].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("gameScale", "true", true); + HintTable[1].init("shortDescription", "Acceleration (m/s^2) applied to all particles at all time steps (added to the scaled scene gravity).", true); + ParamDefTable[7].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=8, longName="particleMass" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[8]; + ParamDef->init("particleMass", TYPE_STRUCT, "RandomF32", true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("longDescription", "Defines parameters of probability distribution of particle masses.\n", true); + HintTable[1].init("shortDescription", "Probability distribution of particle masses for this IOS.", true); + ParamDefTable[8].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=9, longName="particleMass.center" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[9]; + ParamDef->init("center", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Center of distribution", true); + ParamDefTable[9].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=10, longName="particleMass.spread" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[10]; + ParamDef->init("spread", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("longDescription", "Spread is std deviation for normal distribution or halfwidth for uniform distribution.\n", true); + HintTable[1].init("shortDescription", "Spread of distribution", true); + ParamDefTable[10].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=11, longName="particleMass.type" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[11]; + ParamDef->init("type", TYPE_ENUM, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("longDescription", "Type of probability distribution (currently only normal and uniform are supported).\n", true); + HintTable[1].init("shortDescription", "Distribution type", true); + ParamDefTable[11].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + static const char* const EnumVals[] = { "uniform", "normal" }; + ParamDefTable[11].setEnumVals((const char**)EnumVals, 2); + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=12, longName="collisionFilterDataName" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[12]; + ParamDef->init("collisionFilterDataName", TYPE_STRING, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("HIDDEN", uint64_t(1), true); + ParamDefTable[12].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("HIDDEN", uint64_t(1), true); + HintTable[1].init("shortDescription", "The filter data (group/groupsMask) name for IOS vs PhysX interaction.", true); + ParamDefTable[12].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=13, longName="fieldSamplerFilterDataName" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[13]; + ParamDef->init("fieldSamplerFilterDataName", TYPE_STRING, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "The filter data name for IOS vs FieldSampler interaction.", true); + ParamDefTable[13].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=14, longName="staticCollision" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[14]; + ParamDef->init("staticCollision", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("defaultValue", uint64_t(1), true); + ParamDefTable[14].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("defaultValue", uint64_t(1), true); + HintTable[1].init("shortDescription", "Enables collision with static shapes", true); + ParamDefTable[14].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=15, longName="restitutionForStaticShapes" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[15]; + ParamDef->init("restitutionForStaticShapes", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[3]; + static Hint* HintPtrTable[3] = { &HintTable[0], &HintTable[1], &HintTable[2], }; + HintTable[0].init("defaultValue", double(0.5), true); + HintTable[1].init("max", uint64_t(1), true); + HintTable[2].init("min", uint64_t(0), true); + ParamDefTable[15].setHints((const NvParameterized::Hint**)HintPtrTable, 3); + +#else + + static HintImpl HintTable[4]; + static Hint* HintPtrTable[4] = { &HintTable[0], &HintTable[1], &HintTable[2], &HintTable[3], }; + HintTable[0].init("defaultValue", double(0.5), true); + HintTable[1].init("max", uint64_t(1), true); + HintTable[2].init("min", uint64_t(0), true); + HintTable[3].init("shortDescription", "Defines the restitution coefficient used for collisions with static shapes.", true); + ParamDefTable[15].setHints((const NvParameterized::Hint**)HintPtrTable, 4); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=16, longName="dynamicCollision" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[16]; + ParamDef->init("dynamicCollision", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("defaultValue", uint64_t(1), true); + ParamDefTable[16].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("defaultValue", uint64_t(1), true); + HintTable[1].init("shortDescription", "Enables collision with dynamic shapes", true); + ParamDefTable[16].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=17, longName="restitutionForDynamicShapes" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[17]; + ParamDef->init("restitutionForDynamicShapes", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[3]; + static Hint* HintPtrTable[3] = { &HintTable[0], &HintTable[1], &HintTable[2], }; + HintTable[0].init("defaultValue", double(0.5), true); + HintTable[1].init("max", uint64_t(1), true); + HintTable[2].init("min", uint64_t(0), true); + ParamDefTable[17].setHints((const NvParameterized::Hint**)HintPtrTable, 3); + +#else + + static HintImpl HintTable[4]; + static Hint* HintPtrTable[4] = { &HintTable[0], &HintTable[1], &HintTable[2], &HintTable[3], }; + HintTable[0].init("defaultValue", double(0.5), true); + HintTable[1].init("max", uint64_t(1), true); + HintTable[2].init("min", uint64_t(0), true); + HintTable[3].init("shortDescription", "Defines the restitution coefficient used for collisions with dynamic shapes.", true); + ParamDefTable[17].setHints((const NvParameterized::Hint**)HintPtrTable, 4); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=18, longName="collisionDistanceMultiplier" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[18]; + ParamDef->init("collisionDistanceMultiplier", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("min", uint64_t(0), true); + ParamDefTable[18].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("min", uint64_t(0), true); + HintTable[1].init("shortDescription", "Defines the distance (= collisionDistanceMultiplier*particleRadius) between particles and collision geometry, which is maintained during simulation.", true); + ParamDefTable[18].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=19, longName="collisionThreshold" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[19]; + ParamDef->init("collisionThreshold", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("gameScale", "true", true); + HintTable[1].init("min", uint64_t(0), true); + ParamDefTable[19].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#else + + static HintImpl HintTable[3]; + static Hint* HintPtrTable[3] = { &HintTable[0], &HintTable[1], &HintTable[2], }; + HintTable[0].init("gameScale", "true", true); + HintTable[1].init("min", uint64_t(0), true); + HintTable[2].init("shortDescription", "Defines the threshold for collision between particles and collision geometry, inside this threshold collision contact is generated without a response.", true); + ParamDefTable[19].setHints((const NvParameterized::Hint**)HintPtrTable, 3); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=20, longName="collisionWithConvex" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[20]; + ParamDef->init("collisionWithConvex", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("defaultValue", uint64_t(1), true); + ParamDefTable[20].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("defaultValue", uint64_t(1), true); + HintTable[1].init("shortDescription", "Enables collision with convex shapes", true); + ParamDefTable[20].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=21, longName="collisionWithTriangleMesh" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[21]; + ParamDef->init("collisionWithTriangleMesh", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("defaultValue", uint64_t(0), true); + ParamDefTable[21].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("defaultValue", uint64_t(0), true); + HintTable[1].init("shortDescription", "Enables collision with triangle mesh shapes", true); + ParamDefTable[21].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=22, longName="GridDensity" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[22]; + ParamDef->init("GridDensity", TYPE_STRUCT, "GridDensityParams", true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("longDescription", "Settings for Density Grid\n", true); + HintTable[1].init("shortDescription", "Settings for Density Grid", true); + ParamDefTable[22].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=23, longName="GridDensity.Enabled" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[23]; + ParamDef->init("Enabled", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("longDescription", "If this option is true; density will be computed based on the grouping of particles in a 3d grid\n", true); + HintTable[1].init("shortDescription", "Compute Density Using a Grid", true); + ParamDefTable[23].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=24, longName="GridDensity.Resolution" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[24]; + ParamDef->init("Resolution", TYPE_ENUM, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("longDescription", "This enumeration defines the 3d resolution of the grid.\n", true); + HintTable[1].init("shortDescription", "Number of cells in a 3D grid, used to calculate particles positions. Higher values divide the grid into more cells.", true); + ParamDefTable[24].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + static const char* const EnumVals[] = { "GDG_8", "GDG_16", "GDG_32", "GDG_64", "GDG_128", "GDG_256" }; + ParamDefTable[24].setEnumVals((const char**)EnumVals, 6); + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=25, longName="GridDensity.GridSize" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[25]; + ParamDef->init("GridSize", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("DISPLAY_NAME", "Grid Depth", true); + HintTable[1].init("min", uint64_t(0), true); + ParamDefTable[25].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#else + + static HintImpl HintTable[4]; + static Hint* HintPtrTable[4] = { &HintTable[0], &HintTable[1], &HintTable[2], &HintTable[3], }; + HintTable[0].init("DISPLAY_NAME", "Grid Depth", true); + HintTable[1].init("longDescription", "The default value is a 10 units\nMust be positive.\n", true); + HintTable[2].init("min", uint64_t(0), true); + HintTable[3].init("shortDescription", "Depth of grid.", true); + ParamDefTable[25].setHints((const NvParameterized::Hint**)HintPtrTable, 4); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=26, longName="GridDensity.MaxCellCount" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[26]; + ParamDef->init("MaxCellCount", TYPE_U32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("min", uint64_t(0), true); + ParamDefTable[26].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[3]; + static Hint* HintPtrTable[3] = { &HintTable[0], &HintTable[1], &HintTable[2], }; + HintTable[0].init("longDescription", "This is the integer count representing how many particles reside in a single grid cell before the density is considered 1.\nIt is valid for the density to be greater than one. For example, if there were 32 particles in a grid cell with a max-cell count of\n16, then the density would be equal to 2.\n", true); + HintTable[1].init("min", uint64_t(0), true); + HintTable[2].init("shortDescription", "This is the number of particles within a gridcell for a density of 1", true); + ParamDefTable[26].setHints((const NvParameterized::Hint**)HintPtrTable, 3); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=27, longName="enableTemperatureBuffer" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[27]; + ParamDef->init("enableTemperatureBuffer", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("defaultValue", uint64_t(0), true); + ParamDefTable[27].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("defaultValue", uint64_t(0), true); + HintTable[1].init("shortDescription", "Enables temperature buffer.", true); + ParamDefTable[27].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=28, longName="enableDensityBuffer" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[28]; + ParamDef->init("enableDensityBuffer", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("defaultValue", uint64_t(0), true); + ParamDefTable[28].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("defaultValue", uint64_t(0), true); + HintTable[1].init("shortDescription", "Enables density buffer.", true); + ParamDefTable[28].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=29, longName="enableCouplingOverride" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[29]; + ParamDef->init("enableCouplingOverride", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("defaultValue", uint64_t(0), true); + ParamDefTable[29].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#else + + static HintImpl HintTable[2]; + static Hint* HintPtrTable[2] = { &HintTable[0], &HintTable[1], }; + HintTable[0].init("defaultValue", uint64_t(0), true); + HintTable[1].init("shortDescription", "If true, IOS coupling settings are used. If false, dynamic grid coupling settings are used.", true); + ParamDefTable[29].setHints((const NvParameterized::Hint**)HintPtrTable, 2); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=30, longName="particleToGridCoupling" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[30]; + ParamDef->init("particleToGridCoupling", TYPE_STRUCT, "ParticleToGridCouplingParams", true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Settings for particle to grid coupling", true); + ParamDefTable[30].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=31, longName="particleToGridCoupling.accelTimeConstant" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[31]; + ParamDef->init("accelTimeConstant", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Controls rate at which the grid accepts influence from particles. A value of 0 means instant coupling.", true); + ParamDefTable[31].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=32, longName="particleToGridCoupling.decelTimeConstant" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[32]; + ParamDef->init("decelTimeConstant", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Controls rate at which the grid accepts influence from particles. A value of 0 means instant coupling.", true); + ParamDefTable[32].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=33, longName="particleToGridCoupling.thresholdMultiplier" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[33]; + ParamDef->init("thresholdMultiplier", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "A value greater than 1 creates a deadzone, where no particle to grid coupling occurs.", true); + ParamDefTable[33].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=34, longName="gridToParticleCoupling" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[34]; + ParamDef->init("gridToParticleCoupling", TYPE_STRUCT, "GridToParticleCouplingParams", true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Settings for grid to particle coupling", true); + ParamDefTable[34].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=35, longName="gridToParticleCoupling.accelTimeConstant" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[35]; + ParamDef->init("accelTimeConstant", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Controls rate at which particles accept influence from the grid. A value of 0 means instant coupling.", true); + ParamDefTable[35].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=36, longName="gridToParticleCoupling.decelTimeConstant" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[36]; + ParamDef->init("decelTimeConstant", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Controls rate at which particles accept influence from the grid. A value of 0 means instant coupling.", true); + ParamDefTable[36].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=37, longName="gridToParticleCoupling.thresholdMultiplier" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[37]; + ParamDef->init("thresholdMultiplier", TYPE_F32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "A value greater than 1 creates a deadzone, where no grid to particle coupling occurs.", true); + ParamDefTable[37].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // SetChildren for: nodeIndex=0, longName="" + { + static Definition* Children[24]; + Children[0] = PDEF_PTR(1); + Children[1] = PDEF_PTR(2); + Children[2] = PDEF_PTR(3); + Children[3] = PDEF_PTR(4); + Children[4] = PDEF_PTR(5); + Children[5] = PDEF_PTR(6); + Children[6] = PDEF_PTR(7); + Children[7] = PDEF_PTR(8); + Children[8] = PDEF_PTR(12); + Children[9] = PDEF_PTR(13); + Children[10] = PDEF_PTR(14); + Children[11] = PDEF_PTR(15); + Children[12] = PDEF_PTR(16); + Children[13] = PDEF_PTR(17); + Children[14] = PDEF_PTR(18); + Children[15] = PDEF_PTR(19); + Children[16] = PDEF_PTR(20); + Children[17] = PDEF_PTR(21); + Children[18] = PDEF_PTR(22); + Children[19] = PDEF_PTR(27); + Children[20] = PDEF_PTR(28); + Children[21] = PDEF_PTR(29); + Children[22] = PDEF_PTR(30); + Children[23] = PDEF_PTR(34); + + ParamDefTable[0].setChildren(Children, 24); + } + + // SetChildren for: nodeIndex=8, longName="particleMass" + { + static Definition* Children[3]; + Children[0] = PDEF_PTR(9); + Children[1] = PDEF_PTR(10); + Children[2] = PDEF_PTR(11); + + ParamDefTable[8].setChildren(Children, 3); + } + + // SetChildren for: nodeIndex=22, longName="GridDensity" + { + static Definition* Children[4]; + Children[0] = PDEF_PTR(23); + Children[1] = PDEF_PTR(24); + Children[2] = PDEF_PTR(25); + Children[3] = PDEF_PTR(26); + + ParamDefTable[22].setChildren(Children, 4); + } + + // SetChildren for: nodeIndex=30, longName="particleToGridCoupling" + { + static Definition* Children[3]; + Children[0] = PDEF_PTR(31); + Children[1] = PDEF_PTR(32); + Children[2] = PDEF_PTR(33); + + ParamDefTable[30].setChildren(Children, 3); + } + + // SetChildren for: nodeIndex=34, longName="gridToParticleCoupling" + { + static Definition* Children[3]; + Children[0] = PDEF_PTR(35); + Children[1] = PDEF_PTR(36); + Children[2] = PDEF_PTR(37); + + ParamDefTable[34].setChildren(Children, 3); + } + + mBuiltFlag = true; + +} +void BasicIOSAssetParam::initStrings(void) +{ + collisionFilterDataName.isAllocated = true; + collisionFilterDataName.buf = NULL; + fieldSamplerFilterDataName.isAllocated = true; + fieldSamplerFilterDataName.buf = NULL; +} + +void BasicIOSAssetParam::initDynamicArrays(void) +{ +} + +void BasicIOSAssetParam::initDefaults(void) +{ + + freeStrings(); + freeReferences(); + freeDynamicArrays(); + restDensity = float(0); + particleRadius = float(1); + maxParticleCount = uint32_t(16384); + maxInjectedParticleCount = float(0.1); + maxCollidingObjects = uint32_t(32); + sceneGravityScale = float(1); + externalAcceleration = physx::PxVec3(init(0, 0, 0)); + particleMass.center = float(0); + particleMass.spread = float(0); + particleMass.type = (const char*)"uniform"; + + particleMass.center = 1.0f; + + staticCollision = bool(1); + restitutionForStaticShapes = float(0.5f); + dynamicCollision = bool(1); + restitutionForDynamicShapes = float(0.5f); + collisionDistanceMultiplier = float(1.0f); + collisionThreshold = float(0.001f); + collisionWithConvex = bool(1); + collisionWithTriangleMesh = bool(0); + GridDensity.Enabled = bool(0); + GridDensity.Resolution = (const char*)"GDG_16"; + GridDensity.GridSize = float(10); + GridDensity.MaxCellCount = uint32_t(16); + enableTemperatureBuffer = bool(0); + enableDensityBuffer = bool(0); + enableCouplingOverride = bool(0); + particleToGridCoupling.accelTimeConstant = float(0.01); + particleToGridCoupling.decelTimeConstant = float(10); + particleToGridCoupling.thresholdMultiplier = float(2); + gridToParticleCoupling.accelTimeConstant = float(0.01); + gridToParticleCoupling.decelTimeConstant = float(0.01); + gridToParticleCoupling.thresholdMultiplier = float(1); + + initDynamicArrays(); + initStrings(); + initReferences(); +} + +void BasicIOSAssetParam::initReferences(void) +{ +} + +void BasicIOSAssetParam::freeDynamicArrays(void) +{ +} + +void BasicIOSAssetParam::freeStrings(void) +{ + + if (collisionFilterDataName.isAllocated && collisionFilterDataName.buf) + { + mParameterizedTraits->strfree((char*)collisionFilterDataName.buf); + } + + if (fieldSamplerFilterDataName.isAllocated && fieldSamplerFilterDataName.buf) + { + mParameterizedTraits->strfree((char*)fieldSamplerFilterDataName.buf); + } +} + +void BasicIOSAssetParam::freeReferences(void) +{ +} + +} // namespace basicios +} // namespace nvidia diff --git a/APEX_1.4/module/basicios/src/autogen/BasicIosDebugRenderParams.cpp b/APEX_1.4/module/basicios/src/autogen/BasicIosDebugRenderParams.cpp new file mode 100644 index 00000000..beafae10 --- /dev/null +++ b/APEX_1.4/module/basicios/src/autogen/BasicIosDebugRenderParams.cpp @@ -0,0 +1,358 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2015 NVIDIA Corporation. All rights reserved. + +// This file was generated by NvParameterized/scripts/GenParameterized.pl + + +#include "BasicIosDebugRenderParams.h" +#include <string.h> +#include <stdlib.h> + +using namespace NvParameterized; + +namespace nvidia +{ +namespace basicios +{ + +using namespace BasicIosDebugRenderParamsNS; + +const char* const BasicIosDebugRenderParamsFactory::vptr = + NvParameterized::getVptr<BasicIosDebugRenderParams, BasicIosDebugRenderParams::ClassAlignment>(); + +const uint32_t NumParamDefs = 4; +static NvParameterized::DefinitionImpl* ParamDefTable; // now allocated in buildTree [NumParamDefs]; + + +static const size_t ParamLookupChildrenTable[] = +{ + 1, 2, 3, +}; + +#define TENUM(type) nvidia::##type +#define CHILDREN(index) &ParamLookupChildrenTable[index] +static const NvParameterized::ParamLookupNode ParamLookupTable[NumParamDefs] = +{ + { TYPE_STRUCT, false, 0, CHILDREN(0), 3 }, + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->VISUALIZE_BASIC_IOS_ACTOR), NULL, 0 }, // VISUALIZE_BASIC_IOS_ACTOR + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->VISUALIZE_BASIC_IOS_COLLIDE_SHAPES), NULL, 0 }, // VISUALIZE_BASIC_IOS_COLLIDE_SHAPES + { TYPE_BOOL, false, (size_t)(&((ParametersStruct*)0)->VISUALIZE_BASIC_IOS_GRID_DENSITY), NULL, 0 }, // VISUALIZE_BASIC_IOS_GRID_DENSITY +}; + + +bool BasicIosDebugRenderParams::mBuiltFlag = false; +NvParameterized::MutexType BasicIosDebugRenderParams::mBuiltFlagMutex; + +BasicIosDebugRenderParams::BasicIosDebugRenderParams(NvParameterized::Traits* traits, void* buf, int32_t* refCount) : + NvParameters(traits, buf, refCount) +{ + //mParameterizedTraits->registerFactory(className(), &BasicIosDebugRenderParamsFactoryInst); + + if (!buf) //Do not init data if it is inplace-deserialized + { + initDynamicArrays(); + initStrings(); + initReferences(); + initDefaults(); + } +} + +BasicIosDebugRenderParams::~BasicIosDebugRenderParams() +{ + freeStrings(); + freeReferences(); + freeDynamicArrays(); +} + +void BasicIosDebugRenderParams::destroy() +{ + // We cache these fields here to avoid overwrite in destructor + bool doDeallocateSelf = mDoDeallocateSelf; + NvParameterized::Traits* traits = mParameterizedTraits; + int32_t* refCount = mRefCount; + void* buf = mBuffer; + + this->~BasicIosDebugRenderParams(); + + NvParameters::destroy(this, traits, doDeallocateSelf, refCount, buf); +} + +const NvParameterized::DefinitionImpl* BasicIosDebugRenderParams::getParameterDefinitionTree(void) +{ + if (!mBuiltFlag) // Double-checked lock + { + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + if (!mBuiltFlag) + { + buildTree(); + } + } + + return(&ParamDefTable[0]); +} + +const NvParameterized::DefinitionImpl* BasicIosDebugRenderParams::getParameterDefinitionTree(void) const +{ + BasicIosDebugRenderParams* tmpParam = const_cast<BasicIosDebugRenderParams*>(this); + + if (!mBuiltFlag) // Double-checked lock + { + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + if (!mBuiltFlag) + { + tmpParam->buildTree(); + } + } + + return(&ParamDefTable[0]); +} + +NvParameterized::ErrorType BasicIosDebugRenderParams::getParameterHandle(const char* long_name, Handle& handle) const +{ + ErrorType Ret = NvParameters::getParameterHandle(long_name, handle); + if (Ret != ERROR_NONE) + { + return(Ret); + } + + size_t offset; + void* ptr; + + getVarPtr(handle, ptr, offset); + + if (ptr == NULL) + { + return(ERROR_INDEX_OUT_OF_RANGE); + } + + return(ERROR_NONE); +} + +NvParameterized::ErrorType BasicIosDebugRenderParams::getParameterHandle(const char* long_name, Handle& handle) +{ + ErrorType Ret = NvParameters::getParameterHandle(long_name, handle); + if (Ret != ERROR_NONE) + { + return(Ret); + } + + size_t offset; + void* ptr; + + getVarPtr(handle, ptr, offset); + + if (ptr == NULL) + { + return(ERROR_INDEX_OUT_OF_RANGE); + } + + return(ERROR_NONE); +} + +void BasicIosDebugRenderParams::getVarPtr(const Handle& handle, void*& ptr, size_t& offset) const +{ + ptr = getVarPtrHelper(&ParamLookupTable[0], const_cast<BasicIosDebugRenderParams::ParametersStruct*>(¶meters()), handle, offset); +} + + +/* Dynamic Handle Indices */ + +void BasicIosDebugRenderParams::freeParameterDefinitionTable(NvParameterized::Traits* traits) +{ + if (!traits) + { + return; + } + + if (!mBuiltFlag) // Double-checked lock + { + return; + } + + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + + if (!mBuiltFlag) + { + return; + } + + for (uint32_t i = 0; i < NumParamDefs; ++i) + { + ParamDefTable[i].~DefinitionImpl(); + } + + traits->free(ParamDefTable); + + mBuiltFlag = false; +} + +#define PDEF_PTR(index) (&ParamDefTable[index]) + +void BasicIosDebugRenderParams::buildTree(void) +{ + + uint32_t allocSize = sizeof(NvParameterized::DefinitionImpl) * NumParamDefs; + ParamDefTable = (NvParameterized::DefinitionImpl*)(mParameterizedTraits->alloc(allocSize)); + memset(ParamDefTable, 0, allocSize); + + for (uint32_t i = 0; i < NumParamDefs; ++i) + { + NV_PARAM_PLACEMENT_NEW(ParamDefTable + i, NvParameterized::DefinitionImpl)(*mParameterizedTraits); + } + + // Initialize DefinitionImpl node: nodeIndex=0, longName="" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[0]; + ParamDef->init("", TYPE_STRUCT, "STRUCT", true); + + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=1, longName="VISUALIZE_BASIC_IOS_ACTOR" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[1]; + ParamDef->init("VISUALIZE_BASIC_IOS_ACTOR", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Render the IOS Actor in view window", true); + ParamDefTable[1].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=2, longName="VISUALIZE_BASIC_IOS_COLLIDE_SHAPES" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[2]; + ParamDef->init("VISUALIZE_BASIC_IOS_COLLIDE_SHAPES", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Render the IOS collision shapes in view window", true); + ParamDefTable[2].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=3, longName="VISUALIZE_BASIC_IOS_GRID_DENSITY" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[3]; + ParamDef->init("VISUALIZE_BASIC_IOS_GRID_DENSITY", TYPE_BOOL, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "Render the IOS Grid Density in the view window", true); + ParamDefTable[3].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // SetChildren for: nodeIndex=0, longName="" + { + static Definition* Children[3]; + Children[0] = PDEF_PTR(1); + Children[1] = PDEF_PTR(2); + Children[2] = PDEF_PTR(3); + + ParamDefTable[0].setChildren(Children, 3); + } + + mBuiltFlag = true; + +} +void BasicIosDebugRenderParams::initStrings(void) +{ +} + +void BasicIosDebugRenderParams::initDynamicArrays(void) +{ +} + +void BasicIosDebugRenderParams::initDefaults(void) +{ + + freeStrings(); + freeReferences(); + freeDynamicArrays(); + VISUALIZE_BASIC_IOS_ACTOR = bool(true); + VISUALIZE_BASIC_IOS_COLLIDE_SHAPES = bool(false); + VISUALIZE_BASIC_IOS_GRID_DENSITY = bool(false); + + initDynamicArrays(); + initStrings(); + initReferences(); +} + +void BasicIosDebugRenderParams::initReferences(void) +{ +} + +void BasicIosDebugRenderParams::freeDynamicArrays(void) +{ +} + +void BasicIosDebugRenderParams::freeStrings(void) +{ +} + +void BasicIosDebugRenderParams::freeReferences(void) +{ +} + +} // namespace basicios +} // namespace nvidia diff --git a/APEX_1.4/module/basicios/src/autogen/BasicIosModuleParameters.cpp b/APEX_1.4/module/basicios/src/autogen/BasicIosModuleParameters.cpp new file mode 100644 index 00000000..618171a5 --- /dev/null +++ b/APEX_1.4/module/basicios/src/autogen/BasicIosModuleParameters.cpp @@ -0,0 +1,318 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2015 NVIDIA Corporation. All rights reserved. + +// This file was generated by NvParameterized/scripts/GenParameterized.pl + + +#include "BasicIosModuleParameters.h" +#include <string.h> +#include <stdlib.h> + +using namespace NvParameterized; + +namespace nvidia +{ +namespace basicios +{ + +using namespace BasicIosModuleParametersNS; + +const char* const BasicIosModuleParametersFactory::vptr = + NvParameterized::getVptr<BasicIosModuleParameters, BasicIosModuleParameters::ClassAlignment>(); + +const uint32_t NumParamDefs = 2; +static NvParameterized::DefinitionImpl* ParamDefTable; // now allocated in buildTree [NumParamDefs]; + + +static const size_t ParamLookupChildrenTable[] = +{ + 1, +}; + +#define TENUM(type) nvidia::##type +#define CHILDREN(index) &ParamLookupChildrenTable[index] +static const NvParameterized::ParamLookupNode ParamLookupTable[NumParamDefs] = +{ + { TYPE_STRUCT, false, 0, CHILDREN(0), 1 }, + { TYPE_U32, false, (size_t)(&((ParametersStruct*)0)->unused), NULL, 0 }, // unused +}; + + +bool BasicIosModuleParameters::mBuiltFlag = false; +NvParameterized::MutexType BasicIosModuleParameters::mBuiltFlagMutex; + +BasicIosModuleParameters::BasicIosModuleParameters(NvParameterized::Traits* traits, void* buf, int32_t* refCount) : + NvParameters(traits, buf, refCount) +{ + //mParameterizedTraits->registerFactory(className(), &BasicIosModuleParametersFactoryInst); + + if (!buf) //Do not init data if it is inplace-deserialized + { + initDynamicArrays(); + initStrings(); + initReferences(); + initDefaults(); + } +} + +BasicIosModuleParameters::~BasicIosModuleParameters() +{ + freeStrings(); + freeReferences(); + freeDynamicArrays(); +} + +void BasicIosModuleParameters::destroy() +{ + // We cache these fields here to avoid overwrite in destructor + bool doDeallocateSelf = mDoDeallocateSelf; + NvParameterized::Traits* traits = mParameterizedTraits; + int32_t* refCount = mRefCount; + void* buf = mBuffer; + + this->~BasicIosModuleParameters(); + + NvParameters::destroy(this, traits, doDeallocateSelf, refCount, buf); +} + +const NvParameterized::DefinitionImpl* BasicIosModuleParameters::getParameterDefinitionTree(void) +{ + if (!mBuiltFlag) // Double-checked lock + { + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + if (!mBuiltFlag) + { + buildTree(); + } + } + + return(&ParamDefTable[0]); +} + +const NvParameterized::DefinitionImpl* BasicIosModuleParameters::getParameterDefinitionTree(void) const +{ + BasicIosModuleParameters* tmpParam = const_cast<BasicIosModuleParameters*>(this); + + if (!mBuiltFlag) // Double-checked lock + { + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + if (!mBuiltFlag) + { + tmpParam->buildTree(); + } + } + + return(&ParamDefTable[0]); +} + +NvParameterized::ErrorType BasicIosModuleParameters::getParameterHandle(const char* long_name, Handle& handle) const +{ + ErrorType Ret = NvParameters::getParameterHandle(long_name, handle); + if (Ret != ERROR_NONE) + { + return(Ret); + } + + size_t offset; + void* ptr; + + getVarPtr(handle, ptr, offset); + + if (ptr == NULL) + { + return(ERROR_INDEX_OUT_OF_RANGE); + } + + return(ERROR_NONE); +} + +NvParameterized::ErrorType BasicIosModuleParameters::getParameterHandle(const char* long_name, Handle& handle) +{ + ErrorType Ret = NvParameters::getParameterHandle(long_name, handle); + if (Ret != ERROR_NONE) + { + return(Ret); + } + + size_t offset; + void* ptr; + + getVarPtr(handle, ptr, offset); + + if (ptr == NULL) + { + return(ERROR_INDEX_OUT_OF_RANGE); + } + + return(ERROR_NONE); +} + +void BasicIosModuleParameters::getVarPtr(const Handle& handle, void*& ptr, size_t& offset) const +{ + ptr = getVarPtrHelper(&ParamLookupTable[0], const_cast<BasicIosModuleParameters::ParametersStruct*>(¶meters()), handle, offset); +} + + +/* Dynamic Handle Indices */ + +void BasicIosModuleParameters::freeParameterDefinitionTable(NvParameterized::Traits* traits) +{ + if (!traits) + { + return; + } + + if (!mBuiltFlag) // Double-checked lock + { + return; + } + + NvParameterized::MutexType::ScopedLock lock(mBuiltFlagMutex); + + if (!mBuiltFlag) + { + return; + } + + for (uint32_t i = 0; i < NumParamDefs; ++i) + { + ParamDefTable[i].~DefinitionImpl(); + } + + traits->free(ParamDefTable); + + mBuiltFlag = false; +} + +#define PDEF_PTR(index) (&ParamDefTable[index]) + +void BasicIosModuleParameters::buildTree(void) +{ + + uint32_t allocSize = sizeof(NvParameterized::DefinitionImpl) * NumParamDefs; + ParamDefTable = (NvParameterized::DefinitionImpl*)(mParameterizedTraits->alloc(allocSize)); + memset(ParamDefTable, 0, allocSize); + + for (uint32_t i = 0; i < NumParamDefs; ++i) + { + NV_PARAM_PLACEMENT_NEW(ParamDefTable + i, NvParameterized::DefinitionImpl)(*mParameterizedTraits); + } + + // Initialize DefinitionImpl node: nodeIndex=0, longName="" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[0]; + ParamDef->init("", TYPE_STRUCT, "STRUCT", true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "This class is used for initializing the ModuleBasicIos.", true); + ParamDefTable[0].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // Initialize DefinitionImpl node: nodeIndex=1, longName="unused" + { + NvParameterized::DefinitionImpl* ParamDef = &ParamDefTable[1]; + ParamDef->init("unused", TYPE_U32, NULL, true); + +#ifdef NV_PARAMETERIZED_HIDE_DESCRIPTIONS + +#else + + static HintImpl HintTable[1]; + static Hint* HintPtrTable[1] = { &HintTable[0], }; + HintTable[0].init("shortDescription", "No parameters necessary", true); + ParamDefTable[1].setHints((const NvParameterized::Hint**)HintPtrTable, 1); + +#endif /* NV_PARAMETERIZED_HIDE_DESCRIPTIONS */ + + + + + + } + + // SetChildren for: nodeIndex=0, longName="" + { + static Definition* Children[1]; + Children[0] = PDEF_PTR(1); + + ParamDefTable[0].setChildren(Children, 1); + } + + mBuiltFlag = true; + +} +void BasicIosModuleParameters::initStrings(void) +{ +} + +void BasicIosModuleParameters::initDynamicArrays(void) +{ +} + +void BasicIosModuleParameters::initDefaults(void) +{ + + freeStrings(); + freeReferences(); + freeDynamicArrays(); + unused = uint32_t(0); + + initDynamicArrays(); + initStrings(); + initReferences(); +} + +void BasicIosModuleParameters::initReferences(void) +{ +} + +void BasicIosModuleParameters::freeDynamicArrays(void) +{ +} + +void BasicIosModuleParameters::freeStrings(void) +{ +} + +void BasicIosModuleParameters::freeReferences(void) +{ +} + +} // namespace basicios +} // namespace nvidia |