2020-11-06 17:18:55 +00:00
# include "blocklist_driver.h"
# include <base/system.h>
2022-05-29 13:51:38 +00:00
# include <cstddef>
2020-11-06 17:18:55 +00:00
# define VERSION_PARTS 4
struct SVersion
{
2022-06-30 22:36:32 +00:00
int m_aParts [ VERSION_PARTS ] ;
2020-11-06 17:18:55 +00:00
bool operator < = ( const SVersion & Other ) const
{
for ( int i = 0 ; i < VERSION_PARTS ; i + + )
{
2022-06-30 22:36:32 +00:00
if ( m_aParts [ i ] < Other . m_aParts [ i ] )
2020-11-06 17:18:55 +00:00
return true ;
2022-06-30 22:36:32 +00:00
if ( m_aParts [ i ] > Other . m_aParts [ i ] )
2020-11-06 17:18:55 +00:00
return false ;
}
return true ;
}
} ;
2021-05-06 10:23:40 +00:00
enum EBackendDriverBlockListType
{
BACKEND_DRIVER_BLOCKLIST_TYPE_VERSION = 0 ,
BACKEND_DRIVER_BLOCKLIST_TYPE_VENDOR ,
} ;
2020-11-06 17:18:55 +00:00
/* TODO: generalize it more for other drivers / vendors */
struct SBackEndDriverBlockList
{
2021-05-06 10:23:40 +00:00
EBackendDriverBlockListType m_BlockListType ;
2020-11-06 17:18:55 +00:00
SVersion m_VersionMin ;
SVersion m_VersionMax ;
2020-11-07 05:54:08 +00:00
2021-05-06 10:23:40 +00:00
const char * m_pVendorName ;
2020-11-07 05:54:08 +00:00
// the OpenGL version, that is supported
int m_AllowedMajor ;
int m_AllowedMinor ;
int m_AllowedPatch ;
2020-11-06 17:18:55 +00:00
const char * m_pReason ;
2021-05-06 10:23:40 +00:00
bool m_DisplayReason ;
const char * m_pOSName ;
2020-11-06 17:18:55 +00:00
} ;
static SBackEndDriverBlockList gs_aBlockList [ ] = {
2021-05-06 10:23:40 +00:00
{ BACKEND_DRIVER_BLOCKLIST_TYPE_VENDOR , { 26 , 20 , 100 , 7800 } , { 27 , 20 , 100 , 8853 } , " Intel " , 2 , 0 , 0 , " This Intel driver version can cause crashes, please update it to a newer version. " , false , " windows " } } ;
2020-11-06 17:18:55 +00:00
2021-05-06 10:23:40 +00:00
const char * ParseBlocklistDriverVersions ( const char * pVendorStr , const char * pVersionStr , int & BlocklistMajor , int & BlocklistMinor , int & BlocklistPatch , bool & RequiresWarning )
2020-11-06 17:18:55 +00:00
{
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 ;
2022-06-30 22:36:32 +00:00
for ( int & VersionPart : Version . m_aParts )
2020-11-06 17:18:55 +00:00
{
pVersionStrStart = str_next_token ( pVersionStrStart , " . " , aVersionStrHelper , sizeof ( aVersionStrHelper ) ) ;
if ( pVersionStrStart = = NULL )
return NULL ;
VersionPart = str_toint ( aVersionStrHelper ) ;
}
for ( const auto & BlockListItem : gs_aBlockList )
{
2021-05-06 10:23:40 +00:00
if ( str_comp ( BlockListItem . m_pOSName , CONF_FAMILY_STRING ) = = 0 )
2020-11-07 05:54:08 +00:00
{
2021-05-06 10:23:40 +00:00
bool DriverBlocked = false ;
if ( BlockListItem . m_BlockListType = = BACKEND_DRIVER_BLOCKLIST_TYPE_VENDOR )
{
if ( str_find_nocase ( pVendorStr , BlockListItem . m_pVendorName ) ! = NULL )
{
DriverBlocked = true ;
}
}
else if ( BlockListItem . m_BlockListType = = BACKEND_DRIVER_BLOCKLIST_TYPE_VERSION )
{
if ( BlockListItem . m_VersionMin < = Version & & Version < = BlockListItem . m_VersionMax )
{
DriverBlocked = true ;
}
}
if ( DriverBlocked )
{
RequiresWarning = BlockListItem . m_DisplayReason ;
BlocklistMajor = BlockListItem . m_AllowedMajor ;
BlocklistMinor = BlockListItem . m_AllowedMinor ;
BlocklistPatch = BlockListItem . m_AllowedPatch ;
return BlockListItem . m_pReason ;
}
2020-11-07 05:54:08 +00:00
}
2020-11-06 17:18:55 +00:00
}
return NULL ;
}