From 9dab3f9b9b14cbe8aa01f70b6c2c6f0e3ceca9d7 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 11 Jul 2021 13:32:17 +1000 Subject: [PATCH] D3D12/StreamBuffer: Fix edge case of allocating buffer size --- src/common/d3d12/stream_buffer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/d3d12/stream_buffer.cpp b/src/common/d3d12/stream_buffer.cpp index 5a86d5cbd..0812c3dae 100644 --- a/src/common/d3d12/stream_buffer.cpp +++ b/src/common/d3d12/stream_buffer.cpp @@ -56,7 +56,7 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) const u32 required_bytes = num_bytes + alignment; // Check for sane allocations - if (required_bytes > m_size) + if (num_bytes > m_size) { Log_ErrorPrintf("Attempting to allocate %u bytes from a %u byte stream buffer", static_cast(num_bytes), static_cast(m_size)); @@ -68,8 +68,9 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) UpdateCurrentFencePosition(); if (m_current_offset >= m_current_gpu_position) { + const u32 aligned_required_bytes = (m_current_offset > 0) ? required_bytes : num_bytes; const u32 remaining_bytes = m_size - m_current_offset; - if (required_bytes <= remaining_bytes) + if (aligned_required_bytes <= remaining_bytes) { // Place at the current position, after the GPU position. m_current_offset = Common::AlignUp(m_current_offset, alignment);