Procházet zdrojové kódy

Config-option to activate multithreaded/multicore mode for PhysX engine.

enn0x před 15 roky
rodič
revize
7b2df70c7b

+ 13 - 10
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<PhysxEnums::PhysxUpAxis> 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();

+ 1 - 0
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<PhysxEnums::PhysxUpAxis> physx_up_axis;
 
 extern EXPCL_PANDAPHYSX void init_libphysx();

+ 13 - 5
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);