Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/osg/BufferObject
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class OSG_EXPORT GLBufferObject : public GraphicsObject
};

typedef std::list< ref_ptr<GLBufferObject> > GLBufferObjectList;
typedef std::vector<ref_ptr<GLBufferObject>> GLBufferObjectVector;

class OSG_EXPORT GLBufferObjectSet : public Referenced
{
Expand Down Expand Up @@ -322,7 +323,8 @@ class OSG_EXPORT GLBufferObjectSet : public Referenced
BufferObjectProfile _profile;
unsigned int _numOfGLBufferObjects;
GLBufferObjectList _orphanedGLBufferObjects;
GLBufferObjectList _pendingOrphanedGLBufferObjects;
OpenThreads::Atomic _pendingOrphanedGLBufferObjectsSize;
GLBufferObjectVector _pendingOrphanedGLBufferObjects;

GLBufferObject* _head;
GLBufferObject* _tail;
Expand Down Expand Up @@ -368,6 +370,8 @@ class OSG_EXPORT GLBufferObjectManager : public GraphicsObjectManager
void reportStats(std::ostream& out);
void recomputeStats(std::ostream& out) const;

void reportStats(unsigned frameNumber, Stats& stats) const override;

unsigned int& getFrameNumber() { return _frameNumber; }
unsigned int& getNumberFrames() { return _numFrames; }

Expand Down
9 changes: 9 additions & 0 deletions include/osg/ContextData
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
#ifndef OSG_CONTEXTDATA
#define OSG_CONTEXTDATA 1

#include <osg/GLObjects>
#include <osg/GraphicsContext>

namespace osg {

class ContextData;

typedef std::map<unsigned int, osg::ref_ptr<ContextData> > ContextDataMap;

class OSG_EXPORT ContextData : public GraphicsObjectManager
{
public:
Expand Down Expand Up @@ -73,6 +78,8 @@ class OSG_EXPORT ContextData : public GraphicsObjectManager
virtual void reportStats(std::ostream& out);
virtual void recomputeStats(std::ostream& out) const;

void reportStats(unsigned frameNumber, Stats& stats) const override;

/** Flush all deleted OpenGL objects within the specified availableTime.
* Note, must be called from a thread which has current the graphics context associated with contextID. */
virtual void flushDeletedGLObjects(double currentTime, double& availableTime);
Expand Down Expand Up @@ -130,6 +137,8 @@ class OSG_EXPORT ContextData : public GraphicsObjectManager
/** Unregister a GraphicsContext.*/
static void unregisterGraphicsContext(GraphicsContext* gc);

static ContextDataMap getContextDataMap();
Comment thread
Capostrophic marked this conversation as resolved.

protected:
virtual ~ContextData();

Expand Down
7 changes: 6 additions & 1 deletion include/osg/GLObjects
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace osg {

// forward declare
class FrameStamp;
class Stats;

/** Flush all deleted OpenGL objects within the specified availableTime.
* Note, must be called from a thread which has current the graphics context associated with contextID. */
Expand Down Expand Up @@ -67,6 +68,8 @@ class OSG_EXPORT GraphicsObjectManager : public osg::Referenced
virtual void reportStats(std::ostream& /*out*/) {}
virtual void recomputeStats(std::ostream& /*out*/) const {}

virtual void reportStats(unsigned frameNumber, Stats& stats) const {}


/** Flush all deleted OpenGL objects within the specified availableTime.
* Note, must be called from a thread which has current the graphics context associated with contextID. */
Expand Down Expand Up @@ -117,11 +120,13 @@ public:
/** implementation of the actual deletion of an GL object - subclasses from GLObjectManager must implement the appropriate GL calls.*/
virtual void deleteGLObject(GLuint globj) = 0;

void reportStats(unsigned frameNumber, Stats& stats) const override;

protected:
virtual ~GLObjectManager();

typedef std::list<GLuint> GLObjectHandleList;
OpenThreads::Mutex _mutex;
mutable OpenThreads::Mutex _mutex;
GLObjectHandleList _deleteGLObjectHandles;

};
Expand Down
6 changes: 5 additions & 1 deletion include/osg/Texture
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ public:
unsigned int getNumPendingOrphans() const { return static_cast<unsigned int>(_pendingOrphanedTextureObjects.size()); }

protected:
typedef std::vector<ref_ptr<Texture::TextureObject>> TextureObjectVector;
Comment thread
AnyOldName3 marked this conversation as resolved.

virtual ~TextureObjectSet();

Expand All @@ -1176,7 +1177,8 @@ protected:
Texture::TextureProfile _profile;
unsigned int _numOfTextureObjects;
Texture::TextureObjectList _orphanedTextureObjects;
Texture::TextureObjectList _pendingOrphanedTextureObjects;
OpenThreads::Atomic _pendingOrphanedTextureObjectsSize;
TextureObjectVector _pendingOrphanedTextureObjects;

Texture::TextureObject* _head;
Texture::TextureObject* _tail;
Expand Down Expand Up @@ -1232,6 +1234,8 @@ public:
void recomputeStats(std::ostream& out) const;
bool checkConsistency() const;

void reportStats(unsigned frameNumber, Stats& stats) const override;

unsigned int& getFrameNumber() { return _frameNumber; }
unsigned int& getNumberFrames() { return _numFrames; }

Expand Down
79 changes: 45 additions & 34 deletions src/osg/BufferObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <osg/PrimitiveSet>
#include <osg/Array>
#include <osg/ContextData>
#include <osg/Stats>

#include <OpenThreads/ScopedLock>
#include <OpenThreads/Mutex>
Expand All @@ -37,6 +38,19 @@

using namespace osg;

namespace
{

template <class Iterator, class Map>
Iterator eraseIfEmpty(Iterator it, Map& map)
{
if (it->second->getNumOfGLBufferObjects() == 0)
return map.erase(it);
return ++it;
}

}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// GLBufferObject::BufferEntry
Expand Down Expand Up @@ -351,7 +365,7 @@ void GLBufferObjectSet::handlePendingOrphandedGLBufferObjects()

unsigned int numOrphaned = _pendingOrphanedGLBufferObjects.size();

for(GLBufferObjectList::iterator itr = _pendingOrphanedGLBufferObjects.begin();
for(GLBufferObjectVector::iterator itr = _pendingOrphanedGLBufferObjects.begin();
itr != _pendingOrphanedGLBufferObjects.end();
++itr)
{
Expand All @@ -368,6 +382,7 @@ void GLBufferObjectSet::handlePendingOrphandedGLBufferObjects()
_parent->getNumberActiveGLBufferObjects() -= numOrphaned;

_pendingOrphanedGLBufferObjects.clear();
_pendingOrphanedGLBufferObjectsSize.exchange(0);

CHECK_CONSISTENCY
}
Expand All @@ -376,13 +391,11 @@ void GLBufferObjectSet::deleteAllGLBufferObjects()
{
// OSG_NOTICE<<"GLBufferObjectSet::deleteAllGLBufferObjects()"<<std::endl;

if (_pendingOrphanedGLBufferObjectsSize != 0)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedGLBufferObjects.empty())
{
// OSG_NOTICE<<"GLBufferObjectSet::flushDeletedGLBufferObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}
// OSG_NOTICE<<"GLBufferObjectSet::flushDeletedGLBufferObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}

CHECK_CONSISTENCY
Expand Down Expand Up @@ -455,13 +468,11 @@ void GLBufferObjectSet::discardAllGLBufferObjects()

void GLBufferObjectSet::flushAllDeletedGLBufferObjects()
{
if (_pendingOrphanedGLBufferObjectsSize != 0)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedGLBufferObjects.empty())
{
// OSG_NOTICE<<"GLBufferObjectSet::flushDeletedGLBufferObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}
// OSG_NOTICE<<"GLBufferObjectSet::flushDeletedGLBufferObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}

for(GLBufferObjectList::iterator itr = _orphanedGLBufferObjects.begin();
Expand All @@ -487,13 +498,11 @@ void GLBufferObjectSet::discardAllDeletedGLBufferObjects()
// OSG_NOTICE<<"GLBufferObjectSet::discardAllDeletedGLBufferObjects()"<<std::endl;

// clean up the pending orphans.
if (_pendingOrphanedGLBufferObjectsSize != 0)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedGLBufferObjects.empty())
{
// OSG_NOTICE<<"GLBufferObjectSet::flushDeletedGLBufferObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}
// OSG_NOTICE<<"GLBufferObjectSet::flushDeletedGLBufferObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}

unsigned int numDiscarded = _orphanedGLBufferObjects.size();
Expand All @@ -514,13 +523,11 @@ void GLBufferObjectSet::discardAllDeletedGLBufferObjects()

void GLBufferObjectSet::flushDeletedGLBufferObjects(double /*currentTime*/, double& availableTime)
{
if (_pendingOrphanedGLBufferObjectsSize != 0)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedGLBufferObjects.empty())
{
// OSG_NOTICE<<"GLBufferObjectSet::flushDeletedGLBufferObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}
// OSG_NOTICE<<"GLBufferObjectSet::flushDeletedGLBufferObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}

if (_parent->getCurrGLBufferObjectPoolSize()<=_parent->getMaxGLBufferObjectPoolSize())
Expand Down Expand Up @@ -574,11 +581,8 @@ bool GLBufferObjectSet::makeSpace(unsigned int& size)
{
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedGLBufferObjects.empty())
{
// OSG_NOTICE<<"GLBufferSet::::makeSpace(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}
// OSG_NOTICE<<"GLBufferSet::::makeSpace(..) handling orphans"<<std::endl;
handlePendingOrphandedGLBufferObjects();
}

if (!_orphanedGLBufferObjects.empty())
Expand Down Expand Up @@ -795,6 +799,7 @@ void GLBufferObjectSet::orphan(GLBufferObject* to)
// list. This double buffered approach to handling orphaned TO's is used
// to avoid having to mutex the process of appling active TO's.
_pendingOrphanedGLBufferObjects.push_back(to);
++_pendingOrphanedGLBufferObjectsSize;
}

void GLBufferObjectSet::remove(GLBufferObject* to)
Expand Down Expand Up @@ -936,10 +941,10 @@ void GLBufferObjectManager::deleteAllGLObjects()
ElapsedTime elapsedTime(&(getDeleteTime()));

for(GLBufferObjectSetMap::iterator itr = _glBufferObjectSetMap.begin();
itr != _glBufferObjectSetMap.end();
++itr)
itr != _glBufferObjectSetMap.end();)
{
(*itr).second->deleteAllGLBufferObjects();
itr = eraseIfEmpty(itr, _glBufferObjectSetMap);
}
}

Expand All @@ -951,27 +956,28 @@ void GLBufferObjectManager::discardAllGLObjects()
{
(*itr).second->discardAllGLBufferObjects();
}
_glBufferObjectSetMap.clear();
}

void GLBufferObjectManager::flushAllDeletedGLObjects()
{
ElapsedTime elapsedTime(&(getDeleteTime()));

for(GLBufferObjectSetMap::iterator itr = _glBufferObjectSetMap.begin();
itr != _glBufferObjectSetMap.end();
++itr)
itr != _glBufferObjectSetMap.end();)
{
(*itr).second->flushAllDeletedGLBufferObjects();
itr = eraseIfEmpty(itr, _glBufferObjectSetMap);
}
}

void GLBufferObjectManager::discardAllDeletedGLObjects()
{
for(GLBufferObjectSetMap::iterator itr = _glBufferObjectSetMap.begin();
itr != _glBufferObjectSetMap.end();
++itr)
itr != _glBufferObjectSetMap.end();)
{
(*itr).second->discardAllDeletedGLBufferObjects();
itr = eraseIfEmpty(itr, _glBufferObjectSetMap);
}
}

Expand All @@ -980,10 +986,10 @@ void GLBufferObjectManager::flushDeletedGLObjects(double currentTime, double& av
ElapsedTime elapsedTime(&(getDeleteTime()));

for(GLBufferObjectSetMap::iterator itr = _glBufferObjectSetMap.begin();
(itr != _glBufferObjectSetMap.end()) && (availableTime > 0.0);
++itr)
(itr != _glBufferObjectSetMap.end()) && (availableTime > 0.0);)
{
(*itr).second->flushDeletedGLBufferObjects(currentTime, availableTime);
itr = eraseIfEmpty(itr, _glBufferObjectSetMap);
}
}

Expand Down Expand Up @@ -1051,6 +1057,11 @@ void GLBufferObjectManager::recomputeStats(std::ostream& out) const
out<<" getMaxGLBufferObjectPoolSize()="<<getMaxGLBufferObjectPoolSize()<<" current/max size = "<<double(currentSize)/double(getMaxGLBufferObjectPoolSize())<<std::endl;
}

