GL: Added orphaning buffers to avoid transient buffer stalls. Issue #706.

This commit is contained in:
Branimir Karadžić 2016-03-13 18:13:10 -07:00
parent fe89637a8c
commit 937da03f04
2 changed files with 20 additions and 4 deletions

View File

@ -5383,13 +5383,13 @@ namespace bgfx { namespace gl
if (0 < _render->m_iboffset) if (0 < _render->m_iboffset)
{ {
TransientIndexBuffer* ib = _render->m_transientIb; TransientIndexBuffer* ib = _render->m_transientIb;
m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data); m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data, true);
} }
if (0 < _render->m_vboffset) if (0 < _render->m_vboffset)
{ {
TransientVertexBuffer* vb = _render->m_transientVb; TransientVertexBuffer* vb = _render->m_transientVb;
m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data); m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data, true);
} }
_render->sort(); _render->sort();

View File

@ -1058,9 +1058,17 @@ namespace bgfx { namespace gl
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) ); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
} }
void update(uint32_t _offset, uint32_t _size, void* _data) void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false)
{ {
BX_CHECK(0 != m_id, "Updating invalid index buffer."); BX_CHECK(0 != m_id, "Updating invalid index buffer.");
if (_discard)
{
// orphan buffer...
destroy();
create(m_size, NULL, m_flags);
}
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) ); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER GL_CHECK(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, _offset , _offset
@ -1104,9 +1112,17 @@ namespace bgfx { namespace gl
GL_CHECK(glBindBuffer(m_target, 0) ); GL_CHECK(glBindBuffer(m_target, 0) );
} }
void update(uint32_t _offset, uint32_t _size, void* _data) void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false)
{ {
BX_CHECK(0 != m_id, "Updating invalid vertex buffer."); BX_CHECK(0 != m_id, "Updating invalid vertex buffer.");
if (_discard)
{
// orphan buffer...
destroy();
create(m_size, NULL, m_decl, 0);
}
GL_CHECK(glBindBuffer(m_target, m_id) ); GL_CHECK(glBindBuffer(m_target, m_id) );
GL_CHECK(glBufferSubData(m_target GL_CHECK(glBufferSubData(m_target
, _offset , _offset