VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
makVrv::DtMainThreadJobsManager Class Reference

A light weight system for running jobs in the main thread during cull Transient Jobs run once and are removed unless the getKeep flag is true The general goal of the system is to try and keep frame rates smoother by shuttling graphics work from the cull thread to the main thread and trying to get it done ASAP. The best way to think of it as TBB parallel task for the main render thread. It allow us to do arbitrary ICO like tasks without using the ICO infrastructure. Currently it's being used it to speed up texture streaming from indirect: This is pretty much a "simple" multi-threaded producer consumer system where the jobs system will wait till it has work to do and wake up.Currently the ICO can wake it up, or directly adding a transient job. This avoids a spin loop wasting a core. The system also tries to stop doing jobs as soon as cull is done.

There are a number of different job types :

*Persistent Jobs are added once and happen at the beginning of the job update. *Transient Jobs, they typically only happen once and get deleted, but they can also adjust the _keep value with setKeep(), which allows them to get added once and run for a few frames till completion. *The ICO runs after the Transient jobs,The ico can run multiple times if cull isn't finished yet. *Currently there's no guarantee that a job will run in a given frame... could revisit in the future. *When writing new code that does work in draw implementation it's worth thinking about if it could be moved into a job and run after cull.

IMPORTANT: Linux uses the pthread API, which requires that locks are acquired before any call to Condition::wait or Condition::signal. Failing to properly acquire the lock before these calls can result in deadlock

How to subclass a job:

class DtIndirectTextureProcessorJob : public osg::Operation { public: DtIndirectTextureProcessorJob(DtIndirectTextureProcessor* proc) : osg::Operation("indirect_texture_processor", false), myProcessor(proc) { ; } virtual void operator () (osg::Object* sv) { osgUtil::SceneView* sceneView = dynamic_cast<osgUtil::SceneView*>(sv); myProcessor->collectCompiledTextures(sceneView->getRenderInfo()); // could change this dynamically depending on the type of job setKeep(false); }

DtIndirectTextureProcessor* myProcessor; };

How to run a job in cull visitor:

DtOsgCullVisitor* dtcv = dynamic_cast<DtOsgCullVisitor*>(cv); DtOsgRenderer* renderer = dynamic_cast<DtOsgRenderer*> (&(dtcv->de().renderer())); renderer->addMainThreadJob(new DtIndirectTextureProcessorJob(this));

Inheritance diagram for makVrv::DtMainThreadJobsManager:
Inheritance graph
[legend]

Public Member Functions

 DtMainThreadJobsManager (DtDe &de)
 
virtual ~DtMainThreadJobsManager ()
 
virtual void operator() (osg::Object *obj) override
 
virtual void startUp ()
 
virtual void release ()
 
virtual void setIco (osgUtil::IncrementalCompileOperation *ico)
 
virtual void addPersistantJob (osg::Operation *job)
 
virtual void removePersistantJob (osg::Operation *job)
 
virtual void addTransientJob (osg::Operation *job)
 
virtual void addRequiredTransientJob (osg::Operation *job)
 
virtual int numberOfTransientJobs () const
 
virtual void finishFrameTime (double budget, osg::Object *obj)
 
virtual double lastFrameTime () const
 

Protected Member Functions

virtual void runTransientJobs (osgUtil::SceneView *sceneView)
 

Protected Attributes

std::vector< osg::ref_ptr
< osg::Operation > > 
myPersistantJobs
 
std::vector< osg::ref_ptr
< osg::Operation > > 
myRequiredTransientJobs
 
tbb::atomic< intmyNumberOfTransientJobs
 
std::vector< osg::ref_ptr
< osg::Operation > > 
myTransientJobs
 
std::vector< osg::ref_ptr
< osg::Operation > > 
myNextFrameJobs
 
osgUtil::IncrementalCompileOperation * myIco
 
OpenThreads::Mutex myMutex
 
OpenThreads::Condition myRunThreadWaitCond
 
tbb::atomic< boolmyKeepGoing
 
osg::ref_ptr< osg::Operation > myCurrentJob
 
double myLastFrameTime
 
DtDemyDe
 

Private Member Functions