void GLBufferObjectManager::reportStats(unsigned frameNumber, Stats& stats) const
{
stats.setAttribute(frameNumber, "GLBufferObjectManager" + std::to_string(_contextID), static_cast<double>(_glBufferObjectSetMap.size()));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// BufferObject
Expand Down
14 changes: 13 additions & 1 deletion src/osg/ContextData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using namespace osg;


typedef std::map<unsigned int, osg::ref_ptr<ContextData> > ContextIDMap;
typedef ContextDataMap ContextIDMap;
static ContextIDMap s_contextIDMap;
static OpenThreads::ReentrantMutex s_contextIDMapMutex;
static ContextData::GraphicsContexts s_registeredContexts;
Expand Down Expand Up @@ -79,6 +79,12 @@ void ContextData::recomputeStats(std::ostream& out) const
}
}

void ContextData::reportStats(unsigned frameNumber, Stats& stats) const
{
for (ManagerMap::const_iterator it = _managerMap.begin(); it != _managerMap.end(); ++it)
if (osg::GraphicsObjectManager* const v = dynamic_cast<osg::GraphicsObjectManager*>(it->second.get()))
v->reportStats(frameNumber, stats);
}

void ContextData::flushDeletedGLObjects(double currentTime, double& availableTime)
{
Expand Down Expand Up @@ -334,3 +340,9 @@ GraphicsContext* ContextData::getCompileContext(unsigned int contextID)
if (itr != s_contextIDMap.end()) return itr->second->getCompileContext();
else return 0;
}

