From 7b2df70c7bfe484f55f36898b106b455a05d6cbd Mon Sep 17 00:00:00 2001 From: enn0x Date: Fri, 26 Mar 2010 13:13:15 +0000 Subject: [PATCH] Config-option to activate multithreaded/multicore mode for PhysX engine. --- panda/src/physx/config_physx.cxx | 23 +++++++++++++---------- panda/src/physx/config_physx.h | 1 + panda/src/physx/physxManager.cxx | 18 +++++++++++++----- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/panda/src/physx/config_physx.cxx b/panda/src/physx/config_physx.cxx index d8e9bb67de..7821a73f36 100644 --- a/panda/src/physx/config_physx.cxx +++ b/panda/src/physx/config_physx.cxx @@ -54,10 +54,8 @@ #include "physxSphericalJoint.h" #include "physxTriangleMesh.h" #include "physxTriangleMeshShape.h" -//#include "physxVehicle.h" -//#include "physxVehicleGears.h" -//#include "physxVehicleMotor.h" -//#include "physxWheel.h" +#include "physxVehicle.h" +#include "physxWheel.h" #include "physxWheelShape.h" ConfigureDef(config_physx); @@ -75,13 +73,13 @@ PRC_DESC("Specified wether the manager should try to connect to the NVIDIA " ConfigVariableString physx_vrd_host ("physx-vrd-host", "localhost", -PRC_DESC("Specified the host where the NVIDIA PhysX visual debugger is running" +PRC_DESC("Specified the host where the NVIDIA PhysX visual debugger is running " "on. Only used if the config-varibale 'physx-want-visual-debugger' " "is set to 'true'.")); ConfigVariableInt physx_vrd_port ("physx-visual-debugger-port", 5425, -PRC_DESC("Specified the port where the NVIDIA PhysX visual debugger is running" +PRC_DESC("Specified the port where the NVIDIA PhysX visual debugger is running " "on. Only used if the config-varibale 'physx-want-visual-debugger' " "is set to 'true'.")); @@ -89,6 +87,13 @@ ConfigVariableEnum physx_up_axis ("physx-up-axis", PhysxEnums::Z_up, PRC_DESC("Set the up direction for controllers and heightfields.")); +ConfigVariableInt physx_internal_threads +("physx-internal-threads", 0, +PRC_DESC("Specified the number of internal threads to be created by the " + "PhysX engine. The threads will be moved to different cores, if " + "possible. Default value is '0'. PhysX then runs in an external " + "thread, but no additional internal threads will be created.")); + //////////////////////////////////////////////////////////////////// // Function: init_libphysx // Description: Initializes the library. This must be called at @@ -144,10 +149,8 @@ init_libphysx() { PhysxSphericalJoint::init_type(); PhysxTriangleMesh::init_type(); PhysxTriangleMeshShape::init_type(); - //PhysxVehicle::init_type(); - //PhysxVehicleGears::init_type(); - //PhysxVehicleMotor::init_type(); - //PhysxWheel::init_type(); + PhysxVehicle::init_type(); + PhysxWheel::init_type(); PhysxWheelShape::init_type(); PandaSystem *ps = PandaSystem::get_global_ptr(); diff --git a/panda/src/physx/config_physx.h b/panda/src/physx/config_physx.h index acb80ed995..e0b00fa7af 100644 --- a/panda/src/physx/config_physx.h +++ b/panda/src/physx/config_physx.h @@ -30,6 +30,7 @@ NotifyCategoryDecl(physx, EXPCL_PANDAPHYSX, EXPTP_PANDAPHYSX); extern EXPCL_PANDAPHYSX ConfigVariableBool physx_want_vrd; extern EXPCL_PANDAPHYSX ConfigVariableString physx_vrd_host; extern EXPCL_PANDAPHYSX ConfigVariableInt physx_vrd_port; +extern EXPCL_PANDAPHYSX ConfigVariableInt physx_internal_threads; extern EXPCL_PANDAPHYSX ConfigVariableEnum physx_up_axis; extern EXPCL_PANDAPHYSX void init_libphysx(); diff --git a/panda/src/physx/physxManager.cxx b/panda/src/physx/physxManager.cxx index ceee12afb5..254a10036f 100644 --- a/panda/src/physx/physxManager.cxx +++ b/panda/src/physx/physxManager.cxx @@ -132,21 +132,29 @@ get_num_scenes() const { // Description: //////////////////////////////////////////////////////////////////// PhysxScene *PhysxManager:: -create_scene(PhysxSceneDesc &desc) { +create_scene(PhysxSceneDesc &sceneDesc) { - nassertr(desc.is_valid(),NULL); + nassertr(sceneDesc.is_valid(),NULL); //_desc.timeStepMethod = NX_TIMESTEP_FIXED; //_desc.maxTimestep = 1.0f / 240.0f; //_desc.maxIter = 8; - desc._desc.flags |= NX_SF_ENABLE_ACTIVETRANSFORMS; - desc._desc.flags |= NX_SF_SIMULATE_SEPARATE_THREAD; + sceneDesc._desc.flags |= NX_SF_ENABLE_ACTIVETRANSFORMS; + sceneDesc._desc.flags |= NX_SF_SIMULATE_SEPARATE_THREAD; + + if (physx_internal_threads > 0) { + sceneDesc._desc.flags |= NX_SF_ENABLE_MULTITHREAD; + sceneDesc._desc.threadMask=0xfffffffe; + sceneDesc._desc.internalThreadCount = physx_internal_threads; + physx_cat.info() << "Multithreading enabled. " + << "Additional threads: " << physx_internal_threads << endl; + } PhysxScene *scene = new PhysxScene(); nassertr(scene, NULL); - NxScene *scenePtr = _sdk->createScene(desc._desc); + NxScene *scenePtr = _sdk->createScene(sceneDesc._desc); nassertr(scenePtr, NULL); scene->link(scenePtr);