Skip to content

Commit

Permalink
Fix crashing on startup for AMD GPUs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acolwell committed Mar 5, 2024
1 parent ffdf812 commit 531893a
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions Engine/OSGLContext_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,42 +817,42 @@ OSGLContext_win::getGPUInfos(std::list<OpenGLRendererInfo>& 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) {
Expand Down

0 comments on commit 531893a

Please sign in to comment.