mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 08:09:26 +01:00
implement streaming by bufferSubData, split upload and allocation in ringbuffer
This commit is contained in:
parent
30170575c8
commit
878bd7f26c
@ -208,6 +208,7 @@ void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float
|
||||
void ProgramShaderCache::UploadConstants()
|
||||
{
|
||||
if(s_ubo_dirty) {
|
||||
s_buffer->Alloc(s_ubo_buffer_size);
|
||||
size_t offset = s_buffer->Upload(s_ubo_buffer, s_ubo_buffer_size);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->getBuffer(), offset, s_vs_data_offset);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_buffer->getBuffer(), offset + s_vs_data_offset, s_ubo_buffer_size - s_vs_data_offset);
|
||||
|
@ -47,7 +47,7 @@ void StreamBuffer::Align ( u32 stride )
|
||||
}
|
||||
}
|
||||
|
||||
size_t StreamBuffer::Upload ( u8* data, size_t size )
|
||||
void StreamBuffer::Alloc ( size_t size )
|
||||
{
|
||||
switch(m_uploadtype) {
|
||||
case MAP_AND_ORPHAN:
|
||||
@ -55,6 +55,17 @@ size_t StreamBuffer::Upload ( u8* data, size_t size )
|
||||
glBufferData(m_buffertype, m_size, NULL, GL_STREAM_DRAW);
|
||||
m_iterator = 0;
|
||||
}
|
||||
break;
|
||||
case BUFFERSUBDATA:
|
||||
m_iterator = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
size_t StreamBuffer::Upload ( u8* data, size_t size )
|
||||
{
|
||||
switch(m_uploadtype) {
|
||||
case MAP_AND_ORPHAN:
|
||||
pointer = (u8*)glMapBufferRange(m_buffertype, m_iterator, size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||
if(pointer) {
|
||||
memcpy(pointer, data, size);
|
||||
@ -63,17 +74,20 @@ size_t StreamBuffer::Upload ( u8* data, size_t size )
|
||||
ERROR_LOG(VIDEO, "buffer mapping failed");
|
||||
}
|
||||
break;
|
||||
case BUFFERSUBDATA:
|
||||
glBufferSubData(m_buffertype, m_iterator, size, data);
|
||||
break;
|
||||
}
|
||||
size_t ret = m_iterator;
|
||||
m_iterator += size;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void StreamBuffer::Init()
|
||||
{
|
||||
switch(m_uploadtype) {
|
||||
case MAP_AND_ORPHAN:
|
||||
case BUFFERSUBDATA:
|
||||
glBindBuffer(m_buffertype, m_buffer);
|
||||
glBufferData(m_buffertype, m_size, NULL, GL_STREAM_DRAW);
|
||||
break;
|
||||
@ -84,6 +98,7 @@ void StreamBuffer::Shutdown()
|
||||
{
|
||||
switch(m_uploadtype) {
|
||||
case MAP_AND_ORPHAN:
|
||||
case BUFFERSUBDATA:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,8 @@
|
||||
namespace OGL
|
||||
{
|
||||
enum StreamType {
|
||||
MAP_AND_ORPHAN
|
||||
MAP_AND_ORPHAN,
|
||||
BUFFERSUBDATA
|
||||
};
|
||||
|
||||
class StreamBuffer {
|
||||
@ -34,6 +35,7 @@ public:
|
||||
StreamBuffer(u32 type, size_t size);
|
||||
~StreamBuffer();
|
||||
|
||||
void Alloc(size_t size);
|
||||
size_t Upload(u8 *data, size_t size);
|
||||
|
||||
u32 getBuffer() { return m_buffer; }
|
||||
|
@ -114,16 +114,18 @@ void VertexManager::DestroyDeviceObjects()
|
||||
|
||||
void VertexManager::PrepareDrawBuffers(u32 stride)
|
||||
{
|
||||
int vertex_data_size = IndexGenerator::GetNumVerts() * stride;
|
||||
int triangle_index_size = IndexGenerator::GetTriangleindexLen();
|
||||
int line_index_size = IndexGenerator::GetLineindexLen();
|
||||
int point_index_size = IndexGenerator::GetPointindexLen();
|
||||
u32 vertex_data_size = IndexGenerator::GetNumVerts() * stride;
|
||||
u32 triangle_index_size = IndexGenerator::GetTriangleindexLen();
|
||||
u32 line_index_size = IndexGenerator::GetLineindexLen();
|
||||
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);
|
||||
u32 offset = s_vertexBuffer->Upload(LocalVBuffer, vertex_data_size);
|
||||
|
||||
s_baseVertex = offset / stride;
|
||||
|
||||
s_indexBuffer->Alloc(index_size);
|
||||
if(triangle_index_size)
|
||||
{
|
||||
s_offset[0] = s_indexBuffer->Upload((u8*)TIBuffer, triangle_index_size * sizeof(u16));
|
||||
@ -140,9 +142,9 @@ void VertexManager::PrepareDrawBuffers(u32 stride)
|
||||
|
||||
void VertexManager::Draw(u32 stride)
|
||||
{
|
||||
int triangle_index_size = IndexGenerator::GetTriangleindexLen();
|
||||
int line_index_size = IndexGenerator::GetLineindexLen();
|
||||
int point_index_size = IndexGenerator::GetPointindexLen();
|
||||
u32 triangle_index_size = IndexGenerator::GetTriangleindexLen();
|
||||
u32 line_index_size = IndexGenerator::GetLineindexLen();
|
||||
u32 point_index_size = IndexGenerator::GetPointindexLen();
|
||||
if (triangle_index_size > 0)
|
||||
{
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, triangle_index_size, GL_UNSIGNED_SHORT, (u8*)NULL+s_offset[0], s_baseVertex);
|
||||
|
Loading…
x
Reference in New Issue
Block a user