From fd98bf1339935337c58e00081bb8907b5212c12c Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 28 Oct 2018 13:05:49 -0400 Subject: [PATCH] gl_global_cache: Ensure buffer size does not exceed UBO maximum. - Fixes crash with Xenoblade Chronicles 2. --- src/video_core/renderer_opengl/gl_global_cache.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/video_core/renderer_opengl/gl_global_cache.cpp b/src/video_core/renderer_opengl/gl_global_cache.cpp index 35d09fe13b..c7f06569b8 100644 --- a/src/video_core/renderer_opengl/gl_global_cache.cpp +++ b/src/video_core/renderer_opengl/gl_global_cache.cpp @@ -19,8 +19,22 @@ CachedGlobalRegion::CachedGlobalRegion(VAddr addr, u32 size) : addr{addr}, size{ LabelGLObject(GL_BUFFER, buffer.handle, addr); } +/// Helper function to get the maximum size we can use for an OpenGL uniform block +static u32 GetMaxUniformBlockSize() { + GLint max_size{}; + glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size); + return static_cast(max_size); +} + void CachedGlobalRegion::Reload(u32 size_) { + static const u32 max_size{GetMaxUniformBlockSize()}; + size = size_; + if (size > max_size) { + size = max_size; + LOG_CRITICAL(HW_GPU, "Global region size {} exceeded max UBO size of {}!", size_, max_size); + } + glBindBuffer(GL_UNIFORM_BUFFER, buffer.handle); glBufferData(GL_UNIFORM_BUFFER, size, Memory::GetPointer(addr), GL_DYNAMIC_DRAW); }