Skip to content

Commit 34cb0f5

Browse files
committed
Integrate weejobs into PagedNode2
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...
1 parent c5a12ce commit 34cb0f5

File tree

16 files changed

+521
-326
lines changed

16 files changed

+521
-326
lines changed

src/applications/osgearth_collecttriangles/osgearth_collecttriangles.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,7 @@ struct PredictiveDataLoader : public osg::NodeVisitor
949949
if (!pagedNode.isLoaded())
950950
{
951951
float priority = -range;
952-
// TODO: ICO
953-
pagedNode.load(priority, nullptr);
952+
pagedNode.startLoad(priority, nullptr);
954953
_fullyLoaded = false;
955954
}
956955
pagedNode.touch();

src/osgEarth/AnnotationUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <osgEarth/Color>
2525
#include <osgEarth/MeshSubdivider>
2626
#include <osgEarth/TextSymbolizer>
27-
#include <osgEarth/Threading>
2827
#include <osgEarth/Registry>
2928
#include <osgEarth/Capabilities>
3029
#include <osgEarth/CullingUtils>

src/osgEarth/ColorFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>
1818
*/
1919
#include <osgEarth/ColorFilter>
20-
#include <osgEarth/Threading>
20+
#include <mutex>
2121

2222
using namespace osgEarth;
2323

src/osgEarth/DrapingCullSet

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <osgEarth/Common>
2626
#include <osgEarth/Containers>
2727
#include <osgEarth/DrapeableNode>
28-
#include <osgEarth/Threading>
2928
#include <osg/Camera>
3029
#include <osg/ObserverNodePath>
3130
#include <queue>

src/osgEarth/EarthManipulator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,8 @@ EarthManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapt
16091609

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

1612-
_time_s_now = view->getFrameStamp()->getReferenceTime();
1612+
_time_s_now = ea.getTime();
1613+
//_time_s_now = view->getFrameStamp()->getReferenceTime();
16131614

