diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 3246a0261..f91d9a88b 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -4431,18 +4431,16 @@ namespace bgfx uint32_t getAvailTransientIndexBuffer(uint32_t _num, uint16_t _indexSize) { - const uint32_t offset = bx::strideAlign(m_iboffset, _indexSize); - uint32_t iboffset = offset + _num*_indexSize; - iboffset = bx::min(iboffset, g_caps.limits.maxTransientIbSize); - const uint32_t num = (iboffset-offset)/_indexSize; - return num; + const uint64_t offset = bx::strideAlign(m_iboffset, _indexSize); + const uint64_t iboffset = bx::min(offset + uint64_t(_num)*_indexSize, g_caps.limits.maxTransientIbSize); + return uint32_t(bx::max(iboffset, offset) - offset)/_indexSize; } uint32_t allocTransientIndexBuffer(uint32_t& _num, uint16_t _indexSize) { - uint32_t offset = bx::strideAlign(m_iboffset, _indexSize); - uint32_t num = getAvailTransientIndexBuffer(_num, _indexSize); - m_iboffset = offset + num*_indexSize; + const uint32_t offset = bx::strideAlign(m_iboffset, _indexSize); + const uint32_t num = getAvailTransientIndexBuffer(_num, _indexSize); + m_iboffset = 0 == num ? m_iboffset : offset + num*_indexSize; _num = num; return offset; @@ -4450,18 +4448,16 @@ namespace bgfx uint32_t getAvailTransientVertexBuffer(uint32_t _num, uint16_t _stride) { - uint32_t offset = bx::strideAlign(m_vboffset, _stride); - uint32_t vboffset = offset + _num * _stride; - vboffset = bx::min(vboffset, g_caps.limits.maxTransientVbSize); - uint32_t num = (vboffset-offset)/_stride; - return num; + const uint64_t offset = bx::strideAlign(m_vboffset, _stride); + const uint64_t vboffset = bx::min(offset + uint64_t(_num)*_stride, g_caps.limits.maxTransientVbSize); + return uint32_t(bx::max(vboffset, offset) - offset)/_stride; } uint32_t allocTransientVertexBuffer(uint32_t& _num, uint16_t _stride) { - uint32_t offset = bx::strideAlign(m_vboffset, _stride); - uint32_t num = getAvailTransientVertexBuffer(_num, _stride); - m_vboffset = offset + num * _stride; + const uint32_t offset = bx::strideAlign(m_vboffset, _stride); + const uint32_t num = getAvailTransientVertexBuffer(_num, _stride); + m_vboffset = 0 == num ? m_vboffset : offset + num*_stride; _num = num; return offset; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index ce2c39f49..f9acb5a56 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -5937,6 +5937,11 @@ namespace bgfx { namespace d3d12 if (!_finishAll && _waitFence <= m_completedFence) { + while (0 < m_control.getNumUsed() + && consume(0) ) + { + } + return; } }