3255: Add block list for drivers r=def- a=Jupeyy

Only briefly tested,
- the error message is bad
- the impl basically only works for the intel windows string, so its not really a generalized list

fixes #3234
## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2020-11-12 07:40:10 +00:00 committed by GitHub
commit 11d5e87047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 222 additions and 18 deletions

View file

@ -1644,6 +1644,8 @@ if(CLIENT)
set_src(ENGINE_CLIENT GLOB src/engine/client set_src(ENGINE_CLIENT GLOB src/engine/client
backend_sdl.cpp backend_sdl.cpp
backend_sdl.h backend_sdl.h
blocklist_driver.cpp
blocklist_driver.h
client.cpp client.cpp
client.h client.h
demoedit.cpp demoedit.cpp
@ -2114,6 +2116,7 @@ if(GTEST_FOUND OR DOWNLOAD_GTEST)
set_src(TESTS GLOB src/test set_src(TESTS GLOB src/test
aio.cpp aio.cpp
bezier.cpp bezier.cpp
blocklist_driver.cpp
color.cpp color.cpp
csv.cpp csv.cpp
datafile.cpp datafile.cpp
@ -2135,6 +2138,8 @@ if(GTEST_FOUND OR DOWNLOAD_GTEST)
unix.cpp unix.cpp
) )
set(TESTS_EXTRA set(TESTS_EXTRA
src/engine/client/blocklist_driver.cpp
src/engine/client/blocklist_driver.h
src/engine/server/name_ban.cpp src/engine/server/name_ban.cpp
src/engine/server/name_ban.h src/engine/server/name_ban.h
src/game/server/teehistorian.cpp src/game/server/teehistorian.cpp

View file

@ -3763,7 +3763,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderQuadContainerAsSpriteMultipl
// ------------ CCommandProcessorFragment_SDL // ------------ CCommandProcessorFragment_SDL
static void ParseVersionString(const GLubyte *pStr, int &VersionMajor, int &VersionMinor, int &VersionPatch) static void ParseVersionString(const char *pStr, int &VersionMajor, int &VersionMinor, int &VersionPatch)
{ {
if(pStr) if(pStr)
{ {
@ -3774,12 +3774,12 @@ static void ParseVersionString(const GLubyte *pStr, int &VersionMajor, int &Vers
bool LastWasNumber = false; bool LastWasNumber = false;
while(*pStr && TotalNumbersPassed < 3) while(*pStr && TotalNumbersPassed < 3)
{ {
if(*pStr >= (GLubyte)'0' && *pStr <= (GLubyte)'9') if(*pStr >= '0' && *pStr <= '9')
{ {
aCurNumberStr[CurNumberStrLen++] = (char)*pStr; aCurNumberStr[CurNumberStrLen++] = (char)*pStr;
LastWasNumber = true; LastWasNumber = true;
} }
else if(LastWasNumber && (*pStr == (GLubyte)'.' || *pStr == (GLubyte)' ' || *pStr == (GLubyte)'\0')) else if(LastWasNumber && (*pStr == '.' || *pStr == ' ' || *pStr == '\0'))
{ {
int CurNumber = 0; int CurNumber = 0;
if(CurNumberStrLen > 0) if(CurNumberStrLen > 0)
@ -3792,7 +3792,7 @@ static void ParseVersionString(const GLubyte *pStr, int &VersionMajor, int &Vers
LastWasNumber = false; LastWasNumber = false;
if(*pStr != (GLubyte)'.') if(*pStr != '.')
break; break;
} }
else else
@ -3895,34 +3895,73 @@ void CCommandProcessorFragment_SDL::Cmd_Init(const SCommand_Init *pCommand)
dbg_msg("gfx", "Requested OpenGL debug mode, but the driver does not support the required extension"); dbg_msg("gfx", "Requested OpenGL debug mode, but the driver does not support the required extension");
} }
const char *pVendorString = (const char *)glGetString(GL_VENDOR);
dbg_msg("opengl", "Vendor string: %s", pVendorString);
// check what this context can do // check what this context can do
const GLubyte *pVersionString = glGetString(GL_VERSION); const char *pVersionString = (const char *)glGetString(GL_VERSION);
dbg_msg("opengl", "Version string: %s", (const char *)pVersionString); dbg_msg("opengl", "Version string: %s", pVersionString);
// parse version string // parse version string
ParseVersionString(pVersionString, pCommand->m_pCapabilities->m_ContextMajor, pCommand->m_pCapabilities->m_ContextMinor, pCommand->m_pCapabilities->m_ContextPatch); ParseVersionString(pVersionString, pCommand->m_pCapabilities->m_ContextMajor, pCommand->m_pCapabilities->m_ContextMinor, pCommand->m_pCapabilities->m_ContextPatch);
*pCommand->m_pInitError = 0;
int BlocklistMajor = -1, BlocklistMinor = -1, BlocklistPatch = -1;
const char *pErrString = ParseBlocklistDriverVersions(pVendorString, pVersionString, BlocklistMajor, BlocklistMinor, BlocklistPatch);
//if the driver is buggy, and the requested GL version is the default, fallback
if(pErrString != NULL && pCommand->m_RequestedMajor == 3 && pCommand->m_RequestedMinor == 0 && pCommand->m_RequestedPatch == 0)
{
// if not already in the error state, set the GL version
if(g_Config.m_GfxDriverIsBlocked == 0)
{
// fallback to known good GL version
pCommand->m_pCapabilities->m_ContextMajor = BlocklistMajor;
pCommand->m_pCapabilities->m_ContextMinor = BlocklistMinor;
pCommand->m_pCapabilities->m_ContextPatch = BlocklistPatch;
// set backend error string
*pCommand->m_pErrStringPtr = pErrString;
*pCommand->m_pInitError = -2;
g_Config.m_GfxDriverIsBlocked = 1;
}
}
// if the driver was in a blocked error state, but is not anymore, reset all config variables
else if(pErrString == NULL && g_Config.m_GfxDriverIsBlocked == 1)
{
pCommand->m_pCapabilities->m_ContextMajor = 3;
pCommand->m_pCapabilities->m_ContextMinor = 0;
pCommand->m_pCapabilities->m_ContextPatch = 0;
// tell the caller to reinitialize the context
*pCommand->m_pInitError = -2;
g_Config.m_GfxDriverIsBlocked = 0;
}
int MajorV = pCommand->m_pCapabilities->m_ContextMajor; int MajorV = pCommand->m_pCapabilities->m_ContextMajor;
int MinorV = pCommand->m_pCapabilities->m_ContextMinor; int MinorV = pCommand->m_pCapabilities->m_ContextMinor;
*pCommand->m_pInitError = 0; if(*pCommand->m_pInitError == 0)
if(MajorV < pCommand->m_RequestedMajor)
{ {
*pCommand->m_pInitError = -2; if(MajorV < pCommand->m_RequestedMajor)
}
else if(MajorV == pCommand->m_RequestedMajor)
{
if(MinorV < pCommand->m_RequestedMinor)
{ {
*pCommand->m_pInitError = -2; *pCommand->m_pInitError = -2;
} }
else if(MinorV == pCommand->m_RequestedMinor) else if(MajorV == pCommand->m_RequestedMajor)
{ {
int PatchV = pCommand->m_pCapabilities->m_ContextPatch; if(MinorV < pCommand->m_RequestedMinor)
if(PatchV < pCommand->m_RequestedPatch)
{ {
*pCommand->m_pInitError = -2; *pCommand->m_pInitError = -2;
} }
else if(MinorV == pCommand->m_RequestedMinor)
{
int PatchV = pCommand->m_pCapabilities->m_ContextPatch;
if(PatchV < pCommand->m_RequestedPatch)
{
*pCommand->m_pInitError = -2;
}
}
} }
} }
@ -4657,6 +4696,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
GetGlewVersion(GlewMajor, GlewMinor, GlewPatch); GetGlewVersion(GlewMajor, GlewMinor, GlewPatch);
int InitError = 0; int InitError = 0;
const char *pErrorStr = NULL;
InitError = IsVersionSupportedGlew(g_Config.m_GfxOpenGLMajor, g_Config.m_GfxOpenGLMinor, g_Config.m_GfxOpenGLPatch, GlewMajor, GlewMinor, GlewPatch); InitError = IsVersionSupportedGlew(g_Config.m_GfxOpenGLMajor, g_Config.m_GfxOpenGLMinor, g_Config.m_GfxOpenGLPatch, GlewMajor, GlewMinor, GlewPatch);
@ -4681,6 +4721,8 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
m_pProcessor = new CCommandProcessor_SDL_OpenGL(g_Config.m_GfxOpenGLMajor, g_Config.m_GfxOpenGLMinor, g_Config.m_GfxOpenGLPatch); m_pProcessor = new CCommandProcessor_SDL_OpenGL(g_Config.m_GfxOpenGLMajor, g_Config.m_GfxOpenGLMinor, g_Config.m_GfxOpenGLPatch);
StartProcessor(m_pProcessor); StartProcessor(m_pProcessor);
mem_zero(m_aErrorString, sizeof(m_aErrorString) / sizeof(m_aErrorString[0]));
// issue init commands for OpenGL and SDL // issue init commands for OpenGL and SDL
CCommandBuffer CmdBuffer(1024, 512); CCommandBuffer CmdBuffer(1024, 512);
//run sdl first to have the context in the thread //run sdl first to have the context in the thread
@ -4695,6 +4737,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
CmdSDL.m_GlewMinor = GlewMinor; CmdSDL.m_GlewMinor = GlewMinor;
CmdSDL.m_GlewPatch = GlewPatch; CmdSDL.m_GlewPatch = GlewPatch;
CmdSDL.m_pInitError = &InitError; CmdSDL.m_pInitError = &InitError;
CmdSDL.m_pErrStringPtr = &pErrorStr;
CmdBuffer.AddCommand(CmdSDL); CmdBuffer.AddCommand(CmdSDL);
RunBuffer(&CmdBuffer); RunBuffer(&CmdBuffer);
WaitForIdle(); WaitForIdle();
@ -4750,6 +4793,11 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
g_Config.m_GfxOpenGLPatch = m_Capabilites.m_ContextPatch; g_Config.m_GfxOpenGLPatch = m_Capabilites.m_ContextPatch;
} }
if(pErrorStr != NULL)
{
str_copy(m_aErrorString, pErrorStr, sizeof(m_aErrorString) / sizeof(m_aErrorString[0]));
}
return EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_OPENGL_VERSION_FAILED; return EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_OPENGL_VERSION_FAILED;
} }

View file

@ -4,6 +4,7 @@
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#include "blocklist_driver.h"
#include "graphics_threaded.h" #include "graphics_threaded.h"
#include <base/tl/threading.h> #include <base/tl/threading.h>
@ -425,6 +426,8 @@ public:
SDL_GLContext m_GLContext; SDL_GLContext m_GLContext;
SBackendCapabilites *m_pCapabilities; SBackendCapabilites *m_pCapabilities;
const char **m_pErrStringPtr;
int *m_pInitError; int *m_pInitError;
int m_RequestedMajor; int m_RequestedMajor;
@ -493,6 +496,8 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded
bool m_UseNewOpenGL; bool m_UseNewOpenGL;
char m_aErrorString[256];
public: public:
virtual int Init(const char *pName, int *Screen, int *pWidth, int *pHeight, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight, int *pCurrentWidth, int *pCurrentHeight, class IStorage *pStorage); virtual int Init(const char *pName, int *Screen, int *pWidth, int *pHeight, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight, int *pCurrentWidth, int *pCurrentHeight, class IStorage *pStorage);
virtual int Shutdown(); virtual int Shutdown();
@ -518,6 +523,14 @@ public:
virtual bool HasTextBuffering() { return m_Capabilites.m_TextBuffering; } virtual bool HasTextBuffering() { return m_Capabilites.m_TextBuffering; }
virtual bool HasQuadContainerBuffering() { return m_Capabilites.m_QuadContainerBuffering; } virtual bool HasQuadContainerBuffering() { return m_Capabilites.m_QuadContainerBuffering; }
virtual bool Has2DTextureArrays() { return m_Capabilites.m_2DArrayTextures; } virtual bool Has2DTextureArrays() { return m_Capabilites.m_2DArrayTextures; }
virtual const char *GetErrorString()
{
if(m_aErrorString[0] != '\0')
return m_aErrorString;
return NULL;
}
}; };
#endif // ENGINE_CLIENT_BACKEND_SDL_H #endif // ENGINE_CLIENT_BACKEND_SDL_H

View file

@ -0,0 +1,77 @@
#include "blocklist_driver.h"
#include <base/system.h>
#define VERSION_PARTS 4
struct SVersion
{
int m_Parts[VERSION_PARTS];
bool operator<=(const SVersion &Other) const
{
for(int i = 0; i < VERSION_PARTS; i++)
{
if(m_Parts[i] < Other.m_Parts[i])
return true;
if(m_Parts[i] > Other.m_Parts[i])
return false;
}
return true;
}
};
/* TODO: generalize it more for other drivers / vendors */
struct SBackEndDriverBlockList
{
SVersion m_VersionMin;
SVersion m_VersionMax;
// the OpenGL version, that is supported
int m_AllowedMajor;
int m_AllowedMinor;
int m_AllowedPatch;
const char *m_pReason;
};
static SBackEndDriverBlockList gs_aBlockList[] = {
{{26, 20, 100, 7800}, {26, 20, 100, 7999}, 2, 0, 0, "This Intel driver version can cause crashes, please update it to a newer version."}};
const char *ParseBlocklistDriverVersions(const char *pVendorStr, const char *pVersionStr, int &BlocklistMajor, int &BlocklistMinor, int &BlocklistPatch)
{
if(str_find_nocase(pVendorStr, "Intel") == NULL)
return NULL;
const char *pVersionStrStart = str_find_nocase(pVersionStr, "Build ");
if(pVersionStrStart == NULL)
return NULL;
// ignore "Build ", after that, it should directly start with the driver version
pVersionStrStart += (ptrdiff_t)str_length("Build ");
char aVersionStrHelper[512]; // the size is random, but shouldn't be too small probably
SVersion Version;
for(int &VersionPart : Version.m_Parts)
{
pVersionStrStart = str_next_token(pVersionStrStart, ".", aVersionStrHelper, sizeof(aVersionStrHelper));
if(pVersionStrStart == NULL)
return NULL;
VersionPart = str_toint(aVersionStrHelper);
}
for(const auto &BlockListItem : gs_aBlockList)
{
if(BlockListItem.m_VersionMin <= Version && Version <= BlockListItem.m_VersionMax)
{
BlocklistMajor = BlockListItem.m_AllowedMajor;
BlocklistMinor = BlockListItem.m_AllowedMinor;
BlocklistPatch = BlockListItem.m_AllowedPatch;
return BlockListItem.m_pReason;
}
}
return NULL;
}

View file

@ -0,0 +1,6 @@
#ifndef ENGINE_CLIENT_BLOCKLIST_DRIVER_H
#define ENGINE_CLIENT_BLOCKLIST_DRIVER_H
const char *ParseBlocklistDriverVersions(const char *pVendorStr, const char *pVersionStr, int &BlocklistMajor, int &BlocklistMinor, int &BlocklistPatch);
#endif // ENGINE_CLIENT_BLOCKLIST_DRIVER_H

View file

@ -2149,6 +2149,7 @@ int CGraphics_Threaded::IssueInit()
Flags |= IGraphicsBackend::INITFLAG_RESIZABLE; Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
int r = m_pBackend->Init("DDNet Client", &g_Config.m_GfxScreen, &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &m_DesktopScreenWidth, &m_DesktopScreenHeight, &m_ScreenWidth, &m_ScreenHeight, m_pStorage); int r = m_pBackend->Init("DDNet Client", &g_Config.m_GfxScreen, &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &m_DesktopScreenWidth, &m_DesktopScreenHeight, &m_ScreenWidth, &m_ScreenHeight, m_pStorage);
AddBackEndWarningIfExists();
m_IsNewOpenGL = m_pBackend->IsNewOpenGL(); m_IsNewOpenGL = m_pBackend->IsNewOpenGL();
m_OpenGLTileBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasTileBuffering(); m_OpenGLTileBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasTileBuffering();
m_OpenGLQuadBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasQuadBuffering(); m_OpenGLQuadBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasQuadBuffering();
@ -2158,6 +2159,17 @@ int CGraphics_Threaded::IssueInit()
return r; return r;
} }
void CGraphics_Threaded::AddBackEndWarningIfExists()
{
const char *pErrStr = m_pBackend->GetErrorString();
if(pErrStr != NULL)
{
SWarning NewWarning;
str_format(NewWarning.m_aWarningMsg, sizeof(NewWarning.m_aWarningMsg), "%s", Localize(pErrStr));
m_Warnings.emplace_back(NewWarning);
}
}
int CGraphics_Threaded::InitWindow() int CGraphics_Threaded::InitWindow()
{ {
int ErrorCode = IssueInit(); int ErrorCode = IssueInit();

View file

@ -671,6 +671,7 @@ public:
virtual bool HasTextBuffering() { return false; } virtual bool HasTextBuffering() { return false; }
virtual bool HasQuadContainerBuffering() { return false; } virtual bool HasQuadContainerBuffering() { return false; }
virtual bool Has2DTextureArrays() { return false; } virtual bool Has2DTextureArrays() { return false; }
virtual const char *GetErrorString() { return NULL; }
}; };
class CGraphics_Threaded : public IEngineGraphics class CGraphics_Threaded : public IEngineGraphics
@ -801,6 +802,8 @@ class CGraphics_Threaded : public IEngineGraphics
void KickCommandBuffer(); void KickCommandBuffer();
void AddBackEndWarningIfExists();
int IssueInit(); int IssueInit();
int InitWindow(); int InitWindow();

View file

@ -394,6 +394,7 @@ MACRO_CONFIG_INT(GfxOpenGLPatch, gfx_opengl_patch, 0, 0, 10, CFGFLAG_SAVE | CFGF
MACRO_CONFIG_INT(GfxOpenGLTextureLODBIAS, gfx_opengl_texture_lod_bias, -500, -15000, 15000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "The lod bias for OpenGL texture sampling multiplied by 1000") MACRO_CONFIG_INT(GfxOpenGLTextureLODBIAS, gfx_opengl_texture_lod_bias, -500, -15000, 15000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "The lod bias for OpenGL texture sampling multiplied by 1000")
MACRO_CONFIG_INT(Gfx3DTextureAnalysisDone, gfx_3d_texture_analysis_done, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Analyzed, if sampling 3D/2D array textures was correct") MACRO_CONFIG_INT(Gfx3DTextureAnalysisDone, gfx_3d_texture_analysis_done, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Analyzed, if sampling 3D/2D array textures was correct")
MACRO_CONFIG_INT(GfxDriverIsBlocked, gfx_driver_is_blocked, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "If 1, the current driver is in a blocked error state.")
#if !defined(CONF_PLATFORM_MACOSX) #if !defined(CONF_PLATFORM_MACOSX)
MACRO_CONFIG_INT(GfxEnableTextureUnitOptimization, gfx_enable_texture_unit_optimization, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Use multiple texture units, instead of only one.") MACRO_CONFIG_INT(GfxEnableTextureUnitOptimization, gfx_enable_texture_unit_optimization, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Use multiple texture units, instead of only one.")
#else #else

View file

@ -10,7 +10,7 @@ struct SWarning
{ {
str_copy(m_aWarningMsg, pMsg, sizeof(m_aWarningMsg)); str_copy(m_aWarningMsg, pMsg, sizeof(m_aWarningMsg));
} }
char m_aWarningMsg[128]; char m_aWarningMsg[256];
bool m_WasShown; bool m_WasShown;
}; };

View file

@ -0,0 +1,39 @@
#include <gtest/gtest.h>
#include <engine/client/blocklist_driver.h>
TEST(BlocklistDriver, Valid1)
{
int Major = -1, Minor = -1, Patch = -1;
EXPECT_STREQ(ParseBlocklistDriverVersions("Intel", "Build 26.20.100.7810", Major, Minor, Patch), "This Intel driver version can cause crashes, please update it to a newer version.");
EXPECT_EQ(Major, 2);
EXPECT_EQ(Minor, 0);
EXPECT_EQ(Patch, 0);
}
TEST(BlocklistDriver, Valid2)
{
int Major = -1, Minor = -1, Patch = -1;
EXPECT_STREQ(ParseBlocklistDriverVersions("Intel", "Build 26.20.100.7926", Major, Minor, Patch), "This Intel driver version can cause crashes, please update it to a newer version.");
EXPECT_EQ(Major, 2);
EXPECT_EQ(Minor, 0);
EXPECT_EQ(Patch, 0);
}
TEST(BlocklistDriver, Valid3)
{
int Major = -1, Minor = -1, Patch = -1;
EXPECT_STREQ(ParseBlocklistDriverVersions("Intel", "Build 26.20.100.7985", Major, Minor, Patch), "This Intel driver version can cause crashes, please update it to a newer version.");
EXPECT_EQ(Major, 2);
EXPECT_EQ(Minor, 0);
EXPECT_EQ(Patch, 0);
}
TEST(BlocklistDriver, Invalid)
{
int Major, Minor, Patch;
EXPECT_STREQ(ParseBlocklistDriverVersions("Intel", "Build 25.20.100.7810", Major, Minor, Patch), NULL);
EXPECT_STREQ(ParseBlocklistDriverVersions("Intel", "Build 26.20.100.7799", Major, Minor, Patch), NULL);
EXPECT_STREQ(ParseBlocklistDriverVersions("Intel", "Build 26.20.100.8000", Major, Minor, Patch), NULL);
EXPECT_STREQ(ParseBlocklistDriverVersions("Intel", "Build 27.20.100.7900", Major, Minor, Patch), NULL);
}