Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
beb0159
Add m4 and a18 chipsets
NicholasR77 Jun 25, 2025
0362435
Adding a prepare command
NicholasR77 Jun 25, 2025
9575277
Testing out GH action
NicholasR77 Jun 25, 2025
224849e
Swapping to v4
NicholasR77 Jun 25, 2025
34fa5d7
Updating install command
NicholasR77 Jun 25, 2025
f150a60
Add update benchmarks command
NicholasR77 Jun 25, 2025
6ff773e
Updating the script
NicholasR77 Jun 25, 2025
29a4fc3
Try a different approach
NicholasR77 Jun 25, 2025
0800045
Use a different machine
NicholasR77 Jun 25, 2025
85f693a
Change to v4 again
NicholasR77 Jun 25, 2025
562c130
Update publish directory
NicholasR77 Jun 25, 2025
85329d8
Try a different way to use GH pages
NicholasR77 Jun 25, 2025
9686fac
Adding permissions
NicholasR77 Jun 25, 2025
e933bde
Remove branch folder args
NicholasR77 Jun 25, 2025
8c5d4c8
Try to use artifacts instead
NicholasR77 Jun 25, 2025
310cc84
Fixing indentation
NicholasR77 Jun 25, 2025
b915ac7
Bump version
NicholasR77 Jun 25, 2025
c697229
Try again
NicholasR77 Jun 25, 2025
66368d8
Change to actions/upload-pages-artifact@v3
NicholasR77 Jun 25, 2025
b2b412a
Try again I guess?
NicholasR77 Jun 25, 2025
a7162b4
Remove redundant step
NicholasR77 Jun 25, 2025
477f634
Updating logic to handle new shape of data
NicholasR77 Jun 26, 2025
9521a76
Removed their old action and updated formatting
NicholasR77 Jun 26, 2025
fcc37f6
Upgrades the action to run on latest
NicholasR77 Jun 26, 2025
0c0da96
Small change to the yml
NicholasR77 Jun 26, 2025
f58402a
One more change to test shape of benchmarks
NicholasR77 Jun 26, 2025
42dd001
Try one more time
NicholasR77 Jun 26, 2025
26242fb
Attempting to fix local benchmark usage
NicholasR77 Jun 26, 2025
3d21c36
Ok adding a publish step
NicholasR77 Jun 26, 2025
1348293
Testing the ability to publish
NicholasR77 Jun 26, 2025
187daed
Update test yml
NicholasR77 Jun 26, 2025
c920c3b
Bump version
NicholasR77 Jun 26, 2025
573b42d
Adjusting to match charsheet relay
NicholasR77 Jun 26, 2025
13af7f3
Update publish action
NicholasR77 Jun 26, 2025
e3b3149
Bump version
NicholasR77 Jun 26, 2025
93daba7
Update yml
NicholasR77 Jun 26, 2025
b2a5fc2
Updating config one more time to more closely match charsheet relay
NicholasR77 Jun 26, 2025
f80c789
Change when and where the update benchmarks gets run
NicholasR77 Jun 26, 2025
aed40c2
One more version bump
NicholasR77 Jun 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish package to GitHub Packages

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js & GitHub Packages registry
uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://npm.pkg.github.com'

- name: Install, build, & test
run: |
npm install --legacy-peer-deps
npm run build
npm test
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Publish to GitHub Packages
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
63 changes: 63 additions & 0 deletions .github/workflows/roll20-update-benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish benchmarks to GitHub Pages

on:
push:
branches:
- master
workflow_dispatch:
schedule:
- cron: '0 0 */14 * *' # every 14 days at midnight UTC

permissions:
contents: read
pages: write
id-token: write

env:
BENCHMARKS_URL: https://roll20.github.io/detect-gpu

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'

- name: Install & build
run: |
npm install --legacy-peer-deps
npm run build
- name: Update benchmarks
run: npm run update-benchmarks

- name: Validate *local* benchmark JSON shape
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we run the new test to verify that the json generated from the https://gfxbench.com/result.jsp matches the shape we expect

run: |
npx jest test/validate-benchmarks-shape.test.ts \
--env=jsdom \
--runTestsByPath
env:
BENCHMARKS_URL: file://${{ github.workspace }}/benchmarks

