OpenGL: change StreamBuffer in a streaming way

This is a bit slower on map_and_* because of flushing and _very_ much slower on buffer(sub)?data because of a new memcpy.
But this design allow us to decode directly into a gpu buffer, eg vertexloader will profit :)
This commit is contained in:
degasus
2014-01-22 18:02:55 +01:00
parent 650bae12e1
commit be1fee6d74
4 changed files with 66 additions and 67 deletions

View File

@ -193,29 +193,19 @@ void ProgramShaderCache::UploadConstants()
{
if(PixelShaderManager::dirty || VertexShaderManager::dirty)
{
s_buffer->Alloc(s_ubo_buffer_size);
if (DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTREAM))
{
// This is just a hack to support our BUFFERDATA upload method
// as it's broken to uploaded in a splited way
static u8 *tmpbuffer = new u8[s_ubo_buffer_size];
memcpy(tmpbuffer, &PixelShaderManager::constants, sizeof(PixelShaderConstants));
memcpy(tmpbuffer+ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align), &VertexShaderManager::constants, sizeof(VertexShaderConstants));
size_t offset = s_buffer->Upload(tmpbuffer, s_ubo_buffer_size);
glBindBufferRange(GL_UNIFORM_BUFFER, 1,
s_buffer->getBuffer(), offset, sizeof(PixelShaderConstants));
glBindBufferRange(GL_UNIFORM_BUFFER, 2,
s_buffer->getBuffer(), offset+ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align), sizeof(VertexShaderConstants));
}
else
{
size_t offset = s_buffer->Upload((u8*)&PixelShaderManager::constants, ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align));
glBindBufferRange(GL_UNIFORM_BUFFER, 1,
s_buffer->getBuffer(), offset, sizeof(PixelShaderConstants));
offset = s_buffer->Upload((u8*)&VertexShaderManager::constants, ROUND_UP(sizeof(VertexShaderConstants), s_ubo_align));
glBindBufferRange(GL_UNIFORM_BUFFER, 2,
s_buffer->getBuffer(), offset, sizeof(VertexShaderConstants));
}
u8* buffer = s_buffer->Map(s_ubo_buffer_size, s_ubo_align);
memcpy(buffer,
&PixelShaderManager::constants, sizeof(PixelShaderConstants));
memcpy(buffer + ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align),
&VertexShaderManager::constants, sizeof(VertexShaderConstants));
size_t offset = s_buffer->Unmap(s_ubo_buffer_size);
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->getBuffer(), offset,
sizeof(PixelShaderConstants));
glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_buffer->getBuffer(), offset + ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align),
sizeof(VertexShaderConstants));
PixelShaderManager::dirty = false;
VertexShaderManager::dirty = false;