VR-Forces 4.10 Class Documentation
 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 | Private Attributes
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. More...

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

Public Member Functions

 DtMainThreadJobsManager (DtDe &de)
 
virtual ~DtMainThreadJobsManager ()
 DTOR. More...
 
virtual void operator() (osg::Object *obj)
 operation function that core osg code calls every frame. More...
 
virtual void startUp ()
 called by renderer every frame More...
 
virtual void release ()
 lets the jobs system know to exit ASAP More...
 
void setIco (osgUtil::IncrementalCompileOperation *ico)
 sets the pointer to the ico, may or may not exist More...
 
virtual void addPersistantJob (osg::Operation *job)
 add an operation that will run every frame in the main thread while the cull thread is happening. More...
 
virtual void removePersistantJob (osg::Operation *job)
 removes an operation that was running in the main thread while the cull thread is happening. More...
 
virtual void addTransientJob (osg::Operation *job)
 adds a jobs for doing work during cull see class doc for DtMainThreadJobManager for more details More...
 
virtual void addRequiredTransientJob (osg::Operation *job)
 adds a jobs for doing work during cull. This job has to run this frame. see class doc for DtMainThreadJobManager for more details More...
 
virtual int numberOfTransientJobs ()
 number of active transient jobs More...
 
virtual void finishFrameTime (double budget, osg::Object *obj)
 used to control running the ICO and main thread system at the end of the frame, defaults to .016 More...
 
virtual double lastFrameTime ()
 used by profiler More...
 

Protected Member Functions

virtual void runTransientJobs (osgUtil::SceneView *sceneView)
 actually runs the transient jobs More...
 

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
 

Private Member Functions

 DtMainThreadJobsManager (const DtMainThreadJobsManager &rhs)
 Copy Constructor not implemented – Copy Not Allowed. More...
 
DtMainThreadJobsManageroperator= (const DtMainThreadJobsManager &rhs)
 Assignment Operator Not implemented – Assignment Not Allowed. More...
 

Private Attributes

DtDemyDe
 

Detailed Description

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));

Constructor & Destructor Documentation

makVrv::DtMainThreadJobsManager::DtMainThreadJobsManager ( DtDe de)
virtual makVrv::DtMainThreadJobsManager::~DtMainThreadJobsManager ( )
inlinevirtual
makVrv::DtMainThreadJobsManager::DtMainThreadJobsManager ( const DtMainThreadJobsManager rhs)
private

Copy Constructor not implemented – Copy Not Allowed.

Member Function Documentation

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

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

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

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 ( )
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 ( )
inlinevirtual

used by profiler

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

actually runs the transient jobs

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

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
private

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

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)