stream by map and sync

but not working perfectly, so disabled
This commit is contained in:
degasus 2013-02-01 15:15:25 +01:00
parent 878bd7f26c
commit 3af9840a4c
3 changed files with 57 additions and 22 deletions

View File

@ -23,12 +23,15 @@
namespace OGL
{
StreamBuffer::StreamBuffer(u32 type, size_t size)
: m_buffertype(type), m_size(size), m_iterator(0)
static const u32 SYNC_POINTS = 16;
StreamBuffer::StreamBuffer(u32 type, size_t size, StreamType uploadType)
: m_uploadtype(uploadType), m_buffertype(type), m_size(size), m_iterator(0), m_last_iterator(0)
{
glGenBuffers(1, &m_buffer);
m_uploadtype = MAP_AND_ORPHAN;
if(m_uploadtype == STREAM_DETECT)
m_uploadtype = MAP_AND_ORPHAN;
Init();
}
@ -39,32 +42,51 @@ StreamBuffer::~StreamBuffer()
glDeleteBuffers(1, &m_buffer);
}
void StreamBuffer::Align ( u32 stride )
void StreamBuffer::Alloc ( size_t size, u32 stride )
{
if(m_iterator) {
m_iterator--;
m_iterator = m_iterator - (m_iterator % stride) + stride;
size_t m_iterator_aligned = m_iterator;
if(m_iterator_aligned && stride) {
m_iterator_aligned--;
m_iterator_aligned = m_iterator_aligned - (m_iterator_aligned % stride) + stride;
}
}
void StreamBuffer::Alloc ( size_t size )
{
switch(m_uploadtype) {
case MAP_AND_ORPHAN:
if(m_iterator+size >= m_size) {
if(m_iterator_aligned+size >= m_size) {
glBufferData(m_buffertype, m_size, NULL, GL_STREAM_DRAW);
m_iterator = 0;
m_iterator_aligned = 0;
}
break;
case MAP_AND_SYNC:
for(u32 i=m_iterator*SYNC_POINTS/m_size+1; i<(m_iterator_aligned+size)*SYNC_POINTS/m_size+1 && i < SYNC_POINTS; i++)
{
glClientWaitSync(fences[i], GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
glDeleteSync(fences[i]);
}
if(m_iterator_aligned+size >= m_size) {
for(u32 i=m_last_iterator*SYNC_POINTS/m_size; i < SYNC_POINTS; i++)
fences[i] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
m_iterator_aligned = 0;
m_last_iterator = 0;
glClientWaitSync(fences[0], GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
glDeleteSync(fences[0]);
}
break;
case BUFFERSUBDATA:
m_iterator = 0;
m_iterator_aligned = 0;
break;
}
m_iterator = m_iterator_aligned;
}
size_t StreamBuffer::Upload ( u8* data, size_t size )
{
switch(m_uploadtype) {
case MAP_AND_SYNC:
for(u32 i=m_last_iterator*SYNC_POINTS/m_size; i<m_iterator*SYNC_POINTS/m_size; i++)
fences[i] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
case MAP_AND_ORPHAN:
pointer = (u8*)glMapBufferRange(m_buffertype, m_iterator, size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
if(pointer) {
@ -78,14 +100,19 @@ size_t StreamBuffer::Upload ( u8* data, size_t size )
glBufferSubData(m_buffertype, m_iterator, size, data);
break;
}
size_t ret = m_iterator;
m_last_iterator = m_iterator;
m_iterator += size;
return ret;
return m_last_iterator;
}
void StreamBuffer::Init()
{
switch(m_uploadtype) {
case MAP_AND_SYNC:
fences = new GLsync[SYNC_POINTS];
for(u32 i=0; i<SYNC_POINTS; i++)
fences[i] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
case MAP_AND_ORPHAN:
case BUFFERSUBDATA:
glBindBuffer(m_buffertype, m_buffer);
@ -97,6 +124,12 @@ void StreamBuffer::Init()
void StreamBuffer::Shutdown()
{
switch(m_uploadtype) {
case MAP_AND_SYNC:
for(u32 i=0; i<SYNC_POINTS; i++)
glDeleteSync(fences[i]);
delete [] fences;
break;
case MAP_AND_ORPHAN:
case BUFFERSUBDATA:
break;

View File

@ -21,27 +21,28 @@
#include "VideoCommon.h"
#include "FramebufferManager.h"
#include "GLUtil.h"
namespace OGL
{
enum StreamType {
STREAM_DETECT,
MAP_AND_ORPHAN,
MAP_AND_SYNC,
BUFFERSUBDATA
};
class StreamBuffer {
public:
StreamBuffer(u32 type, size_t size);
StreamBuffer(u32 type, size_t size, StreamType uploadType = STREAM_DETECT);
~StreamBuffer();
void Alloc(size_t size);
void Alloc(size_t size, u32 stride = 0);
size_t Upload(u8 *data, size_t size);
u32 getBuffer() { return m_buffer; }
void Align(u32 stride);
private:
void Init();
void Shutdown();
@ -52,6 +53,8 @@ private:
size_t m_size;
u8 *pointer;
size_t m_iterator;
size_t m_last_iterator;
GLsync *fences;
};
}

View File

@ -120,8 +120,7 @@ void VertexManager::PrepareDrawBuffers(u32 stride)
u32 point_index_size = IndexGenerator::GetPointindexLen();
u32 index_size = (triangle_index_size+line_index_size+point_index_size) * sizeof(u16);
s_vertexBuffer->Align(stride);
s_vertexBuffer->Alloc(vertex_data_size);
s_vertexBuffer->Alloc(vertex_data_size, stride);
u32 offset = s_vertexBuffer->Upload(LocalVBuffer, vertex_data_size);
s_baseVertex = offset / stride;