D3D11: Fixed dynamic index/vertex buffer update. Issue #601.

This commit is contained in:
Branimir Karadžić 2015-12-16 11:44:42 -08:00
parent 61b78529af
commit 5a03a03b95
2 changed files with 21 additions and 19 deletions

View File

@ -2324,7 +2324,7 @@ namespace bgfx
DynamicIndexBuffer& dib = m_dynamicIndexBuffers[handle.idx]; DynamicIndexBuffer& dib = m_dynamicIndexBuffers[handle.idx];
dib.m_handle.idx = uint16_t(ptr>>32); dib.m_handle.idx = uint16_t(ptr>>32);
dib.m_offset = uint32_t(ptr); dib.m_offset = uint32_t(ptr);
dib.m_size = size; dib.m_size = _num * indexSize;
dib.m_startIndex = bx::strideAlign(dib.m_offset, indexSize)/indexSize; dib.m_startIndex = bx::strideAlign(dib.m_offset, indexSize)/indexSize;
dib.m_flags = _flags; dib.m_flags = _flags;
@ -2469,9 +2469,9 @@ namespace bgfx
DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[handle.idx]; DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[handle.idx];
dvb.m_handle.idx = uint16_t(ptr>>32); dvb.m_handle.idx = uint16_t(ptr>>32);
dvb.m_offset = uint32_t(ptr); dvb.m_offset = uint32_t(ptr);
dvb.m_size = size; dvb.m_size = _num * _decl.m_stride;
dvb.m_startVertex = bx::strideAlign(dvb.m_offset, _decl.m_stride)/_decl.m_stride; dvb.m_startVertex = bx::strideAlign(dvb.m_offset, _decl.m_stride)/_decl.m_stride;
dvb.m_numVertices = dvb.m_size/_decl.m_stride; dvb.m_numVertices = _num;
dvb.m_stride = _decl.m_stride; dvb.m_stride = _decl.m_stride;
dvb.m_decl = declHandle; dvb.m_decl = declHandle;
dvb.m_flags = _flags; dvb.m_flags = _flags;

View File

@ -1975,7 +1975,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
{ {
ID3D11DeviceContext* deviceCtx = m_deviceCtx; ID3D11DeviceContext* deviceCtx = m_deviceCtx;
m_indexBuffers [_blitter.m_ib->handle.idx].update(0, _numIndices*2, _blitter.m_ib->data); m_indexBuffers [_blitter.m_ib->handle.idx].update(0, _numIndices*2, _blitter.m_ib->data, true);
m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data, true); m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data, true);
deviceCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); deviceCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
@ -3619,8 +3619,6 @@ BX_PRAGMA_DIAGNOSTIC_POP();
#if 0 #if 0
BX_UNUSED(_discard); BX_UNUSED(_discard);
ID3D11Device* device = s_renderD3D11->m_device;
D3D11_BUFFER_DESC desc; D3D11_BUFFER_DESC desc;
desc.ByteWidth = _size; desc.ByteWidth = _size;
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
@ -3634,17 +3632,19 @@ BX_PRAGMA_DIAGNOSTIC_POP();
srd.SysMemPitch = 0; srd.SysMemPitch = 0;
srd.SysMemSlicePitch = 0; srd.SysMemSlicePitch = 0;
D3D11_BOX srcBox;
srcBox.left = 0;
srcBox.top = 0;
srcBox.front = 0;
srcBox.right = _size;
srcBox.bottom = 1;
srcBox.back = 1;
ID3D11Device* device = s_renderD3D11->m_device;
ID3D11Buffer* ptr; ID3D11Buffer* ptr;
DX_CHECK(device->CreateBuffer(&desc, &srd, &ptr) ); DX_CHECK(device->CreateBuffer(&desc, &srd, &ptr) );
D3D11_BOX box;
box.left = 0;
box.top = 0;
box.front = 0;
box.right = _size;
box.bottom = 1;
box.back = 1;
deviceCtx->CopySubresourceRegion(m_ptr deviceCtx->CopySubresourceRegion(m_ptr
, 0 , 0
, _offset , _offset
@ -3652,14 +3652,16 @@ BX_PRAGMA_DIAGNOSTIC_POP();
, 0 , 0
, ptr , ptr
, 0 , 0
, &box , &srcBox
); );
DX_RELEASE(ptr, 0); DX_RELEASE(ptr, 0);
#else #else
D3D11_MAPPED_SUBRESOURCE mapped; D3D11_MAPPED_SUBRESOURCE mapped;
BX_UNUSED(_discard); D3D11_MAP type = _discard
D3D11_MAP type = D3D11_MAP_WRITE_DISCARD; ? D3D11_MAP_WRITE_DISCARD
: D3D11_MAP_WRITE_NO_OVERWRITE
;
DX_CHECK(deviceCtx->Map(m_ptr, 0, type, 0, &mapped) ); DX_CHECK(deviceCtx->Map(m_ptr, 0, type, 0, &mapped) );
memcpy( (uint8_t*)mapped.pData + _offset, _data, _size); memcpy( (uint8_t*)mapped.pData + _offset, _data, _size);
deviceCtx->Unmap(m_ptr, 0); deviceCtx->Unmap(m_ptr, 0);
@ -4666,13 +4668,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
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();