- name: Upload benchmarks as Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: benchmarks

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
12 changes: 9 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run actions on Pull Request or Push
name: Run tests and linting on pull requests
on:
push:
branches:
Expand All @@ -14,20 +14,26 @@ on:

jobs:
test:
name: Run test & lint
runs-on: Ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# make sure we don't pick up our repo's .npmrc
- name: Un-configure GitHub Packages
run: rm -f .npmrc

- uses: actions/setup-node@v4
with:
node-version: '18.x'

- uses: actions/cache@v4
id: yarn-cache
with:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-install-${{ hashFiles('**/yarn.lock') }}

- run: yarn install
if: ${{ steps.yarn-cache.outputs.cache-hit != 'true' }}

Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/update-benchmark.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
@roll20:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
31 changes: 12 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
{
"name": "detect-gpu",
"version": "5.0.70",
"name": "@roll20/detect-gpu",
"version": "5.0.74",
"description": "Classify GPU's based on their benchmark score in order to provide an adaptive experience.",
"author": "Tim van Scherpenzeel",
"license": "MIT",
"main": "dist/detect-gpu.umd.js",
"module": "dist/detect-gpu.esm.js",
"types": "dist/src/index.d.ts",
"homepage": "https://github.com/pmndrs/detect-gpu#readme",
"homepage": "https://github.com/Roll20/detect-gpu#readme",
"bugs": {
"url": "https://github.com/pmndrs/detect-gpu/issues"
"url": "https://github.com/Roll20/detect-gpu/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/pmndrs/detect-gpu.git"
"url": "https://github.com/Roll20/detect-gpu.git"
},
"files": [
"dist"
],
"keywords": [
"gpu",
"detect",
"webgl",
"webgl2",
"three.js",
"babylonjs",
"three",
"babylon",
"3d",
"typescript",
"javascript"
],
"publishConfig": {
"@roll20:registry": "https://npm.pkg.github.com"
},
"keywords": [],
"scripts": {
"start": "rollup -c rollup/config.lib.ts -w --configPlugin rollup-plugin-typescript2",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" \"test/**/*.test.ts\" \"rollup/**/*.ts\" \"scripts/**/*.ts\" \"scripts/**/*.js\" --fix --cache --cache-location ~/.eslintcache/eslintcache",
Expand All @@ -42,7 +33,8 @@
"build": "rollup -c rollup/config.lib.ts --configPlugin rollup-plugin-typescript2",
"example": "rollup -w -c rollup/config.dev.ts --configPlugin rollup-plugin-typescript2",
"parse-analytics": "node ./scripts/analytics_parser.js",
"update-benchmarks": "rimraf benchmarks && mkdir -p benchmarks && mkdir -p benchmarks-min && ts-node -O '{\"module\":\"commonjs\"}' ./scripts/update_benchmarks.ts && tar -czvf benchmarks.tar.gz benchmarks-min/*.json && rm -rf benchmarks-min"
"update-benchmarks": "rimraf benchmarks && mkdir -p benchmarks && mkdir -p benchmarks-min && ts-node -O '{\"module\":\"commonjs\"}' ./scripts/update_benchmarks.ts && tar -czvf benchmarks.tar.gz benchmarks-min/*.json && rm -rf benchmarks-min",
"prepare": "npm run build"
},
"dependencies": {
"webgl-constants": "^1.1.1"
Expand All @@ -53,6 +45,7 @@
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"cross-fetch": "^4.1.0",
"csvtojson": "^2.0.10",
"eslint": "^8.4.1",
"eslint-config-prettier": "^9.0.0",
Expand Down
8 changes: 7 additions & 1 deletion scripts/update_benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
});

async function fetchBenchmarks() {
const browser = await puppeteer.launch({ headless: true });
const browser = await puppeteer.launch({
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
],
});
const page = await browser.newPage();