 DtMainThreadJobsManager (const DtMainThreadJobsManager &rhs)=delete
 
DtMainThreadJobsManageroperator= (const DtMainThreadJobsManager &rhs)=delete
 

Constructor & Destructor Documentation

makVrv::DtMainThreadJobsManager::DtMainThreadJobsManager ( DtDe de)
virtual makVrv::DtMainThreadJobsManager::~DtMainThreadJobsManager ( )
virtual

DTOR.

makVrv::DtMainThreadJobsManager::DtMainThreadJobsManager ( const DtMainThreadJobsManager rhs)
privatedelete

Copy Constructor not implemented – Copy Not Allowed.

Member Function Documentation

virtual void makVrv::DtMainThreadJobsManager::operator() ( osg::Object *  obj)
overridevirtual

operation function that core osg code calls every frame.

virtual void makVrv::DtMainThreadJobsManager::startUp ( )
virtual

called by renderer every frame

virtual void makVrv::DtMainThreadJobsManager::release ( )
virtual

lets the jobs system know to exit ASAP

virtual void makVrv::DtMainThreadJobsManager::setIco ( osgUtil::IncrementalCompileOperation *  ico)
virtual

sets the pointer to the ico, may or may not exist

virtual void makVrv::DtMainThreadJobsManager::addPersistantJob ( osg::Operation *  job)
virtual

add an operation that will run every frame in the main thread while the cull thread is happening.

virtual void makVrv::DtMainThreadJobsManager::removePersistantJob ( osg::Operation *  job)
virtual

removes an operation that was running in the main thread while the cull thread is happening.

virtual void makVrv::DtMainThreadJobsManager::addTransientJob ( osg::Operation *  job)
virtual

adds a jobs for doing work during cull see class doc for DtMainThreadJobManager for more details

virtual void makVrv::DtMainThreadJobsManager::addRequiredTransientJob ( osg::Operation *  job)
virtual

adds a jobs for doing work during cull. This job has to run this frame. see class doc for DtMainThreadJobManager for more details

virtual int makVrv::DtMainThreadJobsManager::numberOfTransientJobs ( ) const
virtual

number of active transient jobs

virtual void makVrv::DtMainThreadJobsManager::finishFrameTime ( double  budget,
osg::Object *  obj 
)
virtual

used to control running the ICO and main thread system at the end of the frame, defaults to .016

virtual double makVrv::DtMainThreadJobsManager::lastFrameTime ( ) const
virtual

used by profiler

virtual void makVrv::DtMainThreadJobsManager::runTransientJobs ( osgUtil::SceneView *  sceneView)
protectedvirtual

actually runs the transient jobs

DtMainThreadJobsManager& makVrv::DtMainThreadJobsManager::operator= ( const DtMainThreadJobsManager rhs)
privatedelete

Assignment Operator Not implemented – Assignment Not Allowed.

Member Data Documentation

std::vector<osg::ref_ptr<osg::Operation> > makVrv::DtMainThreadJobsManager::myPersistantJobs
protected
std::vector<osg::ref_ptr<osg::Operation> > makVrv::DtMainThreadJobsManager::myRequiredTransientJobs
protected
tbb::atomic<int> makVrv::DtMainThreadJobsManager::myNumberOfTransientJobs
protected
std::vector<osg::ref_ptr<osg::Operation> > makVrv::DtMainThreadJobsManager::myTransientJobs
protected
std::vector<osg::ref_ptr<osg::Operation> > makVrv::DtMainThreadJobsManager::myNextFrameJobs
protected
osgUtil::IncrementalCompileOperation* makVrv::DtMainThreadJobsManager::myIco
protected
OpenThreads::Mutex makVrv::DtMainThreadJobsManager::myMutex
protected
OpenThreads::Condition makVrv::DtMainThreadJobsManager::myRunThreadWaitCond
protected
tbb::atomic<bool> makVrv::DtMainThreadJobsManager::myKeepGoing
protected
osg::ref_ptr<osg::Operation> makVrv::DtMainThreadJobsManager::myCurrentJob
protected
double makVrv::DtMainThreadJobsManager::myLastFrameTime
protected
DtDe& makVrv::DtMainThreadJobsManager::myDe
protected

The documentation for this class was generated from the following file:

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)