PhysX Visual Debugger (PVD)

PVD

../_images/PvdScreenshot.png

The PhysX Visual Debugger (PVD) provides a graphical view of the PhysX scene and includes various tools to inspect and visualize variables of every PhysX object. Additionally it can also record and visualize memory and timing data.

PVD can be downloaded from: http://supportcenteronline.com/ics/support/default.asp?deptID=1949

Questions regarding the usage of the GUI should all be answered by its detailed built-in help.

Basic Setup (SDK Side)

PVD integration is enabled in the debug, checked and profiling configurations of the SDK. In order to reduce memory footprint and code size, it is not enabled in the release configuration.

The SDK outputs the PVD debugging data in form of a stream. PVD supports reading the stream either from a TCP/IP network socket or from a file.

Network Setup

Streaming to TCP/IP is supported on almost all platforms, and is usually the most convenient way to collect PVD data. In this mode the stream can be watched in real-time, depending only on network speed and scene complexity. In network mode PVD acts as a TCP/IP server and must therefore be launched before the SDK tries to connect to it. The default listening port is 5425:

// check if PvdConnection manager is available on this platform
if(mPhysics->getPvdConnectionManager() == NULL)
    return;

// setup connection parameters
const char*     pvd_host_ip = "127.0.0.1";  // IP of the PC which is running PVD
int             port        = 5425;         // TCP port to connect to, where PVD is listening
unsigned int    timeout     = 100;          // timeout in milliseconds to wait for PVD to respond,
                                            // consoles and remote PCs need a higher timeout.
PxVisualDebuggerConnectionFlags connectionFlags = PxVisualDebuggerExt::getAllConnectionFlags();

// and now try to connect
PVD::PvdConnection* theConnection = PxVisualDebuggerExt::createConnection(mPhysics->getPvdConnectionManager(),
    pvd_host_ip, port, timeout, connectionFlags));

// remember to release the connection at shutdown
    if (theConnection)
            theConnection->release();

File Setup

Streaming to file is an alternative to network streams. This is the recommended fall-back in case your platform or system setup does not support a network connection to PVD. File streams are often faster than network sockets and therefore a good alternative if performance is more important than real-time viewing. Streams stored as files can be loaded by drag&drop or over the File->Load menu in PVD:

// check if PvdConnection manager is available on this platform
if(mPhysics->getPvdConnectionManager() == NULL)
    return;

// setup connection parameters
const char*     filename = "C:\\PvdCapture.pxd2";  // filename where the stream will be written to
PxVisualDebuggerConnectionFlags connectionFlags = PxVisualDebuggerExt::getAllConnectionFlags();

// and now try to connect
PVD::PvdConnection* theConnection = PxVisualDebuggerExt::createConnection(mPhysics->getPvdConnectionManager(),
    filename, connectionFlags);

// remember to release the connection at shutdown
    if (theConnection)
            theConnection->release();

Advanced Setup

Connection Flags

To optimize the stream size we provide flags to enable specific features. This has both influence on PVD's and the SDK's performance:

  • PxVisualDebuggerConnectionFlag::eDEBUG: Transfer all debug data to visualize and inspect objects. This flag has usually the biggest impact on the stream's size.
  • PxVisualDebuggerConnectionFlag::ePROFILE: Transfer timing information of various profiling zones in our SDK.
  • PxVisualDebuggerConnectionFlag::eMEMORY: Transfer memory usage data of our SDK.

Setup to transfer only profiling data over network:

PVD::PvdConnection* theConnection = PxVisualDebuggerExt::createConnection(mPhysics->getPvdConnectionManager(),
    pvd_host_ip, port, timeout, PxVisualDebuggerConnectionFlag::Profile);

Visualizing Externals and Extended Data

Joints are implemented as an extension to the SDK constraints and therefore need special handling to get transmitted to PVD. Both joint and contact data can increase the stream size significantly. Visualizing it in PVD is therefore disabled by default. To enable them use following API calls:

mPhysics->getVisualDebugger()->setVisualDebuggerFlags(PxVisualDebuggerFlags::eTRANSMIT_CONTACTS | PxVisualDebuggerFlag::eTRANSMIT_CONSTRAINTS);

or set the flags seperately:

mPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlags::eTRANSMIT_CONSTRAINTS, true); mPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlags::eTRANSMIT_CONTACTS, true);

Visualizing SceneQuery

Visualizing SceneQuery in PVD is disabled by default since queries and hits data can increase the stream size significantly. To enable it use following API calls:

mPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlags::eTRANSMIT_SCENEQUERIES, true);

Connection Handler

Implement the PvdConnectionHandler interface if your application needs to react upon connection or disconnection from PVD, or if you plan to send custom PVD events from your application. It is recommended to toggle the contact and constraint visualization in the onPvdConnected/onPvdDisconnected callbacks to avoid potential memory and compute overhead in the SDK. The use of PvdConnectionHandler is demonstrated in our samples and the external joint implementation:

// derive from PvdConnectionHandler
struct MyConnectionHandler : public physx::debugger::comm::PvdConnectionHandler
{
    virtual void onPvdSendClassDescriptions( physx::debugger::comm::PvdConnection& inFactory )
    {
        // send your custom PVD class descriptions from here
        // this then allows PVD to correctly identify and represent
        // custom data that is sent from your application to a PvdConnection.
        // example in JointConnectionHandler
    }
    virtual void onPvdConnected( physx::debugger::comm::PvdConnection& )
    {
        // do something when successfully connected
        // e.g. enable contact and constraint visualization
    }
    virtual void onPvdDisconnected( physx::debugger::comm::PvdConnection&)
    {
        // handle disconnection
        // e.g. disable contact and constraint visualization
    }
};

// register custom handler
MyConnectionHandler myConnectionHandler;
if(mPhysics->getPvdConnectionManager())
    mPhysics->getPvdConnectionManager()->addHandler(&myConnectionHandler);

PVD Error Stream

To send error message to PVD, please call PxVisualDebugger::sendErrorMessage(PxErrorCode::Enum code, const char* message, const char* file, PxU32 line). The message will be listed in ErrorStream view of PVD.

You can call this method in your error callback. Alternatively, PhysxExtensions also provide a helper class PxDefaultPvdErrorCallback as reference. By using this class as the base class of your own error callback, and calling setVisualDebugger() when pvd is connected, the error message can automaticly send to PVD.