From ae4767a9cafde4f438ebbcd7bf49c29f69ecf48a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 7 Mar 2020 12:34:40 +1000 Subject: [PATCH] GPU/HW: Always unmap buffer on flush Should stop assertions firing in some games. --- src/core/gpu_hw_d3d11.cpp | 11 +++++++---- src/core/gpu_hw_opengl.cpp | 14 ++++++++------ src/core/gpu_hw_opengl_es.cpp | 14 ++++++++------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/core/gpu_hw_d3d11.cpp b/src/core/gpu_hw_d3d11.cpp index fbea38a2f..a823b7e6f 100644 --- a/src/core/gpu_hw_d3d11.cpp +++ b/src/core/gpu_hw_d3d11.cpp @@ -723,17 +723,20 @@ void GPU_HW_D3D11::UpdateVRAMReadTexture() void GPU_HW_D3D11::FlushRender() { - const u32 vertex_count = GetBatchVertexCount(); - if (vertex_count == 0) + if (!m_batch_current_vertex_ptr) return; - m_renderer_stats.num_batches++; - + const u32 vertex_count = GetBatchVertexCount(); m_vertex_stream_buffer.Unmap(m_context.Get(), vertex_count * sizeof(BatchVertex)); m_batch_start_vertex_ptr = nullptr; m_batch_end_vertex_ptr = nullptr; m_batch_current_vertex_ptr = nullptr; + if (vertex_count == 0) + return; + + m_renderer_stats.num_batches++; + if (m_batch.NeedsTwoPassRendering()) { SetDrawState(BatchRenderMode::OnlyTransparent); diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index f5d2ce6f9..e079dbd68 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -819,19 +819,21 @@ void GPU_HW_OpenGL::UpdateVRAMReadTexture() void GPU_HW_OpenGL::FlushRender() { - const u32 vertex_count = GetBatchVertexCount(); - if (vertex_count == 0) + static constexpr std::array gl_primitives = {{GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP}}; + + if (!m_batch_current_vertex_ptr) return; - m_renderer_stats.num_batches++; - + const u32 vertex_count = GetBatchVertexCount(); m_vertex_stream_buffer->Unmap(vertex_count * sizeof(BatchVertex)); - m_vertex_stream_buffer->Bind(); m_batch_start_vertex_ptr = nullptr; m_batch_end_vertex_ptr = nullptr; m_batch_current_vertex_ptr = nullptr; + if (vertex_count == 0) + return; - static constexpr std::array gl_primitives = {{GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP}}; + m_vertex_stream_buffer->Bind(); + m_renderer_stats.num_batches++; if (m_batch.NeedsTwoPassRendering()) { diff --git a/src/core/gpu_hw_opengl_es.cpp b/src/core/gpu_hw_opengl_es.cpp index 207cff22c..f715bfc1d 100644 --- a/src/core/gpu_hw_opengl_es.cpp +++ b/src/core/gpu_hw_opengl_es.cpp @@ -639,18 +639,20 @@ void GPU_HW_OpenGL_ES::UpdateVRAMReadTexture() void GPU_HW_OpenGL_ES::FlushRender() { + static constexpr std::array gl_primitives = {{GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP}}; + + if (!m_batch_current_vertex_ptr) + return; + const u32 vertex_count = GetBatchVertexCount(); + m_batch_start_vertex_ptr = nullptr; + m_batch_end_vertex_ptr = nullptr; + m_batch_current_vertex_ptr = nullptr; if (vertex_count == 0) return; m_renderer_stats.num_batches++; - m_batch_start_vertex_ptr = nullptr; - m_batch_end_vertex_ptr = nullptr; - m_batch_current_vertex_ptr = nullptr; - - static constexpr std::array gl_primitives = {{GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP}}; - if (m_batch.NeedsTwoPassRendering()) { SetDrawState(BatchRenderMode::OnlyTransparent);