ContextDataMap ContextData::getContextDataMap()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex);
return s_contextIDMap;
}
12 changes: 11 additions & 1 deletion src/osg/Drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,24 @@ class DisplayListManager : public GraphicsObjectManager
#endif
}

void reportStats(unsigned frameNumber, Stats& stats) const override
{
const std::size_t size = [&](){
const OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex_deletedDisplayListCache);
return _displayListMap.size();
}();

stats.setAttribute(frameNumber, "DisplayListManager" + std::to_string(_contextID), static_cast<double>(size));
}

protected:

int _numberDrawablesReusedLastInLastFrame;
int _numberNewDrawablesInLastFrame;
int _numberDeletedDrawablesInLastFrame;

typedef std::multimap<unsigned int,GLuint> DisplayListMap;
OpenThreads::Mutex _mutex_deletedDisplayListCache;
mutable OpenThreads::Mutex _mutex_deletedDisplayListCache;
DisplayListMap _displayListMap;

};
Expand Down
10 changes: 10 additions & 0 deletions src/osg/GLObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,13 @@ GLuint GLObjectManager::createGLObject()
OSG_INFO<<"void "<<_name<<"::createGLObject() : Not Implemented"<<std::endl;
return 0;
}

void GLObjectManager::reportStats(unsigned frameNumber, Stats& stats) const
{
const std::size_t size = [&](){
const OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return _deleteGLObjectHandles.size();
}();

stats.setAttribute(frameNumber, _name + std::to_string(_contextID), static_cast<double>(size));
}
Loading