From 531893acd16460dabe62bfe678d5bd9ff821f782 Mon Sep 17 00:00:00 2001 From: Aaron Colwell <300262+acolwell@users.noreply.github.com> Date: Tue, 5 Mar 2024 13:20:06 -0800 Subject: [PATCH] Fix crashing on startup for AMD GPUs. This change makes sure there is an active context when GetGPUInfoAMD() is called. While it is not explicitly stated in https://www.opengl.org/registry/specs/AMD/wgl_gpu_association.txt that a GL context needs to be current, it is somewhat implied by the fact that these extension methods are fetched via wglGetProcAddress(). According to the Windows docs, function addresses are specific to a context so using them without an active context seems to be undefined territory. --- Engine/OSGLContext_win.cpp | 54 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Engine/OSGLContext_win.cpp b/Engine/OSGLContext_win.cpp index d3da2cd0b..b9b78ff28 100644 --- a/Engine/OSGLContext_win.cpp +++ b/Engine/OSGLContext_win.cpp @@ -817,42 +817,42 @@ OSGLContext_win::getGPUInfos(std::list& renderers) UINT gpuID = gpuIDs[index]; OpenGLRendererInfo info; - info.rendererName = GetGPUInfoAMDInternal_string(wglInfo, gpuID, WGL_GPU_RENDERER_STRING_AMD); - if (info.rendererName.empty()) { - continue; - } - - info.vendorName = GetGPUInfoAMDInternal_string(wglInfo, gpuID, WGL_GPU_VENDOR_AMD); - if (info.vendorName.empty()) { - continue; - } - - info.glVersionString = GetGPUInfoAMDInternal_string(wglInfo, gpuID, WGL_GPU_OPENGL_VERSION_STRING_AMD); - if (info.glVersionString.empty()) { - continue; - } + info.rendererID.renderID = gpuID; - // note: cannot retrieve GL_SHADING_LANGUAGE_VERSION + { + ScopedGLContext scopedContext(info.rendererID); + if (!scopedContext) { + continue; + } - info.maxMemBytes = 0; - if (!isApplication32Bits()) { - int ramMB = 0; - // AMD drivers are f*** up in 32 bits, they read a wrong buffer size. - // It works fine in 64 bits mode - if (!GetGPUInfoAMDInternal_int(wglInfo, gpuID, WGL_GPU_RAM_AMD, &ramMB)) { + info.rendererName = GetGPUInfoAMDInternal_string(wglInfo, gpuID, WGL_GPU_RENDERER_STRING_AMD); + if (info.rendererName.empty()) { continue; } - info.maxMemBytes = ramMB * 1e6; - } - info.rendererID.renderID = gpuID; + info.vendorName = GetGPUInfoAMDInternal_string(wglInfo, gpuID, WGL_GPU_VENDOR_AMD); + if (info.vendorName.empty()) { + continue; + } - { - ScopedGLContext scopedContext(info.rendererID); - if (!scopedContext) { + info.glVersionString = GetGPUInfoAMDInternal_string(wglInfo, gpuID, WGL_GPU_OPENGL_VERSION_STRING_AMD); + if (info.glVersionString.empty()) { continue; } + // note: cannot retrieve GL_SHADING_LANGUAGE_VERSION + + info.maxMemBytes = 0; + if (!isApplication32Bits()) { + int ramMB = 0; + // AMD drivers are f*** up in 32 bits, they read a wrong buffer size. + // It works fine in 64 bits mode + if (!GetGPUInfoAMDInternal_int(wglInfo, gpuID, WGL_GPU_RAM_AMD, &ramMB)) { + continue; + } + info.maxMemBytes = ramMB * 1e6; + } + try { OSGLContext::checkOpenGLVersion(); } catch (const std::exception& e) {