From f465e4aaf2d3987355ac560ead37527dc381287a Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Wed, 19 Sep 2018 09:22:30 +0200 Subject: [PATCH] gl_rasterizer: Fix StartAddress handling with indexed draw calls. We uploaded the wrong data before. So the offset on the host GPU pointer may work for the first vertices, the last ones run out bounds. Let's just offset the upload instead. --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 274c2dbcff..e37acbfac9 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -484,8 +484,13 @@ void RasterizerOpenGL::DrawArrays() { GLintptr index_buffer_offset = 0; if (is_indexed) { MICROPROFILE_SCOPE(OpenGL_Index); - index_buffer_offset = - buffer_cache.UploadMemory(regs.index_array.StartAddress(), index_buffer_size); + + // Adjust the index buffer offset so it points to the first desired index. + auto index_start = regs.index_array.StartAddress(); + index_start += static_cast(regs.index_array.first) * + static_cast(regs.index_array.FormatSizeInBytes()); + + index_buffer_offset = buffer_cache.UploadMemory(index_start, index_buffer_size); } SetupShaders(); @@ -499,10 +504,6 @@ void RasterizerOpenGL::DrawArrays() { if (is_indexed) { const GLint base_vertex{static_cast(regs.vb_element_base)}; - // Adjust the index buffer offset so it points to the first desired index. - index_buffer_offset += static_cast(regs.index_array.first) * - static_cast(regs.index_array.FormatSizeInBytes()); - if (gpu.state.current_instance > 0) { glDrawElementsInstancedBaseVertexBaseInstance( primitive_mode, regs.index_array.count,