Fix D3D12 VBV reading size (#3194)

* 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: Бранимир Караџић <branimirkaradzic@gmail.com>
This commit is contained in:
Edu Garcia 2023-11-06 19:15:22 +00:00 committed by GitHub
parent b01c5d597a
commit 13d1f19947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -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;
}
}