diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Binaries/ThirdParty/newtonLibrary/Win64/ExampleLibrary.dll b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Binaries/ThirdParty/newtonLibrary/Win64/ExampleLibrary.dll index d7884fe31d..d1f9f02db3 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Binaries/ThirdParty/newtonLibrary/Win64/ExampleLibrary.dll and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Binaries/ThirdParty/newtonLibrary/Win64/ExampleLibrary.dll differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary/x64/Release/vc143.pdb b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary/x64/Release/vc143.pdb index 5e775db703..9c182a21f8 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary/x64/Release/vc143.pdb and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary/x64/Release/vc143.pdb differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/CMakeLists.txt b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/CMakeLists.txt new file mode 100644 index 0000000000..7eb1ea7767 --- /dev/null +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/CMakeLists.txt @@ -0,0 +1,72 @@ +# Copyright (c) <2014-2017> +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely. + +cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR) + +set (projectName "ndCollision") +message (${projectName}) + +#source and header files +file(GLOB CPP_SOURCE *.h *.cpp) +file(GLOB HEADERS *.h) + +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/" FILES ${CPP_SOURCE}) + +include_directories(../dCore/) +include_directories(../dTinyxml/) +include_directories(../dProfiler/) + +if (MSVC) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /fp:fast") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /fp:fast") +endif(MSVC) + +if(NEWTON_BUILD_SHARED_LIBS) + add_definitions(-D_D_COLLISION_EXPORT_DLL) + add_library(${projectName} SHARED ${CPP_SOURCE}) + + if(MSVC OR MINGW) + target_link_options(${projectName} PUBLIC "/DEBUG") + endif() +else() + add_library(${projectName} STATIC ${CPP_SOURCE}) +endif() + +if (MSVC) + if(CMAKE_VS_MSBUILD_COMMAND OR CMAKE_VS_DEVENV_COMMAND) + set_target_properties(${projectName} PROPERTIES COMPILE_FLAGS "/YundCollisionStdafx.h") + set_source_files_properties(ndCollisionStdafx.cpp PROPERTIES COMPILE_FLAGS "/YcndCollisionStdafx.h") + endif() + + if (NEWTON_BUILD_TEST AND NEWTON_BUILD_SHARED_LIBS) + add_custom_command( + TARGET ${projectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${PROJECT_BINARY_DIR}/applications/ndTest/${CMAKE_CFG_INTDIR}/$) + endif () + + if (NEWTON_BUILD_SANDBOX_DEMOS AND NEWTON_BUILD_SHARED_LIBS) + add_custom_command( + TARGET ${projectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${PROJECT_BINARY_DIR}/applications/ndSandbox/${CMAKE_CFG_INTDIR}/$) + endif () + +endif(MSVC) + +target_link_libraries(${projectName} ndCore ndTinyxml) + +install(TARGETS ${projectName} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin) + +install(FILES ${HEADERS} DESTINATION include/${projectName}) + diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/ndScene.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/ndScene.cpp index 12a97e8b4b..34edaa01af 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/ndScene.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/ndScene.cpp @@ -46,8 +46,7 @@ ndVector ndScene::m_angularContactError2(D_CONTACT_ANGULAR_ERROR * D_CONTACT_ANG ndVector ndScene::m_linearContactError2(D_CONTACT_TRANSLATION_ERROR * D_CONTACT_TRANSLATION_ERROR); ndScene::ndScene() - :ndClassAlloc() - ,ndThreadPool("newtonWorker") + :ndThreadPool("newtonWorker") ,m_bodyList() ,m_particleSetList() ,m_contactArray() @@ -56,12 +55,12 @@ ndScene::ndScene() ,m_sceneBodyArray(1024) ,m_activeConstraintArray(1024) ,m_specialUpdateList() - ,m_backgroundThread() ,m_newPairs(1024) ,m_lock() ,m_rootNode(nullptr) ,m_sentinelBody(nullptr) ,m_contactNotifyCallback(new ndContactNotify(nullptr)) + ,m_backgroundThread(nullptr) ,m_timestep(ndFloat32 (0.0f)) ,m_lru(D_CONTACT_DELAY_FRAMES) ,m_frameNumber(0) @@ -78,8 +77,7 @@ ndScene::ndScene() } ndScene::ndScene(const ndScene& src) - :ndClassAlloc() - ,ndThreadPool("newtonWorker") + :ndThreadPool("newtonWorker") ,m_bodyList(src.m_bodyList) ,m_particleSetList() ,m_contactArray(src.m_contactArray) @@ -88,12 +86,12 @@ ndScene::ndScene(const ndScene& src) ,m_sceneBodyArray() ,m_activeConstraintArray() ,m_specialUpdateList() - ,m_backgroundThread() ,m_newPairs(1024) ,m_lock() ,m_rootNode(nullptr) ,m_sentinelBody(nullptr) ,m_contactNotifyCallback(nullptr) + ,m_backgroundThread(nullptr) ,m_timestep(ndFloat32(0.0f)) ,m_lru(src.m_lru) ,m_frameNumber(src.m_frameNumber) @@ -103,7 +101,7 @@ ndScene::ndScene(const ndScene& src) ndScene* const stealData = (ndScene*)&src; SetThreadCount(src.GetThreadCount()); - m_backgroundThread.SetThreadCount(m_backgroundThread.GetThreadCount()); + //m_backgroundThread.SetThreadCount(m_backgroundThread.GetThreadCount()); m_scratchBuffer.Swap(stealData->m_scratchBuffer); m_sceneBodyArray.Swap(stealData->m_sceneBodyArray); @@ -1188,7 +1186,10 @@ void ndScene::BodiesInAabb(ndBodiesInAabbNotify& callback, const ndVector& minBo void ndScene::Cleanup() { Sync(); - m_backgroundThread.Terminate(); + if (m_backgroundThread) + { + m_backgroundThread->Terminate(); + } PrepareCleanup(); m_frameNumber = 0; @@ -1268,7 +1269,15 @@ bool ndScene::ConvexCast(ndConvexCastNotify& callback, const ndShapeInstance& co void ndScene::SendBackgroundTask(ndBackgroundTask* const job) { - m_backgroundThread.SendTask(job); + if (m_backgroundThread) + { + m_backgroundThread->SendTask(job); + } + else + { + ndAssert(0); + delete job; + } } void ndScene::AddPair(ndBodyKinematic* const body0, ndBodyKinematic* const body1, ndInt32 threadId) diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/ndScene.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/ndScene.h index 0c5e437b87..748f4451ee 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/ndScene.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCollision/ndScene.h @@ -55,7 +55,7 @@ class ndSceneTreeNotiFy : public ndClassAlloc } D_GCC_NEWTON_ALIGN_32; D_MSV_NEWTON_ALIGN_32 -class ndScene : public ndClassAlloc, public ndThreadPool +class ndScene : public ndThreadPool { protected: class ndContactPairs @@ -162,7 +162,6 @@ class ndScene : public ndClassAlloc, public ndThreadPool ndArray m_sceneBodyArray; ndArray m_activeConstraintArray; ndSpecialList m_specialUpdateList; - ndThreadBackgroundWorker m_backgroundThread; ndArray m_newPairs; ndArray m_partialNewPairs[D_MAX_THREADS_COUNT]; ndPolygonMeshDesc::ndStaticMeshFaceQuery m_staticMeshQuery[D_MAX_THREADS_COUNT]; @@ -172,6 +171,7 @@ class ndScene : public ndClassAlloc, public ndThreadPool ndBvhNode* m_rootNode; ndBodyKinematic* m_sentinelBody; ndContactNotify* m_contactNotifyCallback; + ndThreadBackgroundWorker* m_backgroundThread; ndFloat32 m_timestep; ndUnsigned32 m_lru; diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/CMakeLists.txt b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/CMakeLists.txt new file mode 100644 index 0000000000..5c05985ead --- /dev/null +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/CMakeLists.txt @@ -0,0 +1,72 @@ +# Copyright (c) <2014-2017> +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely. + +cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR) + +set (projectName "ndCore") +message (${projectName}) + +# source and header files +file(GLOB CPP_SOURCE *.h *.cpp) +file(GLOB HEADERS *.h) + +include_directories(../dTinyxml/) +include_directories(../dProfiler/) + +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/" FILES ${CPP_SOURCE}) + +if(NEWTON_BUILD_SHARED_LIBS STREQUAL "ON") + add_definitions(-D_D_CORE_EXPORT_DLL) + add_library(${projectName} SHARED ${CPP_SOURCE}) + + if(MSVC OR MINGW) + target_link_options(${projectName} PUBLIC "/DEBUG") + endif() + +else() + add_library(${projectName} STATIC ${CPP_SOURCE}) +endif() + +if (MSVC) + if(CMAKE_VS_MSBUILD_COMMAND OR CMAKE_VS_DEVENV_COMMAND) + set_target_properties(${projectName} PROPERTIES COMPILE_FLAGS "/YundCoreStdafx.h") + set_source_files_properties(ndCoreStdAfx.cpp PROPERTIES COMPILE_FLAGS "/YcndCoreStdafx.h") + endif() + + if (NEWTON_BUILD_TEST AND NEWTON_BUILD_SHARED_LIBS) + add_custom_command( + TARGET ${projectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${PROJECT_BINARY_DIR}/applications/ndTest/${CMAKE_CFG_INTDIR}/$) + endif () + + if (NEWTON_BUILD_SANDBOX_DEMOS AND NEWTON_BUILD_SHARED_LIBS) + add_custom_command( + TARGET ${projectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${PROJECT_BINARY_DIR}/applications/ndSandbox/${CMAKE_CFG_INTDIR}/$) + endif () + +endif(MSVC) + +target_include_directories(${projectName} PUBLIC .) + +if (NEWTON_BUILD_PROFILER) + target_link_libraries (${projectName} dProfiler) +endif() + +target_link_libraries (${projectName} ndTinyxml) + +install(TARGETS ${projectName} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin) + +install(FILES ${HEADERS} DESTINATION include/${projectName}) diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndMatrix.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndMatrix.h index 47659d0450..c3fbe626b5 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndMatrix.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndMatrix.h @@ -128,7 +128,7 @@ inline ndMatrix::ndMatrix (const ndVector &front, const ndVector &up, const ndVe { } -inline ndVector& ndMatrix::operator[] (ndInt32 i) +inline ndVector& ndMatrix::operator[] (ndInt32 i) { ndAssert (i < 4); ndAssert (i >= 0); diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndQuaternion.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndQuaternion.h index 9079ac59bd..b402b6a58c 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndQuaternion.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndQuaternion.h @@ -56,7 +56,7 @@ class ndQuaternion: public ndVector inline ndQuaternion::ndQuaternion() //:ndVector(ndVector::m_wOne) - :ndVector(ndFloat32(0.0f), ndFloat32(0.0f), ndFloat32(0.0f), ndFloat32(1.0f)) + :ndVector(ndFloat32 (0.0f), ndFloat32(0.0f), ndFloat32(0.0f), ndFloat32(1.0f)) { } diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThread.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThread.cpp index 403a6e8b60..91bb6e9176 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThread.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThread.cpp @@ -31,19 +31,9 @@ #pragma warning( disable : 4355) #endif -ndThreadInterface::ndThreadInterface() +ndThread::ndThread() :ndClassAlloc() ,ndSemaphore() -{ -} - -ndThreadInterface::~ndThreadInterface() -{ -} - - -ndThread::ndThread() - :ndThreadInterface() #ifndef D_USE_THREAD_EMULATION ,ndAtomic(true) ,std::condition_variable() diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThread.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThread.h index 0e9b0b0eef..0c673a5a83 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThread.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThread.h @@ -36,25 +36,10 @@ class ndThreadName char m_name[32]; }; -class ndThreadInterface: public ndClassAlloc, public ndSemaphore -{ - public: - D_CORE_API ndThreadInterface(); - D_CORE_API virtual ~ndThreadInterface(); - - virtual void Signal() = 0; - virtual void Finish() = 0; - virtual void Release() = 0; - virtual void ThreadFunction() = 0; - virtual void ThreadFunctionCallback() = 0; - virtual void SetName(const char* const name) = 0; - - ndThreadName m_name; -}; - /// Base class for for all multi thread functionality. -class ndThread - :public ndThreadInterface +class ndThread + :public ndClassAlloc + ,public ndSemaphore #ifndef D_USE_THREAD_EMULATION ,public ndAtomic ,public std::condition_variable @@ -72,25 +57,27 @@ class ndThread /// Set thread name. /// Useful for when debugging or profiler and application. - D_CORE_API virtual void SetName(const char* const name) override; + D_CORE_API virtual void SetName(const char* const name); /// Set the thread, to execute one call to and go back to a wait state - D_CORE_API virtual void Signal() override; + D_CORE_API virtual void Signal(); /// Force the thread loop to terminate. /// This function must be call explicitly when the application /// wants to terminate the thread because the destructor does not do it. - D_CORE_API virtual void Finish() override; + D_CORE_API virtual void Finish(); /// Thread function to execute in a perpetual loop until the thread is terminated. /// Each time the thread owner calls function Signal, the loop execute one call to /// this function and upon return, the thread goes back to wait for another signal /// or to exit the loop. - //virtual virtual void ThreadFunction() = 0; + virtual void ThreadFunction() = 0; protected: - D_CORE_API virtual void Release() override; - D_CORE_API virtual void ThreadFunctionCallback() override; + D_CORE_API virtual void Release(); + D_CORE_API virtual void ThreadFunctionCallback(); + + ndThreadName m_name; }; #endif diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThreadPool.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThreadPool.cpp index 86db9499b4..0473e38c00 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThreadPool.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThreadPool.cpp @@ -26,28 +26,6 @@ #include "ndThreadPool.h" #include "ndThreadSyncUtils.h" -class ndThreadPool::ndMainThread: public ndThread -{ - public: - ndMainThread(ndThreadPool* const owner) - :ndThread() - ,m_owner(owner) - { - } - - void ThreadFunction() override - { - m_owner->ThreadFunction(); - } - - virtual void Release() - { - m_owner->Release(); - } - - ndThreadPool* const m_owner; -}; - ndThreadPool::ndWorker::ndWorker() :ndThread() ,m_owner(nullptr) @@ -134,21 +112,19 @@ void ndThreadPool::ndWorker::ThreadFunction() ndThreadPool::ndThreadPool(const char* const baseName) :ndSyncMutex() - ,m_main(nullptr) + ,ndThread() ,m_workers(nullptr) ,m_count(0) { char name[256]; - m_main = new ndMainThread(this); strncpy(m_baseName, baseName, sizeof (m_baseName)); snprintf(name, sizeof (name), "%s_%d", m_baseName, 0); - m_main->SetName(name); + SetName(name); } ndThreadPool::~ndThreadPool() { SetThreadCount(0); - delete m_main; } ndInt32 ndThreadPool::GetMaxThreads() @@ -171,29 +147,21 @@ void ndThreadPool::SetThreadCount(ndInt32 count) { if (m_workers) { - //m_count = 0; - //delete[] m_workers; - //m_workers = nullptr; - for (ndInt32 i = m_count - 1; i >= 0; --i) - { - m_workers[i] = ndSharedPtr(nullptr); - } m_count = 0; delete[] m_workers; + m_workers = nullptr; } if (count) { m_count = count; - //m_workers = new ndWorker[size_t(count)]; - m_workers = new ndSharedPtr[size_t(count)]; + m_workers = new ndWorker[size_t(count)]; for (ndInt32 i = 0; i < count; ++i) { char name[256]; - m_workers[i] = ndSharedPtr(new ndWorker); - m_workers[i]->m_owner = this; - m_workers[i]->m_threadIndex = i; + m_workers[i].m_owner = this; + m_workers[i].m_threadIndex = i; snprintf(name, sizeof(name), "%s_%d", m_baseName, i + 1); - m_workers[i]->SetName(name); + m_workers[i].SetName(name); } } } @@ -205,7 +173,7 @@ void ndThreadPool::Begin() D_TRACKTIME(); for (ndInt32 i = 0; i < m_count; ++i) { - m_workers[i]->Signal(); + m_workers[i].Signal(); } auto BeginJobs = ndMakeObject::ndFunction([this](ndInt32, ndInt32) @@ -220,9 +188,9 @@ void ndThreadPool::End() #ifndef D_USE_THREAD_EMULATION for (ndInt32 i = 0; i < m_count; ++i) { - m_workers[i]->ExecuteTask(nullptr); + m_workers[i].ExecuteTask(nullptr); #if !defined(D_USE_SYNC_SEMAPHORE) - m_workers[i]->m_begin = 0; + m_workers[i].m_begin = 0; #endif } @@ -232,7 +200,7 @@ void ndThreadPool::End() ndUnsigned8 looping = 0; for (ndInt32 i = 0; i < m_count; ++i) { - looping = ndUnsigned8(looping | m_workers[i]->m_stillLooping); + looping = ndUnsigned8(looping | m_workers[i].m_stillLooping); } stillLooping = ndUnsigned8(stillLooping & looping); if (m_count) @@ -248,20 +216,10 @@ void ndThreadPool::Release() ndSyncMutex::Release(); } -void ndThreadPool::Finish() -{ - m_main->Finish(); -} - -void ndThreadPool::Signal() -{ - m_main->Signal(); -} - void ndThreadPool::TickOne() { ndSyncMutex::Tick(); - m_main->ndSemaphore::Signal(); + ndSemaphore::Signal(); #ifdef D_USE_THREAD_EMULATION ThreadFunction(); #endif @@ -276,7 +234,7 @@ void ndThreadPool::WaitForWorkers() ndUnsigned8 inProgess = 0; for (ndInt32 i = 0; i < m_count; ++i) { - inProgess = ndUnsigned8(inProgess | (m_workers[i]->IsTaskInProgress())); + inProgess = ndUnsigned8(inProgess | (m_workers[i].IsTaskInProgress())); } jobsInProgress = ndUnsigned8 (jobsInProgress & inProgess); if (jobsInProgress) diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThreadPool.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThreadPool.h index 3aa3e15f7b..1578e765e8 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThreadPool.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndThreadPool.h @@ -29,9 +29,6 @@ #include "ndSyncMutex.h" #include "ndSemaphore.h" #include "ndClassAlloc.h" -#include "ndThreadSyncUtils.h" -#include "ndContainersAlloc.h" -#include "ndSharedPtr.h" //#define D_USE_SYNC_SEMAPHORE @@ -66,20 +63,16 @@ class ndTask virtual void Execute() const = 0; }; -D_MSV_NEWTON_ALIGN_32 -//class ndThreadPool: public ndSyncMutex, public ndThread -class ndThreadPool: public ndSyncMutex +class ndThreadPool: public ndSyncMutex, public ndThread { - class ndMainThread; - class ndWorker: public ndThread { public: D_CORE_API ndWorker(); D_CORE_API virtual ~ndWorker(); - D_CORE_API virtual ndUnsigned8 IsTaskInProgress() const; - D_CORE_API virtual void ExecuteTask(ndTask* const task); + D_CORE_API ndUnsigned8 IsTaskInProgress() const; + D_CORE_API void ExecuteTask(ndTask* const task); private: virtual void ThreadFunction(); @@ -109,10 +102,6 @@ class ndThreadPool: public ndSyncMutex D_CORE_API void TickOne(); D_CORE_API void Begin(); D_CORE_API void End(); - D_CORE_API void Signal(); - D_CORE_API void Finish(); - - virtual void ThreadFunction() = 0; template void ParallelExecute(const Function& ndFunction); @@ -121,11 +110,10 @@ class ndThreadPool: public ndSyncMutex D_CORE_API virtual void Release(); D_CORE_API virtual void WaitForWorkers(); - ndThreadInterface* m_main; - ndSharedPtr* m_workers; + ndWorker* m_workers; ndInt32 m_count; char m_baseName[32]; -}D_GCC_NEWTON_ALIGN_32; +}; inline ndInt32 ndThreadPool::GetThreadCount() const { @@ -218,8 +206,7 @@ void ndThreadPool::ParallelExecute(const Function& callback) for (ndInt32 i = 0; i < m_count; ++i) { ndTaskImplement* const job = &jobsArray[i + 1]; - //m_workers[i].ExecuteTask(job); - m_workers[i]->ExecuteTask(job); + m_workers[i].ExecuteTask(job); } ndTaskImplement* const job = &jobsArray[0]; diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.cpp index 0e2c10b933..12f96de388 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.cpp @@ -52,7 +52,7 @@ void ndTriangulatePolygon(ndVector* const points, ndInt32 count, ndArraypool(stride * cluster.m_count); + ndStackpool(stride * cluster.m_count); ndStack indirectListBuffer(cluster.m_count); ndSortKey* const indirectList = &indirectListBuffer[0]; @@ -226,9 +226,9 @@ static ndInt32 QuickSortVertices(ndFloat64* const vertListOut, ndInt32 stride, n } ndInt32 sortIndex = 0; -#ifdef D_USE_YZ_VARIANCE + #ifdef D_USE_YZ_VARIANCE const ndBigVector originScale(cluster.m_sum.Scale(ndFloat32(1.0f) / (ndFloat32)cluster.m_count)); - const ndBigVector varianceScale2((cluster.m_sum2.Scale(ndFloat32(1.0f) / (ndFloat32)cluster.m_count) - originScale * originScale).GetMax(ndBigVector(1.0e-6f))); + const ndBigVector varianceScale2((cluster.m_sum2.Scale(ndFloat32(1.0f) / (ndFloat32)cluster.m_count) - originScale * originScale).GetMax (ndBigVector(1.0e-6f))); ndFloat64 maxValue = varianceScale2.m_x; for (ndInt32 i = 1; i < 3; ++i) { @@ -241,7 +241,7 @@ static ndInt32 QuickSortVertices(ndFloat64* const vertListOut, ndInt32 stride, n ndInt32 varianceIndex0 = (sortIndex + 1) % 3; ndInt32 varianceIndex1 = (varianceIndex0 + 1) % 3; const ndBigVector stdScale(ndFloat64(1.0f) / varianceScale2.m_x, ndFloat64(1.0f) / varianceScale2.m_y, ndFloat64(1.0f) / varianceScale2.m_z, ndFloat64(0.0f)); -#endif + #endif ndInt32 baseCount = 0; if (cluster.m_count > D_VERTEXLIST_INDEX_LIST_BASH) @@ -257,15 +257,15 @@ static ndInt32 QuickSortVertices(ndFloat64* const vertListOut, ndInt32 stride, n const ndBigVector variance2(cluster.m_sum2.Scale(ndFloat32(1.0f) / (ndFloat32)cluster.m_count) - origin * origin); ndSortKey* const remapIndex = &indirectList[cluster.m_start]; -#ifdef D_USE_YZ_VARIANCE - ndFloat64 clusterVariance2_0 = stdScale[varianceIndex0] * ndMax(variance2[varianceIndex0], ndFloat64(0.0f)); - ndFloat64 clusterVariance2_1 = stdScale[varianceIndex1] * ndMax(variance2[varianceIndex1], ndFloat64(0.0f)); - ndFloat64 maxNormalizedVariance = ndMax(clusterVariance2_0, clusterVariance2_1); - bool doSort = (maxNormalizedVariance < ndFloat32(1.0f / 8.0f)) || (spliteStack.GetCount() > (spliteStack.GetCapacity() - 4)); -#else - ndFloat64 maxVariance2 = ndMax(ndMax(variance2.m_x, variance2.m_y), variance2.m_z); - bool doSort = (cluster.m_count <= D_VERTEXLIST_INDEX_LIST_BASH) || (spliteStack.GetCount() > (spliteStack.GetCapacity() - 4)) || (maxVariance2 < ndFloat32(4.0f)); -#endif + #ifdef D_USE_YZ_VARIANCE + ndFloat64 clusterVariance2_0 = stdScale[varianceIndex0] * ndMax(variance2[varianceIndex0], ndFloat64(0.0f)); + ndFloat64 clusterVariance2_1 = stdScale[varianceIndex1] * ndMax(variance2[varianceIndex1], ndFloat64(0.0f)); + ndFloat64 maxNormalizedVariance = ndMax (clusterVariance2_0, clusterVariance2_1); + bool doSort = (maxNormalizedVariance < ndFloat32(1.0f/8.0f)) || (spliteStack.GetCount() > (spliteStack.GetCapacity() - 4)); + #else + ndFloat64 maxVariance2 = ndMax(ndMax(variance2.m_x, variance2.m_y), variance2.m_z); + bool doSort = (cluster.m_count <= D_VERTEXLIST_INDEX_LIST_BASH) || (spliteStack.GetCount() > (spliteStack.GetCapacity() - 4)) || (maxVariance2 < ndFloat32(4.0f)); + #endif if (doSort) { ndInt32 newCount = SortVertices(vertListOut, indexListOut, vertList, stride, compareCount, tolerance, remapIndex, cluster, baseCount, sortIndex); @@ -273,22 +273,22 @@ static ndInt32 QuickSortVertices(ndFloat64* const vertListOut, ndInt32 stride, n } else { -#ifdef D_USE_YZ_VARIANCE - //ndInt32 firstSortAxis = (variance2.m_y >= variance2.m_z) ? 1 : 2; - ndInt32 firstSortAxis = (clusterVariance2_0 > clusterVariance2_1) ? varianceIndex0 : varianceIndex1; -#else - ndInt32 firstSortAxis = 0; - if ((variance2.m_y >= variance2.m_x) && (variance2.m_y >= variance2.m_z)) - { - firstSortAxis = 1; - } - else if ((variance2.m_z >= variance2.m_x) && (variance2.m_z >= variance2.m_y)) - { - firstSortAxis = 2; - } -#endif + #ifdef D_USE_YZ_VARIANCE + //ndInt32 firstSortAxis = (variance2.m_y >= variance2.m_z) ? 1 : 2; + ndInt32 firstSortAxis = (clusterVariance2_0 > clusterVariance2_1) ? varianceIndex0 : varianceIndex1; + #else + ndInt32 firstSortAxis = 0; + if ((variance2.m_y >= variance2.m_x) && (variance2.m_y >= variance2.m_z)) + { + firstSortAxis = 1; + } + else if ((variance2.m_z >= variance2.m_x) && (variance2.m_z >= variance2.m_y)) + { + firstSortAxis = 2; + } + #endif ndFloat64 axisVal = origin[firstSortAxis]; - + ndInt32 i0 = 0; ndInt32 i1 = cluster.m_count - 1; while (i0 < i1) @@ -299,14 +299,14 @@ static ndInt32 QuickSortVertices(ndFloat64* const vertListOut, ndInt32 stride, n ++i0; index0 = remapIndex[i0].m_vertexIndex; }; - + ndInt32 index1 = remapIndex[i1].m_vertexIndex; while ((vertList[index1 * stride + firstSortAxis] > axisVal) && (i0 < i1)) { --i1; index1 = remapIndex[i1].m_vertexIndex; } - + ndAssert(i0 <= i1); if (i0 < i1) { @@ -315,28 +315,28 @@ static ndInt32 QuickSortVertices(ndFloat64* const vertListOut, ndInt32 stride, n --i1; } } - + ndInt32 index0 = remapIndex[i0].m_vertexIndex; while ((vertList[index0 * stride + firstSortAxis] <= axisVal) && (i0 < cluster.m_count)) { ++i0; index0 = remapIndex[i0].m_vertexIndex; }; - -#ifdef _DEBUG + + #ifdef _DEBUG for (ndInt32 i = 0; i < i0; ++i) { index0 = remapIndex[i].m_vertexIndex; ndAssert(vertList[index0 * stride + firstSortAxis] <= axisVal); } - + for (ndInt32 i = i0; i < cluster.m_count; ++i) { index0 = remapIndex[i].m_vertexIndex; ndAssert(vertList[index0 * stride + firstSortAxis] > axisVal); } -#endif - + #endif + ndBigVector xc(ndBigVector::m_zero); ndBigVector x2c(ndBigVector::m_zero); for (ndInt32 i = 0; i < i0; ++i) @@ -346,14 +346,14 @@ static ndInt32 QuickSortVertices(ndFloat64* const vertListOut, ndInt32 stride, n xc += x; x2c += x * x; } - + ndSortCluster cluster_i1(cluster); cluster_i1.m_start = cluster.m_start + i0; cluster_i1.m_count = cluster.m_count - i0; cluster_i1.m_sum -= xc; cluster_i1.m_sum2 -= x2c; spliteStack.PushBack(cluster_i1); - + ndSortCluster cluster_i0(cluster); cluster_i0.m_start = cluster.m_start; cluster_i0.m_count = i0; @@ -372,11 +372,11 @@ static ndInt32 QuickSortVertices(ndFloat64* const vertListOut, ndInt32 stride, n ndInt32 ndVertexListToIndexList(ndFloat64* const vertList, ndInt32 strideInBytes, ndInt32 compareCount, ndInt32 vertexCount, ndInt32* const indexListOut, ndFloat64 tolerance) { - if (strideInBytes < 3 * ndInt32(sizeof(ndFloat64))) + if (strideInBytes < 3 * ndInt32(sizeof(ndFloat64))) { return 0; } - if (compareCount < 3) + if (compareCount < 3) { return 0; } diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/CMakeLists.txt b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/CMakeLists.txt new file mode 100644 index 0000000000..6bd3b1f198 --- /dev/null +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/CMakeLists.txt @@ -0,0 +1,145 @@ +# Copyright (c) <2014-2017> +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely. + +cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR) + +set (projectName "ndNewton") +message (${projectName}) + +#source and header files +file(GLOB CPP_SOURCE + *.h + *.cpp + dModels/*.h + dModels/*.cpp + dJoints/*.h + dJoints/*.cpp + dIkSolver/*.h + dIkSolver/*.cpp + dParticles/*.h + dParticles/*.cpp + dModels/dVehicle*.h + dModels/dVehicle/*.cpp + dModels/dCharacter/*.h + dModels/dCharacter/*.cpp) + +file(GLOB HEADERS *.h dJoints/*.h) +file(GLOB HEADERS *.h dModels/*.h) +file(GLOB HEADERS *.h dIkSolver/*.h) +file(GLOB HEADERS *.h dParticles/*.h) +file(GLOB HEADERS *.h dModels/dVehicle/*.h) +file(GLOB HEADERS *.h dModels/dCharacter/*.h) + +if(NEWTON_ENABLE_AVX2_SOLVER) + add_definitions(-D_D_USE_AVX2_SOLVER) +endif() + +include_directories(.) +include_directories(../dCore) +include_directories(../dTinyxml) +include_directories(../dProfiler) +include_directories(../dCollision) + +include_directories(dJoints/) +include_directories(dModels/) +include_directories(dIkSolver/) +include_directories(dParticles/) +include_directories(dModels/dVehicle/) +include_directories(dModels/dCharacter/) + +add_subdirectory(dExtensions) + +if(NEWTON_ENABLE_AVX2_SOLVER) + include_directories(dExtensions/dAvx2) +endif() + +if (NEWTON_ENABLE_CUDA_SOLVER) + add_definitions(-D_D_NEWTON_CUDA) + include_directories(dExtensions/dCuda) + include_directories(dExtensions/dCuda/dContext) + + file(GLOB CPP_SOURCE + ${CPP_SOURCE} + dExtensions/dCuda/*.h + dExtensions/dCuda/*.cpp + dExtensions/dCuda/dContext/*.h) +endif() + +if (NEWTON_ENABLE_SYCL_SOLVER) + add_definitions(-D_D_NEWTON_SYCL) + include_directories(dNewton/dExtensions/dSycl) + include_directories(dNewton/dExtensions/dSycl/ndScene) + + file(GLOB CPP_SOURCE + ${CPP_SOURCE} + dNewton/dExtensions/dSycl/ndScene/*.h + dNewton/dExtensions/dSycl/ndScene/*.cpp) +endif() + +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/" FILES ${CPP_SOURCE}) + +if(NEWTON_BUILD_SHARED_LIBS) + add_definitions(-D_D_NEWTON_EXPORT_DLL) + add_library(${projectName} SHARED ${CPP_SOURCE}) + + if(MSVC OR MINGW) + target_link_options(${projectName} PUBLIC "/DEBUG") + endif() +else() + add_library(${projectName} STATIC ${CPP_SOURCE}) +endif() + +if (MSVC) + if(CMAKE_VS_MSBUILD_COMMAND OR CMAKE_VS_DEVENV_COMMAND) + set_target_properties(${projectName} PROPERTIES COMPILE_FLAGS "/YundNewtonStdafx.h") + set_source_files_properties(ndNewtonStdafx.cpp PROPERTIES COMPILE_FLAGS "/YcndNewtonStdafx.h") + endif() + + if (NEWTON_BUILD_TEST AND NEWTON_BUILD_SHARED_LIBS) + add_custom_command( + TARGET ${projectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${PROJECT_BINARY_DIR}/applications/ndTest/${CMAKE_CFG_INTDIR}/$) + endif () + + if (NEWTON_BUILD_SANDBOX_DEMOS AND NEWTON_BUILD_SHARED_LIBS) + add_custom_command( + TARGET ${projectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${PROJECT_BINARY_DIR}/applications/ndSandbox/${CMAKE_CFG_INTDIR}/$) + endif () + +endif(MSVC) + +target_link_libraries(${projectName} ndTinyxml ndCore ndCollision) + +if(NEWTON_ENABLE_AVX2_SOLVER) + target_link_libraries(${projectName} ndSolverAvx2) +endif() + +if (NEWTON_ENABLE_CUDA_SOLVER) + if(NEWTON_BUILD_SHARED_LIBS) + target_link_libraries (${projectName} ndSolverCuda) + endif() +endif() + +if (NEWTON_ENABLE_SYCL_SOLVER) + if(NEWTON_BUILD_SHARED_LIBS) + target_link_libraries (${projectName} ndSolverSycl) + endif() +endif() + +install(TARGETS ${projectName} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin) + +install(FILES ${HEADERS} DESTINATION include/${projectName}) + diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/CMakeLists.txt b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/CMakeLists.txt new file mode 100644 index 0000000000..2e679db246 --- /dev/null +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) <2014-2017> +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely. + +cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR) + +if(NEWTON_ENABLE_AVX2_SOLVER) + message ("adding avx2 solver") + add_subdirectory(dAvx2) +endif() + +if (NEWTON_ENABLE_CUDA_SOLVER) + message ("adding cuda solver") + add_subdirectory(dCuda) +endif() diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/dAvx2/CMakeLists.txt b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/dAvx2/CMakeLists.txt new file mode 100644 index 0000000000..5e12796fe9 --- /dev/null +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/dAvx2/CMakeLists.txt @@ -0,0 +1,65 @@ +# Copyright (c) <2014-2017> +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely. + +cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR) + +set (projectName "ndSolverAvx2") +message (${projectName}) + +include_directories(../../../.) +include_directories(../../../dCore) +include_directories(../../../dNewton) +include_directories(../../../dProfiler) +include_directories(../../../dCollision) + +file(GLOB CPP_SOURCE *.c *.cpp *.h) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/" FILES ${CPP_SOURCE}) + +if(MSVC) + if (NOT NEWTON_ENABLE_AVX2) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:AVX2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /fp:fast /arch:AVX2") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} /fp:fast /arch:AVX2") + endif() + add_library(${projectName} STATIC ${CPP_SOURCE}) +endif() + +if(MINGW) + if (NOT NEWTON_ENABLE_AVX2) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mavx2 -mfma ") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mavx2 -mfma ") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -mavx2 -mfma") + endif() + add_library(${projectName} STATIC ${CPP_SOURCE}) +endif() + +if(UNIX) + if (NOT NEWTON_ENABLE_AVX2) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -march=haswell ") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=haswell ") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -march=haswell ") + endif() + add_library(${projectName} SHARED ${CPP_SOURCE}) +endif() + +if(MSVC OR MINGW) + target_link_options(${projectName} PUBLIC "/DEBUG") +endif() + +install(TARGETS ${projectName} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin) + +install(FILES ${HEADERS} DESTINATION include/${projectName}) + +if (MSVC) + set_target_properties(${projectName} PROPERTIES FOLDER "physics") +endif() \ No newline at end of file diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/dCuda/CMakeLists.txt b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/dCuda/CMakeLists.txt new file mode 100644 index 0000000000..42bc4cb46f --- /dev/null +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/dExtensions/dCuda/CMakeLists.txt @@ -0,0 +1,82 @@ +# Copyright (c) <2014-2017> +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely. + +cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR) + +set (projectName "ndSolverCuda") +message (${projectName}) + +set(CMAKE_CUDA_STANDARD 14) +CMAKE_POLICY(SET CMP0104 OLD) +project(${projectName} LANGUAGES CXX CUDA) +set(CMAKE_CUDA_COMPILER $ENV{CUDA_PATH}/bin/nvcc.exe) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CUDA_STANDARD 14) + +include_directories(./) +include_directories(dCudaDriver/) + +file(GLOB CPP_SOURCE dContext/*.h dContext/*.cpp dContext/*.cuh dContext/*.cu) + +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/" FILES ${CPP_SOURCE}) + + +Set(CMAKE_CUDA_FLAGS_DEBUG "-Xcompiler=\"-MDd -W4 -wd4100 -wd4201 -wd4324 -wd4505 -Zi -Ob0 -Od /RTC1\" ") +Set(CMAKE_CUDA_FLAGS_RELEASE "-Xcompiler=\"-MD -W4 -wd4100 -wd4201 -wd4324 -wd4505 -Zi -O2 -Ob2\" -DNDEBUG") +Set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "-Xcompiler=\"-MD -W4 -wd4100 -wd4201 -wd4324 -wd4505 -Zi -O2 -Ob1\" -DNDEBUG") + +#Set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -lineinfo") +#Set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} -lineinfo") +#Set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELWITHDEBINFO} -lineinfo") + +Set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} --extended-lambda") +Set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} --extended-lambda") +Set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELWITHDEBINFO} --extended-lambda") + +Set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -rdc=true") +Set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} -rdc=true") +Set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELWITHDEBINFO} -rdc=true") + +#Set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} --ptxas-options=-v") +#Set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} --ptxas-options=-v") +#Set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELWITHDEBINFO} --ptxas-options=-v") + +Set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} --device-debug") +Set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELWITHDEBINFO} --device-debug") + +#Set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -use_fast_math") +#Set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} -use_fast_math") +#Set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELWITHDEBINFO} -use_fast_math") + +message ("cuda debug options ${CMAKE_CUDA_FLAGS_DEBUG}") +message ("cuda release options ${CMAKE_CUDA_FLAGS_RELEASE}") +message ("cuda release with debug options ${CMAKE_CUDA_FLAGS_RELWITHDEBINFO}") + +add_definitions(-D_D_CUDA_EXPORT_DLL) +add_library(${projectName} SHARED ${CPP_SOURCE}) + +set_target_properties(${projectName} PROPERTIES CUDA_SEPARABLE_COMPILATION ON CUDA_RESOLVE_DEVICE_SYMBOLS ON) + +#it seems this is the broken +#target_compile_options(${projectName} PRIVATE $<$:-gencode arch=compute_60 code=sm_60>) +#target_compile_options(${projectName} PRIVATE $<$:-gencode compute_60,sm_60>) +#target_compile_options(${projectName} PRIVATE $<$:-gencode arch=compute_52 code=sm_52>) + +install(FILES ${HEADERS} DESTINATION include/${projectName}) +install(FILES $ DESTINATION bin OPTIONAL) +install(TARGETS ${projectName} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) + +if (NEWTON_BUILD_SANDBOX_DEMOS) + add_custom_command( + TARGET ${projectName} POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${PROJECT_BINARY_DIR}/../../../../applications/ndSandbox/${CMAKE_CFG_INTDIR}/$) +endif () diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/ndWorld.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/ndWorld.cpp index e3efb4936c..83abc50eaf 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/ndWorld.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dNewton/ndWorld.cpp @@ -165,7 +165,7 @@ ndWorld::~ndWorld() void ndWorld::CleanUp() { Sync(); - m_scene->m_backgroundThread.Terminate(); + //m_scene->m_backgroundThread.Terminate(); m_scene->PrepareCleanup(); m_activeSkeletons.Resize(256); @@ -230,7 +230,12 @@ ndInt32 ndWorld::GetThreadCount() const void ndWorld::SetThreadCount(ndInt32 count) { m_scene->SetThreadCount(count); - m_scene->m_backgroundThread.SetThreadCount(count); + + if (m_scene->m_backgroundThread) + { + m_scene->m_backgroundThread->Terminate(); + m_scene->m_backgroundThread->SetThreadCount(count); + } } ndInt32 ndWorld::GetSubSteps() const diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.dll b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.dll index d7884fe31d..d1f9f02db3 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.dll and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.dll differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.lib b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.lib index deb5f17c2b..abbaa4145d 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.lib and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.lib differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.pdb b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.pdb index fa77582a94..537a99bcae 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.pdb and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.pdb differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonWorld.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonWorld.cpp index a357af7cfc..cd44fb8d73 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonWorld.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonWorld.cpp @@ -231,10 +231,14 @@ NewtonWorld::NewtonWorld(ANewtonWorldActor* const owner) ,m_timeAcc(0.0f) ,m_active(true) ,m_terminated(false) + ,m_initialized(false) { m_world = new PhysicsEngine; m_worker = FRunnableThread::Create(this, TEXT("newtonUnrealGlue")); check(m_worker); + + // block until thread is initialized. + while (!m_initialized); } NewtonWorld::~NewtonWorld() @@ -270,8 +274,6 @@ bool NewtonWorld::IsTerminated() const void NewtonWorld::Stop() { - //UE_LOG(LogTemp, Display, TEXT("thread stops")); - //Cleanup(); m_active.store(false); while (!IsTerminated()); } @@ -286,9 +288,9 @@ uint32 NewtonWorld::Run() ndFloat32 updateRate = m_owner->UpdateRate; const ndFloat32 timestep = (1.0f / updateRate); - //ndInt32 thicks0 = 0; - //ndInt32 thicks1 = 0; - + ndInt32 thicks0 = 0; + ndInt32 thicks1 = 0; + m_initialized = true; ndUnsigned64 microSeconds0 = ndGetTimeInMicroseconds(); ndUnsigned64 deltaMicroSeconds = ndUnsigned64(1.0e6f / updateRate); while (m_active.load()) @@ -314,16 +316,12 @@ uint32 NewtonWorld::Run() microSeconds0 += deltaMicroSeconds; //UE_LOG(LogTemp, Display, TEXT("loop time step %f(ms) ticks %d"), ndFloat32 (microSecondStep) * 1.0e-3f, thicks1 - thicks0); - //thicks0 = thicks1; + thicks0 = thicks1; } - //thicks1++; - FPlatformProcess::Sleep(0.0f); + thicks1++; + FPlatformProcess::YieldThread(); } - - // one more update to clean up all pending objects - //ndWorld::Update(timestep); - //Sync(); return 0; } @@ -348,8 +346,12 @@ void NewtonWorld::ApplySettings() const m_world->SelectSolver(mode); m_world->SetSubSteps(m_owner->SolverPasses); - m_world->SetThreadCount(m_owner->ParallelThreads); m_world->SetSolverIterations(m_owner->SolverIterations); + if (m_world->GetThreadCount() != m_owner->ParallelThreads) + { + check(0); + m_world->SetThreadCount(m_owner->ParallelThreads); + } const ndBodyListView& bodyList = m_world->GetBodyList(); for (ndBodyListView::ndNode* node = bodyList.GetFirst(); node; node = node->GetNext()) diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonWorld.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonWorld.h index 827f6d1356..542048fcb6 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonWorld.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonWorld.h @@ -10,6 +10,7 @@ class ndWorld; class ANewtonWorldActor; #define D_USING_UNREAL_TRHEADS + #ifndef D_USING_UNREAL_TRHEADS class NewtonWorld @@ -42,6 +43,8 @@ class NewtonWorld: public FRunnable { class PhysicsEngine; public: + class EngineMainThread; + NewtonWorld(ANewtonWorldActor* const owner); ~NewtonWorld(); @@ -68,6 +71,7 @@ class NewtonWorld: public FRunnable std::atomic m_timeAcc; std::atomic m_active; std::atomic m_terminated; + bool m_initialized; }; #endif \ No newline at end of file