GL3: Optimize volatile vertex buffers

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 516a56acd8
commit f799bdb650

@ -125,6 +125,9 @@ PFNGLUNMAPBUFFERPROC nglUnmapBuffer;
PFNGLGETBUFFERPARAMETERIVPROC nglGetBufferParameteriv; PFNGLGETBUFFERPARAMETERIVPROC nglGetBufferParameteriv;
PFNGLGETBUFFERPOINTERVPROC nglGetBufferPointerv; PFNGLGETBUFFERPOINTERVPROC nglGetBufferPointerv;
PFNGLMAPBUFFERRANGEPROC nglMapBufferRange;
PFNGLFLUSHMAPPEDBUFFERRANGEPROC nglFlushMappedBufferRange;
PFNGLGENQUERIESPROC nglGenQueries; PFNGLGENQUERIESPROC nglGenQueries;
PFNGLDELETEQUERIESPROC nglDeleteQueries; PFNGLDELETEQUERIESPROC nglDeleteQueries;
PFNGLISQUERYPROC nglIsQuery; PFNGLISQUERYPROC nglIsQuery;
@ -420,6 +423,9 @@ static bool setupGLCore(std::vector<const char *> &glext)
CHECK_ADDRESS(PFNGLGETBUFFERPARAMETERIVPROC, glGetBufferParameteriv); CHECK_ADDRESS(PFNGLGETBUFFERPARAMETERIVPROC, glGetBufferParameteriv);
CHECK_ADDRESS(PFNGLGETBUFFERPOINTERVPROC, glGetBufferPointerv); CHECK_ADDRESS(PFNGLGETBUFFERPOINTERVPROC, glGetBufferPointerv);
CHECK_ADDRESS(PFNGLMAPBUFFERRANGEPROC, glMapBufferRange);
CHECK_ADDRESS(PFNGLFLUSHMAPPEDBUFFERRANGEPROC, glFlushMappedBufferRange);
CHECK_ADDRESS(PFNGLGENQUERIESPROC, glGenQueries); CHECK_ADDRESS(PFNGLGENQUERIESPROC, glGenQueries);
CHECK_ADDRESS(PFNGLDELETEQUERIESPROC, glDeleteQueries); CHECK_ADDRESS(PFNGLDELETEQUERIESPROC, glDeleteQueries);
CHECK_ADDRESS(PFNGLISQUERYPROC, glIsQuery); CHECK_ADDRESS(PFNGLISQUERYPROC, glIsQuery);

@ -212,6 +212,9 @@ extern PFNGLUNMAPBUFFERPROC nglUnmapBuffer;
extern PFNGLGETBUFFERPARAMETERIVPROC nglGetBufferParameteriv; extern PFNGLGETBUFFERPARAMETERIVPROC nglGetBufferParameteriv;
extern PFNGLGETBUFFERPOINTERVPROC nglGetBufferPointerv; extern PFNGLGETBUFFERPOINTERVPROC nglGetBufferPointerv;
extern PFNGLMAPBUFFERRANGEPROC nglMapBufferRange;
extern PFNGLFLUSHMAPPEDBUFFERRANGEPROC nglFlushMappedBufferRange;
extern PFNGLGENQUERIESPROC nglGenQueries; extern PFNGLGENQUERIESPROC nglGenQueries;
extern PFNGLDELETEQUERIESPROC nglDeleteQueries; extern PFNGLDELETEQUERIESPROC nglDeleteQueries;
extern PFNGLISQUERYPROC nglIsQuery; extern PFNGLISQUERYPROC nglIsQuery;

@ -87,7 +87,10 @@ void *CVertexBufferGL::lock()
{ {
H_AUTO_OGL(CVertexBufferGLARB_lock); H_AUTO_OGL(CVertexBufferGLARB_lock);
if (m_VertexPtr) return m_VertexPtr; // already locked if (m_VertexPtr) return m_VertexPtr; // already locked :|
const uint size = VB->getNumVertices() * VB->getVertexSize();
if (m_Invalid) if (m_Invalid)
{ {
if (VB->getLocation() != CVertexBuffer::NotResident) if (VB->getLocation() != CVertexBuffer::NotResident)
@ -106,7 +109,6 @@ void *CVertexBufferGL::lock()
m_Driver->incrementResetCounter(); m_Driver->incrementResetCounter();
return &m_DummyVB[0]; return &m_DummyVB[0];
} }
const uint size = VB->getNumVertices() * VB->getVertexSize();
m_Driver->_DriverGLStates.forceBindARBVertexBuffer(vertexBufferID); m_Driver->_DriverGLStates.forceBindARBVertexBuffer(vertexBufferID);
nglBufferData(GL_ARRAY_BUFFER, size, NULL, m_Driver->vertexBufferUsageGL3(m_MemType)); nglBufferData(GL_ARRAY_BUFFER, size, NULL, m_Driver->vertexBufferUsageGL3(m_MemType));
if (glGetError() != GL_NO_ERROR) if (glGetError() != GL_NO_ERROR)
@ -130,7 +132,27 @@ void *CVertexBufferGL::lock()
m_Driver->_DriverGLStates.bindARBVertexBuffer(VertexObjectId); m_Driver->_DriverGLStates.bindARBVertexBuffer(VertexObjectId);
// m_VertexPtr = nglMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
// PERFORMANCE: AMD: This brings framerate from 24fps to 38fps, glitches with volatile buffers such as animated models and gui, likely glitches with others
// m_VertexPtr = nglMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
// PERFORMANCE: AMD: This brings framerate from 24fps to 38fps, glitches with landscape rendering
// m_VertexPtr = nglMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
// Invalidate when updating volatile buffers, framerate from 24fps to 38fps in reference test on AMD platform
// TODO: Find where we can optimize with GL_MAP_UNSYNCHRONIZED_BIT
switch (m_MemType)
{
case CVertexBuffer::AGPVolatile:
case CVertexBuffer::RAMVolatile:
m_VertexPtr = nglMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
break;
default:
m_VertexPtr = nglMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); m_VertexPtr = nglMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
break;
}
if (!m_VertexPtr) if (!m_VertexPtr)
{ {
nglUnmapBuffer(GL_ARRAY_BUFFER); nglUnmapBuffer(GL_ARRAY_BUFFER);

Loading…
Cancel
Save