16141615
if ( ea.getEventType() == osgGA::GUIEventAdapter::FRAME )
16151616
{
@@ -2896,7 +2897,7 @@ EarthManipulator::handlePointAction( const Action& action, float mx, float my, o
28962897
void
28972898
EarthManipulator::handleContinuousAction( const Action& action, osg::View* view )
28982899
{
2899-
double t_factor = (_time_s_now - _last_continuous_action_time)/0.016666666;
2900+
double t_factor = (_time_s_now - _last_continuous_action_time) * 60.0;
29002901
_last_continuous_action_time = _time_s_now;
29012902
handleMovementAction( action._type, _continuous_dx * t_factor, _continuous_dy * t_factor, view );
29022903
}

src/osgEarth/Elevation

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace osgEarth
129129
std::vector<float> _resolutions;
130130
osg::ref_ptr<osg::Image> _ruggedness;
131131
ImageUtils::PixelReader _readRuggedness;
132-
Mutex _mutex;
132+
std::mutex _mutex;
133133
};
134134

135135
/**

src/osgEarth/FileUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <osgEarth/FileUtils>
2121
#include <osgEarth/Registry>
2222
#include <osgEarth/StringUtils>
23-
#include <osgEarth/Threading>
2423
#include "Notify"
2524
#include <osgDB/FileUtils>
2625
#include <osgDB/FileNameUtils>

src/osgEarth/GLUtils

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include <osgEarth/Common>
2727
#include <osgEarth/optional>
28-
#include <osgEarth/Threading>
2928
#include <osgEarth/Math>
3029
#include <osg/StateSet>
3130
#include <osg/OperationThread>
@@ -60,8 +59,6 @@ namespace osgUtil {
6059

6160
namespace osgEarth
6261
{
63-
using namespace Threading;
64-
6562
struct OSGEARTH_EXPORT GLUtils
6663
{
6764
//! Sets any default uniforms required by the implementation
@@ -603,7 +600,7 @@ namespace osgEarth
603600

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

629626
protected:
630627

631-
mutable Mutex _mutex;
628+
mutable std::mutex _mutex;
632629
Collection _objects; // objects being monitored
633630
GLsizeiptr _totalBytes;
634631
unsigned _hits;
@@ -649,9 +646,6 @@ namespace osgEarth
649646

650647
//! Release all objects created in the provided GC
651648
void releaseAll(const osg::GraphicsContext*);
652-
653-
private:
654-
static Mutexed<std::vector<GLObjectPool*>> _pools;
655649
};
656650

657651
/**
@@ -760,7 +754,7 @@ namespace osgEarth
760754
{
761755
public:
762756
//! Result type - future that will eventually contain the return value
763-
using Result = Future<RESULT_TYPE>;
757+
using Result = jobs::future<RESULT_TYPE>;
764758

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

887881
private:
888882
osg::ref_ptr<osg::GraphicsContext> _gc;
889-
static Mutex _mutex;
883+
static std::mutex _mutex;
890884
static std::unordered_map<osg::State*, GLPipeline::Ptr> _lut;
891885

892886
struct Dispatcher : public osg::GraphicsOperation
@@ -895,7 +889,7 @@ namespace osgEarth
895889
void operator()(osg::GraphicsContext*) override;
896890
using OpQ = std::queue<osg::ref_ptr<osg::Operation>>;
897891
OpQ _thisQ;
898-
Mutex _queue_mutex;
892+
std::mutex _queue_mutex;
899893
GLPipeline::WeakPtr _pipeline_ref;
900894
osg::ref_ptr<osg::GraphicsContext> _myGC;
901895
void push(osg::Operation*);
@@ -951,17 +945,29 @@ namespace osgEarth
951945
osg::ref_ptr<osgUtil::StateToCompile> collectState(
952946
osg::Node* node) const;
953947

948+
//! Request that the OSG ICO compile GL object state asychnornously.
949+
//! @node Node to compile
950+
//! @state Collected state to compile for the given node
951+
//! @host Object hosting the ICO itself. If this null, or does not host an ICO,
952+
//! the data will not compile and the promise will be resolved immediately.
953+
//! @promise Promise that the ICO should resolve when the compile is complete.
954+
void requestIncrementalCompile(
955+
const osg::ref_ptr<osg::Node>& node,
956+
osgUtil::StateToCompile* state,
957+
const osg::Object* host,
958+
jobs::promise<osg::ref_ptr<osg::Node>> promise) const;
959+
954960
void compileNow(
955961
const osg::ref_ptr<osg::Node>& node,
956962
const osg::Object* host,
957963
osgEarth::Cancelable* progress) const;
958964

959-
Future<osg::ref_ptr<osg::Node>> compileAsync(
965+
jobs::future<osg::ref_ptr<osg::Node>> compileAsync(
960966
const osg::ref_ptr<osg::Node>& node,
961967
const osg::Object* host,
962968
osgEarth::Cancelable* progress) const;
963969

964-
Future<osg::ref_ptr<osg::Node>> compileAsync(
970+
jobs::future<osg::ref_ptr<osg::Node>> compileAsync(
965971
const osg::ref_ptr<osg::Node>& node,
966972
osgUtil::StateToCompile* state,
967973
const osg::Object* host,

src/osgEarth/GLUtils.cpp

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,12 @@ GL3RealizeOperation::operator()(osg::Object* object)
520520
#define LC "[GLObjectPool] "
521521

522522
// static decl
523-
Mutexed<std::vector<GLObjectPool*>> GLObjectPool::_pools;
523+
namespace
524+
{
525+
std::mutex s_pools_mutex;
526+
std::vector<GLObjectPool*> s_pools;
527+
}
528+
524529

525530
GLObjectPool*
526531
GLObjectPool::get(osg::State& state)
@@ -539,8 +544,8 @@ std::unordered_map<int, GLObjectPool*>
539544
GLObjectPool::getAll()
540545
{
541546
std::unordered_map<int, GLObjectPool*> result;
542-
std::lock_guard<std::mutex> lock(_pools.mutex());
543-
for (auto& pool : _pools)
547+
std::unique_lock<std::mutex> lock(s_pools_mutex);
548+
for (auto& pool : s_pools)
544549
result[pool->getContextID()] = pool;
545550
return result;
546551
}
@@ -553,8 +558,9 @@ GLObjectPool::GLObjectPool(unsigned cxid) :
553558
_avarice(10.f)
554559
{
555560
_gcs.resize(256);
556-
std::lock_guard<std::mutex> lock(_pools.mutex());
557-
_pools.emplace_back(this);
561+
562+
std::unique_lock<std::mutex> lock(s_pools_mutex);
563+
s_pools.emplace_back(this);
558564

559565
char* value = ::getenv("OSGEARTH_GL_OBJECT_POOL_DELAY");
560566
if (value)
@@ -627,7 +633,7 @@ GLObjectPool::track(osg::GraphicsContext* gc)
627633
void
628634
GLObjectPool::watch(GLObject::Ptr object)
629635
{
630-
std::lock_guard<std::mutex> lock(_mutex);
636+
std::unique_lock<std::mutex> lock(_mutex);
631637
_objects.emplace_back(object);
632638

633639
//if (object->shareable())
@@ -705,7 +711,7 @@ GLObjectPool::discardAllGLObjects()
705711
void
706712
GLObjectPool::releaseAll(const osg::GraphicsContext* gc)
707713
{
708-
std::lock_guard<std::mutex> lock(_mutex);
714+
std::unique_lock<std::mutex> lock(_mutex);
709715

710716
GLsizeiptr bytes = 0;
711717
GLObjectPool::Collection keepers;
@@ -730,7 +736,7 @@ GLObjectPool::releaseAll(const osg::GraphicsContext* gc)
730736
void
731737
GLObjectPool::releaseOrphans(const osg::GraphicsContext* gc)
732738
{
733-
std::lock_guard<std::mutex> lock(_mutex);
739+
std::unique_lock<std::mutex> lock(_mutex);
734740

735741
unsigned maxNumToRelease = std::max(1u, (unsigned)pow(4.0f, _avarice));
736742
unsigned numReleased = 0u;
@@ -1680,7 +1686,7 @@ std::unordered_map<osg::State*, GLPipeline::Ptr> GLPipeline::_lut;
16801686
GLPipeline::Ptr
16811687
GLPipeline::get(osg::State& state)
16821688
{
1683-
std::lock_guard<std::mutex> lock(GLPipeline::_mutex);
1689+
std::unique_lock<std::mutex> lock(GLPipeline::_mutex);
16841690
GLPipeline::Ptr& p = _lut[&state];
16851691

16861692
if (p == nullptr)
@@ -1845,13 +1851,13 @@ GLObjectsCompiler::collectState(osg::Node* node) const
18451851
return state;
18461852
}
18471853

1848-
Future<osg::ref_ptr<osg::Node>>
1854+
jobs::future<osg::ref_ptr<osg::Node>>
18491855
GLObjectsCompiler::compileAsync(
18501856
const osg::ref_ptr<osg::Node>& node,
18511857
const osg::Object* host,
18521858
Cancelable* progress) const
18531859
{
1854-
Future<osg::ref_ptr<osg::Node>> result;
1860+
jobs::future<osg::ref_ptr<osg::Node>> result;
18551861

18561862
if (node.valid())
18571863
{
@@ -1886,14 +1892,14 @@ GLObjectsCompiler::compileAsync(
18861892
return result;
18871893
}
18881894

1889-
Future<osg::ref_ptr<osg::Node>>
1895+
jobs::future<osg::ref_ptr<osg::Node>>
18901896
GLObjectsCompiler::compileAsync(
18911897
const osg::ref_ptr<osg::Node>& node,
18921898
osgUtil::StateToCompile* state,
18931899
const osg::Object* host,
18941900
Cancelable* progress) const
18951901
{
1896-
Future<osg::ref_ptr<osg::Node>> result;
1902+
jobs::future<osg::ref_ptr<osg::Node>> result;
18971903

18981904
OE_SOFT_ASSERT_AND_RETURN(node.valid(), result);
18991905

@@ -1925,6 +1931,45 @@ GLObjectsCompiler::compileAsync(
19251931
return result;
19261932
}
19271933

1934+
void
1935+
GLObjectsCompiler::requestIncrementalCompile(
1936+
const osg::ref_ptr<osg::Node>& node,
1937+
osgUtil::StateToCompile* state,
1938+
const osg::Object* host,
1939+
jobs::promise<osg::ref_ptr<osg::Node>> promise) const
1940+
{
1941+
if (!node.valid())
1942+
{
1943+
promise.resolve();
1944+
return;
1945+
}
1946+
1947+
// if there is an ICO available, schedule the GPU compilation
1948+
bool compileScheduled = false;
1949+
1950+
if (state != nullptr && !state->empty())
1951+
{
1952+
osg::ref_ptr<ICO> ico;
1953+
if (ObjectStorage::get(host, ico) && ico->isActive())
1954+
{
1955+
auto compileSet = new osgUtil::IncrementalCompileOperation::CompileSet();
1956+
compileSet->buildCompileMap(ico->getContextSet(), *state);
1957+
ICOCallback* callback = new ICOCallback(node, _jobsActive);
1958+
callback->_promise = promise;
1959+
compileSet->_compileCompletedCallback = callback;
1960+
_jobsActive++;
1961+
ico->add(compileSet, false);
1962+
compileScheduled = true;
1963+
}
1964+
}
1965+
1966+
if (!compileScheduled)
1967+
{
1968+
// no ICO available - just resolve the future immediately
1969+
promise.resolve(node);
1970+
}
1971+
}
1972+
19281973

19291974
void
19301975
GLObjectsCompiler::compileNow(

src/osgEarth/GeoData

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ namespace osgEarth
3939
class TerrainResolver;
4040
class GeoExtent;
4141

42-
using namespace Threading;
43-
4442
/**
4543
* A georeferenced 3D point.
4644
*/
@@ -660,7 +658,7 @@ namespace osgEarth
660658
GeoImage(const osg::Image* image, const GeoExtent& extent);
661659

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

665663
/** dtor */
666664
virtual ~GeoImage() { }
@@ -780,7 +778,7 @@ namespace osgEarth
780778
GeoExtent _extent;
781779
Status _status;
782780
osg::ref_ptr<const osg::Image> _myimage;
783-
mutable optional<Future<osg::ref_ptr<osg::Image>>> _future;
781+
mutable optional<jobs::future<osg::ref_ptr<osg::Image>>> _future;
784782
osg::ref_ptr<osg::Object> _token;
785783
ImageUtils::PixelReader _read;
786784
};

src/osgEarth/GeoPositionNode.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <osgEarth/AnnotationUtils>
2525
#include <osgEarth/AnnotationSettings>
2626
#include <osgEarth/Color>
27-
#include <osgEarth/Threading>
2827
#include <osgEarth/CullingUtils>
2928
#include <osgEarth/MapNode>
3029
#include <osgEarth/TerrainEngineNode>

0 commit comments

Comments
 (0)