From ac92664aa7ed7983b7fed3c4face6af143369b52 Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Wed, 14 Mar 2018 23:36:54 +0100 Subject: [PATCH] OGL: Use stream buffer for vertex data. --- .../renderer_opengl/gl_rasterizer.cpp | 17 ++++++++++++----- src/video_core/renderer_opengl/gl_rasterizer.h | 4 +++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index f028ea001..612540d25 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -41,12 +41,13 @@ RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) { } // Generate VBO, VAO and UBO - vertex_buffer.Create(); + vertex_buffer = OGLStreamBuffer::MakeBuffer(GLAD_GL_ARB_buffer_storage, GL_ARRAY_BUFFER); + vertex_buffer->Create(VERTEX_BUFFER_SIZE, VERTEX_BUFFER_SIZE / 2); vertex_array.Create(); uniform_buffer.Create(); state.draw.vertex_array = vertex_array.handle; - state.draw.vertex_buffer = vertex_buffer.handle; + state.draw.vertex_buffer = vertex_buffer->GetHandle(); state.draw.uniform_buffer = uniform_buffer.handle; state.Apply(); @@ -434,9 +435,15 @@ void RasterizerOpenGL::DrawTriangles() { state.Apply(); // Draw the vertex batch - glBufferData(GL_ARRAY_BUFFER, vertex_batch.size() * sizeof(HardwareVertex), vertex_batch.data(), - GL_STREAM_DRAW); - glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertex_batch.size()); + size_t max_vertices = 3 * (VERTEX_BUFFER_SIZE / (3 * sizeof(HardwareVertex))); + for (size_t base_vertex = 0; base_vertex < vertex_batch.size(); base_vertex += max_vertices) { + size_t vertices = std::min(max_vertices, vertex_batch.size() - base_vertex); + size_t vertex_size = vertices * sizeof(HardwareVertex); + auto map = vertex_buffer->Map(vertex_size, 1); + memcpy(map.first, vertex_batch.data() + base_vertex, vertex_size); + vertex_buffer->Unmap(); + glDrawArrays(GL_TRIANGLES, map.second / sizeof(HardwareVertex), (GLsizei)vertices); + } // Disable scissor test state.scissor.enabled = false; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 18808b1e4..5db9b6b7a 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -27,6 +27,7 @@ #include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_shader_gen.h" #include "video_core/renderer_opengl/gl_state.h" +#include "video_core/renderer_opengl/gl_stream_buffer.h" #include "video_core/renderer_opengl/pica_to_gl.h" #include "video_core/shader/shader.h" @@ -283,7 +284,8 @@ private: std::array texture_samplers; OGLVertexArray vertex_array; - OGLBuffer vertex_buffer; + static constexpr size_t VERTEX_BUFFER_SIZE = 128 * 1024 * 1024; + std::unique_ptr vertex_buffer; OGLBuffer uniform_buffer; OGLFramebuffer framebuffer;