persistance mapping proposal

This commit is contained in:
mp3butcher 2018-01-30 17:52:27 +01:00 committed by Julien Valentin
parent 743bd7ae71
commit 2c942f4771
2 changed files with 45 additions and 67 deletions

View File

@ -98,7 +98,6 @@ class BufferObject;
class BufferObjectProfile
{
public:
BufferObjectProfile():
_target(0),
_usage(0),
@ -240,6 +239,10 @@ class OSG_EXPORT GLBufferObject : public GraphicsObject
void setBufferDataHasBeenRead(const osg::BufferData* bd);
void downloadBuffer(unsigned int entryidx);
void commitDMA(unsigned int entryidx);
protected:
virtual ~GLBufferObject();
@ -588,7 +591,6 @@ class OSG_EXPORT BufferData : public Object
void addClient(osg::Object * /*client*/) { ++_numClients; }
void removeClient(osg::Object * /*client*/) { --_numClients; }
protected:
virtual ~BufferData();

View File

@ -1,6 +1,6 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* Copyright (C) 2012 David Callu
* Copyright (C) 2018 Julien Valentin
* Copyright (C) 2019 Julien Valentin
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
@ -122,7 +122,7 @@ void GLBufferObject::clear()
void GLBufferObject::compileBuffer()
{
_dirty = false;
_persistantDMA=0;
_bufferEntries.reserve(_bufferObject->getNumBufferData());
bool compileAll = false;
@ -214,30 +214,20 @@ _persistantDMA=0;
_allocatedSize = _profile._size;
OSG_INFO<<" Allocating new glBufferData(), _allocatedSize="<<_allocatedSize<<std::endl;
const osg::Array* array = _bufferEntries.begin()->dataSource->asArray();
if(array)_profile._mappingbitfield= GL_MAP_PERSISTENT_BIT| GL_MAP_WRITE_BIT| GL_MAP_COHERENT_BIT; //DEBUG
if(_profile._mappingbitfield != 0)
{
_extensions->glBufferStorage(_profile._target, _profile._size, NULL, _profile._mappingbitfield);
if(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT ){
///debug invalidate mapping
if(_persistantDMA){
_extensions->glUnmapBuffer(_profile._target);
_persistantDMA=0;
if(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT )
{
/// invalidate mapping of previously allocated
if(_persistantDMA)
{
_extensions->glUnmapBuffer(_profile._target);
_persistantDMA = 0;
}
_persistantDMA = _extensions->glMapBufferRange(
_profile._target,
0,
_profile._size,
_profile._mappingbitfield |GL_MAP_INVALIDATE_RANGE_BIT|GL_MAP_FLUSH_EXPLICIT_BIT
);
GLenum err=glGetError();
if(err!=GL_NO_ERROR){
OSG_WARN<<" error"<<err<<std::endl;
}
}
_persistantDMA = _extensions->glMapBufferRange( _profile._target, 0, _profile._size, _profile._mappingbitfield );
}
}
else
@ -272,54 +262,22 @@ _persistantDMA=0;
{
if(_profile._mappingbitfield != 0 )
{
///GL_DYNAMIC_STORAGE_BIT, GL_MAP_READ_BIT GL_MAP_WRITE_BIT, GL_MAP_PERSISTENT_BIT, GL_MAP_COHERENT_BIT, and GL_CLIENT_STORAGE_BIT.
if(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT)
{
///TODO AVOID dirty
if(_persistantDMA){
GLvoid* src=const_cast<GLvoid*>(entry.dataSource->getDataPointer());
if( src)memcpy((unsigned char*)_persistantDMA+entry.offset,src,entry.dataSize);
if(_persistantDMA)
{
GLvoid* src = const_cast<GLvoid*>(entry.dataSource->getDataPointer());
memcpy((unsigned char*)_persistantDMA + entry.offset, src, entry.dataSize);
_extensions->glFlushMappedBufferRange(_profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize );
}
else OSG_WARN<<" GL_MAP_PERSISTENT_BIT problem"<<std::endl;
_extensions->glFlushMappedBufferRange(_profile._target,
(GLintptr)entry.offset,
(GLsizeiptr)entry.dataSize
);
GLenum err=glGetError();
if(err!=GL_NO_ERROR){
OSG_WARN<<" error"<<err<<std::endl;
}
}
//todo *dst=src;
// _extensions->glUnmapBuffer(_profile._target);
}
else
if(_profile._mappingbitfield & GL_MAP_WRITE_BIT)
{ ///GL_MAP_WRITE_BIT classic upload
GLvoid* src=const_cast<GLvoid*>(entry.dataSource->getDataPointer()),
*dst = _extensions->glMapBufferRange(
_profile._target,
(GLintptr)entry.offset,
(GLsizeiptr)entry.dataSize,
_profile._mappingbitfield
);
memcpy(dst,src,entry.dataSize);
_extensions->glUnmapBuffer(_profile._target);
}
else
else if(_profile._mappingbitfield & GL_MAP_WRITE_BIT)
{
/// Readback buffer
GLvoid* dst=const_cast<GLvoid*>(entry.dataSource->getDataPointer()),
*src = _extensions->glMapBufferRange(
_profile._target,
(GLintptr)entry.offset,
(GLsizeiptr)entry.dataSize,
_profile._mappingbitfield
);
memcpy(dst,src,entry.dataSize);
_extensions->glUnmapBuffer(_profile._target);
GLvoid *src = const_cast<GLvoid*>(entry.dataSource->getDataPointer()),
*dst = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._mappingbitfield);
memcpy(dst, src, entry.dataSize);
_extensions->glUnmapBuffer(_profile._target);
}
}
else
@ -331,6 +289,25 @@ _persistantDMA=0;
}
}
void GLBufferObject::commitDMA(unsigned int entryidx)
{
if( !(_profile._mappingbitfield & GL_MAP_PERSISTENT_BIT) ) return;
if (entryidx>=_bufferEntries.size()) compileBuffer();
BufferEntry& entry = _bufferEntries[entryidx];
_extensions->glFlushMappedBufferRange(_profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize);
}
void GLBufferObject::downloadBuffer(unsigned int entryidx)
{
if( !(_profile._mappingbitfield & GL_MAP_READ_BIT) ) return;
if (entryidx>=_bufferEntries.size()) compileBuffer();
BufferEntry& entry = _bufferEntries[entryidx];
GLvoid *dst = const_cast<GLvoid*>(entry.dataSource->getDataPointer()),
*src = _extensions->glMapBufferRange( _profile._target, (GLintptr)entry.offset, (GLsizeiptr)entry.dataSize, _profile._mappingbitfield);
memcpy(dst, src, entry.dataSize);
_extensions->glUnmapBuffer(_profile._target);
}
void GLBufferObject::deleteGLObject()
{
OSG_DEBUG<<"GLBufferObject::deleteGLObject() "<<_glObjectID<<std::endl;
@ -1354,7 +1331,6 @@ void BufferData::releaseGLObjects(State* state) const
}
}
//////////////////////////////////////////////////////////////////////////////////
//
// VertexBufferObject