Skip to content

Commit

Permalink
Integrate weejobs into PagedNode2
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 94aebe1cfa03e3a69e5c766a87370d019e553608
Author: Glenn Waldron <gwaldron@gmail.com>
Date:   Tue Feb 20 10:12:07 2024 -0500

    Upgrade weejobs and pagednode

commit f79665a6a7d6c214fd0338b4b4781ff9321a7f61
Author: Glenn Waldron <gwaldron@gmail.com>
Date:   Sat Feb 17 17:09:17 2024 -0500

    PagedNode: refactor to use weejobs continuations

commit 2a98b4d20f312372ca24d67bedbe994a3315c6fb
Author: Glenn Waldron <gwaldron@gmail.com>
Date:   Fri Feb 16 16:27:34 2024 -0500

    Fix refactor error and fix the gate

commit ead9c8e5acea918162d57fdda397d1387c59271a
Author: Glenn Waldron <gwaldron@gmail.com>
Date:   Fri Feb 16 15:08:42 2024 -0500

    updating pagednode2 to use weejobs continuations...
  • Loading branch information
gwaldron committed Feb 20, 2024
1 parent c5a12ce commit 34cb0f5
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,7 @@ struct PredictiveDataLoader : public osg::NodeVisitor
if (!pagedNode.isLoaded())
{
float priority = -range;
// TODO: ICO
pagedNode.load(priority, nullptr);
pagedNode.startLoad(priority, nullptr);
_fullyLoaded = false;
}
pagedNode.touch();
Expand Down
1 change: 0 additions & 1 deletion src/osgEarth/AnnotationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <osgEarth/Color>
#include <osgEarth/MeshSubdivider>
#include <osgEarth/TextSymbolizer>
#include <osgEarth/Threading>
#include <osgEarth/Registry>
#include <osgEarth/Capabilities>
#include <osgEarth/CullingUtils>
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarth/ColorFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include <osgEarth/ColorFilter>
#include <osgEarth/Threading>
#include <mutex>

using namespace osgEarth;

Expand Down
1 change: 0 additions & 1 deletion src/osgEarth/DrapingCullSet
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <osgEarth/Common>
#include <osgEarth/Containers>
#include <osgEarth/DrapeableNode>
#include <osgEarth/Threading>
#include <osg/Camera>
#include <osg/ObserverNodePath>
#include <queue>
Expand Down
5 changes: 3 additions & 2 deletions src/osgEarth/EarthManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,8 @@ EarthManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapt

osg::View* view = aa.asView();

_time_s_now = view->getFrameStamp()->getReferenceTime();
_time_s_now = ea.getTime();
//_time_s_now = view->getFrameStamp()->getReferenceTime();

