[osg-users] Performance drop in 3.6.4 vs 3.5.1

Anders Backman andersb at cs.umu.se
Thu Jan 9 03:34:56 PST 2020


The biggest issue here is that two windows (without vsync) now h*eavily
affects each other*, which they did not in OSG 3.5.1. That is certainly a
big difference between the two versions.
The performance difference remains after writing a osgt file in 3.5.1


On Wed, Jan 8, 2020 at 5:04 PM Robert Osfield <robert.osfield at gmail.com>
wrote:

> Hi Anders,
>
> Try exporting the .obj file to .osgb or .osgt from 3.5.1 and then compare
> the performance between 3.5.1 and 3.6.4.  This would check whether the .obj
> loader is a variable.
>
> As a general comment, frame rates many times higher than vsync should be
> treated careful, the frame time can be so small that small overheads
> elsewhere can lead to large % changes that appear significant but once you
> start using normal workloads these small differences no longer have an
> outsized % difference.
>
> I would check other OS's to see see if the differences apply there too.
>
> Robert.
>
>
>
> On Wed, 8 Jan 2020 at 15:56, Anders Backman <andersb at cs.umu.se> wrote:
>
>> Hi all.
>>
>> Windows 10.
>> NVida GeForce RTX 2080.
>>
>>
>> I recently switched to 3.6.4 from 3.5.1 and noticed a huge drop in
>> performance, especially when running with two separate windows (two
>> applications).
>>
>> 1. I use *SingleThreaded mode*
>> 2. I use  *m_viewer->setReleaseContextAtEndOfFrameHint(false);*
>> 3.  I use *window->setSyncToVBlank(false);*
>>
>> The above attributes are quite tightly connected to my issues.
>>
>> But first, running osgViewer with those settings I get using a simple obj
>> file. Details not important, see below.
>> When loading a simple .obj file (couple of hundred triangles) into
>> osgViewer:
>>
>> *> osgViewer --window 0 0 1280 720*
>>
>> 3.5.1: 1900 fps. Draw 0.08ms
>> 3.6.4: 2500 fps Draw 0.05ms
>>
>> Now this already show something different between the two versions,
>> although perhaps not so relevant.
>>
>> [image: image.png]
>>
>> But if I start two instances of the viewer at the same time, I get a HUGE
>> difference.
>>
>> 3.5.1: Two windows, both run in ~2000fps, smoothly.
>> 3.6.4: Two windows, fps varies between 80-1200fps. Animations are not
>> smooth at all (when spinning the model).
>>
>> I also have a few more issues, but I have not been able to pin them down
>> yet:
>>
>> I get small objects culled at a certain distance although they where not
>> culled in previous version.
>> Might be some change in how bounding volume update is handled in 3.6.4,
>> will know more later.
>>
>> Anyone else noticed the performance drop/change in 3.6.4?
>>
>> /Anders
>>
>>
>>
>> --
>> __________________________________________
>> Anders Backman, HPC2N
>> 90187 Umeå University, Sweden
>> anders at cs.umu.se http://www.hpc2n.umu.se
>> Cell: +46-70-392 64 67
>> _______________________________________________
>> osg-users mailing list
>> osg-users at lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


-- 
__________________________________________
Anders Backman, HPC2N
90187 Umeå University, Sweden
anders at cs.umu.se http://www.hpc2n.umu.se
Cell: +46-70-392 64 67
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200109/7a1d46d0/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 225353 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200109/7a1d46d0/attachment-0001.png>
-------------- next part --------------
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
 *
 * This application is open source and may be redistributed and/or modified
 * freely and without restriction, both in commercial and non commercial applications,
 * as long as this copyright notice is maintained.
 *
 * This application is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/


// Include file to get the include of windows.h right, which is a bit tricky.
#ifdef _WIN32
#  ifndef WIN32_LEAN_AND_MEAN
#    define WIN32_LEAN_AND_MEAN
#  endif
#  ifndef NOMINMAX
#    define NOMINMAX
#  endif
#  include <windows.h>
#endif

#ifdef far // Defined in WinDef.h
#  undef far
#endif

#ifdef near // Defined in WinDef.h
#  undef near
#endif

#ifdef FAR  // Defined in WinDef.h; has to be defined again
#  undef FAR
#  define FAR
#endif

#ifdef NEAR // Defined in WinDef.h; has to be defined again
#  undef NEAR
#  define NEAR
#endif



#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>

#include <osg/Switch>
#include <osg/Types>
#include <osgText/Text>

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>

#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/SphericalManipulator>

#include <osgGA/Device>
#include <osg/GL2Extensions>
#include <osg/GLExtensions>
#include <osg/Version>
#include <osg/GraphicsContext>
#include <osg/Notify>
#include <iostream>


