![]() |
VR-Forces 5.0.1 Developer's Guide
|
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));

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< int > | myNumberOfTransientJobs |
| 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< bool > | myKeepGoing |
| osg::ref_ptr< osg::Operation > | myCurrentJob |
| double | myLastFrameTime |
| DtDe & | myDe |
Private Member Functions | |
| DtMainThreadJobsManager (const DtMainThreadJobsManager &rhs)=delete | |
| DtMainThreadJobsManager & | operator= (const DtMainThreadJobsManager &rhs)=delete |
| makVrv::DtMainThreadJobsManager::DtMainThreadJobsManager | ( | DtDe & | de | ) |
|
virtual |
DTOR.
|
privatedelete |
Copy Constructor not implemented – Copy Not Allowed.
|
overridevirtual |
operation function that core osg code calls every frame.
|
virtual |
called by renderer every frame
|
virtual |
lets the jobs system know to exit ASAP
|
virtual |
sets the pointer to the ico, may or may not exist
|
virtual |
add an operation that will run every frame in the main thread while the cull thread is happening.
|
virtual |
removes an operation that was running in the main thread while the cull thread is happening.
|
virtual |
adds a jobs for doing work during cull see class doc for DtMainThreadJobManager for more details
|
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 |
number of active transient jobs
|
virtual |
used to control running the ICO and main thread system at the end of the frame, defaults to .016
|
virtual |
used by profiler
|
protectedvirtual |
actually runs the transient jobs
|
privatedelete |
Assignment Operator Not implemented – Assignment Not Allowed.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |