Skip to content

Commit

Permalink
Fix D3D12 VBV reading size (#3194)
Browse files Browse the repository at this point in the history
* Fix D3D12 VBV reading size

When `stream.m_startVertex` is not 0 we target a position past the start of the buffer, so `BufferLocation + SizeInBytes` will be past the end of the buffer, which the debug layer will complaining about.

With this fix we're only creating a view for the part of the buffer we actually need to access.

* Reordered buffer size calculation.

---------

Co-authored-by: Бранимир Караџић <[email protected]>
  • Loading branch information
Arcnor and bkaradzic authored Nov 6, 2023
1 parent b01c5d5 commit 13d1f19
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/renderer_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4240,18 +4240,18 @@ namespace bgfx { namespace d3d12

const uint16_t layoutIdx = !isValid(vb.m_layoutHandle) ? stream.m_layoutHandle.idx : vb.m_layoutHandle.idx;
const VertexLayout& layout = s_renderD3D12->m_vertexLayouts[layoutIdx];
uint32_t stride = layout.m_stride;

D3D12_VERTEX_BUFFER_VIEW& vbv = _vbv[numStreams];
vbv.BufferLocation = vb.m_gpuVA + stream.m_startVertex * stride;
vbv.StrideInBytes = layout.m_stride;
vbv.SizeInBytes = vb.m_size;

const uint32_t stride = layout.m_stride;

_outNumVertices = bx::uint32_min(UINT32_MAX == _draw.m_numVertices
? vb.m_size/stride
: _draw.m_numVertices
, _outNumVertices
);

D3D12_VERTEX_BUFFER_VIEW& vbv = _vbv[numStreams];
vbv.BufferLocation = vb.m_gpuVA + stream.m_startVertex * stride;
vbv.StrideInBytes = stride;
vbv.SizeInBytes = _outNumVertices * stride;
}
}

Expand Down

0 comments on commit 13d1f19

Please sign in to comment.