#include <WinBase.h>
int main(int argc, char** argv)
{
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
    arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad");
    arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField");
    arguments.getApplicationUsage()->addCommandLineOption("-p <filename>","Play specified camera path animation file, previously saved with 'z' key.");
    arguments.getApplicationUsage()->addCommandLineOption("--speed <factor>","Speed factor for animation playing (1 == normal speed).");
    arguments.getApplicationUsage()->addCommandLineOption("--device <device-name>","add named device to the viewer");
    arguments.getApplicationUsage()->addCommandLineOption("--stats","print out load and compile timing stats");

    osg::ref_ptr<osgViewer::Viewer> m_viewer = new osgViewer::Viewer(arguments);

    osg::Vec2i windowSize(1200, 720);
    m_viewer->setUpViewInWindow(0, 0, windowSize[0], windowSize[1]);


    m_viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
    m_viewer->realize();
    osgViewer::Viewer::Windows windows;
    m_viewer->getWindows(windows);
    osgViewer::GraphicsWindow* window = windows[0];
    window->setWindowRectangle(40, 40, windowSize[0], windowSize[1]);
    window->setWindowDecoration(true);
     m_viewer->frame(); // Force OSG to create an OpenGL context for us before calling agxGL::init().
     m_viewer->setReleaseContextAtEndOfFrameHint(false);
     m_viewer->frame();


    {
      osgViewer::Viewer::Windows windows;
      m_viewer->getWindows(windows);

      if (windows.empty()) {
        std::cerr << "Failed to create window when updating vsync" << std::endl;
        return 1;
      }
      osgViewer::GraphicsWindow *window = windows[0];
#if defined(OSG_VERSION_GREATER_OR_EQUAL) && OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
      std::cerr << "VSYNK STATUS: " << window->getSyncToVBlank() << std::endl;
      window->setSyncToVBlank(false);
#endif
    }


    unsigned int helpType = 0;
    if ((helpType = arguments.readHelpType()))
    {
        arguments.getApplicationUsage()->write(std::cout, helpType);
        return 1;
    }

    // report any errors if they have occurred when parsing the program arguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return 1;
    }

    if (arguments.argc()<=1)
    {
        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
        return 1;
    }

    bool printStats = arguments.read("--stats");



    std::string device;
    while(arguments.read("--device", device))
    {
        osg::ref_ptr<osgGA::Device> dev = osgDB::readRefFile<osgGA::Device>(device);
        if (dev.valid())
        {
            m_viewer->addDevice(dev);
        }
    }

    // set up the camera manipulators.
    {
        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;

        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
        keyswitchManipulator->addMatrixManipulator( '5', "Orbit", new osgGA::OrbitManipulator() );
        keyswitchManipulator->addMatrixManipulator( '6', "FirstPerson", new osgGA::FirstPersonManipulator() );
        keyswitchManipulator->addMatrixManipulator( '7', "Spherical", new osgGA::SphericalManipulator() );

        std::string pathfile;
        double animationSpeed = 1.0;
        while(arguments.read("--speed",animationSpeed) ) {}
        char keyForAnimationPath = '8';
        while (arguments.read("-p",pathfile))
        {
            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
            if (apm && !apm->getAnimationPath()->empty())
            {
                apm->setTimeScale(animationSpeed);

                unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
                keyswitchManipulator->selectMatrixManipulator(num);
                ++keyForAnimationPath;
            }
        }

        m_viewer->setCameraManipulator( keyswitchManipulator.get() );
    }

    // add the state manipulator
    m_viewer->addEventHandler( new osgGA::StateSetManipulator(m_viewer->getCamera()->getOrCreateStateSet()) );

    // add the thread model handler
    m_viewer->addEventHandler(new osgViewer::ThreadingHandler);

    // add the window size toggle handler
    m_viewer->addEventHandler(new osgViewer::WindowSizeHandler);

    // add the stats handler
    m_viewer->addEventHandler(new osgViewer::StatsHandler);

    // add the help handler
    m_viewer->addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));

    // add the record camera path handler
    m_viewer->addEventHandler(new osgViewer::RecordCameraPathHandler);

    // add the LOD Scale handler
    m_viewer->addEventHandler(new osgViewer::LODScaleHandler);

    // add the screen capture handler
    m_viewer->addEventHandler(new osgViewer::ScreenCaptureHandler);

    osg::ElapsedTime elapsedTime;

    // load the data
    osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
    if (!loadedModel)
    {
        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
        return 1;
    }

    if (printStats)
    {
        double loadTime = elapsedTime.elapsedTime_m();
        std::cout<<"Load time "<<loadTime<<"ms"<<std::endl;

        m_viewer->getStats()->collectStats("compile", true);
    }


    // any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized();

    // report any errors if they have occurred when parsing the program arguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return 1;
    }


    // optimize the scene graph, remove redundant nodes and state etc.
    osgUtil::Optimizer optimizer;
    optimizer.optimize(loadedModel);

    m_viewer->setSceneData(loadedModel);

    m_viewer->realize();

    return m_viewer->run();

}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: o.osgt
Type: application/octet-stream
Size: 170790 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200109/7a1d46d0/attachment-0001.obj>


More information about the osg-users mailing list