if ( ea.getEventType() == osgGA::GUIEventAdapter::FRAME )
{
Expand Down Expand Up @@ -2896,7 +2897,7 @@ EarthManipulator::handlePointAction( const Action& action, float mx, float my, o
void
EarthManipulator::handleContinuousAction( const Action& action, osg::View* view )
{
double t_factor = (_time_s_now - _last_continuous_action_time)/0.016666666;
double t_factor = (_time_s_now - _last_continuous_action_time) * 60.0;
_last_continuous_action_time = _time_s_now;
handleMovementAction( action._type, _continuous_dx * t_factor, _continuous_dy * t_factor, view );
}
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarth/Elevation
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace osgEarth
std::vector<float> _resolutions;
osg::ref_ptr<osg::Image> _ruggedness;
ImageUtils::PixelReader _readRuggedness;
Mutex _mutex;
std::mutex _mutex;
};

/**
Expand Down
1 change: 0 additions & 1 deletion src/osgEarth/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <osgEarth/FileUtils>
#include <osgEarth/Registry>
#include <osgEarth/StringUtils>
#include <osgEarth/Threading>
#include "Notify"
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
Expand Down
32 changes: 19 additions & 13 deletions src/osgEarth/GLUtils
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <osgEarth/Common>
#include <osgEarth/optional>
#include <osgEarth/Threading>
#include <osgEarth/Math>
#include <osg/StateSet>
#include <osg/OperationThread>
Expand Down Expand Up @@ -60,8 +59,6 @@ namespace osgUtil {

namespace osgEarth
{
using namespace Threading;

struct OSGEARTH_EXPORT GLUtils
{
//! Sets any default uniforms required by the implementation
Expand Down Expand Up @@ -603,7 +600,7 @@ namespace osgEarth

template<typename T>
typename T::Ptr recycle(const GLObject::Compatible& compatible) {
std::lock_guard<std::mutex> lock(_mutex);
std::unique_lock<std::mutex> lock(_mutex);
typename T::Ptr result;
for (auto& object : _objects) {
if (object.use_count() == 1 && compatible(object.get())) {
Expand All @@ -628,7 +625,7 @@ namespace osgEarth

protected:

mutable Mutex _mutex;
mutable std::mutex _mutex;
Collection _objects; // objects being monitored
GLsizeiptr _totalBytes;
unsigned _hits;
Expand All @@ -649,9 +646,6 @@ namespace osgEarth

//! Release all objects created in the provided GC
void releaseAll(const osg::GraphicsContext*);

private:
static Mutexed<std::vector<GLObjectPool*>> _pools;
};

/**
Expand Down Expand Up @@ -760,7 +754,7 @@ namespace osgEarth
{
public:
//! Result type - future that will eventually contain the return value
using Result = Future<RESULT_TYPE>;
using Result = jobs::future<RESULT_TYPE>;

//! Function type of async job
using Function = std::function<RESULT_TYPE(osg::State*, Cancelable*)>;
Expand Down Expand Up @@ -886,7 +880,7 @@ namespace osgEarth

private:
osg::ref_ptr<osg::GraphicsContext> _gc;
static Mutex _mutex;
static std::mutex _mutex;
static std::unordered_map<osg::State*, GLPipeline::Ptr> _lut;

struct Dispatcher : public osg::GraphicsOperation
Expand All @@ -895,7 +889,7 @@ namespace osgEarth
void operator()(osg::GraphicsContext*) override;
using OpQ = std::queue<osg::ref_ptr<osg::Operation>>;
OpQ _thisQ;
Mutex _queue_mutex;
std::mutex _queue_mutex;
GLPipeline::WeakPtr _pipeline_ref;
osg::ref_ptr<osg::GraphicsContext> _myGC;
void push(osg::Operation*);
Expand Down Expand Up @@ -951,17 +945,29 @@ namespace osgEarth
osg::ref_ptr<osgUtil::StateToCompile> collectState(
osg::Node* node) const;

//! Request that the OSG ICO compile GL object state asychnornously.
//! @node Node to compile
//! @state Collected state to compile for the given node
//! @host Object hosting the ICO itself. If this null, or does not host an ICO,
//! the data will not compile and the promise will be resolved immediately.
//! @promise Promise that the ICO should resolve when the compile is complete.
void requestIncrementalCompile(
const osg::ref_ptr<osg::Node>& node,
osgUtil::StateToCompile* state,
const osg::Object* host,
jobs::promise<osg::ref_ptr<osg::Node>> promise) const;

void compileNow(
const osg::ref_ptr<osg::Node>& node,
const osg::Object* host,
osgEarth::Cancelable* progress) const;

Future<osg::ref_ptr<osg::Node>> compileAsync(
jobs::future<osg::ref_ptr<osg::Node>> compileAsync(
const osg::ref_ptr<osg::Node>& node,
const osg::Object* host,
osgEarth::Cancelable* progress) const;

Future<osg::ref_ptr<osg::Node>> compileAsync(
jobs::future<osg::ref_ptr<osg::Node>> compileAsync(
const osg::ref_ptr<osg::Node>& node,
osgUtil::StateToCompile* state,
const osg::Object* host,
Expand Down
71 changes: 58 additions & 13 deletions src/osgEarth/GLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,12 @@ GL3RealizeOperation::operator()(osg::Object* object)
#define LC "[GLObjectPool] "

// static decl
Mutexed<std::vector<GLObjectPool*>> GLObjectPool::_pools;
namespace
{
std::mutex s_pools_mutex;
std::vector<GLObjectPool*> s_pools;
}


GLObjectPool*
GLObjectPool::get(osg::State& state)
Expand All @@ -539,8 +544,8 @@ std::unordered_map<int, GLObjectPool*>
GLObjectPool::getAll()
{
std::unordered_map<int, GLObjectPool*> result;
std::lock_guard<std::mutex> lock(_pools.mutex());
for (auto& pool : _pools)
std::unique_lock<std::mutex> lock(s_pools_mutex);
for (auto& pool : s_pools)
result[pool->getContextID()] = pool;
return result;
}
Expand All @@ -553,8 +558,9 @@ GLObjectPool::GLObjectPool(unsigned cxid) :
_avarice(10.f)
{
_gcs.resize(256);
std::lock_guard<std::mutex> lock(_pools.mutex());
_pools.emplace_back(this);

std::unique_lock<std::mutex> lock(s_pools_mutex);
s_pools.emplace_back(this);

char* value = ::getenv("OSGEARTH_GL_OBJECT_POOL_DELAY");
if (value)
Expand Down Expand Up @@ -627,7 +633,7 @@ GLObjectPool::track(osg::GraphicsContext* gc)
void
GLObjectPool::watch(GLObject::Ptr object)
{
std::lock_guard<std::mutex> lock(_mutex);
std::unique_lock<std::mutex> lock(_mutex);
_objects.emplace_back(object);

//if (object->shareable())
Expand Down Expand Up @@ -705,7 +711,7 @@ GLObjectPool::discardAllGLObjects()
void
GLObjectPool::releaseAll(const osg::GraphicsContext* gc)
{
std::lock_guard<std::mutex> lock(_mutex);
std::unique_lock<std::mutex> lock(_mutex);

GLsizeiptr bytes = 0;
GLObjectPool::Collection keepers;
Expand All @@ -730,7 +736,7 @@ GLObjectPool::releaseAll(const osg::GraphicsContext* gc)
void
GLObjectPool::releaseOrphans(const osg::GraphicsContext* gc)
{
std::lock_guard<std::mutex> lock(_mutex);
std::unique_lock<std::mutex> lock(_mutex);

unsigned maxNumToRelease = std::max(1u, (unsigned)pow(4.0f, _avarice));
unsigned numReleased = 0u;
Expand Down Expand Up @@ -1680,7 +1686,7 @@ std::unordered_map<osg::State*, GLPipeline::Ptr> GLPipeline::_lut;
GLPipeline::Ptr
GLPipeline::get(osg::State& state)
{
std::lock_guard<std::mutex> lock(GLPipeline::_mutex);
std::unique_lock<std::mutex> lock(GLPipeline::_mutex);
GLPipeline::Ptr& p = _lut[&state];

if (p == nullptr)
Expand Down Expand Up @@ -1845,13 +1851,13 @@ GLObjectsCompiler::collectState(osg::Node* node) const
return state;
}

Future<osg::ref_ptr<osg::Node>>
jobs::future<osg::ref_ptr<osg::Node>>
GLObjectsCompiler::compileAsync(
const osg::ref_ptr<osg::Node>& node,
const osg::Object* host,
Cancelable* progress) const
{
Future<osg::ref_ptr<osg::Node>> result;
jobs::future<osg::ref_ptr<osg::Node>> result;

if (node.valid())
{
Expand Down Expand Up @@ -1886,14 +1892,14 @@ GLObjectsCompiler::compileAsync(
return result;
}

Future<osg::ref_ptr<osg::Node>>
jobs::future<osg::ref_ptr<osg::Node>>
GLObjectsCompiler::compileAsync(
const osg::ref_ptr<osg::Node>& node,
osgUtil::StateToCompile* state,
const osg::Object* host,
Cancelable* progress) const
{
Future<osg::ref_ptr<osg::Node>> result;
jobs::future<osg::ref_ptr<osg::Node>> result;

OE_SOFT_ASSERT_AND_RETURN(node.valid(), result);

Expand Down Expand Up @@ -1925,6 +1931,45 @@ GLObjectsCompiler::compileAsync(
return result;
}

void
GLObjectsCompiler::requestIncrementalCompile(
const osg::ref_ptr<osg::Node>& node,
osgUtil::StateToCompile* state,
const osg::Object* host,
jobs::promise<osg::ref_ptr<osg::Node>> promise) const
{
if (!node.valid())
{
promise.resolve();
return;
}

// if there is an ICO available, schedule the GPU compilation
bool compileScheduled = false;

if (state != nullptr && !state->empty())
{
osg::ref_ptr<ICO> ico;
if (ObjectStorage::get(host, ico) && ico->isActive())
{
auto compileSet = new osgUtil::IncrementalCompileOperation::CompileSet();
compileSet->buildCompileMap(ico->getContextSet(), *state);
ICOCallback* callback = new ICOCallback(node, _jobsActive);
callback->_promise = promise;
compileSet->_compileCompletedCallback = callback;
_jobsActive++;
ico->add(compileSet, false);
compileScheduled = true;
}
}

if (!compileScheduled)
{
// no ICO available - just resolve the future immediately
promise.resolve(node);
}
}


void
GLObjectsCompiler::compileNow(
Expand Down
6 changes: 2 additions & 4 deletions src/osgEarth/GeoData
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ namespace osgEarth
class TerrainResolver;
class GeoExtent;

using namespace Threading;

/**
* A georeferenced 3D point.
*/
Expand Down Expand Up @@ -660,7 +658,7 @@ namespace osgEarth
GeoImage(const osg::Image* image, const GeoExtent& extent);

//! Constructs a new goereferenced image from a future.
GeoImage(Future<osg::ref_ptr<osg::Image>> image, const GeoExtent& extent);
GeoImage(jobs::future<osg::ref_ptr<osg::Image>> image, const GeoExtent& extent);

/** dtor */
virtual ~GeoImage() { }
Expand Down Expand Up @@ -780,7 +778,7 @@ namespace osgEarth
GeoExtent _extent;
Status _status;
osg::ref_ptr<const osg::Image> _myimage;
mutable optional<Future<osg::ref_ptr<osg::Image>>> _future;
mutable optional<jobs::future<osg::ref_ptr<osg::Image>>> _future;
osg::ref_ptr<osg::Object> _token;
ImageUtils::PixelReader _read;
};
Expand Down
1 change: 0 additions & 1 deletion src/osgEarth/GeoPositionNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <osgEarth/AnnotationUtils>
#include <osgEarth/AnnotationSettings>
#include <osgEarth/Color>
#include <osgEarth/Threading>
#include <osgEarth/CullingUtils>
#include <osgEarth/MapNode>
#include <osgEarth/TerrainEngineNode>
Expand Down

0 comments on commit 34cb0f5

Please sign in to comment.