void ClothingScene::setSceneRunning(bool on)
{
#ifndef _DEBUG
	PxI32 newValue;
	if (on)
	{
		APEX_CHECK_STAT_TIMER("--------- Start ClothingSimulationTime");
		mClothingSimulationTime.getElapsedSeconds();

		newValue = shdfnd::atomicIncrement(&mSceneRunning);
	}
	else
	{
		ApexStatValue dataVal;
		dataVal.Float = (PxF32)(1000.0f * mClothingSimulationTime.getElapsedSeconds());
		APEX_CHECK_STAT_TIMER("--------- Stop ClothingSimulationTime");
		mApexScene->setApexStatValue(NiApexScene::ClothingSimulationTime, dataVal);

		// Warn if simulation time was bigger than timestep for 10 or more consecutive frames
		PxF32 simulatedTime = 1000.0f * mApexScene->getElapsedTime();
		if (simulatedTime < dataVal.Float)
		{
			mFramesCount++;
			mSimulatedTime	+= simulatedTime;
			mTimestep		+= dataVal.Float;
		}

		if (mFramesCount >= 10)
		{
			float averageSimulatedTime = mSimulatedTime / (PxF32)mFramesCount;
			float averageTimestep = mTimestep / (PxF32)mFramesCount;
			APEX_DEBUG_WARNING("Cloth complexity in scene is too high to be simulated in real time for 10 consecutive frames. (Average Delta Time: %f ms, Average Simulation Time: %f ms)", 
								averageSimulatedTime, averageTimestep);
			mFramesCount	= 0;
			mSimulatedTime	= 0.f;
			mTimestep		= 0.f;
		}

		newValue = shdfnd::atomicDecrement(&mSceneRunning);
	}

	if (newValue != (on ? 1 : 0))
	{
		APEX_INTERNAL_ERROR("scene running state was not tracked properly!: on = %s, prevValue = %d", on ? "true" : "false", newValue);
	}
#else
	PX_UNUSED(on);
#endif
}
示例#2
0
ReadCheck::~ReadCheck()
{
	if (NxGetApexSDK()->isConcurrencyCheckEnabled() && mLockable)
	{
		// By checking if the NpScene::mConcurrentErrorCount has been incremented
		// we can detect if an erroneous read/write was performed during 
		// this objects lifetime. In this case we also print this function's
		// details so that the user can see which two API calls overlapped
		if (mLockable->getReadWriteErrorCount() != mErrorCount && !mLockable->isEnabled())
		{
			APEX_INTERNAL_ERROR("Leaving %s on thread %d, an API overlapping write on another thread was detected.", mName, PxU32(physx::shdfnd::Thread::getId()));
		}

		mLockable->stopRead();
	}
}
示例#3
0
ReadCheck::ReadCheck(const ApexRWLockable* scene, const char* functionName)
	: mLockable(scene), mName(functionName), mErrorCount(0)
{
	if (NxGetApexSDK()->isConcurrencyCheckEnabled() && mLockable && !mLockable->isEnabled())
	{
		if (!mLockable->startRead() && !mLockable->isEnabled())
		{
			APEX_INTERNAL_ERROR("An API read call (%s) was made from thread %d but acquireReadLock() was not called first, note that "
				"when NxApexSDKDesc::enableConcurrencyCheck is enabled all API reads and writes must be "
				"wrapped in the appropriate locks.", mName, PxU32(physx::shdfnd::Thread::getId()));
		}

		// Record the NpScene read/write error counter which is
		// incremented any time a NpScene::startWrite/startRead fails
		// (see destructor for additional error checking based on this count)
		mErrorCount = mLockable->getReadWriteErrorCount();
	}
}
void CudaModuleScene::onAfterLaunchApexCudaFunc(const ApexCudaFunc& func, CUstream stream)
{
	if (mCudaProfileSession)
	{
		mCudaProfileSession->onFuncFinish(func.getProfileId(), stream);
	}

#if !CUDA_KERNEL_CHECK_ALWAYS
	if (mSceneIntl.getCudaKernelCheckEnabled())
#endif
	{
		CUresult ret = cuStreamSynchronize(stream);
		if ( CUDA_SUCCESS != ret )
		{
			APEX_INTERNAL_ERROR("Cuda Error %d after launch of func '%s'", ret, func.getName());
			PX_ALWAYS_ASSERT();
		}
	}
}
void ApexRenderSubmesh::setParams(SubmeshParameters* submeshParams, VertexBufferParameters* vertexBufferParams)
{

	if (vertexBufferParams == NULL && submeshParams != NULL)
	{
		vertexBufferParams = static_cast<VertexBufferParameters*>(submeshParams->vertexBuffer);
		PX_ASSERT(vertexBufferParams != NULL);
	}
	else if (submeshParams != NULL && submeshParams->vertexBuffer == NULL)
	{
		submeshParams->vertexBuffer = vertexBufferParams;
	}
	else if (mParams == NULL)
	{
		// Only emit this warning if mParams is empty yet (not on destruction of the object)
		APEX_INTERNAL_ERROR("Confliciting parameterized objects!");
	}
	mParams = submeshParams;

	mVertexBuffer.setParams(vertexBufferParams);
}
NxCompartment* ClothingScene::getClothCompartment_LocksPhysX(bool hw)
{
#if !defined(PX_WINDOWS)
	PX_UNUSED(hw);
	return NULL;
#else
	if (mModule->getMaxNumCompartments() == 0 || mPhysXScene == NULL)
	{
		return NULL;
	}

	NxCompartment* compartment = NULL;

	mApexScene->acquirePhysXLock();

	if (hw)
	{
		if (mClothHwCompartments.size() <= mNextClothHwCompartmentId)
		{
			PX_ASSERT(mClothHwCompartments.size() == mNextClothHwCompartmentId);
			NxCompartmentDesc compartmentDesc;
			compartmentDesc.type = NX_SCT_CLOTH;
			compartmentDesc.deviceCode = (physx::PxU32)NX_DC_PPU_AUTO_ASSIGN;
			compartment = mPhysXScene->createCompartment(compartmentDesc);
			if (compartment != NULL)
			{
				mClothHwCompartments.pushBack(compartment);
			}
			else
			{
				APEX_INTERNAL_ERROR("GPU compartment could not be created.");
			}
		}
		else
		{
			compartment = mClothHwCompartments[mNextClothHwCompartmentId];
		}

		if (compartment != NULL)
		{
			mNextClothHwCompartmentId = (mNextClothHwCompartmentId + 1) % mModule->getMaxNumCompartments();
		}
	}
	else
	{
		if (mClothSwCompartments.size() <= mNextClothSwCompartmentId)
		{
			PX_ASSERT(mClothSwCompartments.size() == mNextClothSwCompartmentId);
			NxCompartmentDesc compartmentDesc;
			compartmentDesc.type = NX_SCT_CLOTH;
			compartmentDesc.deviceCode = (PxU32)NX_DC_CPU;
			compartment = mPhysXScene->createCompartment(compartmentDesc);
			if (compartment != NULL)
			{
				mClothSwCompartments.pushBack(compartment);
			}
			else
			{
				APEX_INTERNAL_ERROR("CPU compartment could not be created.");
			}
		}
		else
		{
			compartment = mClothSwCompartments[mNextClothSwCompartmentId];
		}

		if (compartment != NULL)
		{
			mNextClothSwCompartmentId = (mNextClothSwCompartmentId + 1) % mModule->getMaxNumCompartments();
		}
	}

	mApexScene->releasePhysXLock();

	return compartment;
#endif
}