\r
// Table gpu\r
$db->gpu->gpu('varchar', 256, false);\r
+ $db->gpu->rgpu('varchar', 256, false);\r
$db->gpu->page('text', 0, false);\r
$db->gpu->version('integer', 0, false);\r
$db->gpu->date('integer', 0, false);\r
$db->gpu->score('integer', 0, false);\r
+ $db->gpu->url('varchar', 512, false);\r
$db->gpu->benchmark('text', 0, false);\r
- $db->gpu->primary('pk_gpu', 'gpu', 'version');\r
+ $db->gpu->primary('pk_gpu', 'gpu', 'rgpu', 'version');\r
+\r
+ // gpu log\r
+ $db->gpu_log->gpu('varchar', 256, false);\r
+ $db->gpu_log->rgpu('varchar', 256, false);\r
+ $db->gpu_log->date('integer', 0, false);\r
+ $db->gpu_log->primary('pk_gpu_log', 'gpu', 'rgpu', 'date');\r
\r
try {\r
$dbi = new CubeDbStruct($this->con);\r
return ['Direct3D', 'DirectX', 'OpenGL', 'Graphics'];
}
+ public static function gpuTests()
+ {
+ return [546, 544, 680, 632];
+ }
+
public function gup()
{
global $core;
$gpu = base64_decode($_GET['gup']);
if (preg_match('/\(([^\)]*)\)/', $gpu, $matches)) {
- $gpu = $matches[1];
+ if (strlen($matches[1]) > 8) {
+ $gpu = $matches[1];
+ }
}
$version = 40;
}
$gpu = trim($gpu);
+ $rgpu = trim(base64_decode($_GET['rgup']));
- $r = $core->con->select("SELECT * FROM gpu WHERE version=" . $version . " AND gpu='" . $core->con->escape($gpu) . "'");
+ $c = $core->con->openCursor('gpu_log');
+ $c->gpu = $gpu;
+ $c->rgpu = $rgpu;
+ $c->date = time();
+ $c->insert();
+
+ $r = $core->con->select("SELECT * FROM gpu WHERE version=" . $version . " AND (gpu='" . $core->con->escape($gpu) . "' OR rgpu='" . $core->con->escape($rgpu) . "')");
header('Content-type: text/plain');
+
if ($r->isEmpty()) {
- $ugpu = urlencode($gpu);
- $url = 'https://gfxbench.com/device.jsp?benchmark=gfx' . $version . '&api=gl&hwtype=dGPU&os=Linux&hwname=' . $ugpu . '&D=' . $ugpu . '&testgroup=graphics&var=median';
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0');
- $response = curl_exec($ch);
- $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- $f = substr($response, $header_size);
+ $search = self::searchGFXDevice($c->gpu, $rgpu, $version);
$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
- $doc->loadHTML($f);
+ $doc->loadHTML($search['body']);
$xml = simplexml_import_dom($doc);
$links = $xml->xpath("//a");
$res[$data['id']] = intval($value);
}
- $scoreids = [680, 544, 632, 546];
+ $scoreids = self::gpuTests();
$num = 0;
$score = 0;
foreach ($scoreids as $scoreid) {
$c = $core->con->openCursor('gpu');
$c->gpu = $gpu;
- $c->page = $f;
+ $c->rgpu = $rgpu;
+ $c->page = $search['body'];
+ $c->url = $search['url'];
$c->version = $version;
$c->benchmark = serialize($res);
$c->score = $score;
$c->date = time();
$c->insert();
-
- echo $score;
} else {
$r->fetch();
- echo $r->score;
+ $score = $r->score;
}
+ ob_end_clean();
+ echo $score;
exit;
}
+
+ public static function searchGFXDevice($gpu, $raw, $gfxVersion = 40)
+ {
+ // First intention direct request
+ $ugpu = urlencode($gpu);
+ $url = 'https://gfxbench.com/device.jsp?benchmark=gfx' . $gfxVersion . '&hwname=' . $ugpu . '&D=' . $ugpu . '&testgroup=graphics&var=median';
+
+ $f = self::_curlRequest($url);
+ if (!stristr($f, '<p class="label1">No such device')) {
+ return ['url' => $url, 'body' => $f];
+ }
+
+ // Second intention is to use the search engine to lookup the gpu by name
+ $tests = self::gpuTests();
+ $cacheLimit = max(time() - 21600, filemtime(__FILE__));
+ foreach ($tests as $test) {
+
+ // Test cache file
+ $cacheTest = WS_CACHE . '/gfxbench/test_' . $test;
+ if (!file_exists($cacheTest) || filemtime($cacheTest) < $cacheLimit) {
+ $f = self::_curlRequest('https://gfxbench.com/result.jsp?benchmark=gfx' . $gfxVersion . '&test=' . $test . '&order=median&base=device');
+
+ // Search database is stored as js variables in code
+ $variables = ['gpuNameLookup', 'deviceId', 'gpuName'];
+ $v = [];
+ foreach ($variables as $variable) {
+ if (preg_match('/var ' . $variable . ' = ([^;]*);/ui', $f, $matches)) {
+ eval('$v[$variable] = ' . $matches[1] . ';');
+ }
+ }
+ file_put_contents($cacheTest, serialize($v));
+ } else {
+ $v = unserialize(file_get_contents($cacheTest));
+ }
+
+ $key = null;
+ foreach ($v['gpuNameLookup'] as $k => $item) {
+ if (stristr($item, $raw)) {
+ $key = $k;
+ break;
+ }
+ }
+
+ // If we get a device id, we have the the device page :)
+ if (null !== $key) {
+ $deviceKey = array_search($key, $v['gpuName']);
+ $deviceId = $v['deviceId'][$deviceKey];
+ $url = 'https://gfxbench.com/device.jsp?benchmark=gfx' . $gfxVersion . '&did=' . $deviceId;
+ $f = self::_curlRequest($url);
+ if (!stristr($f, '<p class="label1">No such device')) {
+ return ['url' => $url, 'body' => $f];
+ }
+ }
+ }
+ return ['url' => '', 'body' => ''];
+ }
+
+
+ protected static function _curlRequest($url)
+ {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_VERBOSE, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 1);
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0');
+ $response = curl_exec($ch);
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ return substr($response, $header_size);
+ }
}