await page.goto(BENCHMARK_URL, { waitUntil: 'networkidle2' });
Expand Down
19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,23 @@ export const getGPUTier = async ({
}

const tokenizedRenderer = tokenizeForLevenshteinDistance(renderer);
// eslint-disable-next-line prefer-const
let [gpu, , , , fpsesByPixelCount] =

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where their old code was going wrong where it was incorrectly retrieving the placement of where the fpsesByPixelCount should be - so for now to support both data shapes we just assume its the last entry in the array which seems to be accurate between how it used to look and now - if this ever changes again though our test should pick it up

// pick the best matching row
const bestMatch =
matchCount > 1
? matched
.map(
(match) =>
[
match,
getLevenshteinDistance(tokenizedRenderer, match[2]),
] as const
.map((match) =>
[match, getLevenshteinDistance(tokenizedRenderer, match[2])] as const
)
.sort(([, a], [, b]) => a - b)[0][0]
: matched[0];

// gpu name is always at index 0
const gpu = bestMatch[0];

// fpses array is always the last element
const fpsesByPixelCount = bestMatch[bestMatch.length - 1] as ModelEntryScreen[];

debug?.(
`${renderer} matched closest to ${gpu} with the following screen sizes`,
JSON.stringify(fpsesByPixelCount)
Expand Down
2 changes: 2 additions & 0 deletions src/internal/deobfuscateAppleGPU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function deobfuscateAppleGPU(
['a15', codeA, 15], // ipad mini 6th gen / ipad 10th gen
['m1', codeA, 15], // ipad pro 11 5nd gen / ipad pro 12.9 5th gen / ipad air 5th gen
['m2', codeA, 15], // ipad pro 11 6nd gen / ipad pro 12.9 6th gen
['m4', codeA, 15], // ipad pro 11 7nd gen / ipad pro 13 7th gen
]
: [
// ['a4', 7], // 4 / ipod touch 4th gen
Expand All @@ -72,6 +73,7 @@ export function deobfuscateAppleGPU(
['a15', codeA, 15], // 13 / 13 mini / 13 pro / 13 pro max / se 3rd gen / 14 / 14 plus
['a16', codeA, 15], // 14 pro / 14 pro max / 15 / 15 plus
['a17', codeA, 15], // 15 pro / 15 pro max
['a18', codeA, 15], // 16 / 16 plus / 16 pro / 16 pro max
];
let chipsets: typeof possibleChipsets;

Expand Down
63 changes: 63 additions & 0 deletions test/validate-benchmarks-shape.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @jest-environment node
*
*/

import fetch from 'cross-fetch';
(global as any).fetch = fetch;

Check warning on line 7 in test/validate-benchmarks-shape.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
import fs from 'fs/promises';

const BENCHMARKS_URL = process.env.BENCHMARKS_URL || 'https://roll20.github.io/detect-gpu';
const TEST_FILE = 'd-apple.json';

interface ScreenEntry extends Array<number> {
0: number;
1: number;
2: number;
}

describe('Live benchmark data shape', () => {
let data: unknown;

beforeAll(async () => {
const base = BENCHMARKS_URL.replace(/\/$/, '');
if (base.startsWith('file://')) {
const dirPath = base.replace(/^file:\/\//, '');
const raw = await fs.readFile(`${dirPath}/${TEST_FILE}`, 'utf8');
data = JSON.parse(raw);
} else {
const res = await fetch(`${base}/${TEST_FILE}`);
expect(res.ok).toBe(true);
data = await res.json();
}
});

it('is an array with a version string at index 0', () => {
expect(Array.isArray(data)).toBe(true);
expect(typeof (data as any)[0]).toBe('string');

Check warning on line 37 in test/validate-benchmarks-shape.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
});

it('each entry has the correct tuple shape', () => {
const entries = (data as any).slice(1);

Check warning on line 41 in test/validate-benchmarks-shape.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
expect(entries.length).toBeGreaterThan(0);

for (const entry of entries) {
expect(Array.isArray(entry)).toBe(true);
expect([4, 5]).toContain(entry.length);

const screens = entry[entry.length - 1];
expect(Array.isArray(screens)).toBe(true);
expect(screens.length).toBeGreaterThan(0);

for (const screen of screens) {
expect(Array.isArray(screen)).toBe(true);
expect((screen as ScreenEntry).length).toBe(3);

const [w, h, fps] = screen as ScreenEntry;
expect(typeof w).toBe('number');
expect(typeof h).toBe('number');
expect(typeof fps).toBe('number');
}
}
});
});