From 6985b134396677b21dd72edffd44a0c938e31303 Mon Sep 17 00:00:00 2001 From: wwylele Date: Wed, 25 Apr 2018 12:55:49 +0300 Subject: [PATCH] [HACK] AMD workaround --- src/video_core/renderer_opengl/gl_stream_buffer.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_stream_buffer.cpp b/src/video_core/renderer_opengl/gl_stream_buffer.cpp index e1698443e..5bd0f21a8 100644 --- a/src/video_core/renderer_opengl/gl_stream_buffer.cpp +++ b/src/video_core/renderer_opengl/gl_stream_buffer.cpp @@ -14,16 +14,25 @@ OGLStreamBuffer::OGLStreamBuffer(GLenum target, GLsizeiptr size, bool prefer_coh gl_buffer.Create(); glBindBuffer(gl_target, gl_buffer.handle); + GLsizeiptr allocate_size = size; + if (target == GL_ARRAY_BUFFER) { + // On AMD GPU there is a strange crash in indexed drawing. The crash happens when the buffer + // read position is near the end and the crash looks like an out-of-bound access. Doubling + // the allocation size for the vertex buffer seems to avoid the crash. + // TODO (wwylele): investigate what actually happens here. + allocate_size *= 2; + } + if (GLAD_GL_ARB_buffer_storage) { persistent = true; coherent = prefer_coherent; GLbitfield flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | (coherent ? GL_MAP_COHERENT_BIT : 0); - glBufferStorage(gl_target, buffer_size, nullptr, flags); + glBufferStorage(gl_target, allocate_size, nullptr, flags); mapped_ptr = static_cast(glMapBufferRange( gl_target, 0, buffer_size, flags | (coherent ? 0 : GL_MAP_FLUSH_EXPLICIT_BIT))); } else { - glBufferData(gl_target, buffer_size, nullptr, GL_STREAM_DRAW); + glBufferData(gl_target, allocate_size, nullptr, GL_STREAM_DRAW); } }